-
Notifications
You must be signed in to change notification settings - Fork 17
/
nw-package.js
102 lines (78 loc) · 2.44 KB
/
nw-package.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
var NwBuilder = require('nw-builder');
module.exports = {
name: 'nw:package',
description: 'Packages your NW.js app',
availableOptions: [
{ name: 'environment', type: String, default: 'production', aliases: ['e', { 'dev': 'development' }, { 'prod': 'production' }] },
{ name: 'output-path', type: String, default: 'dist/', aliases: ['o'] },
{ name: 'config-file', type: String, default: 'config/nw-package.js', aliases: ['f'] }
],
init: function() {
process.env.EMBER_CLI_NW = true;
},
buildApp: function(options) {
var buildTask = new this.tasks.Build({
ui: this.ui,
analytics: this.analytics,
project: this.project
});
return buildTask.run(options);
},
packageApp: function(options) {
var ui = this.ui;
ui.writeLine(chalk.green('Packaging...'));
var config = this.nwConfig(options);
var nw = new NwBuilder(config);
nw.on('log', console.log);
return nw.build().then(function() {
ui.writeLine(chalk.green('Packaged project successfully.'));
});
},
nwConfig: function(options) {
var config = {};
var configFile = path.resolve(this.project.root, options.configFile);
if (fs.existsSync(configFile)) {
config = require(configFile);
}
if (!config.buildDir) {
config.buildDir = 'build/app';
}
if (!config.cacheDir) {
config.cacheDir = 'build/cache';
}
if (!config.files) {
config.files = this.nwFiles(options);
}
if (!config.platforms) {
var detectPlatform = require('../helpers/detect-platform');
var currentPlatform = detectPlatform();
if (currentPlatform) {
config.platforms = [currentPlatform];
}
}
return config;
},
nwFiles: function(options) {
var nwFiles = ['package.json'];
// Contents of the build output directory
nwFiles.push(options.outputPath.replace(/\/?$/, '/**'));
// Non-dev NPM modules
var npmModulesRoot = 'node_modules';
var npmDependencies = this.project.pkg.dependencies || {};
Object.keys(npmDependencies).forEach(function(dependency) {
nwFiles.push(npmModulesRoot + '/' + dependency + '/**');
});
return nwFiles;
},
run: function(options) {
var _this = this;
return this.buildApp(options)
.then(function() {
return _this.packageApp(options);
});
}
};