-
Notifications
You must be signed in to change notification settings - Fork 10
/
prepEnv.js
55 lines (51 loc) · 2.17 KB
/
prepEnv.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
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// This script is used to setup different build configurations
// run by ` node prepEnv.js branded ` for ml-machine-branded config
import { copyFile } from 'fs';
// Validate input
const args = process.argv;
if (args.length < 3) {
throw new Error("Not enough arguments. Try 'node prepEnv.js branded' ")
}
if (args.length > 3) {
throw new Error("Too many arguments. Try 'node prepEnv.js branded' ")
}
// Configure build script and validate input
const fileMoveTargets = {
"branded": [
// Set source(first) and destination(second)
['./src/__viteBuildVariants__/ml-machine/windi.config.js', './windi.config.js'],
['./src/__viteBuildVariants__/ml-machine/features.json', './features.json']
],
"unbranded": [
['./src/__viteBuildVariants__/unbranded/windi.config.js', './windi.config.js'],
['./src/__viteBuildVariants__/unbranded/features.json', './features.json']
],
"simple": [
['./src/__viteBuildVariants__/ml-machine-simple/windi.config.js', './windi.config.js'],
['./src/__viteBuildVariants__/ml-machine-simple/features.json', './features.json']
]
}
const availableTargets = Object.getOwnPropertyNames(fileMoveTargets);
const buildVariantTarget = args[2];
if (!availableTargets.includes(buildVariantTarget)) {
const listTargets = availableTargets.map(target => ` node prepEnv.js ${target}`).join("\n") + "\n";
const errorMessage = `Invalid build variant target!\nUse on of the following build targets: \n${listTargets}`;
throw new Error(errorMessage);
}
// The actual work
const copyFiles = fileMoveTargets[buildVariantTarget];
copyFiles.forEach(element => {
const source = element[0];
const destination = element[1];
copyFile(source, destination, (err) => {
console.log("Copied ", element[0], " -> ", element[1])
if (err) {
console.error("Failed to move ", source, " to ", destination)
throw new Error(err)
}
})
});