feat(cli): exit build when catched errors

This commit is contained in:
陈嘉涵 2019-12-18 15:00:06 +08:00
parent 1f081c1e88
commit 5ebb2fffd3

View File

@ -2,7 +2,7 @@ import { join, relative } from 'path';
import { remove, copy, readdirSync } from 'fs-extra'; import { remove, copy, readdirSync } from 'fs-extra';
import { clean } from './clean'; import { clean } from './clean';
import { CSS_LANG } from '../common/css'; import { CSS_LANG } from '../common/css';
import { getStepper } from '../common/logger'; import { getStepper, logger } from '../common/logger';
import { compileJs } from '../compiler/compile-js'; import { compileJs } from '../compiler/compile-js';
import { compileSfc } from '../compiler/compile-sfc'; import { compileSfc } from '../compiler/compile-sfc';
import { compileStyle } from '../compiler/compile-style'; import { compileStyle } from '../compiler/compile-style';
@ -68,6 +68,7 @@ async function buildESModuleOutputs() {
stepper.success('Build ESModule Outputs'); stepper.success('Build ESModule Outputs');
} catch (err) { } catch (err) {
stepper.error('Build ESModule Outputs', err); stepper.error('Build ESModule Outputs', err);
throw err;
} }
} }
@ -81,6 +82,7 @@ async function buildCommonjsOutputs() {
stepper.success('Build Commonjs Outputs'); stepper.success('Build Commonjs Outputs');
} catch (err) { } catch (err) {
stepper.error('Build Commonjs Outputs', err); stepper.error('Build Commonjs Outputs', err);
throw err;
} }
} }
@ -93,6 +95,7 @@ async function buildStyleEntry() {
stepper.success('Build Style Entry'); stepper.success('Build Style Entry');
} catch (err) { } catch (err) {
stepper.error('Build Style Entry', err); stepper.error('Build Style Entry', err);
throw err;
} }
} }
@ -107,6 +110,7 @@ async function buildPackedOutputs() {
stepper.success('Build Packed Outputs'); stepper.success('Build Packed Outputs');
} catch (err) { } catch (err) {
stepper.error('Build Packed Outputs', err); stepper.error('Build Packed Outputs', err);
throw err;
} }
} }
@ -137,16 +141,21 @@ async function buildPackageEntry() {
stepper.success('Build Package Entry'); stepper.success('Build Package Entry');
} catch (err) { } catch (err) {
stepper.error('Build Package Entry', err); stepper.error('Build Package Entry', err);
throw err;
} }
} }
export async function build() { export async function build() {
setNodeEnv('production'); setNodeEnv('production');
await clean(); try {
await buildESModuleOutputs(); await clean();
await buildCommonjsOutputs(); await buildESModuleOutputs();
await buildStyleEntry(); await buildCommonjsOutputs();
await buildPackageEntry(); await buildStyleEntry();
await buildPackedOutputs(); await buildPackageEntry();
await buildPackedOutputs();
} catch (err) {
logger.error('Build failed');
}
} }