UNPKG

1.21 kBJavaScriptView Raw
1const ChildProcess = require('child_process');
2const Fs = require('fs-extra');
3const Path = require('path');
4
5// Independent from process.cwd()
6const cwd = Path.resolve(__dirname, '..');
7
8const main = () => {
9 // Abort if build failed (status code isn't 0)
10 if (compileProject()) return
11 chmodCLI()
12 archiveSkeleton()
13}
14
15// Typescript to es5
16const compileProject = () => {
17 const tscFile = Path.resolve(cwd, 'node_modules/typescript/bin/tsc');
18 const tsConfig = Path.resolve(cwd, 'tsconfig.json');
19
20 const { status } = ChildProcess.spawnSync(tscFile, ['-p', tsConfig], {
21 stdio: 'inherit',
22 cwd
23 });
24
25 return status
26}
27
28// Ensure CLI files can be executed without sudo
29const chmodCLI = () => {
30 const cliDir = Path.resolve(cwd, 'dist/cli');
31 const cliFiles = Fs.readdirSync(cliDir).map(fileName => Path.resolve(cliDir, fileName));
32
33 cliFiles.forEach((cliFile) => {
34 Fs.chmodSync(cliFile, '755');
35 });
36}
37
38// Put the skeleton in a .tar file.
39// Necessary if we would like to preserve in the NPM registry without files disappearing
40const archiveSkeleton = () => {
41 ChildProcess.spawnSync('tar', ['-cvf', 'dist/skeleton.tar', 'skeleton'], {
42 stdio: 'inherit',
43 cwd,
44 });
45}
46
47main()