UNPKG

2.29 kBJavaScriptView Raw
1/**
2 *
3 * 2app
4 * 2016-03-23
5 *
6 * Haochuan Liu <haochuan.liu@gmail.com>
7 * http://haochuan.io
8 *
9 */
10var inquirer = require("inquirer");
11var packager = require('electron-packager');
12var fs = require('fs');
13var assign = require('object-assign');
14var exec = require('child_process').exec;
15
16var questions = [
17 // ask about the name of the app
18 {
19 type: 'input',
20 name: 'name',
21 message: "What's the name of your App?"
22 },
23 // ask about the version of the app
24 {
25 type: 'input',
26 name: 'app-version',
27 message: "What's the version of your App?"
28 },
29 // platform
30 {
31 type: 'list',
32 name: 'platform',
33 message: "Select your App's target platform: ",
34 choices: [
35 "linux",
36 "win32",
37 "darwin"
38 ]
39 },
40 // arch
41 {
42 type: 'list',
43 name: 'arch',
44 message: "Select your App's architecture: ",
45 choices: [
46 "ia32",
47 "x64"
48 ]
49 }
50 // ask about electron version
51 // {
52 // type: 'input',
53 // name: 'version',
54 // message: "Enter the Electron version to build your App, you can find the version list here: https://github.com/atom/electron/releases. For example, you can enter: 0.37.2"
55 // }
56];
57
58var pack = function(src) {
59 inquirer.prompt( questions, function( answers ) {
60 /**
61 * Test if ./build/App.app exsit
62 */
63 var destPath = './' + answers.name;
64 switch (answers.platform) {
65 case 'linux':
66 destPath += '-linux';
67 break;
68 case 'win32':
69 destPath += '-linux';
70 break;
71 case 'darwin':
72 destPath += '.app';
73 break;
74 }
75 if (fs.existsSync(destPath)) {
76 console.log(answers.name + " is already exsited in the current directory, now re-builting...");
77 exec('rm -r ' + destPath);
78 }
79 var opts = assign({dir: src}, answers, {version: "1.0.1"});
80 packager(opts, function done (err, appPath) {
81 if (err) throw err;
82 console.log("The app have been packaged successfully in: " + appPath);
83 });
84 });
85}
86
87module.exports = pack;
88