Skip to content

Commit

Permalink
feat(pack): 添加pack静默模式
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhaoju committed Oct 9, 2016
1 parent 34f162e commit f5b9139
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 11 deletions.
7 changes: 6 additions & 1 deletion lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ exports.setOptions = function (optimist) {
optimist.describe('g', 'exports 分组');
optimist.alias('c', 'clean');
optimist.describe('c', '打包前清空输出目录');
optimist.alias('q', 'quiet');
optimist.describe('q', '静默模式');
};

exports.run = function (options) {
var cwd = options.cwd,
min = options.m || options.min || false,
lint = options.l || options.lint || false,
clean = options.c || options.clean || false,
quiet = options.q || options.quiet || false,
group = options.g || options.group,
sourcemap = options.s || options.sourcemap,
project = this.project;
Expand All @@ -39,7 +42,8 @@ exports.run = function (options) {
lint: lint,
min: min,
sourcemap: sourcemap,
clean: clean
clean: clean,
quiet: quiet
}, function (err, stats) {
if (err) {
if (err !== true) {
Expand All @@ -50,5 +54,6 @@ exports.run = function (options) {
project.packCallbacks.forEach(function (cb) {
return cb(options, stats);
});
process.exit(0);
});
};
3 changes: 3 additions & 0 deletions lib/commands/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ exports.run = function (options) {
}
});

nextConfig.plugins.push(require('../plugins/progressBarPlugin.js'));

return nextConfig;
});

Expand Down Expand Up @@ -230,6 +232,7 @@ exports.run = function (options) {

if (project.check()) {
compiler = project.getServerCompiler(function (config) {
config.plugins.push(require('../plugins/progressBarPlugin.js'));
return config;
});

Expand Down
2 changes: 1 addition & 1 deletion lib/models/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var Config = function () {
}],
postLoaders: []
},
plugins: [require('../plugins/extTemplatedPathPlugin.js'), require('../plugins/requireModulePlugin.js'), require('../plugins/progressBarPlugin.js'), require('../plugins/compileInfoPlugin.js')],
plugins: [require('../plugins/extTemplatedPathPlugin.js'), require('../plugins/requireModulePlugin.js'), require('../plugins/compileInfoPlugin.js')],
resolve: {
root: [],
extensions: ['', '.js', '.css', '.json', '.string', '.tpl'],
Expand Down
6 changes: 5 additions & 1 deletion lib/models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ var Project = function () {
config.devtool = opt.sourcemap;
}

if (!opt.quiet) {
config.plugins.push(require('../plugins/progressBarPlugin.js'));
}

if (opt.min) {
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
Expand Down Expand Up @@ -470,4 +474,4 @@ var Project = function () {
return Project;
}();

module.exports = Project;
module.exports = Project;
6 changes: 3 additions & 3 deletions lib/plugins/progressBarPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ function ProgressBarPlugin() {

return new webpack.ProgressPlugin(function (percent, msg) {
if (stream) {
stream.clearLine();
stream.cursorTo(0);
if (msg) {
stream.clearLine && stream.clearLine();
stream.cursorTo && stream.cursorTo(0);
if (msg && stream.write) {
stream.write(colors.grey('[Bundler] ') + colors.green(msg));
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ exports.setOptions = (optimist) => {
optimist.describe('g', 'exports 分组');
optimist.alias('c', 'clean');
optimist.describe('c', '打包前清空输出目录');
optimist.alias('q', 'quiet');
optimist.describe('q', '静默模式');
};

exports.run = function (options) {
let cwd = options.cwd,
min = options.m || options.min || false,
lint = options.l || options.lint || false,
clean = options.c || options.clean || false,
quiet = options.q || options.quiet || false,
group = options.g || options.group,
sourcemap = options.s || options.sourcemap,
project = this.project;
Expand All @@ -39,7 +42,8 @@ exports.run = function (options) {
lint: lint,
min: min,
sourcemap: sourcemap,
clean: clean
clean: clean,
quiet: quiet,
}, (err, stats) => {
if (err) {
if (err !== true) {
Expand All @@ -48,5 +52,6 @@ exports.run = function (options) {
}

project.packCallbacks.forEach(cb => cb(options, stats));
process.exit(0);
});
};
3 changes: 3 additions & 0 deletions src/commands/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ exports.run = (options) => {
}
})

nextConfig.plugins.push(require('../plugins/progressBarPlugin.js'))

return nextConfig
});

Expand Down Expand Up @@ -220,6 +222,7 @@ exports.run = (options) => {

if (project.check()) {
compiler = project.getServerCompiler(function(config) {
config.plugins.push(require('../plugins/progressBarPlugin.js'))
return config
});

Expand Down
1 change: 0 additions & 1 deletion src/models/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Config {
plugins: [
require('../plugins/extTemplatedPathPlugin.js'),
require('../plugins/requireModulePlugin.js'),
require('../plugins/progressBarPlugin.js'),
require('../plugins/compileInfoPlugin.js'),
],
resolve: {
Expand Down
4 changes: 4 additions & 0 deletions src/models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ class Project {
config.devtool = opt.sourcemap
}

if (!opt.quiet) {
config.plugins.push(require('../plugins/progressBarPlugin.js'));
}

if (opt.min) {
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/progressBarPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function ProgressBarPlugin() {

return new webpack.ProgressPlugin(function(percent, msg) {
if(stream) {
stream.clearLine();
stream.cursorTo(0);
if(msg) {
stream.clearLine && stream.clearLine();
stream.cursorTo && stream.cursorTo(0);
if(msg && stream.write) {
stream.write(colors.grey('[Bundler] ') + colors.green(msg));
}
}
Expand Down

0 comments on commit f5b9139

Please sign in to comment.