这是indexloc提供的服务,不要输入任何密码
Skip to content

Change theme package name #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions bin/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand All @@ -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.
Expand All @@ -77,13 +77,13 @@ const setupTheme = ( 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`,
Expand Down Expand Up @@ -115,6 +115,7 @@ const setupTheme = ( 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,
Expand Down Expand Up @@ -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' ) );
}
Expand Down Expand Up @@ -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 + '_';
Expand All @@ -285,6 +288,7 @@ const generateThemeInfo = ( themeName ) => {

return {
themeName,
packageName,
themeNameLowerCase,
kebabCase,
snakeCase,
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rtcamp/elementary-theme",
"name": "rtcamp/elementary",
"description": "A Block based starter theme.",
"type": "wordpress-theme",
"homepage": "https://rtcamp.com/",
Expand Down