mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { build as _build } from '../api/build';
|
|
import colors from 'kleur';
|
|
import { locations } from '../config';
|
|
import validate_bundler from './utils/validate_bundler';
|
|
import { repeat } from '../utils';
|
|
|
|
export function build(opts: { bundler?: string, legacy?: boolean }) {
|
|
const bundler = validate_bundler(opts.bundler);
|
|
|
|
if (opts.legacy && bundler === 'webpack') {
|
|
throw new Error(`Legacy builds are not supported for projects using webpack`);
|
|
}
|
|
|
|
return new Promise((fulfil, reject) => {
|
|
try {
|
|
const emitter = _build({
|
|
legacy: opts.legacy,
|
|
bundler
|
|
}, {
|
|
dest: locations.dest(),
|
|
app: locations.app(),
|
|
routes: locations.routes(),
|
|
webpack: 'webpack',
|
|
rollup: 'rollup'
|
|
});
|
|
|
|
emitter.on('build', event => {
|
|
let banner = `built ${event.type}`;
|
|
let c = colors.cyan;
|
|
|
|
const { warnings } = event.result;
|
|
if (warnings.length > 0) {
|
|
banner += ` with ${warnings.length} ${warnings.length === 1 ? 'warning' : 'warnings'}`;
|
|
c = colors.yellow;
|
|
}
|
|
|
|
console.log();
|
|
console.log(c(`┌─${repeat('─', banner.length)}─┐`));
|
|
console.log(c(`│ ${colors.bold(banner) } │`));
|
|
console.log(c(`└─${repeat('─', banner.length)}─┘`));
|
|
|
|
console.log(event.result.print());
|
|
});
|
|
|
|
emitter.on('error', event => {
|
|
reject(event.error);
|
|
});
|
|
|
|
emitter.on('done', event => {
|
|
fulfil();
|
|
});
|
|
} catch (err) {
|
|
reject(err);
|
|
}
|
|
});
|
|
} |