-
Notifications
You must be signed in to change notification settings - Fork 10
/
move_artifacts.js
55 lines (45 loc) · 1.53 KB
/
move_artifacts.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
const fs = require('fs');
const path = require('path');
const sourceDir = './artifacts';
const npmDir = './npm';
const outDirs = fs.readdirSync(npmDir);
const binaries = collectNodeBinaries(sourceDir);
console.log(binaries)
binaries.forEach((file) => {
// console.log(file);
// const sourcePath = path.join(sourceDir, file);
console.log(`moving artifact: ${file}`);
const terms = file.split('.');
if (terms.pop() !== 'node') {
console.error(`non node file found: ${file}`);
return;
}
const platform = terms.pop()
if (!platform) {
console.error(`can't find platform for: ${file}`);
return;
}
if (!outDirs.includes(platform)) {
console.error(`invalid platform: ${platform} for file: ${file}`);
return;
}
const destPath = path.join(npmDir, platform, path.parse(file).base);
fs.copyFile(file, destPath, (copyErr) => {
if (copyErr) {
console.error(`Could not copy the file: ${copyErr}`);
return;
}
console.log(`Copied ${file} to ${destPath}`);
});
});
function collectNodeBinaries(root) {
const files = fs.readdirSync(root, { withFileTypes: true })
const nodeBinaries = files
.filter((file) => file.isFile() && file.name.endsWith('.node'))
.map((file) => path.join(root, file.name))
const dirs = files.filter((file) => file.isDirectory())
for (const dir of dirs) {
nodeBinaries.push(...(collectNodeBinaries(path.join(root, dir.name))))
}
return nodeBinaries
}