8
0
Просмотр исходного кода

Improved logging – made it distinguisable what's a message and what's a shell output.

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
3a9d9bf5da
3 измененных файлов с 17 добавлено и 15 удалено
  1. 5 1
      dev/tasks/dev/tasks.js
  2. 9 8
      dev/tasks/dev/utils/tools.js
  3. 3 6
      dev/tests/dev/tools.js

+ 5 - 1
dev/tasks/dev/tasks.js

@@ -14,13 +14,17 @@ const pluginCreateTask = require( './tasks/create-package' );
 const updateTask = require( './tasks/update' );
 const relinkTask = require( './tasks/relink' );
 const log = require( './utils/log' );
+const gutil = require( 'gulp-util' );
 
 module.exports = ( config ) => {
 	const ckeditor5Path = process.cwd();
 	const packageJSON = require( '../../../package.json' );
 
 	// Configure logging.
-	log.configure( console.log, console.error );
+	log.configure(
+		( msg ) => gutil.log( msg ),
+		( msg ) => gutil.log( gutil.colors.red( msg ) )
+	);
 
 	gulp.task( 'init', () => {
 		initTask( installTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR );

+ 9 - 8
dev/tasks/dev/utils/tools.js

@@ -5,8 +5,9 @@
 
 'use strict';
 
+const gutil = require( 'gulp-util' );
+
 const dependencyRegExp = /^ckeditor5-/;
-const log = require( '../utils/log' );
 
 module.exports = {
 
@@ -20,25 +21,25 @@ module.exports = {
 	 */
 	shExec( command, logOutput ) {
 		const sh = require( 'shelljs' );
+
 		sh.config.silent = true;
 		logOutput = logOutput !== false;
 
 		const ret = sh.exec( command );
+		const logColor = ret.code ? gutil.colors.red : gutil.colors.grey;
 
 		if ( logOutput ) {
-			if ( ret.stdout !== '' ) {
-				log.out( ret.stdout );
+			if ( ret.stdout ) {
+				console.log( '\n' + logColor( ret.stdout.trim() ) + '\n' );
 			}
 
-			if ( ret.stderr !== '' ) {
-				log.err( ret.stderr );
+			if ( ret.stderr ) {
+				console.log( '\n' + gutil.colors.grey( ret.stderr.trim() ) + '\n' );
 			}
 		}
 
 		if ( ret.code ) {
-			throw new Error(
-				`Error while executing ${ command }: ${ ret.stderr }`
-			);
+			throw new Error( `Error while executing ${ command }: ${ ret.stderr }` );
 		}
 
 		return ret.stdout;

+ 3 - 6
dev/tests/dev/tools.js

@@ -50,16 +50,13 @@ describe( 'utils', () => {
 			it( 'should output using log functions', () => {
 				const sh = require( 'shelljs' );
 				const execStub = sandbox.stub( sh, 'exec' ).returns( { code: 0, stdout: 'out', stderr: 'err' } );
-				const log = require( '../../tasks/dev/utils/log' );
-				const outFn = sandbox.spy();
-				const errFn = sandbox.spy();
-				log.configure( outFn, errFn );
+
+				sandbox.stub( console, 'log' );
 
 				tools.shExec( 'command' );
 
 				sinon.assert.calledOnce( execStub );
-				sinon.assert.calledWithExactly( outFn, 'out' );
-				sinon.assert.calledWithExactly( errFn, 'err' );
+				sinon.assert.calledTwice( console.log );
 			} );
 
 			it( 'should not log when in silent mode', () => {