AlexDisler / cordova-icon

Automatic icon resizing for Cordova
MIT License
689 stars 292 forks source link

Cordova /hooks directory is deprecated, update to newer format #98

Open FranciscoG opened 7 years ago

FranciscoG commented 7 years ago

Cordova Hooks documentation shows using the /hooks directory is deprecated. Suggest updating your documentation to use newer hook scripts format.

This worked for me. It's probably not perfect but for now it works

I created a hook_scripts folder. Then in my config.xml I have this:

<hook src="hook_scripts/after_prepare.js" type="after_prepare" />
#!/usr/bin/env node
const spawnSync = require('child_process').spawnSync;

var options = {
  cwd: process.cwd(),
  encoding : 'utf8'
};

var icon = spawnSync('cordova-icon', ['--icon=res/icon.png'], options);

if (icon.stderr) {
  console.log(icon.stderr.toString());
}

console.log(icon.stdout.toString());
kw-pr commented 6 years ago

That is nice. With windows you need to call cordova-icon.cmd so I made some changes to your code:

#!/usr/bin/env node
const spawnSync = require('child_process').spawnSync;

var options = {
  cwd: process.cwd(),
  encoding : 'utf8'
};

const os = require('os');
var cmdSuffix = (os.platform() === 'win32' ? '.cmd' : '');
var icon = spawnSync('cordova-icon' + cmdSuffix, ['--icon=res/icon.png'], options);

if (icon.stderr) {
  console.log(icon.stderr.toString());
}

console.log(icon.stdout.toString());