forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-npm.js
More file actions
71 lines (61 loc) · 1.76 KB
/
build-npm.js
File metadata and controls
71 lines (61 loc) · 1.76 KB
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
const fs = require('fs');
const pkg = require('../package.json');
const dir = `${__dirname}/..`;
const triples = [
'x86_64-apple-darwin',
'x86_64-unknown-linux-gnu',
'x86_64-pc-windows-msvc',
'aarch64-apple-darwin',
'aarch64-unknown-linux-gnu',
'armv7-unknown-linux-gnueabihf',
'aarch64-unknown-linux-musl',
'x86_64-unknown-linux-musl'
];
const cpuToNodeArch = {
x86_64: 'x64',
aarch64: 'arm64',
i686: 'ia32',
armv7: 'arm',
};
const sysToNodePlatform = {
linux: 'linux',
freebsd: 'freebsd',
darwin: 'darwin',
windows: 'win32',
};
let optionalDependencies = {};
try {
fs.mkdirSync(dir + '/npm');
} catch (err) {}
for (let triple of triples) {
let [cpu, , os, abi] = triple.split('-');
cpu = cpuToNodeArch[cpu] || cpu;
os = sysToNodePlatform[os] || os;
let t = `${os}-${cpu}`;
if (abi) {
t += '-' + abi;
}
let name = `parcel-css.${t}.node`;
let pkg2 = {...pkg};
pkg2.name += '-' + t;
pkg2.os = [os];
pkg2.cpu = [cpu];
pkg2.main = name;
pkg2.files = [name];
delete pkg2.napi;
delete pkg2.devDependencies;
delete pkg2.dependencies;
delete pkg2.optionalDependencies;
delete pkg2.targets;
delete pkg2.scripts;
delete pkg2.types;
optionalDependencies[pkg2.name] = '^' + pkg.version;
try {
fs.mkdirSync(dir + '/npm/' + t);
} catch (err) {}
fs.writeFileSync(`${dir}/npm/${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${name}`, `${dir}/npm/${t}/${name}`);
fs.writeFileSync(`${dir}/npm/${t}/README.md`, `This is the ${triple} build of @parcel/css. See https://github.com/parcel-bundler/parcel-css for details.`);
}
pkg.optionalDependencies = optionalDependencies;
fs.writeFileSync(`${dir}/package.json`, JSON.stringify(pkg, false, 2) + '\n');