From f7f9830c580fac87317ffe0b3016edb551c4369e Mon Sep 17 00:00:00 2001 From: RahiDroid Date: Tue, 19 Apr 2022 14:39:09 +0530 Subject: [PATCH 1/2] Refact: Descriptive function name --- bin/init.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/init.js b/bin/init.js index fbd387fb..cace8c08 100755 --- a/bin/init.js +++ b/bin/init.js @@ -40,7 +40,7 @@ rl.question( 'Would you like to setup the theme? (y/n) ', ( answer ) => { process.exit( 0 ); } rl.question( 'Enter theme name (shown in WordPress admin)*: ', ( themeName ) => { - const themeInfo = setupTheme( themeName ); + const themeInfo = loadThemeSetupModal( themeName ); rl.question( 'Confirm the Theme Details (y/n) ', ( confirm ) => { if ( 'n' === confirm.toLowerCase() ) { console.log( info.warning( '\nTheme Setup Cancelled.\n' ) ); @@ -57,13 +57,13 @@ rl.on( 'close', () => { } ); /** - * Theme Setup + * Renders the theme setup modal with all necessary information related to the search-replace. * * @param {string} themeName * * @return {Object} themeInfo */ -const setupTheme = ( themeName ) => { +const loadThemeSetupModal = ( themeName ) => { console.log( info.success( '\nFiring up the theme setup...' ) ); // Ask theme name. From a4cbd5a93e555e599ea23067cb230d0aa03a2d6d Mon Sep 17 00:00:00 2001 From: RahiDroid Date: Tue, 19 Apr 2022 14:59:30 +0530 Subject: [PATCH 2/2] Refact: Update init script to handle composer.json separately --- bin/init.js | 18 +++++++++++------- composer.json | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/init.js b/bin/init.js index cace8c08..44dd22a5 100755 --- a/bin/init.js +++ b/bin/init.js @@ -77,13 +77,13 @@ const loadThemeSetupModal = ( themeName ) => { const themeDetails = { 'Theme Name: ': `${ themeInfo.themeName }`, - 'Theme Version: ': `1.0.0`, - 'Text Domain: ': `${ themeInfo.kebabCase }`, - 'Package: ': `${ themeInfo.trainCase }`, - 'Namespace: ': `${ themeInfo.pascalSnakeCase }`, - 'Function Prefix: ': `${ themeInfo.snakeCaseWithUnderscoreSuffix }`, - 'CSS Class Prefix: ': `${ themeInfo.kebabCaseWithHyphenSuffix }`, - 'PHP Variable Prefix: ': `${ themeInfo.snakeCaseWithUnderscoreSuffix }`, + 'Theme Version: ': '1.0.0', + 'Text Domain: ': themeInfo.kebabCase, + 'Package: ': themeInfo.trainCase, + 'Namespace: ': themeInfo.pascalSnakeCase, + 'Function Prefix: ': themeInfo.snakeCaseWithUnderscoreSuffix, + 'CSS Class Prefix: ': themeInfo.kebabCaseWithHyphenSuffix, + 'PHP Variable Prefix: ': themeInfo.snakeCaseWithUnderscoreSuffix, 'Version Constant: ': `${ themeInfo.macroCase }_VERSION`, 'Theme Directory Constant: ': `${ themeInfo.macroCase }_TEMP_DIR`, 'Theme Build Directory Constant: ': `${ themeInfo.macroCase }_BUILD_DIR`, @@ -115,6 +115,7 @@ const loadThemeSetupModal = ( themeName ) => { */ const initTheme = ( themeInfo ) => { const chunksToReplace = { + 'rtcamp/elementary': themeInfo.packageName, // Specifically targets composer.json file. 'elementary theme': themeInfo.themeNameLowerCase, 'Elementary Theme': themeInfo.themeName, 'ELEMENTARY THEME': themeInfo.themeNameCobolCase, @@ -150,6 +151,7 @@ const initTheme = ( themeInfo ) => { Object.keys( chunksToReplace ).forEach( ( key ) => { replaceFileContent( files, key, chunksToReplace[ key ] ); } ); + if ( ! fileContentUpdated ) { console.log( info.error( 'No file content updated.\n' ) ); } @@ -265,6 +267,7 @@ const generateThemeInfo = ( themeName ) => { const themeNameLowerCase = themeName.toLowerCase(); const kebabCase = themeName.replace( /\s+/g, '-' ).toLowerCase(); + const packageName = `rtcamp/${ kebabCase }`; const snakeCase = kebabCase.replace( /\-/g, '_' ); const kebabCaseWithHyphenSuffix = kebabCase + '-'; const snakeCaseWithUnderscoreSuffix = snakeCase + '_'; @@ -285,6 +288,7 @@ const generateThemeInfo = ( themeName ) => { return { themeName, + packageName, themeNameLowerCase, kebabCase, snakeCase, diff --git a/composer.json b/composer.json index bd492a61..b76ae56a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "rtcamp/elementary-theme", + "name": "rtcamp/elementary", "description": "A Block based starter theme.", "type": "wordpress-theme", "homepage": "https://rtcamp.com/",