Files
sapper/src/cli/build.ts
Rich Harris 1a4bace5f4 add dev API
2018-05-23 09:05:24 -04:00

32 lines
740 B
TypeScript

import { build as _build } from '../api/build';
import * as colors from 'ansi-colors';
import { locations } from '../config';
export function build() {
return new Promise((fulfil, reject) => {
try {
const emitter = _build({
dest: locations.dest(),
app: locations.app(),
routes: locations.routes(),
webpack: 'webpack'
});
emitter.on('build', event => {
console.log(colors.inverse(`\nbuilt ${event.type}`));
console.log(event.webpack_stats.toString({ colors: true }));
});
emitter.on('error', event => {
reject(event.error);
});
emitter.on('done', event => {
fulfil();
});
} catch (err) {
console.log(`${colors.bold.red(`> ${err.message}`)}`);
process.exit(1);
}
});
}