nw-builder 3.6.0 → 3.7.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/.editorconfig +17 -0
- package/.github/CHANGELOG.md +77 -35
- package/.github/CODE_OF_CONDUCT.md +55 -0
- package/.github/{ISSUE_REQUEST_TEMPLATE.md → ISSUE_TEMPLATE.md} +1 -0
- package/.github/workflows/cd.yml +3 -3
- package/.github/workflows/ci.yml +9 -5
- package/README.md +81 -23
- package/bin/nwbuild.cjs +102 -0
- package/dist/index.cjs +1 -0
- package/lib/Version.cjs +81 -0
- package/lib/downloader.cjs +177 -0
- package/lib/index.cjs +1078 -0
- package/lib/{platformOverrides.js → platformOverrides.cjs} +61 -36
- package/lib/utils.cjs +293 -0
- package/lib/versions.cjs +206 -0
- package/package.json +57 -29
- package/src/constants/Platform.js +16 -0
- package/src/constants/Platforms.js +143 -0
- package/src/constants/index.js +7 -0
- package/src/index.js +2 -0
- package/src/utilities/checkCache.js +30 -0
- package/src/utilities/detectCurrentPlatform.js +24 -0
- package/src/utilities/index.js +4 -0
- package/{example/icons → test/demo}/icon.icns +0 -0
- package/{example/icons → test/demo}/icon.ico +0 -0
- package/test/demo/index.cjs +14 -0
- package/test/demo/index.html +10 -0
- package/{example/nwapp → test/demo}/package.json +7 -6
- package/test/downloader.cjs +131 -0
- package/test/expected/README.md +1 -1
- package/test/expected/merged +1 -1
- package/test/expected/oneOveriddenRestNot/README.md +1 -1
- package/test/expected/oneOveriddenRestNot/osx32.json +7 -7
- package/test/expected/oneOveriddenRestNot/osx64.json +7 -7
- package/test/expected/osx-plist/README.md +1 -1
- package/test/expected/platformOverrides/README.md +1 -1
- package/test/expected/platformOverrides/linux32.json +12 -12
- package/test/expected/platformOverrides/linux64.json +8 -8
- package/test/expected/platformOverrides/osx32.json +10 -10
- package/test/expected/platformOverrides/osx64.json +10 -10
- package/test/expected/platformOverrides/win32.json +10 -10
- package/test/expected/platformOverrides/win64.json +10 -10
- package/test/fixtures/README.md +1 -1
- package/test/fixtures/invalid.json +1 -1
- package/test/fixtures/manifest/README.md +1 -1
- package/test/fixtures/manifest/versions.json +9 -3
- package/test/fixtures/nwapp/README.md +1 -1
- package/test/fixtures/nwapp/images/imagefile.img +1 -1
- package/test/fixtures/nwapp/index.html +5 -2
- package/test/fixtures/nwapp/javascript/bower_packages/simple/package.json +1 -1
- package/test/fixtures/nwapp/javascript/jsfile.js +1 -1
- package/test/fixtures/nwapp/package.json +1 -1
- package/test/fixtures/oneOveriddenRestNot/README.md +1 -1
- package/test/fixtures/oneOveriddenRestNot/package.json +13 -13
- package/test/fixtures/osx-plist/README.md +1 -1
- package/test/fixtures/platformOverrides/README.md +1 -1
- package/test/fixtures/platformOverrides/package.json +68 -48
- package/test/fixtures/testVersions.html +73 -16
- package/test/nwBuilder.cjs +339 -0
- package/test/unit/checkCache.test.js +19 -0
- package/test/unit/checkCacheDir/v0.64.1/linux64/nw1.app +0 -0
- package/test/unit/checkCacheDir/v0.64.1/linux64/nw2.app +0 -0
- package/test/unit/detectCurrentPlatform.test.js +58 -0
- package/test/utils.cjs +310 -0
- package/test/versions.cjs +485 -0
- package/bin/nwbuild +0 -98
- package/demo.js +0 -22
- package/example/icons/README.md +0 -7
- package/example/nwapp/Credits.html +0 -9
- package/example/nwapp/README.md +0 -7
- package/example/nwapp/images/README.md +0 -7
- package/example/nwapp/images/kitten.jpg +0 -0
- package/example/nwapp/index.html +0 -22
- package/example/package.json +0 -7
- package/index.js +0 -1
- package/lib/Version.js +0 -60
- package/lib/detectCurrentPlatform.js +0 -17
- package/lib/downloader.js +0 -192
- package/lib/index.js +0 -873
- package/lib/platforms.js +0 -76
- package/lib/utils.js +0 -249
- package/lib/versions.js +0 -198
- package/test/downloader.js +0 -87
- package/test/nwBuilder.js +0 -237
- package/test/utils.js +0 -232
- package/test/versions.js +0 -330
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { detectCurrentPlatform } from "../../src/utilities";
|
|
2
|
+
import { Platform } from "../../src/constants";
|
|
3
|
+
|
|
4
|
+
const processEnv = { ...process.env };
|
|
5
|
+
|
|
6
|
+
test("for OSX 32 platform", () => {
|
|
7
|
+
const process = {};
|
|
8
|
+
process.platform = "darwin";
|
|
9
|
+
process.arch = "x32";
|
|
10
|
+
|
|
11
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.OSX_32);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("for OSX 64 platform", () => {
|
|
15
|
+
const process = {};
|
|
16
|
+
process.platform = "darwin";
|
|
17
|
+
process.arch = "x64";
|
|
18
|
+
|
|
19
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.OSX_64);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("for Linux 32 platform", () => {
|
|
23
|
+
const process = {};
|
|
24
|
+
process.platform = "linux";
|
|
25
|
+
process.arch = "x32";
|
|
26
|
+
|
|
27
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.NIX_32);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("for Linux 64 platform", () => {
|
|
31
|
+
const process = {};
|
|
32
|
+
process.platform = "linux";
|
|
33
|
+
process.arch = "x64";
|
|
34
|
+
|
|
35
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.NIX_64);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("for Windows 32 platform", () => {
|
|
39
|
+
const process = {};
|
|
40
|
+
process.platform = "win32";
|
|
41
|
+
process.arch = "x32";
|
|
42
|
+
process.env = { ...processEnv };
|
|
43
|
+
process.env.PROCESSOR_ARCHITEW6432 = undefined;
|
|
44
|
+
|
|
45
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.WIN_32);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("for Windows 64 platform", () => {
|
|
49
|
+
const process = {};
|
|
50
|
+
process.platform = "win32";
|
|
51
|
+
process.arch = "x64";
|
|
52
|
+
process.env = { ...processEnv };
|
|
53
|
+
process.env.PROCESSOR_ARCHITEW6432 = undefined;
|
|
54
|
+
|
|
55
|
+
expect(detectCurrentPlatform(process)).toBe(Platform.WIN_64);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export {};
|
package/test/utils.cjs
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
var test = require("tape");
|
|
2
|
+
var testSetup = require("redtape");
|
|
3
|
+
var temp = require("temp");
|
|
4
|
+
var fs = require("fs");
|
|
5
|
+
var path = require("path");
|
|
6
|
+
var utils = require("../lib/utils.cjs");
|
|
7
|
+
var DecompressZip = require("decompress-zip");
|
|
8
|
+
var _ = require("lodash");
|
|
9
|
+
var EventEmitter = require("events").EventEmitter;
|
|
10
|
+
var del = require("rimraf");
|
|
11
|
+
var thenify = require("thenify");
|
|
12
|
+
var isWindows = process.platform === "win32";
|
|
13
|
+
var tempFile = thenify(temp.open);
|
|
14
|
+
|
|
15
|
+
var tempFileCleanup = function () {
|
|
16
|
+
return new Promise(function (resolve, reject) {
|
|
17
|
+
temp.cleanup(function (err, result) {
|
|
18
|
+
if (err) {
|
|
19
|
+
return reject(err);
|
|
20
|
+
}
|
|
21
|
+
resolve(result);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
test("getPackageInfo invalid", function (t) {
|
|
27
|
+
t.plan(1);
|
|
28
|
+
utils.getPackageInfo("./test/fixtures/invalid.json").catch(function (error) {
|
|
29
|
+
t.ok(error);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("getPackageInfo valid", function (t) {
|
|
34
|
+
t.plan(2);
|
|
35
|
+
utils
|
|
36
|
+
.getPackageInfo("./test/fixtures/nwapp/package.json")
|
|
37
|
+
.then(function (pkg) {
|
|
38
|
+
t.equal(pkg.name, "nw-demo", "get package name");
|
|
39
|
+
t.equal(pkg.version, "0.1.0", "get package version");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("generate and write a valid plist file", function (t) {
|
|
44
|
+
t.plan(2);
|
|
45
|
+
var tests = [];
|
|
46
|
+
|
|
47
|
+
// custom properties
|
|
48
|
+
tests.push(
|
|
49
|
+
tempFile("plist-1").then(function (info) {
|
|
50
|
+
var options = utils.getPlistOptions(
|
|
51
|
+
{
|
|
52
|
+
name: "TestApp",
|
|
53
|
+
version: "1.3.3.7",
|
|
54
|
+
copyright: "(c) by me",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
CFBundleDisplayName: "My cool TestApp",
|
|
58
|
+
LSEnvironment: {
|
|
59
|
+
PATH: "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
return utils
|
|
64
|
+
.editPlist("./test/fixtures/osx-plist/Info.plist", info.path, options)
|
|
65
|
+
.then(function () {
|
|
66
|
+
var actual = fs
|
|
67
|
+
.readFileSync(info.path)
|
|
68
|
+
.toString()
|
|
69
|
+
.replace(/\r|\n/gm, "");
|
|
70
|
+
var expected = fs
|
|
71
|
+
.readFileSync("./test/expected/osx-plist/1.plist")
|
|
72
|
+
.toString()
|
|
73
|
+
.replace(/\r|\n/gm, "");
|
|
74
|
+
t.equal(actual, expected, "with custom properties");
|
|
75
|
+
});
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// without copyright information
|
|
80
|
+
tests.push(
|
|
81
|
+
tempFile("plist-2").then(function (info) {
|
|
82
|
+
var options = utils.getPlistOptions({
|
|
83
|
+
name: "TestApp",
|
|
84
|
+
version: "1.3.3.7",
|
|
85
|
+
});
|
|
86
|
+
return utils
|
|
87
|
+
.editPlist("./test/fixtures/osx-plist/Info.plist", info.path, options)
|
|
88
|
+
.then(function () {
|
|
89
|
+
var actual = fs
|
|
90
|
+
.readFileSync(info.path)
|
|
91
|
+
.toString()
|
|
92
|
+
.replace(/\r|\n/gm, "");
|
|
93
|
+
var expected = fs
|
|
94
|
+
.readFileSync("./test/expected/osx-plist/2.plist")
|
|
95
|
+
.toString()
|
|
96
|
+
.replace(/\r|\n/gm, "");
|
|
97
|
+
t.equal(actual, expected, "without copyright information");
|
|
98
|
+
});
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
Promise.all(tests)
|
|
103
|
+
.then(tempFileCleanup)
|
|
104
|
+
.then(function () {
|
|
105
|
+
t.end();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("getFileList", function (t) {
|
|
110
|
+
t.plan(5);
|
|
111
|
+
|
|
112
|
+
utils
|
|
113
|
+
.getFileList([
|
|
114
|
+
"./test/fixtures/nwapp/**",
|
|
115
|
+
"!./test/fixtures/nwapp/README.md",
|
|
116
|
+
])
|
|
117
|
+
.then(function (data) {
|
|
118
|
+
t.equal(
|
|
119
|
+
data.json,
|
|
120
|
+
path.normalize("test/fixtures/nwapp/package.json"),
|
|
121
|
+
"figure out the right json",
|
|
122
|
+
);
|
|
123
|
+
var expected = [
|
|
124
|
+
{
|
|
125
|
+
src: path.normalize("test/fixtures/nwapp/images/imagefile.img"),
|
|
126
|
+
dest: path.normalize("images/imagefile.img"),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
src: path.normalize("test/fixtures/nwapp/index.html"),
|
|
130
|
+
dest: path.normalize("index.html"),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
src: path.normalize(
|
|
134
|
+
"test/fixtures/nwapp/javascript/bower_packages/simple/package.json",
|
|
135
|
+
),
|
|
136
|
+
dest: path.normalize("javascript/bower_packages/simple/package.json"),
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
src: path.normalize("test/fixtures/nwapp/javascript/jsfile.js"),
|
|
140
|
+
dest: path.normalize("javascript/jsfile.js"),
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
src: path.normalize(
|
|
144
|
+
"test/fixtures/nwapp/node_modules/package/package.json",
|
|
145
|
+
),
|
|
146
|
+
dest: path.normalize("node_modules/package/package.json"),
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
src: path.normalize("test/fixtures/nwapp/package.json"),
|
|
150
|
+
dest: path.normalize("package.json"),
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
t.deepEqual(data.files, expected);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
utils.getFileList("./test/fixtures/nwapp/images/**").then(
|
|
157
|
+
function () {},
|
|
158
|
+
function (error) {
|
|
159
|
+
t.equal(
|
|
160
|
+
error,
|
|
161
|
+
"Could not find a package.json in your src folder",
|
|
162
|
+
"throw an error if there is no package json",
|
|
163
|
+
);
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
utils.getFileList("./test/fixtures/nwapp/images/*.js").then(
|
|
168
|
+
function () {},
|
|
169
|
+
function (error) {
|
|
170
|
+
t.equal(error, "No files matching");
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
utils
|
|
175
|
+
.getFileList([
|
|
176
|
+
"./test/fixtures/nwapp/**/*",
|
|
177
|
+
"!./test/fixtures/nwapp/node_modules/**/*",
|
|
178
|
+
"!./test/fixtures/nwapp/javascript/**/*",
|
|
179
|
+
"!./test/fixtures/nwapp/README.md",
|
|
180
|
+
])
|
|
181
|
+
.then(function (data) {
|
|
182
|
+
var expected = [
|
|
183
|
+
{
|
|
184
|
+
src: path.normalize("test/fixtures/nwapp/images/imagefile.img"),
|
|
185
|
+
dest: path.normalize("images/imagefile.img"),
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
src: path.normalize("test/fixtures/nwapp/index.html"),
|
|
189
|
+
dest: path.normalize("index.html"),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
src: path.normalize("test/fixtures/nwapp/package.json"),
|
|
193
|
+
dest: path.normalize("package.json"),
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
t.deepEqual(data.files, expected);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("should zip the app and create the app.nw file + log it", function (t) {
|
|
201
|
+
t.plan(6);
|
|
202
|
+
|
|
203
|
+
var files = [
|
|
204
|
+
{
|
|
205
|
+
src: path.normalize("test/fixtures/nwapp/images/imagefile.img"),
|
|
206
|
+
dest: path.normalize("images/imagefile.img"),
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
src: path.normalize(
|
|
210
|
+
"test/fixtures/nwapp/javascript/bower_packages/simple/package.json",
|
|
211
|
+
),
|
|
212
|
+
dest: path.normalize("javascript/bower_packages/simple/package.json"),
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
src: path.normalize("test/fixtures/nwapp/javascript/jsfile.js"),
|
|
216
|
+
dest: path.normalize("javascript/jsfile.js"),
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
src: path.normalize(
|
|
220
|
+
"test/fixtures/nwapp/node_modules/package/package.json",
|
|
221
|
+
),
|
|
222
|
+
dest: path.normalize("node_modules/package/package.json"),
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
src: path.normalize("test/fixtures/nwapp/package.json"),
|
|
226
|
+
dest: path.normalize("package.json"),
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
expected = _.map(files, "dest").sort();
|
|
230
|
+
|
|
231
|
+
var _evt = new EventEmitter();
|
|
232
|
+
_evt.on("log", function (logging) {
|
|
233
|
+
t.ok(logging, "LOG: " + logging);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
utils.generateZipFile(files, _evt).then(function (nwfile) {
|
|
237
|
+
var unzipper = new DecompressZip(nwfile);
|
|
238
|
+
unzipper.on("list", function (files) {
|
|
239
|
+
t.deepEqual(files.sort(), expected);
|
|
240
|
+
});
|
|
241
|
+
unzipper.list();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
testSetup({
|
|
246
|
+
afterEach: function (done) {
|
|
247
|
+
del("./test/temp/platform-specific-unzipped", done);
|
|
248
|
+
},
|
|
249
|
+
})(
|
|
250
|
+
"should zip but use platform-specific manifest with overrides in package.json",
|
|
251
|
+
function (t) {
|
|
252
|
+
t.plan(3);
|
|
253
|
+
|
|
254
|
+
var files = [
|
|
255
|
+
{
|
|
256
|
+
src: path.normalize("test/fixtures/nwapp/images/imagefile.img"),
|
|
257
|
+
dest: path.normalize("images/imagefile.img"),
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
src: path.normalize("test/fixtures/nwapp/package.json"),
|
|
261
|
+
dest: path.normalize("package.json"),
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
expectedPackage = "{hello: 'world'}";
|
|
265
|
+
|
|
266
|
+
var _evt = new EventEmitter();
|
|
267
|
+
_evt.on("log", function (logging) {
|
|
268
|
+
t.ok(logging, "LOG: " + logging);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
utils.generateZipFile(files, _evt, expectedPackage).then(function (nwfile) {
|
|
272
|
+
var unzipper = new DecompressZip(nwfile),
|
|
273
|
+
unzipDestination = "test/temp/platform-specific-unzipped";
|
|
274
|
+
|
|
275
|
+
unzipper.on("extract", function () {
|
|
276
|
+
t.equal(
|
|
277
|
+
fs
|
|
278
|
+
.readFileSync(path.join(unzipDestination, "package.json"))
|
|
279
|
+
.toString(),
|
|
280
|
+
expectedPackage,
|
|
281
|
+
);
|
|
282
|
+
t.end();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
unzipper.extract({
|
|
286
|
+
path: unzipDestination,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
test("mergeFiles", async function (t) {
|
|
293
|
+
await t.plan(isWindows ? 1 : 2);
|
|
294
|
+
|
|
295
|
+
var releasefile = temp.openSync();
|
|
296
|
+
fs.writeFileSync(releasefile.path, "A");
|
|
297
|
+
|
|
298
|
+
var zipFile = temp.openSync();
|
|
299
|
+
fs.writeFileSync(zipFile.path, "B");
|
|
300
|
+
|
|
301
|
+
await utils.mergeFiles(releasefile.path, zipFile.path, "0755").then(function () {
|
|
302
|
+
var contents = fs.readFileSync(releasefile.path);
|
|
303
|
+
var stats = fs.lstatSync(releasefile.path);
|
|
304
|
+
t.equal(contents.toString(), "AB", "merge two files");
|
|
305
|
+
|
|
306
|
+
if (!isWindows) {
|
|
307
|
+
t.equal(stats.mode.toString(8), "100755", "fix the permission"); // DOES NOT WORK ON WINDOWS
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|