-
Notifications
You must be signed in to change notification settings - Fork 624
/
package.js
48 lines (43 loc) · 1.39 KB
/
package.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
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const fs = require('fs');
const yargs = require('yargs').argv;
const ora = require('ora');
const rimraf = require('rimraf');
require('colors');
const isVerbose = yargs.verbose === 'true' || yargs.verbose === true;
const TO_PRESERVE_DURING_CLEAN_UP = [
'dist',
'package.json',
'.git',
'.gitignore',
'node_modules',
'LICENSE.md',
'README.md',
'tailwind.config.js'
];
const run = async () => {
const srcPath = __dirname;
const srcFiles = fs.readdirSync(srcPath);
const buildingPackageSpinner = ora(`Building fresh package...`).start();
try {
console.log('Generating package...');
await exec('npm run build:library');
console.log('Package generated with success');
} catch (error) {
buildingPackageSpinner.fail('Package build failed.');
if (isVerbose) {
console.error(error);
}
process.exit(-1);
}
buildingPackageSpinner.succeed('Package built.');
const postBuildCleanUpSpinner = ora('Doing post-build clean-up...').start();
srcFiles
.filter((name) => !TO_PRESERVE_DURING_CLEAN_UP.includes(name))
.forEach((fileName) => {
rimraf.sync(__dirname + `/${fileName}`, {}, () => {});
});
postBuildCleanUpSpinner.succeed('Did post-build clean up.');
};
run();