-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
40 lines (36 loc) · 1.66 KB
/
build.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
const execSync = require('child_process').execSync;
const path = require('path');
const fs = require('fs');
const archiver = require('archiver');
const modulesToBuild = [
{name: "cpu-features", files: ['build/Release/cpufeatures.node'] },
{name: "drivelist", files: ['build/Release/drivelist.node'] },
{name: "find-git-repositories", files: ['build/Release/findGitRepos.node'] },
{name: "keytar", files: ['build/Release/keytar.node'] },
{name: "nsfw", files: ['build/Release/nsfw.node'] },
{name: "node-pty", files: ['build/Release/pty.node', 'build/Release/spawn-helper', 'build/Release/winpty-agent.exe', 'build/Release/winpty.dll'] },
//{name: "ssh2", files: [] },
]
const artifactsPath = path.join(process.cwd(), 'artifacts');
if(fs.existsSync(artifactsPath)) {
fs.rmSync(artifactsPath, {recursive: true});
}
for(let module of modulesToBuild) {
const modulePath = path.join(process.cwd(), 'node_modules' , module.name)
execSync('node-gyp rebuild', {cwd: modulePath, stdio: 'inherit'});
const dstDir = path.join(artifactsPath, module.name);
for(let file of module.files) {
if(!fs.existsSync(dstDir)) {
fs.mkdirSync(dstDir, {recursive: true});
}
const fileToCopy = path.join(modulePath.toString(), file)
if(fs.existsSync(fileToCopy)) {
fs.copyFileSync(fileToCopy, path.join(dstDir, path.basename(file)));
}
}
const archive = archiver('zip');
const output = fs.createWriteStream(path.join(artifactsPath, `${module.name}-${process.platform}-${process.arch}.zip`), { flags: "w" });
archive.pipe(output);
archive.directory(dstDir, false);
archive.finalize();
}