Skip to content

Commit 423afe8

Browse files
author
Ahmad Awais
committed
👌 IMPROVE: Start and Build Scripts Communication
1 parent 28a0fe0 commit 423afe8

2 files changed

Lines changed: 30 additions & 26 deletions

File tree

packages/cgb-scripts/scripts/build.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
* Build
33
*
44
* The create-guten-block CLI builds here.
5-
*
6-
* TODO:
7-
* - checkRequiredFiles
8-
* - printBuildError
95
*/
6+
107
'use strict';
118

129
// Do this as the first thing so that any code reading it knows the right env.
@@ -66,16 +63,13 @@ const spinner = new ora( { text: '' } );
6663
* @param {json} webpackConfig config
6764
*/
6865
async function build( webpackConfig ) {
69-
// Start the build.
70-
console.log( '\n' );
71-
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
72-
7366
// Compiler Instance.
7467
const compiler = await webpack( webpackConfig );
75-
spinner.succeed();
7668

7769
// Run the compiler.
7870
compiler.run( ( err, stats ) => {
71+
clearConsole();
72+
7973
if ( err ) {
8074
return console.log( err );
8175
}
@@ -93,8 +87,10 @@ async function build( webpackConfig ) {
9387
// Formatted errors.
9488
clearConsole();
9589
console.log( '\n❌ ', chalk.black.bgRed( ' Failed to compile build. \n' ) );
96-
const logErrors = console.log( '\n👉 ', messages.errors.join( '\n\n' ) );
97-
return logErrors;
90+
console.log( '\n👉 ', messages.errors.join( '\n\n' ) );
91+
92+
// Don't go beyond this point at this time.
93+
return;
9894
}
9995

10096
// CI.
@@ -110,10 +106,11 @@ async function build( webpackConfig ) {
110106
'Most CI servers set it automatically.\n'
111107
)
112108
);
113-
return console.log( messages.warnings.join( '\n\n' ) );
109+
console.log( messages.warnings.join( '\n\n' ) );
114110
}
115111

116-
clearConsole();
112+
// Start the build.
113+
console.log( `\n ${ chalk.dim( 'Let\'s build and compile the files...' ) }` );
117114
console.log( '\n✅ ', chalk.black.bgGreen( ' Built successfully! \n' ) );
118115

119116
console.log(

packages/cgb-scripts/scripts/start.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ const spinner = new ora( { text: '' } );
5656

5757
// Create the production build and print the deployment instructions.
5858
async function build( webpackConfig ) {
59-
// Start the build.
60-
console.log( '\n' );
61-
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
62-
6359
// Compiler Instance.
6460
const compiler = await webpack( webpackConfig );
65-
spinner.succeed();
6661

6762
// Run the compiler.
6863
compiler.watch( {}, ( err, stats ) => {
64+
clearConsole();
65+
6966
if ( err ) {
7067
return console.log( err );
7168
}
@@ -80,10 +77,19 @@ async function build( webpackConfig ) {
8077
if ( messages.errors.length > 1 ) {
8178
messages.errors.length = 1;
8279
}
83-
// Formatted errors.
80+
81+
// Clear success messages.
8482
clearConsole();
83+
84+
// Formatted errors.
8585
console.log( '\n❌ ', chalk.black.bgRed( ' Failed to compile. \n' ) );
8686
const logErrors = console.log( '\n👉 ', messages.errors.join( '\n\n' ) );
87+
console.log( '\n' );
88+
spinner.start(
89+
chalk.dim(
90+
'Watching for changes... let\'s fix this... (Press CTRL + C to stop).'
91+
)
92+
);
8793
return logErrors;
8894
}
8995

@@ -103,16 +109,17 @@ async function build( webpackConfig ) {
103109
return console.log( messages.warnings.join( '\n\n' ) );
104110
}
105111

106-
clearConsole();
112+
// Start the build.
113+
console.log( `\n${ chalk.dim( 'Let\'s build and compile the files...' ) }` );
107114
console.log( '\n✅ ', chalk.black.bgGreen( ' Compiled successfully! \n' ) );
108115
console.log(
109-
chalk.dim( ' Watching for changes... (Press CTRL + C to stop). \n\n' )
110-
);
111-
return console.log(
112-
chalk.dim( ' Note that the development build is not optimized. \n' ),
113-
chalk.dim( 'To create a production build, use' ),
116+
chalk.dim( ' Note that the development build is not optimized. \n' ),
117+
chalk.dim( ' To create a production build, use' ),
114118
chalk.green( 'npm' ),
115-
chalk.white( 'run build' )
119+
chalk.white( 'run build\n' )
120+
);
121+
return spinner.start(
122+
`${ chalk.dim( 'Watching for changes... (Press CTRL + C to stop).' ) }`
116123
);
117124
} );
118125
}

0 commit comments

Comments
 (0)