This repository has been archived by the owner on Jul 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild-pre.js
87 lines (79 loc) · 2.1 KB
/
build-pre.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require('fs-extra');
const request = require('request');
const AdmZip = require('adm-zip');
// setup prism binaries
fs.removeSync('build-tmp');
fs.removeSync('dist');
fs.mkdirsSync('build-tmp');
fs.mkdirsSync('build-tmp/prism');
const proxyMap = {
mac: {
x64: {
source: 'prism_darwin_amd64',
target: 'prism',
},
},
linux: {
x64: {
source: 'prism_linux_amd64',
target: 'prism',
},
ia32: {
source: 'prism_linux_386',
target: 'prism',
},
},
win: {
x64: {
source: 'prism_windows_amd64.exe',
target: 'prism.exe',
},
ia32: {
source: 'prism_windows_386.exe',
target: 'prism.exe',
},
},
};
const mkProxyFiles = (os, arch) => {
const buildPath = `build-tmp/${os}/${arch}/proxy`;
// copy the correct binary over
const proxyDetails = proxyMap[os][arch];
fs.copySync(
`build-tmp/prism/bundle/${proxyDetails.source}`,
`${buildPath}/${proxyDetails.target}`
);
fs.chmodSync(`${buildPath}/${proxyDetails.target}`, '777');
};
const mkFiles = () => {
mkProxyFiles('mac', 'x64');
mkProxyFiles('linux', 'x64');
mkProxyFiles('linux', 'ia32');
mkProxyFiles('win', 'x64');
mkProxyFiles('win', 'ia32');
};
// Fetch the latest prism binaries, unzip them, and save them to build-tmp/prism
// When that is done, call mkFiles to begin the copy / preparation process
console.log('HTTP: Fetching latest digest.');
request(
{
url: 'https://api.github.com/repos/stoplightio/prism/releases/latest',
headers: {
'User-Agent': 'request',
},
},
(err, resp, body) => {
const zipUrl = `https://github.com/stoplightio/prism/releases/download/${
JSON.parse(body).tag_name
}/bundle.zip`;
console.log('HTTP: Fetching latest zip.', zipUrl);
request(zipUrl)
.pipe(fs.createWriteStream('build-tmp/prism/bundle.zip'))
.on('close', () => {
console.log('ZIP: Opening latest zip.');
const zip = new AdmZip('build-tmp/prism/bundle.zip');
zip.extractAllTo('build-tmp/prism', true);
console.log('ZIP: Opened!');
mkFiles();
});
}
);