@@ -25,9 +25,10 @@ const mkdirp = require('mkdirp');
2525const babel = require ( 'babel-core' ) ;
2626const chalk = require ( 'chalk' ) ;
2727const micromatch = require ( 'micromatch' ) ;
28-
28+ const stringLength = require ( 'string-length' ) ;
2929const getPackages = require ( './_getPackages' ) ;
3030
31+ const OK = chalk . reset . inverse . bold . green ( ' DONE ' ) ;
3132const SRC_DIR = 'src' ;
3233const BUILD_DIR = 'build' ;
3334const BUILD_ES5_DIR = 'build-es5' ;
@@ -46,8 +47,9 @@ const babelEs5Options = Object.assign(
4647 { plugins : [ ...babelNodeOptions . plugins , 'transform-runtime' ] }
4748) ;
4849
49- const fixedWidth = str => {
50- const WIDTH = 80 ;
50+ const adjustToTerminalWidth = str => {
51+ const columns = process . stdout . columns || 80 ;
52+ const WIDTH = columns - stringLength ( OK ) + 1 ;
5153 const strs = str . match ( new RegExp ( `(.{1,${ WIDTH } })` , 'g' ) ) ;
5254 let lastString = strs [ strs . length - 1 ] ;
5355 if ( lastString . length < WIDTH ) {
@@ -73,10 +75,10 @@ function buildPackage(p) {
7375 const pattern = path . resolve ( srcDir , '**/*' ) ;
7476 const files = glob . sync ( pattern , { nodir : true } ) ;
7577
76- process . stdout . write ( fixedWidth ( `${ path . basename ( p ) } \n` ) ) ;
78+ process . stdout . write ( adjustToTerminalWidth ( `${ path . basename ( p ) } \n` ) ) ;
7779
7880 files . forEach ( file => buildFile ( file , true ) ) ;
79- process . stdout . write ( `[ ${ chalk . green ( 'OK' ) } ] \n` ) ;
81+ process . stdout . write ( `${ OK } \n` ) ;
8082}
8183
8284function buildFile ( file , silent ) {
@@ -141,7 +143,7 @@ const files = process.argv.slice(2);
141143if ( files . length ) {
142144 files . forEach ( buildFile ) ;
143145} else {
144- process . stdout . write ( chalk . bold . inverse ( 'Building packages\n' ) ) ;
146+ process . stdout . write ( chalk . inverse ( ' Building packages \n' ) ) ;
145147 getPackages ( ) . forEach ( buildPackage ) ;
146148 process . stdout . write ( '\n' ) ;
147149}
0 commit comments