-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
76 lines (60 loc) · 2.13 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
'use strict';
const shell = require('shelljs');
const chalk = require('chalk');
const config = require('./package.json');
const DIST_DIR = 'dist';
const CONF_DIR = 'build';
// Package version
shell.echo('Setup package version');
const versionContent = `export default {
name: '${config.name}',
version: '${config.version}'
};`;
const versionFilePath = './src/version.ts';
shell.touch(versionFilePath);
shell.echo(versionContent).to(versionFilePath);
shell.echo(chalk.green(`${config.name} v${config.version}`));
shell.echo('Start building...');
shell.rm('-Rf', `${DIST_DIR}/*`);
shell.echo('Create TS declarations');
if (shell.exec(`tsc -p ${CONF_DIR}/tsconfig-typings.json`).code !== 0) {
shell.echo(chalk.red('Error: tsc declarations failed'));
shell.exit(1);
}
shell.echo('Start transpiling...');
shell.echo('Run TS -> ESM5 conversion');
if (shell.exec(`tsc -p ${CONF_DIR}/tsconfig-esm5.json`).code !== 0) {
shell.echo(chalk.red('Error: tsc conversion failed'));
shell.exit(1);
}
shell.echo('Run TS -> ESM2015 conversion');
if (shell.exec(`tsc -p ${CONF_DIR}/tsconfig-esm6.json`).code !== 0) {
shell.echo(chalk.red('Error: tsc conversion failed'));
shell.exit(1);
}
// shell.echo('Run TS -> CommonJS conversion');
// if (shell.exec(`tsc -p ${CONF_DIR}/tsconfig-cjs.json`).code !== 0) {
// shell.echo(chalk.red('Error: tsc conversion failed'));
// shell.exit(1);
// }
shell.echo('Indenting 4 -> 2');
shell.ls(`${DIST_DIR}/**/*.js`, `${DIST_DIR}/**/*.d.ts`).forEach(file => {
shell.sed('-i', /( {4})/g, ' ', file);
});
shell.echo('Start bundling...');
shell.echo('Rollup to FESM5');
if (shell.exec(`rollup -c ${CONF_DIR}/rollup.esm5.config.js`).code !== 0) {
shell.echo(chalk.red('Error: FESM5 bundling failed'));
shell.exit(1);
}
shell.echo('Rollup to FESM2015');
if (shell.exec(`rollup -c ${CONF_DIR}/rollup.esm6.config.js`).code !== 0) {
shell.echo(chalk.red('Error: FESM2015 bundling failed'));
shell.exit(1);
}
shell.echo('Rollup to UMD');
if (shell.exec(`rollup -c ${CONF_DIR}/rollup.umd.config.js`).code !== 0) {
shell.echo(chalk.red('Error: UMD bundling failed'));
shell.exit(1);
}
shell.echo(chalk.green('End building'));