nw-builder 3.6.0 → 3.7.0
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/.github/CHANGELOG.md +58 -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 +7 -4
- package/README.md +81 -23
- package/bin/nwbuild.cjs +97 -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/platforms.cjs +141 -0
- package/lib/utils.cjs +293 -0
- package/lib/versions.cjs +206 -0
- package/package.json +56 -28
- package/src/index.js +2 -0
- package/src/schema/Platform.js +16 -0
- package/src/schema/index.js +3 -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/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/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 +486 -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
|
@@ -6,45 +6,58 @@ Apply platform-specific manifest values. Works with JSON or plain objects. The p
|
|
|
6
6
|
|
|
7
7
|
var applyOverrides, detectPlatform, getOverridesToApply, os, _;
|
|
8
8
|
|
|
9
|
-
os = require(
|
|
10
|
-
_ = require(
|
|
9
|
+
os = require("os");
|
|
10
|
+
_ = require("lodash");
|
|
11
11
|
|
|
12
|
-
detectPlatform = function() {
|
|
12
|
+
detectPlatform = function () {
|
|
13
13
|
var platform;
|
|
14
14
|
platform = os.platform();
|
|
15
|
-
if (platform ===
|
|
16
|
-
platform =
|
|
15
|
+
if (platform === "darwin") {
|
|
16
|
+
platform = "osx";
|
|
17
17
|
} else if (platform.match(/^win/)) {
|
|
18
|
-
platform =
|
|
18
|
+
platform = "win";
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
21
|
agnostic: platform,
|
|
22
|
-
specific:
|
|
22
|
+
specific:
|
|
23
|
+
platform +
|
|
24
|
+
(process.arch === "x64" ||
|
|
25
|
+
Object.prototype.hasOwnProperty.call(
|
|
26
|
+
process.env,
|
|
27
|
+
"PROCESSOR_ARCHITEW6432",
|
|
28
|
+
)
|
|
29
|
+
? 64
|
|
30
|
+
: 32),
|
|
23
31
|
};
|
|
24
32
|
};
|
|
25
33
|
|
|
26
|
-
getOverridesToApply = function(platform, cb) {
|
|
34
|
+
getOverridesToApply = function (platform, cb) {
|
|
27
35
|
var agnosticPlatform, architectureAgnostic, architectureSpecific, _i, _len;
|
|
28
|
-
architectureAgnostic = [
|
|
36
|
+
architectureAgnostic = ["linux", "osx", "win"];
|
|
29
37
|
architectureSpecific = [];
|
|
30
38
|
for (_i = 0, _len = architectureAgnostic.length; _i < _len; _i++) {
|
|
31
39
|
agnosticPlatform = architectureAgnostic[_i];
|
|
32
|
-
architectureSpecific.push(agnosticPlatform +
|
|
33
|
-
architectureSpecific.push(agnosticPlatform +
|
|
40
|
+
architectureSpecific.push(agnosticPlatform + "32");
|
|
41
|
+
architectureSpecific.push(agnosticPlatform + "64");
|
|
34
42
|
}
|
|
35
43
|
if (platform) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
44
|
+
if (
|
|
45
|
+
!(
|
|
46
|
+
architectureAgnostic.indexOf(platform) > -1 ||
|
|
47
|
+
architectureSpecific.indexOf(platform) > -1
|
|
48
|
+
)
|
|
49
|
+
) {
|
|
50
|
+
return cb(new Error("Invalid platform passed", null));
|
|
38
51
|
}
|
|
39
52
|
if (architectureAgnostic.indexOf(platform) > -1) {
|
|
40
53
|
return cb(null, {
|
|
41
54
|
agnostic: platform,
|
|
42
|
-
specific: null
|
|
55
|
+
specific: null,
|
|
43
56
|
});
|
|
44
57
|
} else {
|
|
45
58
|
return cb(null, {
|
|
46
59
|
agnostic: platform.substr(0, platform.length - 2),
|
|
47
|
-
specific: platform
|
|
60
|
+
specific: platform,
|
|
48
61
|
});
|
|
49
62
|
}
|
|
50
63
|
} else {
|
|
@@ -52,30 +65,39 @@ getOverridesToApply = function(platform, cb) {
|
|
|
52
65
|
}
|
|
53
66
|
};
|
|
54
67
|
|
|
55
|
-
applyOverrides = function(_arg) {
|
|
68
|
+
applyOverrides = function (_arg) {
|
|
56
69
|
var cb, options, platform, result;
|
|
57
|
-
platform = _arg.platform, options = _arg.options, cb = _arg.cb;
|
|
70
|
+
(platform = _arg.platform), (options = _arg.options), (cb = _arg.cb);
|
|
58
71
|
result = _.cloneDeep(options);
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
if (
|
|
73
|
+
options.platformOverrides[platform] != null &&
|
|
74
|
+
Object.keys(options.platformOverrides[platform]).length
|
|
75
|
+
) {
|
|
76
|
+
result = _.mergeWith(
|
|
77
|
+
result,
|
|
78
|
+
options.platformOverrides[platform],
|
|
79
|
+
function (optionValue, overrideValue) {
|
|
80
|
+
/*
|
|
63
81
|
If overrides.x is {} but source.x is a non-empty object {prop:0, another:2},
|
|
64
82
|
take the {}}
|
|
65
83
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
if (
|
|
85
|
+
(_.isPlainObject(overrideValue) || _.isArray(overrideValue)) &&
|
|
86
|
+
_.isEmpty(overrideValue)
|
|
87
|
+
) {
|
|
88
|
+
return overrideValue;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
);
|
|
70
92
|
}
|
|
71
93
|
return cb(result);
|
|
72
94
|
};
|
|
73
95
|
|
|
74
|
-
module.exports = function(_arg, cb) {
|
|
96
|
+
module.exports = function (_arg, cb) {
|
|
75
97
|
var callback, options, platform;
|
|
76
|
-
options = _arg.options, platform = _arg.platform;
|
|
77
|
-
callback = cb != null ? cb :
|
|
78
|
-
return getOverridesToApply(platform, function(err, overridesToApply) {
|
|
98
|
+
(options = _arg.options), (platform = _arg.platform);
|
|
99
|
+
callback = cb != null ? cb : function () {};
|
|
100
|
+
return getOverridesToApply(platform, function (err, overridesToApply) {
|
|
79
101
|
var applySpecificOverrides, objectMode, originalOptions;
|
|
80
102
|
if (err != null) {
|
|
81
103
|
return callback(err, null);
|
|
@@ -89,28 +111,31 @@ module.exports = function(_arg, cb) {
|
|
|
89
111
|
return callback(err, null);
|
|
90
112
|
}
|
|
91
113
|
if (options.platformOverrides != null) {
|
|
92
|
-
applySpecificOverrides = function(optionsToOverride) {
|
|
114
|
+
applySpecificOverrides = function (optionsToOverride) {
|
|
93
115
|
return applyOverrides({
|
|
94
116
|
platform: overridesToApply.specific,
|
|
95
117
|
options: optionsToOverride,
|
|
96
|
-
cb: function(result) {
|
|
118
|
+
cb: function (result) {
|
|
97
119
|
delete result.platformOverrides;
|
|
98
120
|
return callback(null, objectMode ? result : JSON.stringify(result));
|
|
99
|
-
}
|
|
121
|
+
},
|
|
100
122
|
});
|
|
101
123
|
};
|
|
102
124
|
if (overridesToApply.agnostic != null) {
|
|
103
125
|
return applyOverrides({
|
|
104
126
|
platform: overridesToApply.agnostic,
|
|
105
127
|
options: options,
|
|
106
|
-
cb: function(result) {
|
|
128
|
+
cb: function (result) {
|
|
107
129
|
if (overridesToApply.specific != null) {
|
|
108
130
|
return applySpecificOverrides(result);
|
|
109
131
|
} else {
|
|
110
132
|
delete result.platformOverrides;
|
|
111
|
-
return callback(
|
|
133
|
+
return callback(
|
|
134
|
+
null,
|
|
135
|
+
objectMode ? result : JSON.stringify(result),
|
|
136
|
+
);
|
|
112
137
|
}
|
|
113
|
-
}
|
|
138
|
+
},
|
|
114
139
|
});
|
|
115
140
|
} else {
|
|
116
141
|
return applySpecificOverrides(options);
|
|
@@ -119,4 +144,4 @@ module.exports = function(_arg, cb) {
|
|
|
119
144
|
return callback(null, originalOptions);
|
|
120
145
|
}
|
|
121
146
|
});
|
|
122
|
-
};
|
|
147
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var semver = require("semver");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
win32: {
|
|
5
|
+
needsZip: true,
|
|
6
|
+
getRunnable: function () {
|
|
7
|
+
return "nw.exe";
|
|
8
|
+
},
|
|
9
|
+
files: {
|
|
10
|
+
// First file must be the executable
|
|
11
|
+
"<=0.9.2": [
|
|
12
|
+
"nw.exe",
|
|
13
|
+
"ffmpegsumo.dll",
|
|
14
|
+
"icudt.dll",
|
|
15
|
+
"libEGL.dll",
|
|
16
|
+
"libGLESv2.dll",
|
|
17
|
+
"nw.pak",
|
|
18
|
+
],
|
|
19
|
+
">0.9.2 <0.12.0": [
|
|
20
|
+
"nw.exe",
|
|
21
|
+
"ffmpegsumo.dll",
|
|
22
|
+
"icudtl.dat",
|
|
23
|
+
"libEGL.dll",
|
|
24
|
+
"libGLESv2.dll",
|
|
25
|
+
"nw.pak",
|
|
26
|
+
"locales",
|
|
27
|
+
],
|
|
28
|
+
">=0.12.0": [
|
|
29
|
+
"nw.exe",
|
|
30
|
+
"ffmpegsumo.dll",
|
|
31
|
+
"icudtl.dat",
|
|
32
|
+
"libEGL.dll",
|
|
33
|
+
"libGLESv2.dll",
|
|
34
|
+
"nw.pak",
|
|
35
|
+
"locales",
|
|
36
|
+
"d3dcompiler_47.dll",
|
|
37
|
+
"pdf.dll",
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
versionNameTemplate: "v${ version }/${ name }-v${ version }-win-ia32.zip",
|
|
41
|
+
},
|
|
42
|
+
win64: {
|
|
43
|
+
needsZip: true,
|
|
44
|
+
getRunnable: function () {
|
|
45
|
+
return "nw.exe";
|
|
46
|
+
},
|
|
47
|
+
files: {
|
|
48
|
+
// First file must be the executable
|
|
49
|
+
"<=0.9.2": [
|
|
50
|
+
"nw.exe",
|
|
51
|
+
"ffmpegsumo.dll",
|
|
52
|
+
"icudt.dll",
|
|
53
|
+
"libEGL.dll",
|
|
54
|
+
"libGLESv2.dll",
|
|
55
|
+
"nw.pak",
|
|
56
|
+
"locales",
|
|
57
|
+
],
|
|
58
|
+
">0.9.2 <0.12.0": [
|
|
59
|
+
"nw.exe",
|
|
60
|
+
"ffmpegsumo.dll",
|
|
61
|
+
"icudtl.dat",
|
|
62
|
+
"libEGL.dll",
|
|
63
|
+
"libGLESv2.dll",
|
|
64
|
+
"nw.pak",
|
|
65
|
+
"locales",
|
|
66
|
+
],
|
|
67
|
+
">=0.12.0": [
|
|
68
|
+
"nw.exe",
|
|
69
|
+
"ffmpegsumo.dll",
|
|
70
|
+
"icudtl.dat",
|
|
71
|
+
"libEGL.dll",
|
|
72
|
+
"libGLESv2.dll",
|
|
73
|
+
"nw.pak",
|
|
74
|
+
"locales",
|
|
75
|
+
"d3dcompiler_47.dll",
|
|
76
|
+
"pdf.dll",
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
versionNameTemplate: "v${ version }/${ name }-v${ version }-win-x64.zip",
|
|
80
|
+
},
|
|
81
|
+
osx32: {
|
|
82
|
+
needsZip: false,
|
|
83
|
+
getRunnable: function (version) {
|
|
84
|
+
if (semver.satisfies(version, ">=0.12.0 || ~0.12.0-alpha")) {
|
|
85
|
+
return "nwjs.app/Contents/MacOS/nwjs";
|
|
86
|
+
} else {
|
|
87
|
+
return "node-webkit.app/Contents/MacOS/node-webkit";
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
files: {
|
|
91
|
+
"<0.12.0-alpha": ["node-webkit.app"],
|
|
92
|
+
">=0.12.0 || ~0.12.0-alpha": ["nwjs.app"],
|
|
93
|
+
},
|
|
94
|
+
versionNameTemplate: "v${ version }/${ name }-v${ version }-osx-ia32.zip",
|
|
95
|
+
},
|
|
96
|
+
osx64: {
|
|
97
|
+
needsZip: false,
|
|
98
|
+
getRunnable: function (version) {
|
|
99
|
+
if (semver.satisfies(version, ">=0.12.0 || ~0.12.0-alpha")) {
|
|
100
|
+
return "nwjs.app/Contents/MacOS/nwjs";
|
|
101
|
+
} else {
|
|
102
|
+
return "node-webkit.app/Contents/MacOS/node-webkit";
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
files: {
|
|
106
|
+
"<0.12.0-alpha": ["node-webkit.app"],
|
|
107
|
+
">=0.12.0 || ~0.12.0-alpha": ["nwjs.app"],
|
|
108
|
+
},
|
|
109
|
+
versionNameTemplate: "v${ version }/${ name }-v${ version }-osx-x64.zip",
|
|
110
|
+
},
|
|
111
|
+
linux32: {
|
|
112
|
+
needsZip: true,
|
|
113
|
+
chmod: "0755",
|
|
114
|
+
getRunnable: function () {
|
|
115
|
+
return "nw";
|
|
116
|
+
},
|
|
117
|
+
files: {
|
|
118
|
+
// First file must be the executable
|
|
119
|
+
"<=0.9.2": ["nw", "nw.pak", "libffmpegsumo.so"],
|
|
120
|
+
">0.9.2 <=0.10.1": ["nw", "nw.pak", "libffmpegsumo.so", "icudtl.dat"],
|
|
121
|
+
">0.10.1": ["nw", "nw.pak", "libffmpegsumo.so", "icudtl.dat", "locales"],
|
|
122
|
+
},
|
|
123
|
+
versionNameTemplate:
|
|
124
|
+
"v${ version }/${ name }-v${ version }-linux-ia32.tar.gz",
|
|
125
|
+
},
|
|
126
|
+
linux64: {
|
|
127
|
+
needsZip: true,
|
|
128
|
+
chmod: "0755", // chmod file file to be executable
|
|
129
|
+
getRunnable: function () {
|
|
130
|
+
return "nw";
|
|
131
|
+
},
|
|
132
|
+
files: {
|
|
133
|
+
// First file must be the executable
|
|
134
|
+
"<=0.9.2": ["nw", "nw.pak", "libffmpegsumo.so"],
|
|
135
|
+
">0.9.2 <=0.10.1": ["nw", "nw.pak", "libffmpegsumo.so", "icudtl.dat"],
|
|
136
|
+
">0.10.1": ["nw", "nw.pak", "libffmpegsumo.so", "icudtl.dat", "locales"],
|
|
137
|
+
},
|
|
138
|
+
versionNameTemplate:
|
|
139
|
+
"v${ version }/${ name }-v${ version }-linux-x64.tar.gz",
|
|
140
|
+
},
|
|
141
|
+
};
|
package/lib/utils.cjs
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
var fs = require("graceful-fs-extra");
|
|
2
|
+
var path = require("path");
|
|
3
|
+
var _ = require("lodash");
|
|
4
|
+
var plist = require("plist");
|
|
5
|
+
var Glob = require("simple-glob");
|
|
6
|
+
var temp = require("temp");
|
|
7
|
+
var archiver = require("archiver");
|
|
8
|
+
var thenify = require("thenify");
|
|
9
|
+
|
|
10
|
+
var readFile = thenify(fs.readFile);
|
|
11
|
+
var writeFile = thenify(fs.writeFile);
|
|
12
|
+
|
|
13
|
+
// Automatically track and cleanup files at exit
|
|
14
|
+
temp.track();
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
getPackageInfo: function (path) {
|
|
18
|
+
return new Promise(function (resolve, reject) {
|
|
19
|
+
fs.readFile(path, function (err, data) {
|
|
20
|
+
if (err) return reject(err);
|
|
21
|
+
try {
|
|
22
|
+
var appPkg = JSON.parse(data);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(
|
|
25
|
+
"Invalid package.json: " +
|
|
26
|
+
e +
|
|
27
|
+
"\nMake sure the file is encoded as utf-8",
|
|
28
|
+
);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!appPkg.name || !appPkg.version) {
|
|
32
|
+
reject(
|
|
33
|
+
"Please make sure that your project's package.json includes a version and a name value",
|
|
34
|
+
);
|
|
35
|
+
} else {
|
|
36
|
+
resolve(appPkg);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
getFileList: function (fileglob) {
|
|
42
|
+
var self = this,
|
|
43
|
+
jsonfile,
|
|
44
|
+
destFiles = [],
|
|
45
|
+
srcFiles = [],
|
|
46
|
+
package_path,
|
|
47
|
+
matches = Glob(fileglob);
|
|
48
|
+
|
|
49
|
+
return new Promise(function (resolve, reject) {
|
|
50
|
+
if (!matches.length) return reject("No files matching");
|
|
51
|
+
|
|
52
|
+
matches.forEach(function (file) {
|
|
53
|
+
var internalFileName = path.normalize(file);
|
|
54
|
+
if (internalFileName.match("package.json")) {
|
|
55
|
+
jsonfile = self.closerPathDepth(internalFileName, jsonfile);
|
|
56
|
+
package_path = path.normalize(
|
|
57
|
+
jsonfile.split("package.json")[0] || "./",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (!fs.lstatSync(internalFileName).isDirectory()) {
|
|
61
|
+
srcFiles.push(internalFileName);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!jsonfile) {
|
|
66
|
+
return reject("Could not find a package.json in your src folder");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
srcFiles.forEach(function (file) {
|
|
70
|
+
destFiles.push({
|
|
71
|
+
src: file,
|
|
72
|
+
dest: file.replace(package_path, ""),
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
resolve({
|
|
77
|
+
files: destFiles,
|
|
78
|
+
json: jsonfile,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
closerPathDepth: function (path1, path2) {
|
|
83
|
+
if (!path2) {
|
|
84
|
+
return path1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
var d1 = this.pathDepth(path1),
|
|
88
|
+
d2 = this.pathDepth(path2);
|
|
89
|
+
|
|
90
|
+
return d1 < d2 ? path1 : path2;
|
|
91
|
+
},
|
|
92
|
+
pathDepth: function (absolutePath) {
|
|
93
|
+
return absolutePath.split(path.sep).length;
|
|
94
|
+
},
|
|
95
|
+
copyFile: function (src, dest, _event, options) {
|
|
96
|
+
return new Promise(function (resolve, reject) {
|
|
97
|
+
options = options || {};
|
|
98
|
+
var stats = fs.lstatSync(src);
|
|
99
|
+
fs.copy(src, dest, options, function (err) {
|
|
100
|
+
if (err) return reject(err);
|
|
101
|
+
|
|
102
|
+
var retryCount = 0;
|
|
103
|
+
var existsCallback = function (exists) {
|
|
104
|
+
if (exists) {
|
|
105
|
+
fs.chmod(dest, stats.mode, function (err) {
|
|
106
|
+
// ignore error
|
|
107
|
+
if (err) {
|
|
108
|
+
_event.emit(
|
|
109
|
+
"log",
|
|
110
|
+
"chmod " +
|
|
111
|
+
stats.mode +
|
|
112
|
+
" on " +
|
|
113
|
+
dest +
|
|
114
|
+
" failed after copying, ignoring",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
} else if (retryCount++ < 2) {
|
|
121
|
+
// This is antipattern!!!
|
|
122
|
+
// Callback should be called when the copy is finished!!!!
|
|
123
|
+
setTimeout(function () {
|
|
124
|
+
fs.exists(dest, existsCallback);
|
|
125
|
+
}, 1000);
|
|
126
|
+
} else {
|
|
127
|
+
reject(
|
|
128
|
+
new Error(
|
|
129
|
+
"Copied file (" +
|
|
130
|
+
dest +
|
|
131
|
+
") doesn't exist in destination after copying",
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
fs.exists(dest, existsCallback);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
mergeFiles: function (app, zipfile, chmod) {
|
|
142
|
+
// we need to pipe the app into the zipfile and chmod it
|
|
143
|
+
return new Promise(function (resolve, reject) {
|
|
144
|
+
var zipStream = fs.createReadStream(zipfile),
|
|
145
|
+
writeStream = fs.createWriteStream(app, { flags: "a" });
|
|
146
|
+
|
|
147
|
+
zipStream.on("error", reject);
|
|
148
|
+
writeStream.on("error", reject);
|
|
149
|
+
|
|
150
|
+
writeStream.on("finish", function () {
|
|
151
|
+
if (chmod) {
|
|
152
|
+
fs.chmodSync(app, chmod);
|
|
153
|
+
}
|
|
154
|
+
resolve();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
zipStream.pipe(writeStream);
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
generateZipFile: function (
|
|
161
|
+
files,
|
|
162
|
+
_event,
|
|
163
|
+
platformSpecificManifest,
|
|
164
|
+
zipOptions,
|
|
165
|
+
) {
|
|
166
|
+
var destStream = temp.createWriteStream(),
|
|
167
|
+
archive = archiver("zip", zipOptions || {});
|
|
168
|
+
|
|
169
|
+
return new Promise(function (resolve, reject) {
|
|
170
|
+
// Resolve on close
|
|
171
|
+
destStream.on("close", function () {
|
|
172
|
+
resolve(destStream.path);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Reject on Error
|
|
176
|
+
archive.on("error", reject);
|
|
177
|
+
|
|
178
|
+
// Add the files
|
|
179
|
+
files.forEach(function (file) {
|
|
180
|
+
if (file.dest === "package.json" && platformSpecificManifest) {
|
|
181
|
+
archive.append(platformSpecificManifest, { name: "package.json" });
|
|
182
|
+
} else {
|
|
183
|
+
archive.file(file.src, { name: file.dest });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Some logs
|
|
188
|
+
archive.on("entry", function (file) {
|
|
189
|
+
_event.emit("log", "Zipping " + file.name);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Pipe the stream
|
|
193
|
+
archive.pipe(destStream);
|
|
194
|
+
archive.finalize();
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
getPlistOptions: function (parsedParams, custom) {
|
|
198
|
+
var obj = {};
|
|
199
|
+
if (parsedParams.name) {
|
|
200
|
+
obj.CFBundleName = parsedParams.name;
|
|
201
|
+
obj.CFBundleDisplayName = parsedParams.name;
|
|
202
|
+
}
|
|
203
|
+
if (parsedParams.version) {
|
|
204
|
+
obj.CFBundleVersion = parsedParams.version;
|
|
205
|
+
obj.CFBundleShortVersionString = "Version " + parsedParams.version;
|
|
206
|
+
}
|
|
207
|
+
if (parsedParams.copyright) {
|
|
208
|
+
obj.NSHumanReadableCopyright = parsedParams.copyright;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return _.merge(obj, custom);
|
|
212
|
+
},
|
|
213
|
+
editPlist: function (plistInput, plistOutput, options) {
|
|
214
|
+
options = options || {};
|
|
215
|
+
|
|
216
|
+
// Make sure all required properties are set
|
|
217
|
+
[
|
|
218
|
+
"CFBundleName",
|
|
219
|
+
"CFBundleDisplayName",
|
|
220
|
+
"CFBundleVersion",
|
|
221
|
+
"CFBundleShortVersionString",
|
|
222
|
+
].forEach(function (prop) {
|
|
223
|
+
if (!Object.prototype.hasOwnProperty.call(options, prop)) {
|
|
224
|
+
throw new Error("Missing macPlist property '" + prop + "'");
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Bundle identifier based on package name
|
|
229
|
+
if (options.CFBundleIdentifier === undefined) {
|
|
230
|
+
options.CFBundleIdentifier =
|
|
231
|
+
"com.nw-builder." +
|
|
232
|
+
options.CFBundleName.toLowerCase().replace(/[^a-z-]/g, "");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Read the input file
|
|
236
|
+
return (
|
|
237
|
+
readFile(plistInput, "utf8")
|
|
238
|
+
// Parse it
|
|
239
|
+
.then(plist.parse)
|
|
240
|
+
// Then overwrite the properties with custom values
|
|
241
|
+
.then(function (info) {
|
|
242
|
+
// Keep backwards compatibility and handle aliases
|
|
243
|
+
Object.keys(options).forEach(function (key) {
|
|
244
|
+
var value = options[key];
|
|
245
|
+
switch (key) {
|
|
246
|
+
case "mac_bundle_id":
|
|
247
|
+
info.CFBundleIdentifier = value;
|
|
248
|
+
break;
|
|
249
|
+
case "mac_document_types":
|
|
250
|
+
info.CFBundleDocumentTypes = value.map(function (type) {
|
|
251
|
+
return {
|
|
252
|
+
CFBundleTypeName: type.name,
|
|
253
|
+
CFBundleTypeExtensions: type.extensions,
|
|
254
|
+
CFBundleTypeRole: type.role,
|
|
255
|
+
LSIsAppleDefaultForType: type.isDefault,
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
info[key] = value;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Remove some unwanted properties
|
|
265
|
+
if (
|
|
266
|
+
!(
|
|
267
|
+
Object.prototype.hasOwnProperty.call(
|
|
268
|
+
options,
|
|
269
|
+
"mac_document_types",
|
|
270
|
+
) ||
|
|
271
|
+
Object.prototype.hasOwnProperty.call(
|
|
272
|
+
options,
|
|
273
|
+
"CFBundleDocumentTypes",
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
) {
|
|
277
|
+
info.CFBundleDocumentTypes = [];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (
|
|
281
|
+
!Object.prototype.hasOwnProperty.call(
|
|
282
|
+
options,
|
|
283
|
+
"UTExportedTypeDeclarations",
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
info.UTExportedTypeDeclarations = [];
|
|
287
|
+
|
|
288
|
+
// Write output file
|
|
289
|
+
return writeFile(plistOutput, plist.build(info));
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
},
|
|
293
|
+
};
|