2015-03-22 19:51:19 -07:00
|
|
|
#!/usr/bin/env node
|
2015-07-05 14:17:40 +08:00
|
|
|
var fs = require('fs');
|
|
|
|
var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar', 'all', 'overwrite']});
|
|
|
|
var packager = require('./');
|
|
|
|
var usage = fs.readFileSync(__dirname + '/usage.txt').toString();
|
2015-07-05 14:16:07 +08:00
|
|
|
var validator = require('validator');
|
2015-07-05 16:43:32 +08:00
|
|
|
var tempDir = require('./tempDir');
|
2015-03-22 19:51:19 -07:00
|
|
|
|
2015-07-05 16:43:32 +08:00
|
|
|
|
|
|
|
args.dir = 'blah'; // set to true first
|
2015-07-05 14:08:13 +08:00
|
|
|
args.name = args._[0];
|
2015-07-06 10:12:30 +08:00
|
|
|
args.target = args._[1];
|
2015-03-22 19:51:19 -07:00
|
|
|
|
2015-07-05 14:17:40 +08:00
|
|
|
var protocolSchemes = [].concat(args.protocol || []);
|
|
|
|
var protocolNames = [].concat(args['protocol-name'] || []);
|
2015-04-04 21:13:27 -07:00
|
|
|
|
|
|
|
if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes.length) {
|
2015-07-05 14:17:40 +08:00
|
|
|
args.protocols = protocolSchemes.map(function (scheme, i) {
|
|
|
|
return {schemes: [scheme], name: protocolNames[i]};
|
|
|
|
})
|
2015-04-04 21:13:27 -07:00
|
|
|
}
|
|
|
|
|
2015-07-05 15:10:36 +08:00
|
|
|
if (!args.dir || !args.name || !args.version || !args.target || (!args.all && (!args.platform || !args.arch))) {
|
|
|
|
console.error(usage);
|
2015-07-05 14:16:07 +08:00
|
|
|
|
2015-07-05 14:17:40 +08:00
|
|
|
process.exit(1);
|
2015-07-05 14:16:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-05 15:10:36 +08:00
|
|
|
if (!validator.isURL(args.target)) {
|
|
|
|
console.error('Enter a valid target url');
|
2015-07-05 14:17:40 +08:00
|
|
|
process.exit(1);
|
2015-03-22 19:51:19 -07:00
|
|
|
}
|
2015-05-10 13:57:42 -07:00
|
|
|
|
2015-07-06 10:31:09 +08:00
|
|
|
tempDir(args.name, args.target, args.badge, args.width, args.height, function (error, appDir) {
|
2015-07-05 14:08:13 +08:00
|
|
|
|
2015-07-05 16:43:32 +08:00
|
|
|
if (error) {
|
|
|
|
console.error(error);
|
2015-07-05 14:17:40 +08:00
|
|
|
process.exit(1);
|
2015-07-05 16:43:32 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
args.dir = appDir;
|
|
|
|
packager(args, function done(err, appPaths) {
|
|
|
|
if (err) {
|
|
|
|
if (err.message) console.error(err.message);
|
|
|
|
else console.error(err, err.stack);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appPaths.length > 1) console.error('Wrote new apps to:\n' + appPaths.join('\n'));
|
|
|
|
else if (appPaths.length === 1) console.error('Wrote new app to', appPaths[0]);
|
|
|
|
});
|
2015-07-05 14:17:40 +08:00
|
|
|
}
|
2015-04-04 09:47:01 -07:00
|
|
|
|
2015-07-05 14:17:40 +08:00
|
|
|
});
|