This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnpmScriptsManager.js
66 lines (55 loc) · 1.96 KB
/
npmScriptsManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const SCRIPT_TEMPLATES = Object.freeze({
"ns-bundle": "ns-bundle",
"start-[PLATFORM]-bundle": "npm run ns-bundle --[PLATFORM] --run-app",
"build-[PLATFORM]-bundle": "npm run ns-bundle --[PLATFORM] --build-app",
"publish-ios-bundle": "npm run ns-bundle --ios --publish-app",
"generate-android-snapshot": "generate-android-snapshot --targetArchs arm,arm64,ia32 --install"
});
const DEPRECATED_SCRIPT_TEMPLATES = Object.freeze([
"clean-[PLATFORM]",
"prewebpack-[PLATFORM]",
"webpack-[PLATFORM]",
"prestart-[PLATFORM]-bundle",
"prebuild-[PLATFORM]-bundle",
]);
const PLATFORMS = Object.freeze(["android", "ios"]);
function addNpmScripts(scripts = {}) {
Object.keys(SCRIPT_TEMPLATES).forEach(name => {
addPlatformScript(scripts, name, SCRIPT_TEMPLATES[name]);
});
}
function removeDeprecatedNpmScripts(scripts) {
return removeNpmScripts(scripts, DEPRECATED_SCRIPT_TEMPLATES);
}
function removeNpmScripts(scripts, scriptTemplates = Object.keys(SCRIPT_TEMPLATES)) {
scriptTemplates.forEach(templateName => {
removePlatformScripts(scripts, templateName);
});
}
function addPlatformScript(scripts, nameTemplate, commandTemplate) {
PLATFORMS.forEach(platform => {
const name = nameTemplate.replace(/\[PLATFORM\]/g, platform);
const command = commandTemplate.replace(/\[PLATFORM\]/g, platform);
if (!scripts[name]) {
console.info(`Registering script: ${name}`);
scripts[name] = command;
}
});
}
function removePlatformScripts(scripts, nameTemplate) {
PLATFORMS.forEach(platform => {
const name = nameTemplate.replace(/\[PLATFORM\]/g, platform);
delete scripts[name];
});
}
function forceUpdateNpmScripts(scripts) {
removeDeprecatedNpmScripts(scripts);
removeNpmScripts(scripts);
addNpmScripts(scripts);
}
module.exports = {
addNpmScripts,
removeDeprecatedNpmScripts,
removeNpmScripts,
forceUpdateNpmScripts,
};