Skip to content

Commit

Permalink
feat: add silent
Browse files Browse the repository at this point in the history
  • Loading branch information
ikobe-zz committed Jun 15, 2017
1 parent 46aaf26 commit ee87776
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $ atool-build -h
--devtool <devtool> sourcemap generate method, default is null
--config <path> custom config path, default is webpack.config.js
--no-compress build without compress
--silent build without notify
```

### 配置扩展
Expand Down
5 changes: 3 additions & 2 deletions bin/atool-build
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ program
.option('--publicPath <publicPath>', 'publicPath for webpack')
.option('--devtool <devtool>', 'sourcemap generate method, default is null')
.option('--config <path>', 'custom config path, default is webpack.config.js')
.option('--no-compress','build without compress')
.option('--json','running webpack with --json, ex. result.json')
.option('--no-compress', 'build without compress')
.option('--silent', 'close notifier')
.option('--json', 'running webpack with --json, ex. result.json')
.option('--verbose', 'run with more logging messages.')
.parse(process.argv);

Expand Down
16 changes: 9 additions & 7 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ export default function build(args, callback) {
console.error(buildInfo);
} else {
console.log(buildInfo);
notifier.notify({
title: 'ant tool',
message: 'done',
subtitle: 'build successfully',
contentImage: join(__dirname, '../assets/success.png'),
sound: 'Glass',
});
if (args.silent !== true) {
notifier.notify({
title: 'ant tool',
message: 'done',
subtitle: 'build successfully',
contentImage: join(__dirname, '../assets/success.png'),
sound: 'Glass',
});
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/getWebpackCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function getWebpackCommonConfig(args) {
const cssFileName = args.hash ? '[name]-[chunkhash].css' : '[name].css';
const commonName = args.hash ? 'common-[chunkhash].js' : 'common.js';

const silent = args.silent === true;
const babelQuery = getBabelCommonConfig();
const tsQuery = getTSCommonConfig();
tsQuery.declaration = false;
Expand Down Expand Up @@ -201,6 +202,7 @@ export default function getWebpackCommonConfig(args) {
new CaseSensitivePathsPlugin(),
new FriendlyErrorsWebpackPlugin({
onErrors: (severity, errors) => {
if (silent) return;
if (severity !== 'error') {
notifier.notify({
title: 'ant tool',
Expand Down
3 changes: 3 additions & 0 deletions test/build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ describe('lib/build', function () {
expect(err.message).toEqual('no webpack entry found');
});
});
it('should support silent', () => {
return testBuild({ hash: true, silent: true }, 'build-normal');
});
});

0 comments on commit ee87776

Please sign in to comment.