-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
96 lines (83 loc) · 2.06 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
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
88
89
90
91
92
93
94
95
96
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
const dist = path.resolve(__dirname, './dist');
const destination = path.resolve(dist, './index.js');
const sharpDestination = path.resolve(dist, './node_modules');
const source = path.resolve(__dirname, './src/index.ts');
const externals = [
'bindings',
'color',
'color-convert',
'color-name',
'color-string',
'detect-libc',
'is-arrayish',
'file-uri-to-path',
'semver',
'sharp',
'simple-swizzle',
];
require('@zeit/ncc')(source, {
externals,
}).then(
({ assets, code, map }) => {
// remove dist
shell.rm('-rf', dist);
// now create dist
shell.mkdir(dist);
fs.writeFileSync(destination, code);
// now copy sharp to dist
shell.mkdir('-p', path.resolve(__dirname, './dist/node_modules'));
externals.forEach(lib => {
shell.cp(
'-R',
path.resolve(__dirname, `./node_modules/${lib}`),
path.resolve(__dirname, `./dist/node_modules/${lib}`),
);
});
const blacklist = [
'README',
'CHANGELOG.md',
'LICENSE',
'.eslintrc.json',
'.npmignore',
'yarn-error.log',
'range.bnf',
'History.md',
'index.d.ts',
'.travis.yml',
'test.js',
'tests.json',
];
shell.find(path.resolve(__dirname, './dist/node_modules')).forEach(f => {
if (blacklist.some(b => f.includes(b))) {
shell.rm(f);
}
});
// clean up sharp
['docs', 'install', 'src', 'node_modules'].forEach(dir => {
shell.rm('-rf', path.resolve(sharpDestination, 'sharp', dir));
});
// clean up semver
['bin'].forEach(dir => {
shell.rm(
'-rf',
path.resolve(__dirname, `./dist/node_modules/semver/${dir}`),
);
});
// clean up detect-libc
['bin'].forEach(dir => {
shell.rm(
'-rf',
path.resolve(__dirname, `./dist/node_modules/detect-libc/${dir}`),
);
});
console.log('Done');
process.exit(0);
},
err => {
console.error(err);
process.exit(1);
},
);