-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
61 lines (56 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const debug = require('debug')('index');
const packager = require('electron-packager');
const fs = require('fs');
const chalk = require('chalk');
const path = require('path');
const manifest = require('./lib/manifest');
module.exports = function (options) {
options = options || {};
debug('options', options);
const appUrl = options.appUrl;
const appPath = options.path;
const manifestUrl = options.manifestUrl;
return manifest.fetchManifestDetails(appUrl, manifestUrl)
.then(function(manifestJson) {
debug('manifestJson', manifestJson);
var name = manifestJson.name || manifestJson.short_name;
var start_url = appUrl + (manifestJson.start_url || '');
var appData = {
appUrl: start_url
};
fs.writeFileSync(path.join(__dirname, 'template', 'prefs.json'), JSON.stringify(appData));
var packagerOpts = {
name: name,
arch: 'all',
overwrite: true,
dir: path.join(__dirname, 'template'),
platform: options.platforms || 'all'
};
if (options.icon) {
packagerOpts.icon = options.icon
}
return new Promise(function (resolve) {
if(appPath) {
if(fs.existsSync(appPath)) {
process.chdir(appPath);
} else {
throw new Error("Path doesn't exsists.");
}
}
packager(packagerOpts, function done_callback(err, appPaths) {
if (err) {
throw err;
} else {
resolve({
appPaths: appPaths
})
}
})
})
})
.then(function (result) {
console.log(chalk.green('Your app is ready!'), result.appPaths);
}).catch(function (err) {
throw err;
})
};