@@ -45,8 +45,6 @@
|
|
45
45
|
* @returns {Promise<string | null>}
|
46
46
|
*/
|
47
47
|
module.exports.resolveLicense = async function (license) {
|
48
|
-
console.log("\n");
|
49
|
-
|
50
48
|
if (typeof license !== "object") {
|
51
49
|
return license;
|
52
50
|
}
|
@@ -60,7 +58,7 @@
|
|
60
58
|
return null;
|
61
59
|
}
|
62
60
|
|
63
|
-
console.log("Resolve license for " + license.id + "::" + license.key);
|
61
|
+
console.log("INFO: Resolve license for " + license.id + "::" + license.key);
|
64
62
|
const url = await fetch(LICENSE_ENDPOINT, { method: "GET" });
|
65
63
|
if (!url.ok) {
|
66
64
|
console.warn("WARN: Failed to fetch license URL from endpoint. " + url.statusText);
|
@@ -8,57 +8,45 @@
|
|
8
8
|
* @param {import('../types/userconfig.js').userSettings}
|
9
9
|
*/
|
10
10
|
export const needleLicense = (command, config, userSettings) => {
|
11
|
+
let license = undefined;
|
12
|
+
|
11
13
|
return {
|
12
14
|
name: "needle-license",
|
13
15
|
enforce: 'pre',
|
16
|
+
async configResolved() {
|
17
|
+
if (userSettings.license) {
|
18
|
+
// we only accept a license object here
|
19
|
+
if (typeof userSettings.license === "object")
|
20
|
+
license = await resolveLicense(userSettings.license);
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
const needleConfig = await loadConfig();
|
24
|
+
if (needleConfig) {
|
25
|
+
license = await resolveLicense(needleConfig.license);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
14
29
|
async transform(src, id) {
|
15
30
|
const isNeedleEngineFile = id.includes("engine/engine_license") || id.includes("needle-tools_engine");
|
16
31
|
// sometimes the actual license parameter is in a unnamed chunk file
|
17
32
|
const isViteChunkFile = id.includes("chunk") && id.includes(".vite");
|
18
33
|
if (isNeedleEngineFile || isViteChunkFile) {
|
19
34
|
|
20
|
-
if (
|
21
|
-
|
22
|
-
if (typeof userSettings.license === "object")
|
23
|
-
await applyLicense(userSettings.license);
|
35
|
+
if (!license) {
|
36
|
+
return;
|
24
37
|
}
|
25
|
-
else {
|
26
|
-
const needleConfig = await loadConfig();
|
27
|
-
if (needleConfig) {
|
28
|
-
await applyLicense(needleConfig.license);
|
29
|
-
}
|
30
|
-
}
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
const index = src.indexOf("NEEDLE_ENGINE_LICENSE_TYPE");
|
40
|
+
if (index >= 0) {
|
41
|
+
const end = src.indexOf(";", index);
|
42
|
+
if (end >= 0) {
|
43
|
+
const line = src.substring(index, end);
|
44
|
+
const replaced = "NEEDLE_ENGINE_LICENSE_TYPE = \"" + license + "\"";
|
45
|
+
src = src.replace(line, replaced);
|
46
|
+
return { code: src, map: null }
|
39
47
|
}
|
40
|
-
|
41
|
-
// TODO: remove allowing to apply a string license here
|
42
|
-
|
43
|
-
if (typeof license !== "string") {
|
44
|
-
license = await resolveLicense(license).catch(err => {
|
45
|
-
console.error("Error resolving license", err.message);
|
46
|
-
return null;
|
47
|
-
});
|
48
|
-
}
|
49
|
-
|
50
|
-
const index = src.indexOf("NEEDLE_ENGINE_LICENSE_TYPE");
|
51
|
-
if (index >= 0) {
|
52
|
-
const end = src.indexOf(";", index);
|
53
|
-
if (end >= 0) {
|
54
|
-
const line = src.substring(index, end);
|
55
|
-
const replaced = "NEEDLE_ENGINE_LICENSE_TYPE = \"" + license + "\"";
|
56
|
-
src = src.replace(line, replaced);
|
57
|
-
return { code: src, map: null }
|
58
|
-
}
|
59
|
-
}
|
60
48
|
}
|
61
49
|
}
|
62
50
|
}
|
63
51
|
}
|
64
|
-
};
|
52
|
+
};
|