Skip to content

Commit 1839d4c

Browse files
author
Ahmad Awais
committed
👌 IMPROVE: CGB no deps for cgb-scripts
1 parent d1868aa commit 1839d4c

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

packages/create-guten-block/createGutenBlock.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const ora = require( 'ora' );
44
const chalk = require( 'chalk' );
55
const execa = require( 'execa' );
66
const shell = require( 'shelljs' );
7-
const resolvePkg = require( 'resolve-pkg' );
8-
const template = resolvePkg( 'cgb-scripts/template', { cwd: __dirname } );
97
const directoryExists = require( 'directory-exists' );
108

119
/**
@@ -104,6 +102,9 @@ const createPluginDir = () => {
104102

105103
// Copy template to the plugin dir.
106104
const copyTemplateToPluginDir = () => {
105+
const resolvePkg = require( 'resolve-pkg' );
106+
const template = resolvePkg( 'cgb-scripts/template', { cwd: __dirname } );
107+
107108
return new Promise( resolve => {
108109
shell.cd( blockDir );
109110
shell.cp( '-RL', `${ template }/*`, './' );
@@ -131,8 +132,15 @@ const npmInstallBuild = () => {
131132

132133
// Install latest cgb-scripts.
133134
await execa( 'npm', [ 'install', 'cgb-scripts', '--slient' ] );
135+
resolve();
136+
} );
137+
};
138+
139+
// Final npm run build to build the block.
140+
const finalNpmBuild = () => {
141+
return new Promise( async resolve => {
134142
// Build.
135-
// await execa( 'npm', [ 'run', 'build', '--slient' ] );
143+
await execa( 'npm', [ 'run', 'build', '--slient' ] );
136144
resolve();
137145
} );
138146
};
@@ -205,12 +213,16 @@ const run = async() => {
205213
await createPluginDir();
206214
spinner.succeed();
207215

208-
spinner.start( '2. Building plugin files in the block directory...' );
216+
spinner.start( '2. Installing npm packages...' );
217+
await npmInstallBuild();
218+
spinner.succeed();
219+
220+
spinner.start( '3. Creating plugin files...' );
209221
await copyTemplateToPluginDir();
210222
spinner.succeed();
211223

212-
spinner.start( '3. Installing node packages & building the block...' );
213-
await npmInstallBuild();
224+
spinner.start( '4. Finally building the block...' );
225+
finalNpmBuild();
214226
spinner.succeed();
215227

216228
await printNextSteps();
@@ -219,5 +231,10 @@ const run = async() => {
219231
// console.clear();
220232
clearConsole();
221233

234+
// Update notifier.
235+
const updateNotifier = require( 'update-notifier' );
236+
const pkg = require( './package.json' );
237+
updateNotifier( { pkg } ).notify();
238+
222239
// Run the CLI.
223240
run();

packages/create-guten-block/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,5 @@ if ( major < 8 ) {
5353
process.exit( 1 );
5454
}
5555

56-
// Update notifier.
57-
const updateNotifier = require( 'update-notifier' );
58-
const pkg = require( './package.json' );
59-
updateNotifier( { pkg } ).notify();
60-
6156
// Otherwise, run the app.
6257
require( './createGutenBlock' );

packages/create-guten-block/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"version": "1.3.4",
44
"description": "Create a gutenberg block plugin on the go.",
55
"main": "index.js",
6-
"keywords": [
7-
"gutenberg",
8-
"create-gutenberg-block",
9-
"wordpress"
10-
],
6+
"keywords": ["gutenberg", "create-gutenberg-block", "wordpress"],
117
"author": "AhmadAwais",
128
"license": "MIT",
139
"repository": {
@@ -19,7 +15,6 @@
1915
},
2016
"homepage": "https://github.com/ahmadawais/create-guten-block#readme",
2117
"dependencies": {
22-
"cgb-scripts": "^1.0.4",
2318
"chalk": "^2.3.0",
2419
"directory-exists": "^1.0.2",
2520
"execa": "^0.9.0",
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
11
console.log( 'MANNUAL TEST!' );
2-
3-
// const resolvePkg = require( 'resolve-pkg' );
4-
// console.log( resolvePkg( 'cgb-scripts/template', { cwd: __dirname } ) );
5-
6-
const directoryExists = require( 'directory-exists' );
7-
8-
console.log( directoryExists.sync( './node_modules' ) ); //retuns boolean
9-
console.log( directoryExists.sync( './demo' ) ); //retuns boolean

0 commit comments

Comments
 (0)