1
0
mirror of https://github.com/jiahaog/Nativefier synced 2024-07-05 09:00:55 +02:00
Nativefier/cli.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-03-23 03:51:19 +01:00
#!/usr/bin/env node
2015-07-05 08:17:40 +02: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 08:16:07 +02:00
var validator = require('validator');
2015-03-23 03:51:19 +01:00
2015-07-05 08:08:13 +02:00
args.dir = './app';
args.name = args._[0];
2015-03-23 03:51:19 +01:00
2015-07-05 08:17:40 +02:00
var protocolSchemes = [].concat(args.protocol || []);
var protocolNames = [].concat(args['protocol-name'] || []);
2015-04-05 06:13:27 +02:00
if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes.length) {
2015-07-05 08:17:40 +02:00
args.protocols = protocolSchemes.map(function (scheme, i) {
return {schemes: [scheme], name: protocolNames[i]};
})
2015-04-05 06:13:27 +02:00
}
if (!args.dir || !args.name || !args.version || !args.target || (!args.all && (!args.platform || !args.arch))) {
console.error(usage);
2015-07-05 08:16:07 +02:00
2015-07-05 08:17:40 +02:00
process.exit(1);
2015-07-05 08:16:07 +02:00
}
if (!validator.isURL(args.target)) {
console.error('Enter a valid target url');
2015-07-05 08:17:40 +02:00
process.exit(1);
2015-03-23 03:51:19 +01:00
}
// writes parameters for the app into a text file
// I'm not exactly sure how to pass these as an argument through code
2015-07-05 08:08:13 +02:00
var appArgs = {
name: args.name,
targetUrl: args.target
};
2015-07-05 10:02:31 +02:00
fs.writeFileSync(__dirname + '/app/targetUrl.txt', JSON.stringify(appArgs));
2015-07-05 08:08:13 +02:00
2015-07-05 08:17:40 +02:00
packager(args, function done(err, appPaths) {
if (err) {
if (err.message) console.error(err.message);
else console.error(err, err.stack);
process.exit(1);
}
2015-07-05 08:17:40 +02:00
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]);
});