From 180b56023905e94c90edf3a153c453141619848e Mon Sep 17 00:00:00 2001 From: Noah Mason Date: Thu, 22 Feb 2024 09:15:37 -0500 Subject: [PATCH 1/4] Adds constant prefix arg. Removes composer.lock when lock files are cleaned. --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1866c22..a950b5c 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ const defaultArgs = { wpVersionTested: '5.0.0', functionPrefix: 'wp_theme', classPrefix: 'WP_Theme', + constantPrefix: 'WP_THEME', path: process.cwd(), }; @@ -54,6 +55,7 @@ const argTypes = { wpVersionTested: 'string', functionPrefix: 'string', classPrefix: 'string', + constantPrefix: 'string', path: 'string', }; @@ -75,6 +77,7 @@ const argTitles = { wpVersionTested: 'WP Version Tested', functionPrefix: 'Function Prefix', classPrefix: 'Class Prefix', + constantPrefix: 'Constant Prefix', path: 'Path', }; @@ -96,6 +99,7 @@ const argDescriptions = { wpVersionTested: 'The version of WordPress the theme has been tested up to', functionPrefix: 'The prefix for PHP functions', classPrefix: 'The prefix for PHP classes', + constantPrefix: 'The prefix for PHP constants', path: 'The path where the built theme directory will be placed.', }; @@ -117,6 +121,7 @@ const argAliases = { wpVersionTested: 'w', functionPrefix: 'F', classPrefix: 'C', + constantPrefix: 'c', path: 'p', }; @@ -145,6 +150,7 @@ const tmpPath = path.join(__dirname, 'tmp'); const tmpThemePath = path.join(tmpPath, 'package'); const tmpThemePkgPath = path.join(tmpThemePath, 'package.json'); const tmpThemePkgLockPath = path.join(tmpThemePath, 'package-lock.json'); +const tmpThemeComposerLockPath = path.join(tmpThemePath, 'composer.lock'); const tmpThemeGulpPath = path.join(tmpThemePath, 'gulpfile.js'); const tmpThemeLicPath = path.join(tmpThemePath, 'LICENSE'); const themeDirName = changeCase.paramCase(program.args[0]); @@ -275,6 +281,7 @@ function replaceRename(args = null) { if (/WP Theme/g.test(content) || /WP_Theme/g.test(content) || /wp-theme/g.test(content) || /wp_theme/g.test(content)) { content = content .replace(/WP Theme/g, args.themeName) + .replace(/WP_THEME/g, args.constantPrefix.replace(/[^a-zA-Z\d]/g, '_')) .replace(/WP_Theme/g, args.classPrefix.replace(/[^a-zA-Z\d]/g, '_')) .replace(/wp-theme/g, themeDirName) .replace(/wp_theme/g, changeCase.snakeCase(args.functionPrefix)); @@ -287,10 +294,10 @@ function replaceRename(args = null) { } function writePackage(args = null) { - del([tmpThemePkgLockPath], { force: true }) + del([tmpThemePkgLockPath, tmpThemeComposerLockPath], { force: true }) .then(function (paths) { if (paths.length > 0) { - console.info(chalk.bold.yellow('package-lock.json cleaned:'), paths.join(', ')); + console.info(chalk.bold.yellow('Lock files cleaned:'), paths.join(', ')); } fs.readFile(tmpThemePkgPath, function (error, data) { if (error) { From 49543964979310ccb1ee3a598a56b18c0b08a4da Mon Sep 17 00:00:00 2001 From: Noah Mason Date: Thu, 22 Feb 2024 09:20:22 -0500 Subject: [PATCH 2/4] 1.2.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ab68a07..10b5056 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dreamsicle.io/create-wp-theme", - "version": "1.1.1", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@dreamsicle.io/create-wp-theme", - "version": "1.1.1", + "version": "1.2.0", "license": "GPL-3.0", "dependencies": { "chalk": "~4.1.2", diff --git a/package.json b/package.json index 9458c26..51bea8f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dreamsicle.io/create-wp-theme", - "version": "1.1.1", + "version": "1.2.0", "description": "A command line tool for creating modern, optimized WordPress themes.", "main": "index.js", "bin": { From 7f2a22794aaa13a19b61db7b77e5ed282815937d Mon Sep 17 00:00:00 2001 From: Noah Mason Date: Thu, 22 Feb 2024 09:27:37 -0500 Subject: [PATCH 3/4] Updates Readme. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 40abc22..14c3a0e 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ WP Version Required: (5.0.0) WP Version Tested: (5.0.0) Function Prefix: (wp_theme) Class Prefix: (WP_Theme) +Constant Prefix: (WP_THEME) Path: () ``` @@ -58,7 +59,6 @@ The tool will log its progress and errors in the console, exiting on completion Creating theme: WP Theme in C:\Users\noahm\Code\create-wp-theme-dev\app\public\wp-content\themes\my-theme Repo cloned: https://github.com/dreamsicle-io/wp-theme-assets.git --> C:\Users\noahm\Code\create-wp-theme\tmp -package-lock.json cleaned: C:\Users\noahm\Code\create-wp-theme\tmp\package\package-lock.json package.json written: C:\Users\noahm\Code\create-wp-theme\tmp\package\package.json File Renamed: C:\Users\noahm\Code\create-wp-theme\tmp\package\includes\class-wp-theme-assets.php File built: C:\Users\noahm\Code\create-wp-theme\tmp\package\includes\class-wp-theme-assets.php @@ -123,6 +123,7 @@ Options: "5.0.0") -F, --functionPrefix [string] The prefix for PHP functions (default: "wp_theme") -C, --classPrefix [string] The prefix for PHP classes (default: "WP_Theme") + -c, --constantPrefix [string] The prefix for PHP constants (default: "WP_THEME") -p, --path [string] The path where the built theme directory will be placed. (default: "C:\\Users\\noahm\\source\\repos\\create-wp-theme") -h, --help display help for command From 716bcf7ede18e80d04f7fd12d912aa7a5fc9d389 Mon Sep 17 00:00:00 2001 From: Noah Mason Date: Thu, 22 Feb 2024 09:27:56 -0500 Subject: [PATCH 4/4] Adds constant check to replace rename conditions. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a950b5c..9a3af07 100644 --- a/index.js +++ b/index.js @@ -278,7 +278,7 @@ function replaceRename(args = null) { file = newFile; } var content = fs.readFileSync(file, 'utf8'); - if (/WP Theme/g.test(content) || /WP_Theme/g.test(content) || /wp-theme/g.test(content) || /wp_theme/g.test(content)) { + if (/WP Theme/g.test(content) || /WP_Theme/g.test(content) || /WP_THEME/g.test(content) || /wp-theme/g.test(content) || /wp_theme/g.test(content)) { content = content .replace(/WP Theme/g, args.themeName) .replace(/WP_THEME/g, args.constantPrefix.replace(/[^a-zA-Z\d]/g, '_'))