Skip to content

Commit 17b911c

Browse files
author
Ahmad Awais
committed
🐛 FIX: Win32 Support
1 parent 637dcd5 commit 17b911c

4 files changed

Lines changed: 48 additions & 72 deletions

File tree

packages/cgb-scripts/scripts/build.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ process.on( 'unhandledRejection', err => {
2222

2323
// Modules.
2424
const fs = require( 'fs' );
25+
const ora = require( 'ora' );
2526
const path = require( 'path' );
2627
const chalk = require( 'chalk' );
2728
const webpack = require( 'webpack' );
2829
const fileSize = require( 'filesize' );
2930
const gzipSize = require( 'gzip-size' );
3031
const resolvePkg = require( 'resolve-pkg' );
31-
const isWindows = require( 'is-windows' );
32-
const ora = isWindows() ? false : require( 'ora' );
3332
const config = require( '../config/webpack.config.prod' );
3433
const cgbDevUtilsPath = resolvePkg( 'cgb-dev-utils', { cwd: __dirname } );
3534
const clearConsole = require( cgbDevUtilsPath + '/clearConsole' );
@@ -57,7 +56,7 @@ const getFileSize = filePath => {
5756
clearConsole();
5857

5958
// Init the spinner.
60-
const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
59+
const spinner = new ora( { text: '' } );
6160

6261
/**
6362
* Build function
@@ -68,18 +67,11 @@ const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
6867
*/
6968
async function build( webpackConfig ) {
7069
// Start the build.
71-
if ( spinner ) {
72-
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
73-
} else {
74-
console.log( chalk.green( 'Building and compiling blocks...' ) );
75-
}
70+
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
7671

7772
// Compiler Instance.
7873
const compiler = await webpack( webpackConfig );
79-
80-
if ( spinner ) {
81-
spinner.succeed();
82-
}
74+
spinner.succeed();
8375

8476
// Run the compiler.
8577
compiler.run( ( err, stats ) => {

packages/cgb-scripts/scripts/init.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
'use strict';
1010

11-
const fs = require( 'fs-extra' );
11+
const ora = require( 'ora' );
1212
const path = require( 'path' );
13+
const fs = require( 'fs-extra' );
1314
const chalk = require( 'chalk' );
1415
const shell = require( 'shelljs' );
15-
const isWindows = require( 'is-windows' );
16-
const ora = isWindows() ? false : require( 'ora' );
1716

1817
// Makes the script crash on unhandled rejections instead of silently
1918
// ignoring them. In the future, promise rejections that are not handled will
@@ -171,22 +170,16 @@ module.exports = async( root, blockName, blockDir ) => {
171170

172171
// 1.Copy template to the plugin dir.
173172
// Init the spinner.
174-
const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
175-
if ( spinner ) {
176-
spinner.start( '3. Creating plugin files...' );
177-
} else {
178-
console.log( chalk.green( '3. Creating plugin files...' ) );
179-
}
173+
const spinner = new ora( { text: '' } );
174+
spinner.start( '3. Creating plugin files...' );
180175
await copyTemplateFiles(
181176
blockName,
182177
blockDir,
183178
blockNamePHPLower,
184179
blockNamePHPUpper
185180
);
181+
spinner.succeed();
186182

187-
if ( spinner ) {
188-
spinner.succeed();
189-
}
190183
// 2. Prints next steps.
191184
await printNextSteps( blockName, blockDir );
192185
};

packages/cgb-scripts/scripts/start.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,49 @@ process.env.NODE_ENV = 'development';
1919
process.on( 'unhandledRejection', err => {
2020
throw err;
2121
} );
22+
23+
const ora = require( 'ora' );
2224
const chalk = require( 'chalk' );
2325
const webpack = require( 'webpack' );
24-
const isWindows = require( 'is-windows' );
25-
const ora = isWindows() ? false : require( 'ora' );
2626
const config = require( '../config/webpack.config.dev' );
2727
const resolvePkg = require( 'resolve-pkg' );
2828
const cgbDevUtilsPath = resolvePkg( 'cgb-dev-utils', { cwd: __dirname } );
2929
const clearConsole = require( cgbDevUtilsPath + '/clearConsole' );
3030
const formatWebpackMessages = require( cgbDevUtilsPath +
3131
'/formatWebpackMessages' );
32-
// const clearConsole = require( '../../cgb-dev-utils/clearConsole' );
33-
// const formatWebpackMessages = require( '../../cgb-dev-utils/formatWebpackMessages' );
32+
33+
// Don't run below node 8.
34+
const currentNodeVersion = process.versions.node;
35+
const semver = currentNodeVersion.split( '.' );
36+
const major = semver[ 0 ];
37+
38+
// If below Node 8.
39+
if ( major < 8 ) {
40+
console.error(
41+
chalk.red(
42+
'You are running Node ' +
43+
currentNodeVersion +
44+
'.\n' +
45+
'Create Guten Block requires Node 8 or higher. \n' +
46+
'Kindly, update your version of Node.'
47+
)
48+
);
49+
process.exit( 1 );
50+
}
3451

3552
clearConsole();
3653

3754
// Init the spinner.
38-
const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
55+
const spinner = new ora( { text: '' } );
3956

4057
// Create the production build and print the deployment instructions.
4158
async function build( webpackConfig ) {
4259
// Start the build.
43-
if ( spinner ) {
44-
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
45-
} else {
46-
console.log( chalk.green( 'Building and compiling blocks...' ) );
47-
}
60+
spinner.start( `${ chalk.dim( 'Building and compiling blocks...' ) }` );
4861

4962
// Compiler Instance.
5063
const compiler = await webpack( webpackConfig );
51-
52-
if ( spinner ) {
53-
spinner.succeed();
54-
}
64+
spinner.succeed();
5565

5666
// Run the compiler.
5767
compiler.watch( {}, ( err, stats ) => {

packages/create-guten-block/app/run.js

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66

77
'use strict';
88

9+
const ora = require( 'ora' );
910
const chalk = require( 'chalk' );
10-
const isWindows = require( 'is-windows' );
11-
const ora = isWindows() ? false : require( 'ora' );
12-
const clearConsole = require( './consoleClear' );
1311
const cli = require( './cli' );
14-
const getBlockName = require( './getBlockName' );
15-
const getBlockDir = require( './getBlockDir' );
1612
const prePrint = require( './prePrint' );
17-
const createPluginDir = require( './createPluginDir' );
18-
const npmInstallScripts = require( './npmInstallScripts' );
1913
const initBlock = require( './initBlock' );
14+
const getBlockDir = require( './getBlockDir' );
15+
const clearConsole = require( './consoleClear' );
16+
const getBlockName = require( './getBlockName' );
2017
const updateNotifier = require( './updateNotifier' );
18+
const createPluginDir = require( './createPluginDir' );
19+
const npmInstallScripts = require( './npmInstallScripts' );
2120

2221
module.exports = async() => {
2322
// 0. Set the CLI.
@@ -38,39 +37,21 @@ module.exports = async() => {
3837

3938
// 3. Create the plugin directory.
4039
// Init the spinner.
41-
const spinner = ora ? new ora( { text: '', enabled: true } ) : false;
42-
43-
if ( spinner ) {
44-
spinner.start(
45-
`1. Creating the plugin directory called → ${ chalk.black.bgWhite(
46-
` ${ blockName } `
47-
) }`
48-
);
49-
} else {
50-
console.log(
51-
chalk.green( ' 1. Creating the plugin directory called → ' ) +
52-
chalk.black.bgWhite( ` ${ blockName } ` )
53-
);
54-
}
40+
const spinner = ora( { text: '' } );
5541

42+
spinner.start(
43+
`1. Creating the plugin directory called → ${ chalk.black.bgWhite(
44+
` ${ blockName } `
45+
) }`
46+
);
5647
await createPluginDir( blockName );
57-
58-
if ( spinner ) {
59-
spinner.succeed();
60-
}
48+
spinner.succeed();
6149

6250
// 4. NPM install cgb-scripts.
63-
if ( spinner ) {
64-
spinner.start( '2. Installing npm packages...' );
65-
} else {
66-
console.log( chalk.green( '2. Installing npm packages...' ) );
67-
}
6851

52+
spinner.start( '2. Installing npm packages...' );
6953
await npmInstallScripts( blockName, blockDir );
70-
71-
if ( spinner ) {
72-
spinner.succeed();
73-
}
54+
spinner.succeed();
7455

7556
// 5. Initialize the block.
7657
await initBlock( blockName, blockDir );

0 commit comments

Comments
 (0)