forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
66 lines (57 loc) · 1.66 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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
const { resolve } = require('path');
const del = require('del');
const supportsColor = require('supports-color');
const { run, withProcRunner } = require('@kbn/dev-utils');
const ROOT_DIR = resolve(__dirname, '..');
const BUILD_DIR = resolve(ROOT_DIR, 'target');
const padRight = (width, str) =>
str.length >= width ? str : `${str}${' '.repeat(width - str.length)}`;
run(
async ({ log, flags }) => {
await withProcRunner(log, async (proc) => {
if (!flags.watch) {
log.info('Deleting old output');
await del(BUILD_DIR);
}
const cwd = ROOT_DIR;
const env = { process };
if (supportsColor.stdout) {
env.FORCE_COLOR = 'true';
}
log.info(`Starting babel and typescript${flags.watch ? ' in watch mode' : ''}`);
await proc.run(padRight(10, `babel`), {
cmd: 'babel',
args: [
'src',
'--config-file',
require.resolve('../babel.config.js'),
'--out-dir',
BUILD_DIR,
'--extensions',
'.ts,.js,.tsx',
'--copy-files',
...(flags.watch ? ['--watch'] : ['--quiet']),
],
wait: true,
env,
cwd,
});
log.success('Complete');
});
},
{
description: 'Simple build tool for Canvas Storybook addon',
flags: {
boolean: ['watch'],
help: `
--watch Run in watch mode
`,
},
}
);