Skip to content

Commit b21b55e

Browse files
author
Ahmad Awais
committed
📖 DOC: Better inline docs and interaction
1 parent c3540c7 commit b21b55e

2 files changed

Lines changed: 64 additions & 34 deletions

File tree

packages/cgb-scripts/scripts/eject.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
* Eject
33
*
44
* The create-guten-block CLI ejects here.
5-
* Eject the following things:
6-
* - Webpack configs
7-
* - .babelrc
8-
* - Packages from package.json
9-
*
10-
* TODO:
11-
* - checkRequiredFiles
12-
* - printBuildError
135
*/
146
'use strict';
157

@@ -22,15 +14,17 @@ process.on( 'unhandledRejection', err => {
2214
throw err;
2315
} );
2416

25-
const fs = require( 'fs-extra' );
2617
const path = require( 'path' );
18+
const fs = require( 'fs-extra' );
2719
const execSync = require( 'child_process' ).execSync;
2820
const chalk = require( 'chalk' );
2921
const paths = require( '../config/paths' );
3022
const inquirer = require( 'inquirer' );
3123
const spawnSync = require( 'cross-spawn' ).sync;
3224
const resolvePkg = require( 'resolve-pkg' );
33-
const cgbDevUtilsPath = resolvePkg( 'cgb-dev-utils', { cwd: __dirname } );
25+
const cgbDevUtilsPath = resolvePkg( 'cgb-dev-utils', {
26+
cwd: __dirname,
27+
} );
3428
const clearConsole = require( cgbDevUtilsPath + '/clearConsole' );
3529

3630
const green = chalk.green;
@@ -49,6 +43,8 @@ function getGitStatus() {
4943
}
5044
}
5145

46+
console.log( '\n ', chalk.black.bgGreen( ' Getting started to eject. \n' ) );
47+
5248
inquirer
5349
.prompt( {
5450
type: 'confirm',
@@ -58,38 +54,47 @@ inquirer
5854
} )
5955
.then( answer => {
6056
if ( ! answer.shouldEject ) {
61-
console.log( cyan( '\n\nClose one! Eject aborted.\n\n' ) );
57+
console.log(
58+
'\n\n— ' + chalk.black.bgWhite( ' Close one! Eject aborted. ' ),
59+
'\n\n'
60+
);
6261
return;
6362
}
6463

6564
const gitStatus = getGitStatus();
6665
if ( gitStatus ) {
6766
console.error(
68-
chalk.red(
69-
'This git repository has untracked files or uncommitted changes:'
70-
) +
67+
'\n\n' +
68+
chalk.black.bgRed(
69+
' This git repository has untracked files or uncommitted changes: '
70+
) +
7171
'\n\n' +
7272
gitStatus
7373
.split( '\n' )
7474
.map( line => line.match( / .*/g )[ 0 ].trim() )
7575
.join( '\n' ) +
7676
'\n\n' +
77-
chalk.red(
78-
'Remove untracked files, stash or commit any changes, and try again.'
79-
)
77+
chalk.black.bgRed(
78+
' Remove untracked files, stash or commit any changes, and try again. '
79+
),
80+
'\n\n'
8081
);
8182
process.exit( 1 );
8283
}
8384

84-
console.log( 'Ejecting...' );
85+
// Checks passed now let's start ejecting.
86+
console.log( '\n\n' + chalk.black.bgGreen( '⏳ Ejecting...' ), '\n\n' );
8587

8688
const ownPath = paths.ownPath;
8789
const appPath = paths.appPath;
8890

8991
function verifyAbsent( file ) {
9092
if ( fs.existsSync( path.join( appPath, file ) ) ) {
9193
console.error(
92-
`\`${ file }\` already exists in your app folder. We cannot ` +
94+
'\n\n' +
95+
`\`${ chalk.red(
96+
file
97+
) }\` already exists in your plugin's folder. We cannot ` +
9398
'continue as you would lose all the changes in that file or directory. ' +
9499
'Please move or delete it (maybe make a copy for backup) and run this ' +
95100
'command again.'
@@ -98,6 +103,7 @@ inquirer
98103
}
99104
}
100105

106+
// Folders to be moved.
101107
const folders = [ 'config', 'scripts' ];
102108

103109
// Make shallow array of files paths.
@@ -116,13 +122,17 @@ inquirer
116122
folders.forEach( verifyAbsent );
117123
files.forEach( verifyAbsent );
118124

119-
console.log();
120-
console.log( cyan( `Copying files into ${ appPath }` ) );
125+
console.log(
126+
`\n\n 👉 ${ chalk.black.bgYellow( ' Copying files to your plugin... ' ) }
127+
${ chalk.dim( 'In the directory: ', appPath ) }`
128+
);
121129

130+
// Go through all folders to build paths.
122131
folders.forEach( folder => {
123132
fs.mkdirSync( path.join( appPath, folder ) );
124133
} );
125134

135+
// Read all files and skip content that needs to be skipped.
126136
files.forEach( file => {
127137
let content = fs.readFileSync( file, 'utf8' );
128138

@@ -143,9 +153,12 @@ inquirer
143153
''
144154
)
145155
.trim() + '\n';
146-
console.log( ` Adding ${ cyan( file.replace( ownPath, '' ) ) } to the project` );
156+
console.log(
157+
` ➕ Adding ${ green( file.replace( ownPath, '' ) ) } to your plugin.`
158+
);
147159
fs.writeFileSync( file.replace( ownPath, appPath ), content );
148160
} );
161+
149162
console.log();
150163

151164
// Select cgb-scripts/package.json file.
@@ -154,7 +167,9 @@ inquirer
154167
// Assume a file called package.json file in current folder.
155168
const appPackage = require( path.join( appPath, 'package.json' ) );
156169

157-
console.log( cyan( 'Updating the dependencies' ) );
170+
console.log(
171+
`\n\n 👉 ${ chalk.black.bgYellow( ' Updating the dependencies... ' ) }`
172+
);
158173

159174
// Name: cgb-scripts.
160175
const ownPackageName = ownPackage.name;
@@ -163,7 +178,9 @@ inquirer
163178
if ( appPackage.devDependencies ) {
164179
// We used to put cgb-scripts in devDependencies.
165180
if ( appPackage.devDependencies[ ownPackageName ] ) {
166-
console.log( ` Removing ${ cyan( ownPackageName ) } from devDependencies` );
181+
console.log(
182+
` ➖ Removing ${ cyan( ownPackageName ) } from devDependencies.`
183+
);
167184
delete appPackage.devDependencies[ ownPackageName ];
168185
}
169186
}
@@ -172,7 +189,7 @@ inquirer
172189
appPackage.dependencies = appPackage.dependencies || {};
173190
if ( appPackage.dependencies[ ownPackageName ] ) {
174191
// Del cgb-scripts from dependencies now.
175-
console.log( ` Removing ${ cyan( ownPackageName ) } from dependencies` );
192+
console.log( ` Removing ${ cyan( ownPackageName ) } from dependencies.` );
176193
delete appPackage.dependencies[ ownPackageName ];
177194
}
178195

@@ -182,7 +199,7 @@ inquirer
182199
// if ( ownPackage.optionalDependencies[ key ] ) {
183200
// return;
184201
// }
185-
console.log( ` Adding ${ cyan( key ) } to dependencies` );
202+
console.log( ` Adding ${ green( key ) } to dependencies.` );
186203
appPackage.dependencies[ key ] = ownPackage.dependencies[ key ];
187204
} );
188205

