-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.js
49 lines (39 loc) · 1.26 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
'use strict';
process.env.NODE_ENV = 'production';
process.env.BABEL_ENV = 'production';
process.on('unhandledRejection', (err) => {
throw err;
});
const babel = require('@babel/core');
const fs = require('fs');
const readAllFiles = require('../utils/readAllFiles');
const deletePath = require('../utils/deletePath');
const resolverPath = require('../utils/resolverPath');
const babelConfig = require('../configs/babelConfig');
process.on('unhandledRejection', (err) => {
throw err;
});
const APP_PATH = resolverPath('src/lib');
const BUILD_PATH = resolverPath('dist');
deletePath(BUILD_PATH);
fs.mkdirSync(BUILD_PATH);
console.log(`Create directory:\t${BUILD_PATH}`);
const files = readAllFiles(APP_PATH);
files.map((path) => {
const newPath = path.name.replace(APP_PATH, BUILD_PATH);
if (path.isFile) {
if (
path.name.match('^.+\\.(js|jsx|ts|tsx)$') &&
!path.name.match('^.+\\.d.ts$')
) {
const result = babel.transformFileSync(path.name, babelConfig);
fs.appendFileSync(newPath, result.code);
} else {
fs.appendFileSync(newPath, fs.readFileSync(path.name));
}
console.log('\x1b[32m', `Create file:\t\t${newPath}`, '\x1b[0m');
} else {
fs.mkdirSync(newPath);
console.log(`Create directory:\t${newPath}`);
}
});