#!/usr/bin/env node
var fs = require('fs');
var args = require('minimist')(process.argv.slice(2), {boolean: ['prune', 'asar', 'all', 'overwrite']});
var archive = require("../lib/archive-zip");
var packager = require('electron-packager');
var path = require("path");
var usage = fs.readFileSync(path.normalize(__dirname + '/../node_modules/electron-packager/usage.txt')).toString();

args.dir = args._[0];
args.name = args._[1];

var protocolSchemes = [].concat(args.protocol || []);
var protocolNames = [].concat(args['protocol-name'] || []);

if (protocolSchemes && protocolNames && protocolNames.length === protocolSchemes.length) {
    args.protocols = protocolSchemes.map(function (scheme, i) {
        return {schemes: [scheme], name: protocolNames[i]}
    })
}

if (!args.dir || !args.name || !args.version || (!args.all && (!args.platform || !args.arch))) {
    console.error(usage);
    process.exit(1);
}

packager(args, function done(err, appPaths) {
    if (err) {
        if (err.message) {
            console.error(err.message);
        } else {
            console.error(err, err.stack);
        }
        process.exit(1);
    }

    var zippedPromises = appPaths.map(function (appPath) {
        console.log(appPath + ".zip");
        return archive(appPath, appPath + ".zip");
    });
    Promise.all(zippedPromises).then(function () {
        console.log('Wrote new apps');
    }).catch(function (error) {
        console.error(error, error.stack);
    });
});

@@ -264,125 +264,8 @@
 %22);%0A
-var usage = fs.readFileSync(path.normalize(__dirname + '/../node_modules/electron-packager/usage.txt')).toString();%0A%0A
 args
@@ -649,155 +649,8 @@
 %0A%7D%0A%0A
-if (!args.dir %7C%7C !args.name %7C%7C !args.version %7C%7C (!args.all && (!args.platform %7C%7C !args.arch))) %7B%0A    console.error(usage);%0A    process.exit(1);%0A%7D%0A%0A
 pack

fix help error