From 2376cffbe8bf7587c713f3f8ecd2b9b68a8479a4 Mon Sep 17 00:00:00 2001 From: meixg Date: Mon, 13 May 2019 14:08:44 +0800 Subject: [PATCH 1/2] feat(cli): prompting while every dep is latest --- packages/mars-cli/lib/update.js | 42 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/mars-cli/lib/update.js b/packages/mars-cli/lib/update.js index 7a19600d..2a315488 100644 --- a/packages/mars-cli/lib/update.js +++ b/packages/mars-cli/lib/update.js @@ -3,26 +3,28 @@ * @author meixuguang */ -const {error, stopSpinner} = require('@vue/cli-shared-utils'); +/* eslint-disable fecs-no-require */ +/* eslint-disable no-console */ + +const {stopSpinner} = require('@vue/cli-shared-utils'); +const logger = require('@vue/cli-shared-utils/lib/logger'); const execa = require('execa'); const fs = require('fs-extra'); -function executeCommand(command, args, targetDir) { - return new Promise((resolve, reject) => { - - const child = execa(command, args, { - cwd: targetDir, - stdio: ['inherit', 'inherit', 'inherit'] - }); - - child.on('close', code => { - if (code !== 0) { - reject(`command failed: ${command} ${args.join(' ')}`); - return; - } - resolve(); - }); +async function executeCommand(command, args, targetDir) { + const child = execa(command, args, { + cwd: targetDir }); + + child.stdout.pipe(process.stdout); + + const res = await child; + + if (res.code !== 0) { + logger.error(`command failed: ${command} ${args.join(' ')}\n`); + } + + return res; } const dependencyList = [ @@ -49,7 +51,11 @@ async function update(cmd) { forceUpdate(cmd.registry); } else { - compatibleUpdate(cmd.registry); + const res = await compatibleUpdate(cmd.registry); + + if (!res.stdout && !res.stderr) { + logger.info('所有依赖已是最新。'); + } } } @@ -84,7 +90,7 @@ async function forceUpdate(registry) { module.exports = (...args) => update(...args).catch(err => { stopSpinner(false); // do not persist - error(err); + logger.error(err); if (!process.env.VUE_CLI_TEST) { process.exit(1); } From 162661396be217b3e015a77e92fd94ae1fb22b28 Mon Sep 17 00:00:00 2001 From: meixg Date: Mon, 13 May 2019 14:29:23 +0800 Subject: [PATCH 2/2] fix(build): watching stopped when compile error --- packages/mars-build/src/compiler/file/compiler.js | 12 ++++++------ packages/mars-build/src/gulp-mars-base.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/mars-build/src/compiler/file/compiler.js b/packages/mars-build/src/compiler/file/compiler.js index ab930e1c..46e4971a 100644 --- a/packages/mars-build/src/compiler/file/compiler.js +++ b/packages/mars-build/src/compiler/file/compiler.js @@ -98,12 +98,12 @@ exports.gulpPlugin = function (options) { return cb(); } if (file.isBuffer()) { - try { - compile(file, options).then(_ => cb(null, file)); - } - catch (e) { - log.error('[COMPILE ERROR]:', e); - } + compile(file, options) + .then(_ => cb(null, file)) + .catch(err => { + log.error('[COMPILE ERROR]:', err); + cb(null, file); + }); return; } // for other file type diff --git a/packages/mars-build/src/gulp-mars-base.js b/packages/mars-build/src/gulp-mars-base.js index f3516577..0a54ca49 100644 --- a/packages/mars-build/src/gulp-mars-base.js +++ b/packages/mars-build/src/gulp-mars-base.js @@ -69,12 +69,12 @@ function gulpPlugin(opt = {dest: './dist'}, compilers) { return cb(); } if (file.isBuffer()) { - try { - compile(file, opt, compilers).then(_ => cb(null, file)); - } - catch (e) { - log.error('[COMPILE ERROR]:', e); - } + compile(file, opt, compilers) + .then(_ => cb(null, file)) + .catch(err => { + log.error('[COMPILE ERROR]:', err); + cb(null, file); + }); } }); return stream;