nw-builder 3.8.6-beta.1 → 3.8.6-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.github/workflows/cd.yml +0 -2
- package/.github/workflows/ci.yml +8 -2
- package/.prettierignore +6 -0
- package/{.github/CHANGELOG.md → CHANGELOG.md} +16 -2
- package/README.md +33 -0
- package/bin/nwbuild.cjs +1 -21
- package/cfg/eslint.config.cjs +17 -0
- package/demo.cjs +29 -24
- package/docs/getting-started.md +6 -6
- package/e2e/test.js +47 -0
- package/lib/index.cjs +777 -790
- package/lib/utils.cjs +4 -3
- package/package.json +12 -50
- package/src/get.js +206 -204
- package/src/index.js +9 -5
- package/src/log.js +32 -32
- package/src/run.js +78 -79
- package/src/util.js +275 -103
- package/src/utilities/checkCache.js +3 -3
- package/src/utilities/detectCurrentPlatform.js +3 -3
- package/test/fixtures/nwapp/index.html +4 -3
- package/test/fixtures/testVersions.html +54 -66
- package/src/utilities/checkPkgOptions.js +0 -28
- package/src/utilities/parseOptions.js +0 -10
package/lib/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const { resolve } = require("node:path");
|
|
2
|
-
const {
|
|
3
|
-
const
|
|
1
|
+
const { basename, resolve } = require("node:path");
|
|
2
|
+
const { version } = require("node:process");
|
|
3
|
+
const { mkdir, cp, rm, rename } = require("node:fs/promises");
|
|
4
|
+
const { readFileSync } = require("node:fs");
|
|
5
|
+
const glob = require("simple-glob");
|
|
4
6
|
var _ = require("lodash");
|
|
5
|
-
var inherits = require("inherits");
|
|
6
|
-
var EventEmitter = require("events").EventEmitter;
|
|
7
7
|
var fs = require("graceful-fs-extra");
|
|
8
8
|
var path = require("path");
|
|
9
9
|
var thenify = require("thenify");
|
|
@@ -11,945 +11,932 @@ var rcedit = require("rcedit");
|
|
|
11
11
|
var winresourcer = thenify(require("winresourcer"));
|
|
12
12
|
var semver = require("semver");
|
|
13
13
|
var platformOverrides = require("./platformOverrides.cjs");
|
|
14
|
-
var deprecate = require("deprecate");
|
|
15
14
|
|
|
16
15
|
const {
|
|
17
16
|
checkCache,
|
|
18
|
-
detectCurrentPlatform,
|
|
19
17
|
get,
|
|
20
|
-
|
|
18
|
+
getReleaseInfo,
|
|
19
|
+
isCached,
|
|
20
|
+
log,
|
|
21
|
+
setLogLevel,
|
|
21
22
|
Platforms,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
parse,
|
|
24
|
+
run,
|
|
25
|
+
validate,
|
|
25
26
|
} = require("../dist/index.cjs");
|
|
26
27
|
var NwVersions = require("./versions.cjs");
|
|
27
28
|
var Version = require("./Version.cjs");
|
|
28
29
|
var Utils = require("./utils.cjs");
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
class NwBuilder {
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.init(options).then(() => {
|
|
34
|
+
this._platforms = { ...Platforms };
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
// clear all unused platforms
|
|
37
|
+
for (const name in this._platforms) {
|
|
38
|
+
if (
|
|
39
|
+
this.options.platforms &&
|
|
40
|
+
this.options.platforms.indexOf(name) === -1
|
|
41
|
+
)
|
|
42
|
+
delete this._platforms[name];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
async init(options) {
|
|
48
|
+
let manifest = {};
|
|
49
|
+
let releaseInfo = {};
|
|
50
|
+
try {
|
|
51
|
+
options = parse(options, manifest);
|
|
46
52
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
for (const file of glob(options.files)) {
|
|
54
|
+
if (basename(file) === "package.json" && manifest === undefined) {
|
|
55
|
+
manifest = JSON.parse(readFileSync(file));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
52
58
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.options.platforms.indexOf("osx"),
|
|
59
|
-
1,
|
|
60
|
-
"osx32",
|
|
61
|
-
"osx64",
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
if (this.options.platforms && this.options.platforms.indexOf("win") >= 0) {
|
|
65
|
-
this.options.platforms.splice(
|
|
66
|
-
this.options.platforms.indexOf("win"),
|
|
67
|
-
1,
|
|
68
|
-
"win32",
|
|
69
|
-
"win64",
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (
|
|
73
|
-
this.options.platforms &&
|
|
74
|
-
this.options.platforms.indexOf("linux") >= 0
|
|
75
|
-
) {
|
|
76
|
-
this.options.platforms.splice(
|
|
77
|
-
this.options.platforms.indexOf("linux"),
|
|
78
|
-
1,
|
|
79
|
-
"linux32",
|
|
80
|
-
"linux64",
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
59
|
+
if (manifest === undefined) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"package.json not found in options.files glob patterns.",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
84
64
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
65
|
+
if (typeof manifest?.nwbuild === "object") {
|
|
66
|
+
options = manifest.nwbuild;
|
|
67
|
+
}
|
|
89
68
|
|
|
90
|
-
|
|
91
|
-
throw new Error("No platform to build!");
|
|
69
|
+
options = parse(options, manifest);
|
|
92
70
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
71
|
+
let platform = options.currentPlatform.slice(
|
|
72
|
+
0,
|
|
73
|
+
options.currentPlatform.length - 2,
|
|
74
|
+
);
|
|
75
|
+
let arch =
|
|
76
|
+
"x" + options.currentPlatform.slice(options.currentPlatform.length - 2);
|
|
77
|
+
|
|
78
|
+
getReleaseInfo(
|
|
79
|
+
options.version,
|
|
80
|
+
options.cacheDir,
|
|
81
|
+
options.manifestUrl,
|
|
82
|
+
).then((info) => {
|
|
83
|
+
releaseInfo = info;
|
|
84
|
+
validate(options, info)
|
|
85
|
+
.then(() => {
|
|
86
|
+
// Remove leading "v" from version string
|
|
87
|
+
options.version = info.version.slice(1);
|
|
88
|
+
})
|
|
89
|
+
.catch((error) => {
|
|
90
|
+
log.error(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
100
93
|
|
|
101
|
-
|
|
94
|
+
setLogLevel(options.quiet);
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
96
|
+
if (options.quiet === "debug") {
|
|
97
|
+
log.debug(`Platform: ${platform}`);
|
|
98
|
+
log.debug(`Archicture: ${arch}`);
|
|
99
|
+
log.debug(`Node Version: ${version}`);
|
|
100
|
+
log.debug(`NW.js Version: ${options.version}\n`);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
log.error(error);
|
|
104
|
+
} finally {
|
|
105
|
+
this.options = options;
|
|
106
|
+
}
|
|
107
107
|
}
|
|
108
|
-
}
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
build(callback) {
|
|
110
|
+
// Let's create a NWjs app
|
|
111
|
+
var build = this.checkFiles()
|
|
112
|
+
.then(this.downloadNwjs.bind(this))
|
|
113
|
+
.then(this.preparePlatformSpecificManifests.bind(this))
|
|
114
|
+
.then(this.createReleaseFolder.bind(this))
|
|
115
|
+
.then(this.copyNwjs.bind(this))
|
|
116
|
+
.then(this.handleLinuxApp.bind(this))
|
|
117
|
+
.then(this.handleMacApp.bind(this))
|
|
118
|
+
.then(this.handleWinApp.bind(this))
|
|
119
|
+
.then(this.zipAppFiles.bind(this))
|
|
120
|
+
.then(this.mergeAppFiles.bind(this))
|
|
121
|
+
.then(function (info) {
|
|
122
|
+
// the promise(s) resolves to nothing in some cases
|
|
123
|
+
return info || this;
|
|
124
|
+
});
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
.then(this.handleMacApp.bind(this))
|
|
135
|
-
.then(this.handleWinApp.bind(this))
|
|
136
|
-
.then(this.zipAppFiles.bind(this))
|
|
137
|
-
.then(this.mergeAppFiles.bind(this))
|
|
138
|
-
.then(function (info) {
|
|
139
|
-
// the promise(s) resolves to nothing in some cases
|
|
140
|
-
return info || this;
|
|
141
|
-
});
|
|
126
|
+
if (typeof callback === "function") {
|
|
127
|
+
build
|
|
128
|
+
.then(function (result) {
|
|
129
|
+
callback(false, result);
|
|
130
|
+
})
|
|
131
|
+
.catch(callback);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
142
134
|
|
|
143
|
-
|
|
144
|
-
build
|
|
145
|
-
.then(function (result) {
|
|
146
|
-
callback(false, result);
|
|
147
|
-
})
|
|
148
|
-
.catch(callback);
|
|
149
|
-
return true;
|
|
135
|
+
return build;
|
|
150
136
|
}
|
|
151
137
|
|
|
152
|
-
|
|
153
|
-
|
|
138
|
+
run(callback) {
|
|
139
|
+
// We do not want to download nwjs for other platforms if are going to run the App
|
|
140
|
+
var platforms = this.options.platforms;
|
|
141
|
+
this.options.platforms = [this.options.currentPlatform];
|
|
142
|
+
|
|
143
|
+
// Let's run this NWjs app
|
|
144
|
+
var run = this.checkFiles()
|
|
145
|
+
.then(this.downloadNwjs.bind(this))
|
|
146
|
+
.then(this.runApp.bind(this));
|
|
147
|
+
|
|
148
|
+
if (typeof callback === "function") {
|
|
149
|
+
run
|
|
150
|
+
.then(function (result) {
|
|
151
|
+
this.options.platforms = platforms;
|
|
152
|
+
callback(false, result);
|
|
153
|
+
})
|
|
154
|
+
.catch(function (error) {
|
|
155
|
+
this.options.platforms = platforms;
|
|
156
|
+
callback(true, error);
|
|
157
|
+
});
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return run;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
checkFiles() {
|
|
165
|
+
var self = this;
|
|
154
166
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// Let's run this NWjs app
|
|
161
|
-
var run = this.checkFiles()
|
|
162
|
-
.then(this.downloadNwjs.bind(this))
|
|
163
|
-
.then(this.runApp.bind(this));
|
|
164
|
-
|
|
165
|
-
if (typeof callback === "function") {
|
|
166
|
-
run
|
|
167
|
-
.then(function (result) {
|
|
168
|
-
this.options.platforms = platforms;
|
|
169
|
-
callback(false, result);
|
|
167
|
+
return Utils.getFileList(this.options.files)
|
|
168
|
+
.then(function (data) {
|
|
169
|
+
self._appPkg = data.json;
|
|
170
|
+
self._files = data.files;
|
|
171
|
+
return self._appPkg;
|
|
170
172
|
})
|
|
171
|
-
.
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
.then(Utils.getPackageInfo)
|
|
174
|
+
.then(function (appPkg) {
|
|
175
|
+
self._appPkg = appPkg;
|
|
176
|
+
|
|
177
|
+
if (!self.options.appName || !self.options.appVersion) {
|
|
178
|
+
self.options.appName = self.options.appName
|
|
179
|
+
? self.options.appName
|
|
180
|
+
: appPkg.name;
|
|
181
|
+
self.options.appVersion = self.options.appVersion
|
|
182
|
+
? self.options.appVersion
|
|
183
|
+
: appPkg.version;
|
|
184
|
+
}
|
|
174
185
|
});
|
|
175
|
-
return true;
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
|
|
179
|
-
|
|
188
|
+
resolveLatestVersion() {
|
|
189
|
+
var self = this;
|
|
180
190
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
self.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.then(function (appPkg) {
|
|
192
|
-
self._appPkg = appPkg;
|
|
193
|
-
|
|
194
|
-
if (!self.options.appName || !self.options.appVersion) {
|
|
195
|
-
self.options.appName = self.options.appName
|
|
196
|
-
? self.options.appName
|
|
197
|
-
: appPkg.name;
|
|
198
|
-
self.options.appVersion = self.options.appVersion
|
|
199
|
-
? self.options.appVersion
|
|
200
|
-
: appPkg.version;
|
|
201
|
-
}
|
|
191
|
+
if (self.options.version !== "latest") return Promise.resolve();
|
|
192
|
+
|
|
193
|
+
return NwVersions.getLatestVersion(
|
|
194
|
+
self.options.downloadUrl,
|
|
195
|
+
self.options.manifestUrl,
|
|
196
|
+
self.options.flavor,
|
|
197
|
+
).then(function (latestVersion) {
|
|
198
|
+
log.debug("Latest Version: v" + latestVersion.version);
|
|
199
|
+
self.options.version = latestVersion.version;
|
|
200
|
+
return latestVersion;
|
|
202
201
|
});
|
|
203
|
-
}
|
|
202
|
+
}
|
|
204
203
|
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
checkVersion() {
|
|
205
|
+
var version = this.options.version,
|
|
206
|
+
flavor =
|
|
207
|
+
semver.valid(version) && semver.satisfies(version, "<0.12.3")
|
|
208
|
+
? "sdk"
|
|
209
|
+
: this.options.flavor,
|
|
210
|
+
self = this;
|
|
207
211
|
|
|
208
|
-
|
|
212
|
+
if (!semver.valid(version)) {
|
|
213
|
+
return Promise.reject("The version " + version + " is not valid.");
|
|
214
|
+
}
|
|
209
215
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
var getVersionFromManifest = function () {
|
|
217
|
+
return NwVersions.getVersion({
|
|
218
|
+
desiredVersion: version,
|
|
219
|
+
downloadUrl: self.options.downloadUrl,
|
|
220
|
+
manifestUrl: self.options.manifestUrl,
|
|
221
|
+
flavor: flavor,
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
var getVersion;
|
|
225
|
+
|
|
226
|
+
// if the user specified the exact version and all its platforms are cached, don't hit the manifest at all;
|
|
227
|
+
// just trust the ones are cached and assume they're supported
|
|
228
|
+
if (self.options.version !== "latest") {
|
|
229
|
+
var areAllPlatformsCached = true;
|
|
230
|
+
this._forEachPlatform(function (name, platform) {
|
|
231
|
+
var platformToCheck = platform;
|
|
232
|
+
|
|
233
|
+
if (semver.satisfies(self.options.version, ">=0.12.3")) {
|
|
234
|
+
platformToCheck = _.clone(platform);
|
|
235
|
+
platformToCheck.files = ["*"]; // otherwise it'll try to check cache legacy version files
|
|
236
|
+
}
|
|
220
237
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
238
|
+
if (
|
|
239
|
+
!self.isPlatformCached(
|
|
240
|
+
name,
|
|
241
|
+
platformToCheck,
|
|
242
|
+
self.options.version,
|
|
243
|
+
flavor,
|
|
244
|
+
)
|
|
245
|
+
) {
|
|
246
|
+
areAllPlatformsCached = false;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
if (areAllPlatformsCached) {
|
|
250
|
+
getVersion = Promise.resolve(
|
|
251
|
+
new Version({
|
|
252
|
+
version: version,
|
|
253
|
+
flavors: [flavor],
|
|
254
|
+
downloadUrl: self.options.downloadUrl,
|
|
255
|
+
supportedPlatforms: Object.keys(this._platforms),
|
|
256
|
+
}),
|
|
257
|
+
);
|
|
258
|
+
} else {
|
|
259
|
+
// otherwise hit the manifest
|
|
260
|
+
getVersion = getVersionFromManifest();
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
// otherwise hit the manifest
|
|
264
|
+
getVersion = getVersionFromManifest();
|
|
265
|
+
}
|
|
228
266
|
|
|
229
|
-
|
|
230
|
-
|
|
267
|
+
return getVersion.then(function (version) {
|
|
268
|
+
self._version = version;
|
|
269
|
+
self._version.flavor = flavor;
|
|
270
|
+
log.debug(
|
|
271
|
+
"Using v" +
|
|
272
|
+
self._version.version +
|
|
273
|
+
" (" +
|
|
274
|
+
(self._version.flavor === "" ? "normal" : self._version.flavor + ")"),
|
|
275
|
+
);
|
|
276
|
+
if (self._version.isLegacy) {
|
|
277
|
+
log.warn("NW.js / node-webkit versions <0.12.3 are deprecated.");
|
|
278
|
+
}
|
|
279
|
+
});
|
|
231
280
|
}
|
|
232
281
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
desiredVersion: version,
|
|
236
|
-
downloadUrl: self.options.downloadUrl,
|
|
237
|
-
manifestUrl: self.options.manifestUrl,
|
|
238
|
-
flavor: flavor,
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
var getVersion;
|
|
282
|
+
platformFilesForVersion() {
|
|
283
|
+
var self = this;
|
|
242
284
|
|
|
243
|
-
// if the user specified the exact version and all its platforms are cached, don't hit the manifest at all;
|
|
244
|
-
// just trust the ones are cached and assume they're supported
|
|
245
|
-
if (self.options.version !== "latest") {
|
|
246
|
-
var areAllPlatformsCached = true;
|
|
247
285
|
this._forEachPlatform(function (name, platform) {
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
if (semver.satisfies(self.options.version, ">=0.12.3")) {
|
|
251
|
-
platformToCheck = _.clone(platform);
|
|
252
|
-
platformToCheck.files = ["*"]; // otherwise it'll try to check cache legacy version files
|
|
253
|
-
}
|
|
286
|
+
var satisfied = self.preparePlatformFiles(name, platform);
|
|
254
287
|
|
|
288
|
+
// need the second condition for newer NW.js versions
|
|
255
289
|
if (
|
|
256
|
-
!
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
self.options.version,
|
|
260
|
-
flavor,
|
|
290
|
+
!(
|
|
291
|
+
satisfied &&
|
|
292
|
+
!!self._version.platforms[name + "-" + self._version.flavor]
|
|
261
293
|
)
|
|
262
294
|
) {
|
|
263
|
-
|
|
295
|
+
throw new Error(
|
|
296
|
+
"Unsupported NW.js version '" +
|
|
297
|
+
self._version.version +
|
|
298
|
+
" (" +
|
|
299
|
+
self._version.flavor +
|
|
300
|
+
")' for platform '" +
|
|
301
|
+
name +
|
|
302
|
+
"'",
|
|
303
|
+
);
|
|
264
304
|
}
|
|
265
305
|
});
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
getVersion = getVersionFromManifest();
|
|
306
|
+
|
|
307
|
+
return Promise.resolve();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async downloadNwjs() {
|
|
311
|
+
let options = this.options;
|
|
312
|
+
let built;
|
|
313
|
+
|
|
314
|
+
built = await isCached(options.cacheDir);
|
|
315
|
+
if (built === false) {
|
|
316
|
+
await mkdir(options.cacheDir, { recursive: true });
|
|
278
317
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
(self._version.flavor === "" ? "normal" : self._version.flavor + ")"),
|
|
293
|
-
);
|
|
294
|
-
if (self._version.isLegacy) {
|
|
295
|
-
deprecate("NW.js / node-webkit versions <0.12.3 are deprecated.");
|
|
318
|
+
for await (const os of options.platforms) {
|
|
319
|
+
let platform = os.slice(0, os.length - 2);
|
|
320
|
+
let arch = "x" + os.slice(os.length - 2);
|
|
321
|
+
await get({
|
|
322
|
+
version: options.version,
|
|
323
|
+
flavor: options.flavor,
|
|
324
|
+
platform: platform,
|
|
325
|
+
arch: arch,
|
|
326
|
+
downloadUrl: options.downloadUrl,
|
|
327
|
+
cacheDir: options.cacheDir,
|
|
328
|
+
cache: !options.forceDownload,
|
|
329
|
+
ffmpeg: false,
|
|
330
|
+
});
|
|
296
331
|
}
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
NwBuilder.prototype.platformFilesForVersion = function () {
|
|
301
|
-
var self = this;
|
|
332
|
+
}
|
|
302
333
|
|
|
303
|
-
|
|
304
|
-
|
|
334
|
+
buildGypModules() {
|
|
335
|
+
// @todo
|
|
336
|
+
// If we trigger a rebuild we have to copy
|
|
337
|
+
// the node_modules to a tmp location because
|
|
338
|
+
// we don't want to change the source files
|
|
339
|
+
}
|
|
305
340
|
|
|
306
|
-
|
|
341
|
+
preparePlatformSpecificManifests() {
|
|
307
342
|
if (
|
|
308
343
|
!(
|
|
309
|
-
|
|
310
|
-
|
|
344
|
+
this._appPkg.platformOverrides &&
|
|
345
|
+
Object.keys(this._appPkg.platformOverrides).length
|
|
311
346
|
)
|
|
312
347
|
) {
|
|
313
|
-
|
|
314
|
-
"Unsupported NW.js version '" +
|
|
315
|
-
self._version.version +
|
|
316
|
-
" (" +
|
|
317
|
-
self._version.flavor +
|
|
318
|
-
")' for platform '" +
|
|
319
|
-
name +
|
|
320
|
-
"'",
|
|
321
|
-
);
|
|
348
|
+
return Promise.resolve();
|
|
322
349
|
}
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
return Promise.resolve();
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
NwBuilder.prototype.downloadNwjs = async function () {
|
|
329
|
-
let options = this.options;
|
|
330
|
-
let built;
|
|
331
350
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
351
|
+
var self = this;
|
|
352
|
+
var promises = [];
|
|
353
|
+
|
|
354
|
+
self._forEachPlatform(function (name, platform) {
|
|
355
|
+
promises.push(
|
|
356
|
+
new Promise(function (resolve, reject) {
|
|
357
|
+
var overrides = self._appPkg.platformOverrides;
|
|
358
|
+
if (overrides[name] || overrides[name.substr(0, name.length - 2)]) {
|
|
359
|
+
platformOverrides(
|
|
360
|
+
{
|
|
361
|
+
options: self._appPkg,
|
|
362
|
+
platform: name,
|
|
363
|
+
},
|
|
364
|
+
function (err, result) {
|
|
365
|
+
if (err) {
|
|
366
|
+
return reject(err);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
platform.platformSpecificManifest = result;
|
|
370
|
+
resolve();
|
|
371
|
+
},
|
|
372
|
+
);
|
|
373
|
+
} else {
|
|
374
|
+
resolve();
|
|
375
|
+
}
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
348
378
|
});
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
379
|
|
|
352
|
-
|
|
353
|
-
// @todo
|
|
354
|
-
// If we trigger a rebuild we have to copy
|
|
355
|
-
// the node_modules to a tmp location because
|
|
356
|
-
// we don't want to change the source files
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
NwBuilder.prototype.preparePlatformSpecificManifests = function () {
|
|
360
|
-
if (
|
|
361
|
-
!(
|
|
362
|
-
this._appPkg.platformOverrides &&
|
|
363
|
-
Object.keys(this._appPkg.platformOverrides).length
|
|
364
|
-
)
|
|
365
|
-
) {
|
|
366
|
-
return Promise.resolve();
|
|
380
|
+
return Promise.all(promises);
|
|
367
381
|
}
|
|
368
382
|
|
|
369
|
-
|
|
370
|
-
|
|
383
|
+
createReleaseFolder() {
|
|
384
|
+
var self = this,
|
|
385
|
+
releasePath,
|
|
386
|
+
directoryCreationPromises = [];
|
|
371
387
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
} else {
|
|
392
|
-
resolve();
|
|
393
|
-
}
|
|
394
|
-
}),
|
|
395
|
-
);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
return Promise.all(promises);
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
NwBuilder.prototype.createReleaseFolder = function () {
|
|
402
|
-
var self = this,
|
|
403
|
-
releasePath,
|
|
404
|
-
directoryCreationPromises = [];
|
|
405
|
-
|
|
406
|
-
if (_.isFunction(self.options.buildType)) {
|
|
407
|
-
releasePath = self.options.buildType.call(self.options);
|
|
408
|
-
} else {
|
|
409
|
-
// buildTypes
|
|
410
|
-
switch (self.options.buildType) {
|
|
411
|
-
case "timestamped":
|
|
412
|
-
releasePath =
|
|
413
|
-
self.options.appName +
|
|
414
|
-
" - " +
|
|
415
|
-
Math.round(Date.now() / 1000).toString();
|
|
416
|
-
break;
|
|
417
|
-
|
|
418
|
-
case "versioned":
|
|
419
|
-
releasePath = self.options.appName + " - v" + self.options.appVersion;
|
|
420
|
-
break;
|
|
421
|
-
|
|
422
|
-
default:
|
|
423
|
-
releasePath = self.options.appName;
|
|
388
|
+
if (_.isFunction(self.options.buildType)) {
|
|
389
|
+
releasePath = self.options.buildType.call(self.options);
|
|
390
|
+
} else {
|
|
391
|
+
// buildTypes
|
|
392
|
+
switch (self.options.buildType) {
|
|
393
|
+
case "timestamped":
|
|
394
|
+
releasePath =
|
|
395
|
+
self.options.appName +
|
|
396
|
+
" - " +
|
|
397
|
+
Math.round(Date.now() / 1000).toString();
|
|
398
|
+
break;
|
|
399
|
+
|
|
400
|
+
case "versioned":
|
|
401
|
+
releasePath = self.options.appName + " - v" + self.options.appVersion;
|
|
402
|
+
break;
|
|
403
|
+
|
|
404
|
+
default:
|
|
405
|
+
releasePath = self.options.appName;
|
|
406
|
+
}
|
|
424
407
|
}
|
|
425
|
-
}
|
|
426
408
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// Ensure that there is a release Folder, delete and create it.
|
|
437
|
-
fs.remove(platform.releasePath, function (err) {
|
|
438
|
-
if (err) return reject(err);
|
|
409
|
+
this._forEachPlatform(function (name, platform) {
|
|
410
|
+
directoryCreationPromises.push(
|
|
411
|
+
new Promise(function (resolve, reject) {
|
|
412
|
+
platform.releasePath = path.resolve(
|
|
413
|
+
self.options.buildDir,
|
|
414
|
+
releasePath,
|
|
415
|
+
name,
|
|
416
|
+
);
|
|
439
417
|
|
|
440
|
-
|
|
418
|
+
// Ensure that there is a release Folder, delete and create it.
|
|
419
|
+
fs.remove(platform.releasePath, function (err) {
|
|
441
420
|
if (err) return reject(err);
|
|
442
421
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
"Create release folder in " + platform.releasePath,
|
|
446
|
-
);
|
|
447
|
-
resolve();
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
}),
|
|
451
|
-
);
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
return Promise.all(directoryCreationPromises);
|
|
455
|
-
};
|
|
422
|
+
fs.mkdirp(platform.releasePath, function (err) {
|
|
423
|
+
if (err) return reject(err);
|
|
456
424
|
|
|
457
|
-
|
|
425
|
+
log.debug("Create release folder in " + platform.releasePath);
|
|
426
|
+
resolve();
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
});
|
|
458
432
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const arch = "x" + os.slice(os.length - 2);
|
|
433
|
+
return Promise.all(directoryCreationPromises);
|
|
434
|
+
}
|
|
462
435
|
|
|
463
|
-
|
|
436
|
+
async copyNwjs() {
|
|
437
|
+
for await (const os of this.options.platforms) {
|
|
438
|
+
const platform = os.slice(0, os.length - 2);
|
|
439
|
+
const arch = "x" + os.slice(os.length - 2);
|
|
464
440
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
441
|
+
await rm(resolve(this.options.buildDir, this.options.appName, os), {
|
|
442
|
+
recursive: true,
|
|
443
|
+
force: true,
|
|
444
|
+
});
|
|
469
445
|
|
|
470
|
-
|
|
446
|
+
const nwDir = resolve(
|
|
447
|
+
this.options.cacheDir,
|
|
448
|
+
`nwjs${this.options.flavor === "sdk" ? "-sdk" : ""}-v${
|
|
449
|
+
this.options.version
|
|
450
|
+
}-${platform}-${arch}`,
|
|
451
|
+
);
|
|
471
452
|
|
|
472
|
-
for (const file of glob(this.options.files)) {
|
|
473
453
|
await cp(
|
|
474
|
-
|
|
475
|
-
resolve(
|
|
476
|
-
|
|
477
|
-
platform !== "osx"
|
|
478
|
-
? "package.nw"
|
|
479
|
-
: "nwjs.app/Contents/Resources/app.nw",
|
|
480
|
-
file,
|
|
481
|
-
),
|
|
482
|
-
{ recursive: true, verbatimSymlinks: true },
|
|
454
|
+
nwDir,
|
|
455
|
+
resolve(this.options.buildDir, this.options.appName, os),
|
|
456
|
+
{ recursive: true },
|
|
483
457
|
);
|
|
458
|
+
|
|
459
|
+
for (const file of glob(this.options.files)) {
|
|
460
|
+
await cp(
|
|
461
|
+
file,
|
|
462
|
+
resolve(
|
|
463
|
+
this.options.buildDir,
|
|
464
|
+
this.options.appName,
|
|
465
|
+
os,
|
|
466
|
+
platform !== "osx"
|
|
467
|
+
? "package.nw"
|
|
468
|
+
: "nwjs.app/Contents/Resources/app.nw",
|
|
469
|
+
file,
|
|
470
|
+
),
|
|
471
|
+
{ recursive: true, verbatimSymlinks: true },
|
|
472
|
+
);
|
|
473
|
+
}
|
|
484
474
|
}
|
|
485
475
|
}
|
|
486
|
-
};
|
|
487
476
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
477
|
+
isPlatformNeedingZip(name, platform) {
|
|
478
|
+
var self = this,
|
|
479
|
+
needsZip = platform.needsZip;
|
|
491
480
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return needsZip;
|
|
500
|
-
};
|
|
481
|
+
if (name.indexOf("osx") === 0 && self.options.macZip != null) {
|
|
482
|
+
log.warn("macZip is deprecated. Use the zip option instead.");
|
|
483
|
+
needsZip = self.options.macZip;
|
|
484
|
+
} else if (self.options.zip != null) {
|
|
485
|
+
needsZip = self.options.zip;
|
|
486
|
+
}
|
|
501
487
|
|
|
502
|
-
|
|
503
|
-
|
|
488
|
+
return needsZip;
|
|
489
|
+
}
|
|
504
490
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
zipOptions = this.options.zipOptions,
|
|
508
|
-
numberOfPlatformsWithoutOverrides = 0;
|
|
491
|
+
zipAppFiles() {
|
|
492
|
+
var self = this;
|
|
509
493
|
|
|
510
|
-
|
|
494
|
+
// Check if zip is needed
|
|
495
|
+
var doAnyNeedZip = false,
|
|
496
|
+
zipOptions = this.options.zipOptions,
|
|
497
|
+
numberOfPlatformsWithoutOverrides = 0;
|
|
511
498
|
|
|
512
|
-
|
|
513
|
-
var needsZip = self.isPlatformNeedingZip(name, platform);
|
|
499
|
+
self._zips = {};
|
|
514
500
|
|
|
515
|
-
|
|
516
|
-
var
|
|
501
|
+
this._forEachPlatform(function (name, platform) {
|
|
502
|
+
var needsZip = self.isPlatformNeedingZip(name, platform);
|
|
517
503
|
|
|
518
|
-
|
|
504
|
+
if (needsZip) {
|
|
505
|
+
var platformSpecific = !!platform.platformSpecificManifest;
|
|
519
506
|
|
|
520
|
-
|
|
521
|
-
}
|
|
507
|
+
self._zips[name] = { platformSpecific: platformSpecific };
|
|
522
508
|
|
|
523
|
-
|
|
524
|
-
|
|
509
|
+
numberOfPlatformsWithoutOverrides += !platformSpecific;
|
|
510
|
+
}
|
|
525
511
|
|
|
526
|
-
|
|
512
|
+
doAnyNeedZip = doAnyNeedZip || needsZip;
|
|
513
|
+
});
|
|
527
514
|
|
|
528
|
-
|
|
529
|
-
if (!self._needsZip) {
|
|
530
|
-
resolve();
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
515
|
+
self._needsZip = doAnyNeedZip;
|
|
533
516
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (numberOfPlatformsWithoutOverrides > 1) {
|
|
537
|
-
Utils.generateZipFile(self._files, self, null, zipOptions).then(
|
|
538
|
-
function (zip) {
|
|
539
|
-
resolve(zip);
|
|
540
|
-
},
|
|
541
|
-
reject,
|
|
542
|
-
);
|
|
543
|
-
} else {
|
|
517
|
+
return new Promise(function (resolve, reject) {
|
|
518
|
+
if (!self._needsZip) {
|
|
544
519
|
resolve();
|
|
520
|
+
return;
|
|
545
521
|
}
|
|
546
|
-
}).then(function (platformAgnosticZip) {
|
|
547
|
-
var zipPromises = [];
|
|
548
522
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
523
|
+
// create (or don't create) a ZIP for multiple platforms
|
|
524
|
+
new Promise(function (resolve, reject) {
|
|
525
|
+
if (numberOfPlatformsWithoutOverrides > 1) {
|
|
526
|
+
Utils.generateZipFile(self._files, self, null, zipOptions).then(
|
|
527
|
+
function (zip) {
|
|
528
|
+
resolve(zip);
|
|
529
|
+
},
|
|
530
|
+
reject,
|
|
531
|
+
);
|
|
532
|
+
} else {
|
|
533
|
+
resolve();
|
|
553
534
|
}
|
|
535
|
+
}).then(function (platformAgnosticZip) {
|
|
536
|
+
var zipPromises = [];
|
|
537
|
+
|
|
538
|
+
_.forEach(self._zips, function (zip, platformName) {
|
|
539
|
+
if (platformAgnosticZip && !zip.platformSpecific) {
|
|
540
|
+
zip.file = platformAgnosticZip;
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
zipPromises.push(
|
|
545
|
+
Utils.generateZipFile(
|
|
546
|
+
self._files,
|
|
547
|
+
self,
|
|
548
|
+
JSON.stringify(
|
|
549
|
+
self._platforms[platformName].platformSpecificManifest,
|
|
550
|
+
),
|
|
551
|
+
zipOptions,
|
|
552
|
+
).then(function (file) {
|
|
553
|
+
zip.file = file;
|
|
554
|
+
}),
|
|
555
|
+
);
|
|
556
|
+
});
|
|
554
557
|
|
|
555
|
-
zipPromises.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
JSON.stringify(
|
|
560
|
-
self._platforms[platformName].platformSpecificManifest,
|
|
561
|
-
),
|
|
562
|
-
zipOptions,
|
|
563
|
-
).then(function (file) {
|
|
564
|
-
zip.file = file;
|
|
565
|
-
}),
|
|
566
|
-
);
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
Promise.all(zipPromises).then(resolve, reject);
|
|
570
|
-
}, reject);
|
|
571
|
-
});
|
|
572
|
-
};
|
|
558
|
+
Promise.all(zipPromises).then(resolve, reject);
|
|
559
|
+
}, reject);
|
|
560
|
+
});
|
|
561
|
+
}
|
|
573
562
|
|
|
574
|
-
|
|
575
|
-
|
|
563
|
+
mergeAppFiles() {
|
|
564
|
+
var self = this;
|
|
576
565
|
|
|
577
|
-
|
|
566
|
+
var copyPromises = [];
|
|
578
567
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
568
|
+
this._forEachPlatform(function (name, platform) {
|
|
569
|
+
var zipping = self.isPlatformNeedingZip(name, platform);
|
|
570
|
+
// We copy the app files if we are on mac and don't force zip
|
|
571
|
+
if (!zipping) {
|
|
572
|
+
// no zip, copy the files
|
|
573
|
+
self._files.forEach(function (file) {
|
|
574
|
+
var dest;
|
|
575
|
+
|
|
576
|
+
if (name == "osx32" || name === "osx64") {
|
|
577
|
+
dest = path.resolve(
|
|
578
|
+
self.getResourcesDirectoryPath(platform),
|
|
579
|
+
"app.nw",
|
|
580
|
+
file.dest,
|
|
581
|
+
);
|
|
582
|
+
} else {
|
|
583
|
+
dest = path.resolve(platform.releasePath, file.dest);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (
|
|
587
|
+
file.dest === "package.json" &&
|
|
588
|
+
platform.platformSpecificManifest
|
|
589
|
+
) {
|
|
590
|
+
copyPromises.push(
|
|
591
|
+
self.writePlatformSpecificManifest(platform, dest),
|
|
592
|
+
);
|
|
593
|
+
} else {
|
|
594
|
+
copyPromises.push(Utils.copyFile(file.src, dest, self));
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
} else if (!self.options.mergeZip) {
|
|
598
|
+
// copy the zipped package.nw into the app directory
|
|
599
|
+
copyPromises.push(
|
|
600
|
+
Utils.copyFile(
|
|
601
|
+
self.getZipFile(name),
|
|
602
|
+
path.resolve(platform.releasePath, "package.nw"),
|
|
603
|
+
self,
|
|
604
|
+
),
|
|
605
|
+
);
|
|
606
|
+
} else if (name == "osx32" || name == "osx64") {
|
|
607
|
+
// zip just copy the app.nw
|
|
608
|
+
copyPromises.push(
|
|
609
|
+
Utils.copyFile(
|
|
610
|
+
self.getZipFile(name),
|
|
611
|
+
path.resolve(self.getResourcesDirectoryPath(platform), "app.nw"),
|
|
612
|
+
self,
|
|
613
|
+
),
|
|
614
|
+
);
|
|
615
|
+
} else {
|
|
616
|
+
var executableToMergeWith = self.getExecutableName(name);
|
|
617
|
+
|
|
618
|
+
// We cat the app.nw file into the .exe / nw
|
|
619
|
+
copyPromises.push(
|
|
620
|
+
Utils.mergeFiles(
|
|
621
|
+
path.resolve(platform.releasePath, executableToMergeWith),
|
|
622
|
+
self.getZipFile(name),
|
|
623
|
+
platform.chmod,
|
|
624
|
+
),
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
586
628
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
self.getResourcesDirectoryPath(platform),
|
|
590
|
-
"app.nw",
|
|
591
|
-
file.dest,
|
|
592
|
-
);
|
|
593
|
-
} else {
|
|
594
|
-
dest = path.resolve(platform.releasePath, file.dest);
|
|
595
|
-
}
|
|
629
|
+
return Promise.all(copyPromises);
|
|
630
|
+
}
|
|
596
631
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
copyPromises.push(Utils.copyFile(file.src, dest, self));
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
} else if (!self.options.mergeZip) {
|
|
604
|
-
// copy the zipped package.nw into the app directory
|
|
605
|
-
copyPromises.push(
|
|
606
|
-
Utils.copyFile(
|
|
607
|
-
self.getZipFile(name),
|
|
608
|
-
path.resolve(platform.releasePath, "package.nw"),
|
|
609
|
-
self,
|
|
610
|
-
),
|
|
611
|
-
);
|
|
612
|
-
} else if (name == "osx32" || name == "osx64") {
|
|
613
|
-
// zip just copy the app.nw
|
|
614
|
-
copyPromises.push(
|
|
615
|
-
Utils.copyFile(
|
|
616
|
-
self.getZipFile(name),
|
|
617
|
-
path.resolve(self.getResourcesDirectoryPath(platform), "app.nw"),
|
|
618
|
-
self,
|
|
619
|
-
),
|
|
620
|
-
);
|
|
621
|
-
} else {
|
|
622
|
-
var executableToMergeWith = self.getExecutableName(name);
|
|
623
|
-
|
|
624
|
-
// We cat the app.nw file into the .exe / nw
|
|
625
|
-
copyPromises.push(
|
|
626
|
-
Utils.mergeFiles(
|
|
627
|
-
path.resolve(platform.releasePath, executableToMergeWith),
|
|
628
|
-
self.getZipFile(name),
|
|
629
|
-
platform.chmod,
|
|
630
|
-
),
|
|
631
|
-
);
|
|
632
|
-
}
|
|
633
|
-
});
|
|
632
|
+
getZipFile(platformName) {
|
|
633
|
+
return (this._zips[platformName] && this._zips[platformName].file) || null;
|
|
634
|
+
}
|
|
634
635
|
|
|
635
|
-
|
|
636
|
-
|
|
636
|
+
writePlatformSpecificManifest(platform, dest) {
|
|
637
|
+
return new Promise(function (resolve, reject) {
|
|
638
|
+
var pkgParentDirectory = path.join(dest, "../");
|
|
639
|
+
if (!fs.existsSync(pkgParentDirectory)) fs.mkdirpSync(pkgParentDirectory);
|
|
637
640
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
fs.writeFile(
|
|
642
|
+
dest,
|
|
643
|
+
JSON.stringify(platform.platformSpecificManifest),
|
|
644
|
+
function (err) {
|
|
645
|
+
if (err) return reject(err);
|
|
646
|
+
resolve();
|
|
647
|
+
},
|
|
648
|
+
);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
646
651
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
JSON.stringify(platform.platformSpecificManifest),
|
|
650
|
-
function (err) {
|
|
651
|
-
if (err) return reject(err);
|
|
652
|
-
resolve();
|
|
653
|
-
},
|
|
654
|
-
);
|
|
655
|
-
});
|
|
656
|
-
};
|
|
652
|
+
handleLinuxApp() {
|
|
653
|
+
var self = this;
|
|
657
654
|
|
|
658
|
-
|
|
659
|
-
|
|
655
|
+
this._forEachPlatform(async function (name, platform) {
|
|
656
|
+
if (["linux64", "linux32"].indexOf(name) < 0) return;
|
|
660
657
|
|
|
661
|
-
|
|
662
|
-
if (["linux64", "linux32"].indexOf(name) < 0) return;
|
|
658
|
+
var executableName = self.getExecutableName(name);
|
|
663
659
|
|
|
664
|
-
|
|
660
|
+
await rename(
|
|
661
|
+
resolve(platform.releasePath, "nw"),
|
|
662
|
+
resolve(platform.releasePath, executableName),
|
|
663
|
+
);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
665
666
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
);
|
|
670
|
-
});
|
|
671
|
-
}
|
|
667
|
+
handleMacApp() {
|
|
668
|
+
var self = this,
|
|
669
|
+
allDone = [];
|
|
672
670
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
allDone = [];
|
|
671
|
+
this._forEachPlatform(async function (name, platform) {
|
|
672
|
+
if (["osx32", "osx64"].indexOf(name) < 0) return;
|
|
676
673
|
|
|
677
|
-
|
|
678
|
-
if (["osx32", "osx64"].indexOf(name) < 0) return;
|
|
674
|
+
var executableName = self.getExecutableName(name);
|
|
679
675
|
|
|
680
|
-
|
|
676
|
+
await rename(
|
|
677
|
+
resolve(platform.releasePath, "nwjs.app"),
|
|
678
|
+
resolve(platform.releasePath, executableName),
|
|
679
|
+
);
|
|
681
680
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
681
|
+
// Let's first handle the mac icon
|
|
682
|
+
if (self.options.macIcns) {
|
|
683
|
+
if (semver.satisfies(self._version.version, "<=0.12.3")) {
|
|
684
|
+
allDone.push(
|
|
685
|
+
Utils.copyFile(
|
|
686
|
+
self.options.macIcns,
|
|
687
|
+
path.resolve(self.getResourcesDirectoryPath(platform), "nw.icns"),
|
|
688
|
+
self,
|
|
689
|
+
),
|
|
690
|
+
);
|
|
691
|
+
} else {
|
|
692
|
+
allDone.push(
|
|
693
|
+
Utils.copyFile(
|
|
694
|
+
self.options.macIcns,
|
|
695
|
+
path.resolve(
|
|
696
|
+
self.getResourcesDirectoryPath(platform),
|
|
697
|
+
"app.icns",
|
|
698
|
+
),
|
|
699
|
+
self,
|
|
700
|
+
),
|
|
701
|
+
);
|
|
702
|
+
allDone.push(
|
|
703
|
+
Utils.copyFile(
|
|
704
|
+
self.options.macIcns,
|
|
705
|
+
path.resolve(
|
|
706
|
+
self.getResourcesDirectoryPath(platform),
|
|
707
|
+
"document.icns",
|
|
708
|
+
),
|
|
709
|
+
self,
|
|
710
|
+
),
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
686
714
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
if (semver.satisfies(self._version.version, "<=0.12.3")) {
|
|
715
|
+
// Handle mac credits
|
|
716
|
+
if (self.options.macCredits) {
|
|
690
717
|
allDone.push(
|
|
691
718
|
Utils.copyFile(
|
|
692
|
-
self.options.
|
|
693
|
-
path.resolve(self.getResourcesDirectoryPath(platform), "nw.icns"),
|
|
694
|
-
self,
|
|
695
|
-
),
|
|
696
|
-
);
|
|
697
|
-
} else {
|
|
698
|
-
allDone.push(
|
|
699
|
-
Utils.copyFile(
|
|
700
|
-
self.options.macIcns,
|
|
701
|
-
path.resolve(self.getResourcesDirectoryPath(platform), "app.icns"),
|
|
702
|
-
self,
|
|
703
|
-
),
|
|
704
|
-
);
|
|
705
|
-
allDone.push(
|
|
706
|
-
Utils.copyFile(
|
|
707
|
-
self.options.macIcns,
|
|
719
|
+
self.options.macCredits,
|
|
708
720
|
path.resolve(
|
|
709
721
|
self.getResourcesDirectoryPath(platform),
|
|
710
|
-
"
|
|
722
|
+
"Credits.html",
|
|
711
723
|
),
|
|
712
724
|
self,
|
|
713
725
|
),
|
|
714
726
|
);
|
|
715
727
|
}
|
|
716
|
-
}
|
|
717
728
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
self.getResourcesDirectoryPath(platform),
|
|
725
|
-
"Credits.html",
|
|
726
|
-
),
|
|
727
|
-
self,
|
|
728
|
-
),
|
|
729
|
+
// Let's handle the Plist
|
|
730
|
+
var PlistPath = path.resolve(
|
|
731
|
+
platform.releasePath,
|
|
732
|
+
self.options.appName + ".app",
|
|
733
|
+
"Contents",
|
|
734
|
+
"Info.plist",
|
|
729
735
|
);
|
|
730
|
-
}
|
|
731
736
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
var plistOptions = Utils.getPlistOptions(
|
|
746
|
-
{
|
|
747
|
-
name: self.options.appName,
|
|
748
|
-
version: self.options.appVersion,
|
|
749
|
-
copyright: self._appPkg.copyright,
|
|
750
|
-
},
|
|
751
|
-
self.options.macPlist,
|
|
752
|
-
);
|
|
753
|
-
|
|
754
|
-
allDone.push(Utils.editPlist(PlistPath, PlistPath, plistOptions));
|
|
755
|
-
}
|
|
756
|
-
});
|
|
737
|
+
// If the macPlist is a string we just copy the file
|
|
738
|
+
if (typeof self.options.macPlist === "string") {
|
|
739
|
+
allDone.push(Utils.copyFile(self.options.macPlist, PlistPath, self));
|
|
740
|
+
} else {
|
|
741
|
+
// Setup the Plist
|
|
742
|
+
var plistOptions = Utils.getPlistOptions(
|
|
743
|
+
{
|
|
744
|
+
name: self.options.appName,
|
|
745
|
+
version: self.options.appVersion,
|
|
746
|
+
copyright: self._appPkg.copyright,
|
|
747
|
+
},
|
|
748
|
+
self.options.macPlist,
|
|
749
|
+
);
|
|
757
750
|
|
|
758
|
-
|
|
759
|
-
}
|
|
751
|
+
allDone.push(Utils.editPlist(PlistPath, PlistPath, plistOptions));
|
|
752
|
+
}
|
|
753
|
+
});
|
|
760
754
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
allDone = [];
|
|
755
|
+
return Promise.all(allDone);
|
|
756
|
+
}
|
|
764
757
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
["win32", "win64"].indexOf(name) < 0
|
|
769
|
-
)
|
|
770
|
-
return;
|
|
758
|
+
handleWinApp() {
|
|
759
|
+
var self = this,
|
|
760
|
+
allDone = [];
|
|
771
761
|
|
|
772
|
-
|
|
773
|
-
|
|
762
|
+
this._forEachPlatform(async function (name, platform) {
|
|
763
|
+
if (
|
|
764
|
+
(!self.options.winIco && !self.options.winVersionString) ||
|
|
765
|
+
["win32", "win64"].indexOf(name) < 0
|
|
766
|
+
)
|
|
767
|
+
return;
|
|
774
768
|
|
|
775
|
-
|
|
776
|
-
resolve(platform.releasePath,
|
|
777
|
-
resolve(platform.releasePath, executableName),
|
|
778
|
-
);
|
|
769
|
+
var executableName = self.getExecutableName(name);
|
|
770
|
+
var executablePath = path.resolve(platform.releasePath, executableName);
|
|
779
771
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
{},
|
|
784
|
-
{
|
|
785
|
-
// The process name used in the Task Manager
|
|
786
|
-
FileDescription: self.options.appName,
|
|
787
|
-
},
|
|
788
|
-
self.options.winVersionString,
|
|
772
|
+
await rename(
|
|
773
|
+
resolve(platform.releasePath, "nw.exe"),
|
|
774
|
+
resolve(platform.releasePath, executableName),
|
|
789
775
|
);
|
|
790
|
-
}
|
|
791
|
-
if (self.options.winIco && self.options.useRcedit) {
|
|
792
|
-
rcConf["icon"] = path.resolve(self.options.winIco);
|
|
793
|
-
}
|
|
794
776
|
|
|
795
|
-
|
|
777
|
+
var rcConf = {};
|
|
778
|
+
if (self.options.winVersionString) {
|
|
779
|
+
rcConf["version-string"] = Object.assign(
|
|
780
|
+
{},
|
|
781
|
+
{
|
|
782
|
+
// The process name used in the Task Manager
|
|
783
|
+
FileDescription: self.options.appName,
|
|
784
|
+
},
|
|
785
|
+
self.options.winVersionString,
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
if (self.options.winIco && self.options.useRcedit) {
|
|
789
|
+
rcConf["icon"] = path.resolve(self.options.winIco);
|
|
790
|
+
}
|
|
796
791
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
(
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
792
|
+
var updateVersionStringPromise = rcedit(executablePath, rcConf);
|
|
793
|
+
|
|
794
|
+
var updateIconsPromise = updateVersionStringPromise.then(function () {
|
|
795
|
+
return new Promise(function (resolve, reject) {
|
|
796
|
+
if (!self.options.winIco || self.options.useRcedit) {
|
|
797
|
+
resolve();
|
|
798
|
+
} else {
|
|
799
|
+
log.debug("Update " + name + " executable icon");
|
|
800
|
+
// Set icon
|
|
801
|
+
winresourcer(
|
|
802
|
+
{
|
|
803
|
+
operation: "Update",
|
|
804
|
+
exeFile: executablePath,
|
|
805
|
+
resourceType: "Icongroup",
|
|
806
|
+
resourceName: "IDR_MAINFRAME",
|
|
807
|
+
lang: 1033, // Required, except when updating or deleting
|
|
808
|
+
resourceFile: path.resolve(self.options.winIco),
|
|
809
|
+
},
|
|
810
|
+
function (err) {
|
|
811
|
+
if (!err) {
|
|
812
|
+
resolve();
|
|
813
|
+
} else {
|
|
814
|
+
reject(
|
|
815
|
+
"Error while updating the Windows icon." +
|
|
816
|
+
(process.platform !== "win32"
|
|
817
|
+
? " Wine (winehq.org) must be installed to add custom icons from Mac and Linux."
|
|
818
|
+
: ""),
|
|
819
|
+
);
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
});
|
|
827
825
|
});
|
|
828
|
-
});
|
|
829
826
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
827
|
+
// build a promise chain
|
|
828
|
+
allDone.push(updateIconsPromise);
|
|
829
|
+
});
|
|
833
830
|
|
|
834
|
-
|
|
835
|
-
}
|
|
831
|
+
return Promise.all(allDone);
|
|
832
|
+
}
|
|
836
833
|
|
|
837
|
-
|
|
838
|
-
|
|
834
|
+
async runApp() {
|
|
835
|
+
const options = this.options;
|
|
839
836
|
|
|
840
|
-
|
|
841
|
-
|
|
837
|
+
let platform = options.currentPlatform.slice(
|
|
838
|
+
0,
|
|
839
|
+
options.currentPlatform.length - 2,
|
|
840
|
+
);
|
|
841
|
+
let arch =
|
|
842
|
+
"x" + options.currentPlatform.slice(options.currentPlatform.length - 2);
|
|
842
843
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
844
|
+
await run({
|
|
845
|
+
version: options.version,
|
|
846
|
+
flavor: options.flavor,
|
|
847
|
+
platform: platform,
|
|
848
|
+
arch: arch,
|
|
849
|
+
srcDir: options.files,
|
|
850
|
+
cacheDir: options.cacheDir,
|
|
851
|
+
argv: options.argv,
|
|
852
|
+
});
|
|
853
|
+
}
|
|
852
854
|
|
|
853
|
-
|
|
855
|
+
isAppRunning() {
|
|
856
|
+
return this._nwProcess !== undefined;
|
|
857
|
+
}
|
|
854
858
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
859
|
+
getAppProcess() {
|
|
860
|
+
return this._nwProcess;
|
|
861
|
+
}
|
|
858
862
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
863
|
+
_forEachPlatform(fn) {
|
|
864
|
+
_.forEach(this._platforms, function (platform, name) {
|
|
865
|
+
return fn(name, platform);
|
|
866
|
+
});
|
|
867
|
+
}
|
|
862
868
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
return
|
|
866
|
-
|
|
867
|
-
|
|
869
|
+
// Mac only
|
|
870
|
+
getResourcesDirectoryPath(platform) {
|
|
871
|
+
return path.resolve(
|
|
872
|
+
platform.releasePath,
|
|
873
|
+
this.options.appName + ".app",
|
|
874
|
+
"Contents",
|
|
875
|
+
"Resources",
|
|
876
|
+
);
|
|
877
|
+
}
|
|
868
878
|
|
|
869
|
-
//
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
platform.releasePath,
|
|
873
|
-
this.options.appName + ".app",
|
|
874
|
-
"Contents",
|
|
875
|
-
"Resources",
|
|
876
|
-
);
|
|
877
|
-
};
|
|
879
|
+
// Don't use if legacy version
|
|
880
|
+
getExecutableName(platform) {
|
|
881
|
+
var executableExtension = "";
|
|
878
882
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
883
|
+
if (platform.indexOf("osx") === 0) {
|
|
884
|
+
executableExtension = ".app";
|
|
885
|
+
} else if (platform.indexOf("win") === 0) {
|
|
886
|
+
executableExtension = ".exe";
|
|
887
|
+
}
|
|
882
888
|
|
|
883
|
-
|
|
884
|
-
executableExtension = ".app";
|
|
885
|
-
} else if (platform.indexOf("win") === 0) {
|
|
886
|
-
executableExtension = ".exe";
|
|
889
|
+
return this.options.appName + executableExtension;
|
|
887
890
|
}
|
|
888
891
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
) {
|
|
898
|
-
if (!platform.cache) {
|
|
899
|
-
platform.cache = path.resolve(
|
|
900
|
-
this.options.cacheDir,
|
|
901
|
-
version + "-" + flavor,
|
|
902
|
-
platformName,
|
|
903
|
-
);
|
|
892
|
+
setPlatformCacheDirectory(platformName, platform, version, flavor) {
|
|
893
|
+
if (!platform.cache) {
|
|
894
|
+
platform.cache = path.resolve(
|
|
895
|
+
this.options.cacheDir,
|
|
896
|
+
version + "-" + flavor,
|
|
897
|
+
platformName,
|
|
898
|
+
);
|
|
899
|
+
}
|
|
904
900
|
}
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
NwBuilder.prototype.isPlatformCached = function (
|
|
908
|
-
platformName,
|
|
909
|
-
platform,
|
|
910
|
-
version,
|
|
911
|
-
flavor,
|
|
912
|
-
) {
|
|
913
|
-
this.setPlatformCacheDirectory(platformName, platform, version, flavor);
|
|
914
|
-
if (this.options.forceDownload) {
|
|
915
|
-
return false;
|
|
916
|
-
}
|
|
917
|
-
this.preparePlatformFiles(platformName, platform, version);
|
|
918
|
-
return checkCache(platform.cache, platform.files);
|
|
919
|
-
};
|
|
920
901
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
)
|
|
927
|
-
|
|
928
|
-
if (
|
|
929
|
-
Object.keys(platform.files)[0] !==
|
|
930
|
-
Object.keys(Platforms[platformName].files)[0]
|
|
931
|
-
) {
|
|
932
|
-
return true;
|
|
902
|
+
isPlatformCached(platformName, platform, version, flavor) {
|
|
903
|
+
this.setPlatformCacheDirectory(platformName, platform, version, flavor);
|
|
904
|
+
if (this.options.forceDownload) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
this.preparePlatformFiles(platformName, platform, version);
|
|
908
|
+
return checkCache(platform.cache, platform.files);
|
|
933
909
|
}
|
|
934
910
|
|
|
935
|
-
if
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
911
|
+
// returns a Boolean; true if the desired platform is supported
|
|
912
|
+
preparePlatformFiles(platformName, platform, version) {
|
|
913
|
+
// return if platform.files is already prepared
|
|
914
|
+
if (
|
|
915
|
+
Object.keys(platform.files)[0] !==
|
|
916
|
+
Object.keys(Platforms[platformName].files)[0]
|
|
917
|
+
) {
|
|
944
918
|
return true;
|
|
945
|
-
}
|
|
946
|
-
}
|
|
919
|
+
}
|
|
947
920
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
921
|
+
if (semver.satisfies(version, "<0.12.3")) {
|
|
922
|
+
return !Object.keys(platform.files).every(function (range) {
|
|
923
|
+
if (semver.satisfies(version, range)) {
|
|
924
|
+
platform.files = platform.files[range];
|
|
925
|
+
if ("string" === typeof platform.files) {
|
|
926
|
+
platform.files = [platform.files];
|
|
927
|
+
}
|
|
928
|
+
return false;
|
|
929
|
+
}
|
|
930
|
+
return true;
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
platform.files = ["*"]; // otherwise bad stuff will happen like at attempt to download legacy version files
|
|
935
|
+
// all we can do here is assume it's oke because this._version might not exist yet, but callers of this function
|
|
936
|
+
// will check properly where necessary
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
953
940
|
|
|
954
941
|
const nwbuild = (options) => {
|
|
955
942
|
let nw = new NwBuilder(options);
|
|
@@ -962,7 +949,7 @@ const nwbuild = (options) => {
|
|
|
962
949
|
nw.run();
|
|
963
950
|
return 0;
|
|
964
951
|
} else {
|
|
965
|
-
|
|
952
|
+
log.warn("[ WARN ] Invalid mode option.");
|
|
966
953
|
return 1;
|
|
967
954
|
}
|
|
968
955
|
};
|