@@ -194,10 +211,11 @@ inquirer
194211
.forEach( key => {
195212
appPackage.dependencies[ key ] = unsortedDependencies[ key ];
196213
} );
214+
console.log( ` ♻ ${ green( 'Sorting... ' ) }` );
197215
console.log();
198216

199217
// Update the scripts.
200-
console.log( cyan( 'Updating the scripts' ) );
218+
console.log( `\n\n 👉 ${ chalk.black.bgYellow( ' Updating the scripts... ' ) }` );
201219

202220
// Del the eject script.
203221
delete appPackage.scripts.eject;
@@ -214,18 +232,20 @@ inquirer
214232
'node scripts/$1.js'
215233
);
216234
console.log(
217-
` Replacing ${ cyan( `"${ binKey } ${ key }"` ) } with ${ cyan(
235+
` Replacing ${ cyan( `"${ binKey } ${ key }"` ) } with ${ green(
218236
`"node scripts/${ key }.js"`
219237
) }`
220238
);
221239
} );
222240
} );
223241

224242
console.log();
225-
console.log( cyan( 'Configuring package.json' ) );
243+
console.log(
244+
`\n\n 👉 ${ chalk.black.bgYellow( ' Configuring package.json... ' ) }`
245+
);
226246

227247
// Add Babel config.
228-
console.log( ` Adding ${ cyan( 'Babel' ) } preset` );
248+
console.log( ` Adding ${ green( 'Babel' ) } preset.` );
229249
appPackage.babel = {
230250
presets: [
231251
[
@@ -310,17 +330,19 @@ inquirer
310330
// console.log(cyan('Running yarn...'));
311331
// spawnSync('yarnpkg', [], { stdio: 'inherit' });
312332
} else {
313-
console.log( cyan( 'Running npm install...' ) );
333+
console.log(
334+
`\n\n 👉 ${ chalk.black.bgYellow( ' Running npm install... ' ) }`
335+
);
314336
spawnSync( 'npm', [ 'install', '--loglevel', 'error' ], {
315337
stdio: 'inherit',
316338
} );
317339
}
318-
console.log( green( 'Ejected successfully!' ) );
340+
console.log( '\n\n✅ ', chalk.black.bgGreen( ' Ejected successfully! \n' ) );
319341
console.log();
320342

321343
console.log(
322344
green( 'Please consider sharing why you ejected in this survey:' )
323345
);
324-
console.log( green( ' http://goo.gl/forms/ADDDDD' ) );
346+
console.log( green( ' https://goo.gl/forms/T901kvHr1kNsJGaJ3 ' ) );
325347
console.log();
326348
} );

packages/create-guten-block/createGutenBlock.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ const createPluginDir = () => {
8383
` A directory with this name already exists: ${ blockName } \n`
8484
)
8585
);
86-
console.log( ` ${ chalk.dim( 'Provide a different name for your block.' ) }` );
86+
87+
console.log(
88+
` ${ chalk.dim(
89+
'Please move or delete it (maybe make a copy for backup) and run this command again.'
90+
) }`
91+
);
92+
console.log(
93+
` ${ chalk.dim( 'Or provide a different name for your block.' ) }`
94+
);
8795
console.log( chalk.dim( '\nFor example: \n' ) );
8896
console.log(
8997
` ${ chalk.dim( 'create-guten-block' ) } ${ chalk.green( 'new-block-name' ) }\n`

0 commit comments

Comments
 (0)