Updated to match new Cordova hook specs

- Script to match module definition (fixes paths)  
- Instructions to define hooks in recommend way
This commit is contained in:
Karri Rasinmäki 2018-02-25 00:46:08 +02:00 committed by GitHub
parent 954bd876de
commit 97d5d10c71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -307,13 +307,23 @@ export enum OSActionType {
* #### Icons * #### Icons
* If you want to use generated icons with command `ionic cordova resources`: * If you want to use generated icons with command `ionic cordova resources`:
* *
* 1. Add a file to your `hooks` directory inside the `after_prepare` folder called `030_copy_android_notification_icons.js` * 1. Add a file to your `hooks` directory called `copy_android_notification_icons.js`
* *
* 2. Put the following code in it: * 2. Configure the hook in your config.xml
* ```
* <platform name="android">
* <hook type="after_prepare" src="hooks/copy_android_notification_icons.js" />
* </platform>
* ```
*
* 3. Put the following code in it:
* *
* ``` * ```
* #!/usr/bin/env node * #!/usr/bin/env node
*
* var fs = require('fs');
* var path = require('path');
* var filestocopy = [{ * var filestocopy = [{
* "resources/android/icon/drawable-hdpi-icon.png": * "resources/android/icon/drawable-hdpi-icon.png":
* "platforms/android/res/drawable-hdpi/ic_stat_onesignal_default.png" * "platforms/android/res/drawable-hdpi/ic_stat_onesignal_default.png"
@ -330,19 +340,18 @@ export enum OSActionType {
* "resources/android/icon/drawable-xxxhdpi-icon.png": * "resources/android/icon/drawable-xxxhdpi-icon.png":
* "platforms/android/res/drawable-xxxhdpi/ic_stat_onesignal_default.png" * "platforms/android/res/drawable-xxxhdpi/ic_stat_onesignal_default.png"
* } ]; * } ];
*
* var fs = require('fs'); * module.exports = function(context) {
* var path = require('path');
*
* // no need to configure below * // no need to configure below
* var rootdir = process.argv[2]; * var rootdir = context.opts.projectRoot;
*
* filestocopy.forEach(function(obj) { * filestocopy.forEach(function(obj) {
* Object.keys(obj).forEach(function(key) { * Object.keys(obj).forEach(function(key) {
* var val = obj[key]; * var val = obj[key];
* var srcfile = path.join(rootdir, key); * var srcfile = path.join(rootdir, key);
* var destfile = path.join(rootdir, val); * var destfile = path.join(rootdir, val);
* //console.log("copying "+srcfile+" to "+destfile); * console.log("copying "+srcfile+" to "+destfile);
* var destdir = path.dirname(destfile); * var destdir = path.dirname(destfile);
* if (fs.existsSync(srcfile) && fs.existsSync(destdir)) { * if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
* fs.createReadStream(srcfile).pipe( * fs.createReadStream(srcfile).pipe(
@ -350,6 +359,8 @@ export enum OSActionType {
* } * }
* }); * });
* }); * });
* };
* ``` * ```
* *
* 3. From the root of your project make the file executable: * 3. From the root of your project make the file executable: