Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 48999fe

Browse files
committed
refactor: fetch v8Versions map from external url
1 parent b76ab7f commit 48999fe

File tree

4 files changed

+79
-56
lines changed

4 files changed

+79
-56
lines changed

‎bin/ns-bundle‎

100644100755
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
const { spawn } = require("child_process");
44
const { resolve: pathResolve, join } = require("path");
55
const { existsSync } = require("fs");
6+
7+
const semver = require("semver");
8+
69
const { getPackageJson } = require("../projectHelpers");
7-
const { isVersionGte } = require("../utils");
810

911
const PROJECT_DIR = pathResolve(__dirname, "../../../");
1012
const packageJson = getPackageJson(PROJECT_DIR);
@@ -79,7 +81,8 @@ function cleanBuildArtefacts(platform) {
7981
getTnsVersion().then(version => {
8082
// the android build artefacts should be cleaned manually
8183
// for nativescript-cli v3.0.1 and below or if using uglify
82-
if (!isVersionGte(version, "3.0.1") || shouldUglify()) {
84+
version = version.replace(/-(.*)/, "");
85+
if (!semver.gte(version, "3.0.1") || shouldUglify()) {
8386
gradlewClean().then(resolve).catch(throwError);
8487
} else {
8588
return resolve();

‎snapshot/android/project-snapshot-generator.js‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const semver = require("semver");
77

88
const SnapshotGenerator = require("./snapshot-generator");
99
const TnsJavaClassesGenerator = require("./tns-java-classes-generator");
10+
const { getJsonFile } = require("./utils");
1011
const { getPackageJson } = require("../../projectHelpers");
1112

1213
const MIN_ANDROID_RUNTIME_VERSION = "3.0.0";
1314
const VALID_ANDROID_RUNTIME_TAGS = Object.freeze(["next", "rc"]);
15+
const V8_VERSIONS_URL = "https://api.myjson.com/bins/b3s3l";
1416

1517
const resolveRelativePath = (path) => {
1618
if (path)
@@ -97,21 +99,14 @@ ProjectSnapshotGenerator.installSnapshotArtefacts = function(projectRoot) {
9799
}
98100

99101
ProjectSnapshotGenerator.prototype.getV8Version = function() {
100-
const runtimeVersion = this.getAndroidRuntimeVersion();
101-
102-
if (!runtimeVersion) {
103-
return;
104-
} else if (
105-
VALID_ANDROID_RUNTIME_TAGS.includes(runtimeVersion) ||
106-
107-
semver.gte(runtimeVersion, "3.1.0")
108-
) {
109-
return "5.5.372";
110-
} else if (semver.gte(runtimeVersion, "2.4.0")) {
111-
return "5.2.361";
112-
} else if (semver.gte(runtimeVersion, "2.0.0")) {
113-
return "4.7.80";
114-
}
102+
const v8VersionsMap = getJsonFile();
103+
const runtimeVersion = this.getAndroidRuntimeVersion(V8_VERSIONS_URL);
104+
105+
const runtimeRange = Object.keys(v8VersionsMap).find(range =>
106+
semver.satisfies(runtimeVersion, range)
107+
);
108+
109+
return v8VersionsMap[runtimeRange];
115110
}
116111

117112
ProjectSnapshotGenerator.prototype.validateAndroidRuntimeVersion = function() {

‎snapshot/android/snapshot-generator.js‎

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const fs = require("fs");
2-
const shelljs = require("shelljs");
32
const { join, dirname } = require("path");
43
const os = require("os");
54
const child_process = require("child_process");
6-
const https = require("https");
5+
6+
const shelljs = require("shelljs");
7+
8+
const { downloadFile } = require("./utils");
79

810
const NDK_BUILD_SEED_PATH = join(__dirname, "snapshot-generator-tools/ndk-build");
911
const BUNDLE_PREAMBLE_PATH = join(__dirname, "snapshot-generator-tools/bundle-preamble.js");
@@ -61,45 +63,10 @@ SnapshotGenerator.prototype.downloadMksnapshotTool = function(snapshotToolsPath,
6163
return snapshotToolsDownloads[mksnapshotToolPath];
6264

6365
const downloadUrl = MKSNAPSHOT_TOOLS_DOWNLOAD_ROOT_URL + mksnapshotToolRelativePath;
64-
snapshotToolsDownloads[mksnapshotToolPath] = this.downloadExecFile(downloadUrl, mksnapshotToolPath);
66+
snapshotToolsDownloads[mksnapshotToolPath] = downloadFile(downloadUrl, mksnapshotToolPath);
6567
return snapshotToolsDownloads[mksnapshotToolPath];
6668
}
6769

68-
SnapshotGenerator.prototype.downloadExecFile = function(url, destinationFilePath) {
69-
return new Promise((resolve, reject) => {
70-
const request = https.get(url, (response) => {
71-
switch (response.statusCode) {
72-
case 200:
73-
shelljs.mkdir("-p", dirname(destinationFilePath));
74-
const file = fs.createWriteStream(destinationFilePath);
75-
file.on('error', function (error) {
76-
return reject(error);
77-
});
78-
file.on("finish", function() {
79-
file.close();
80-
fs.chmodSync(destinationFilePath, 0755);
81-
return resolve(destinationFilePath);
82-
});
83-
response.pipe(file);
84-
break;
85-
case 301:
86-
case 302:
87-
case 303:
88-
const redirectUrl = response.headers.location;
89-
return this.downloadExecFile(redirectUrl, destinationFilePath);
90-
default:
91-
return reject(new Error("Unable to download file at " + url + ". Status code: " + response.statusCode));
92-
}
93-
});
94-
95-
request.end();
96-
97-
request.on('error', function(err) {
98-
return reject(err);
99-
});
100-
});
101-
}
102-
10370
SnapshotGenerator.prototype.convertToAndroidArchName = function(archName) {
10471
switch (archName) {
10572
case "arm": return "armeabi-v7a";
@@ -205,4 +172,4 @@ SnapshotGenerator.prototype.generate = function(options) {
205172
}
206173
return this.buildPath;
207174
});
208-
}
175+
}

‎snapshot/android/utils.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const https = require("https");
2+
3+
const shelljs = require("shelljs");
4+
5+
const downloadFile = (url, destinationFilePath) =>
6+
new Promise((resolve, reject) => {
7+
const request = https.get(url, response => {
8+
switch (response.statusCode) {
9+
case 200:
10+
shelljs.mkdir("-p", dirname(destinationFilePath));
11+
const file = fs.createWriteStream(destinationFilePath);
12+
file.on('error', function (error) {
13+
return reject(error);
14+
});
15+
file.on("finish", function() {
16+
file.close();
17+
fs.chmodSync(destinationFilePath, 0755);
18+
return resolve(destinationFilePath);
19+
});
20+
response.pipe(file);
21+
break;
22+
case 301:
23+
case 302:
24+
case 303:
25+
const redirectUrl = response.headers.location;
26+
return this.downloadExecFile(redirectUrl, destinationFilePath);
27+
default:
28+
return reject(new Error("Unable to download file at " + url + ". Status code: " + response.statusCode));
29+
}
30+
});
31+
32+
request.end();
33+
34+
request.on('error', function(err) {
35+
return reject(err);
36+
});
37+
});
38+
39+
const getJsonFile = url =>
40+
new Promise((resolve, reject) => {
41+
https.get(url, res => {
42+
const body = "";
43+
res.on("data", chunk => {
44+
body += chunk;
45+
})
46+
47+
res.on("end", () => {
48+
const data = JSON.parse(body);
49+
return resolve(data);
50+
});
51+
}).on("error", reject);
52+
});
53+
54+
module.exports = {
55+
downloadFile,
56+
getJsonFile,
57+
};
58+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /