-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
build-push.mjs
32 lines (29 loc) · 912 Bytes
/
build-push.mjs
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
import path from 'node:path';
import { copyFileSync, existsSync, readFileSync } from 'fs';
const devTargets = path.resolve('./.dev-target.json');
const distDir = path.resolve('./dist');
try {
if (!existsSync(devTargets)) {
console.log(`No ${devTargets} file found. Exiting.`);
process.exit(0);
}
const data = JSON.parse(readFileSync(devTargets, 'utf-8'));
Object.keys(data).forEach((key) => {
const srcFile = path.resolve(distDir, key);
const targets = data[key];
if (targets === undefined) {
return;
} else if (Array.isArray(targets)) {
targets.forEach((t) => {
console.log(`copy ${key} to ${t}`);
copyFileSync(srcFile, path.resolve(t));
})
} else {
console.log(`copy ${key} to ${targets}`);
copyFileSync(srcFile, path.resolve(targets));
}
});
} catch (err) {
console.error(err);
process.exit(1);
}