Skip to content

Commit f979585

Browse files
committed
📦 NEW: Canary testing
1 parent 0f1ad17 commit f979585

5 files changed

Lines changed: 36 additions & 39 deletions

File tree

‎package.json‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
"beforepublish": "lerna bootstrap",
3838
"publishScript": "bash tasks/publish.sh && echo 'Now update dependency packages.'",
3939
"publishNPM": "bash tasks/publish.sh --npm-client=npm",
40-
"publish-canary": "yarn && lerna bootstrap && lerna publish --independent --npm-client=npm --canary",
4140
"lerna": "yarn && lerna updated && lerna bootstrap && lerna publish --independent --npm-client=npm",
42-
"release": "yarn && lerna updated && lerna bootstrap && lerna publish --independent --npm-client=npm"
41+
"publishCanary": "yarn && lerna bootstrap && lerna publish --independent --npm-client=npm --canary",
42+
"release": "yarn && lerna updated && lerna bootstrap && lerna publish --independent --npm-client=npm",
43+
"releaseCanary": "yarn && lerna updated && lerna bootstrap && lerna publish --independent --npm-client=npm --canary"
4344
}
4445
}

‎packages/cgb-scripts/template/src/init.php‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,15 @@
2828
* @since 1.0.0
2929
*/
3030
function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
31-
/**
32-
* Register block styles for both frontend + backend.
33-
*/
31+
// Register block styles for both frontend + backend.
3432
wp_register_style(
3533
'<% blockNamePHPLower %>-cgb-style-css', // Handle.
3634
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
3735
array( 'wp-editor' ), // Dependency to include the CSS after it.
3836
null, // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
3937
);
4038

41-
/**
42-
* Register block editor script for backend.
43-
*/
39+
// Register block editor script for backend.
4440
wp_register_script(
4541
'<% blockNamePHPLower %>-cgb-block-js', // Handle.
4642
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
@@ -49,9 +45,7 @@ function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
4945
true // Enqueue the script in the footer.
5046
);
5147

52-
/**
53-
* Register block editor styles for backend.
54-
*/
48+
// Register block editor styles for backend.
5549
wp_register_style(
5650
'<% blockNamePHPLower %>-cgb-block-editor-css', // Handle.
5751
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
@@ -67,12 +61,18 @@ function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
6761
* enqueued when the editor loads.
6862
*
6963
* @link https://wordpress.org/gutenberg/handbook/blocks/writing-your-first-block-type#enqueuing-block-scripts
64+
* @since 1.16.0
7065
*/
71-
register_block_type( 'cgb/block-<% blockName %>', array(
72-
'style' => '<% blockNamePHPLower %>-cgb-style-css', // Enqueue blocks.style.build.css on both frontend & backend.
73-
'editor_script' => '<% blockNamePHPLower %>-cgb-block-js', // Enqueue blocks.build.js in the editor only.
74-
'editor_style' => '<% blockNamePHPLower %>-cgb-block-editor-css', // Enqueue blocks.editor.build.css in the editor only.
75-
) );
66+
register_block_type(
67+
'cgb/block-<% blockName %>', array(
68+
// Enqueue blocks.style.build.css on both frontend & backend.
69+
'style' => '<% blockNamePHPLower %>-cgb-style-css',
70+
// Enqueue blocks.build.js in the editor only.
71+
'editor_script' => '<% blockNamePHPLower %>-cgb-block-js',
72+
// Enqueue blocks.editor.build.css in the editor only.
73+
'editor_style' => '<% blockNamePHPLower %>-cgb-block-editor-css',
74+
)
75+
);
7676
}
7777

7878
// Hook: Block assets.

‎packages/create-guten-block/app/cli.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ module.exports = () => {
2929
console.log( `\n Only ${ chalk.green( '<block-name>' ) } is required.\n` );
3030
} )
3131
.option( '-d, --debug', 'Prints envinfo for debugging' )
32+
.option( '-c, --canary', 'To use latest canary version for dev-testing' )
3233
.description(
33-
`CGB ${ chalk.dim(
34-
'(create-guten-block)'
35-
) } is a Zero-Config #OCJS for builing WordPress Gutenberg Blocks.`
34+
`CGB ${ chalk.dim( '(create-guten-block)' ) } is a Zero-Config #OCJS for builing WordPress Gutenberg Blocks.`
3635
)
3736
.version( packageJson.version, '-v, --version' )
3837
.parse( process.argv );
3938

39+
const isCanary = program.canary ? true : false;
40+
4041
// If no blockName.
4142
if ( typeof blockName === 'undefined' ) {
4243
// Maybe user asked for debug info.
@@ -60,5 +61,5 @@ module.exports = () => {
6061
invalidBlockName();
6162
}
6263

63-
return formatBlockName;
64+
return { blockName: formatBlockName, isCanary: isCanary };
6465
};

‎packages/create-guten-block/app/npmInstallScripts.js‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const fs = require( 'fs-extra' );
1616
const execa = require( 'execa' );
1717
const shell = require( 'shelljs' );
1818

19-
module.exports = ( blockName, blockDir ) => {
19+
module.exports = ( blockName, blockDir, isCanary ) => {
2020
shell.cd( blockDir );
2121
shell.touch( 'package.json' );
2222

@@ -33,20 +33,19 @@ module.exports = ( blockName, blockDir ) => {
3333
};
3434

3535
// Write the package.json file.
36-
fs.writeFileSync(
37-
path.join( process.cwd(), 'package.json' ),
38-
JSON.stringify( appPackage, null, 2 ) + '\n'
39-
);
36+
fs.writeFileSync( path.join( process.cwd(), 'package.json' ), JSON.stringify( appPackage, null, 2 ) + '\n' );
4037

38+
// Are we testing or not?
39+
if ( isCanary ) {
40+
// Install latest canary version of cgb-scripts for test in development of CGB.
41+
return new Promise( async resolve => {
42+
await execa( 'npm', [ 'install', 'cgb-scripts@canary', '--save', '--save-exact', '--silent' ] );
43+
resolve( true );
44+
} );
45+
}
4146
// Install latest exact version of cgb-scripts.
4247
return new Promise( async resolve => {
43-
await execa( 'npm', [
44-
'install',
45-
'cgb-scripts',
46-
'--save',
47-
'--save-exact',
48-
'--silent',
49-
] );
48+
await execa( 'npm', [ 'install', 'cgb-scripts', '--save', '--save-exact', '--silent' ] );
5049
resolve( true );
5150
} );
5251
};

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = async() => {
2424
updateNotifier();
2525

2626
// 1. Set the CLI and get the blockName.
27-
const blockName = cli();
27+
const { blockName, isCanary } = cli();
2828

2929
// 2. Build the block directory path.
3030
const blockDir = await getBlockDir( blockName );
@@ -36,17 +36,13 @@ module.exports = async() => {
3636
// Init the spinner.
3737
const spinner = ora( { text: '' } );
3838

39-
spinner.start(
40-
`1. Creating the plugin directory called → ${ chalk.black.bgWhite(
41-
` ${ blockName } `
42-
) }`
43-
);
39+
spinner.start( `1. Creating the plugin directory called → ${ chalk.black.bgWhite( ` ${ blockName } ` ) }` );
4440
await createPluginDir( blockName, blockDir );
4541
spinner.succeed();
4642

4743
// 4. NPM install cgb-scripts.
4844
spinner.start( '2. Installing npm packages...' );
49-
await npmInstallScripts( blockName, blockDir );
45+
await npmInstallScripts( blockName, blockDir, isCanary );
5046
spinner.succeed();
5147

5248
// 5. Initialize the block.

0 commit comments

Comments
 (0)