wp-advads 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.github/workflows/test.yml +17 -0
  2. package/CHANGELOG.md +23 -1
  3. package/LICENSE +15 -0
  4. package/README.md +8 -7
  5. package/package.json +9 -7
  6. package/src/app.js +17 -11
  7. package/src/commands/build.js +72 -59
  8. package/src/commands/class.js +34 -40
  9. package/src/commands/css.js +13 -19
  10. package/src/commands/init.js +4 -1
  11. package/src/commands/javascript.js +13 -19
  12. package/src/commands/release/change-version.js +14 -17
  13. package/src/commands/release/changelog.js +23 -31
  14. package/src/commands/release/git.js +25 -11
  15. package/src/commands/release/github.js +63 -12
  16. package/src/commands/release/semver.js +22 -25
  17. package/src/commands/release/translations.js +17 -23
  18. package/src/commands/release.js +3 -4
  19. package/src/commands/updates.js +20 -17
  20. package/src/commands/views.js +16 -18
  21. package/src/commands/wp-glotpress.js +125 -126
  22. package/src/commands/wp-pot.js +17 -9
  23. package/src/utilities/filesystem.js +57 -36
  24. package/src/utilities/flow.js +21 -0
  25. package/src/utilities/formatting.js +13 -4
  26. package/src/utilities/index.js +1 -1
  27. package/src/utilities/misc.js +1 -6
  28. package/src/utilities/settings.js +34 -14
  29. package/src/utilities/shell.js +60 -8
  30. package/template/files/class-singleton.php +5 -0
  31. package/template/files/javascript.js +0 -2
  32. package/template/files/view.php +2 -0
  33. package/test/build.test.js +168 -0
  34. package/test/changelog-locales.test.js +49 -0
  35. package/test/class.test.js +47 -0
  36. package/test/compile-templates.test.js +70 -0
  37. package/test/deps-hygiene.test.js +46 -0
  38. package/test/engines.test.js +11 -0
  39. package/test/get-latest-tag.test.js +51 -0
  40. package/test/git-precheck.test.js +44 -0
  41. package/test/github-final.test.js +93 -0
  42. package/test/glotpress-download.test.js +176 -0
  43. package/test/nested-path.test.js +39 -0
  44. package/test/no-fs-extra.test.js +11 -0
  45. package/test/package-identity.test.js +19 -0
  46. package/test/path-confine.test.js +42 -0
  47. package/test/pot-docs.test.js +27 -0
  48. package/test/pot-headers.test.js +49 -0
  49. package/test/project-root.test.js +26 -0
  50. package/test/release-waterfall.test.js +62 -0
  51. package/test/semver.test.js +25 -0
  52. package/test/settings-clone.test.js +34 -0
  53. package/test/settings-path.test.js +31 -0
  54. package/test/shell.test.js +100 -0
  55. package/test/singleton.test.js +14 -0
  56. package/test/stable-tag.test.js +13 -0
  57. package/test/stub-security.test.js +37 -0
  58. package/test/template-folder.test.js +19 -0
  59. package/test/translations.test.js +51 -0
  60. package/test/update-file-content.test.js +38 -0
  61. package/test/updates.test.js +39 -0
  62. package/test/version.test.js +22 -0
  63. package/test/view-escape.test.js +17 -0
  64. package/test/view.test.js +33 -0
  65. package/test/write-force.test.js +47 -0
  66. package/src/utilities/semver.js +0 -45
  67. package/template/.github/pull_request_template.md +0 -52
  68. package/template/configs/.editorconfig +0 -27
  69. package/template/configs/.eslintignore +0 -13
  70. package/template/configs/.eslintrc.js +0 -13
  71. package/template/configs/.phpcs.xml.dist +0 -87
  72. package/template/configs/.prettierignore +0 -49
  73. package/template/configs/.prettierrc.js +0 -3
  74. package/template/configs/.stylelintrc +0 -44
  75. package/template/configs/composer.json +0 -51
  76. package/template/configs/gitattributes +0 -34
  77. package/template/configs/gitignore +0 -43
  78. package/template/configs/package.json +0 -66
  79. package/template/configs/postcss.config.js +0 -6
  80. package/template/configs/tailwind.config.js +0 -8
  81. package/template/configs/webpack.mix.js +0 -65
  82. package/template/configs/webpack.mix.local.js +0 -3
  83. package/template/includes/index.php +0 -2
  84. package/template/index.js +0 -0
  85. package/template/index.php +0 -4
  86. package/template/plugin/assets/scss/app.scss +0 -0
  87. package/template/plugin/assets/src/app.js +0 -0
  88. package/template/tools/laravel-mix/wp-pot.js +0 -57
  89. package/template/tools/wp-glotpress.js +0 -162
@@ -0,0 +1,17 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-node@v4
13
+ with:
14
+ node-version: 22
15
+ cache: npm
16
+ - run: npm ci
17
+ - run: npm test
package/CHANGELOG.md CHANGED
@@ -4,9 +4,31 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
5
5
 
6
6
  ---
7
+ ## [1.0.34] - 2026-09-11
8
+
9
+ ### Changed
10
+ - `init` only writes `wp.advads`; this CLI is commands inside an existing plugin, not a full-plugin generator.
11
+ - `build` runs the consumer `package.json` `scripts.build` when present, and no longer mutates release commit messages.
12
+ - Release git commit uses an explicit file list and runs hooks (`--no-verify` and `git add .` are gone).
13
+ - Shell-outs fail closed; large builds stream via `spawn`.
14
+ - Scaffold writes stay inside the project root and refuse to overwrite unless `--force`.
15
+ - Nested `js` / `css` / `view` paths accept `/` and `\`.
16
+ - POT headers come from `author` in config; `pot` docs match that it writes a `.pot`.
17
+ - Requires Node `>=18`. Package description grammar and license (ISC) match the repo.
18
+
19
+ ### Fixed
20
+ - `view` and `updates` compile with the real `init` config shape (`description`, `misc.prefix`).
21
+ - Class `--heading` plus `-i`/`-g`/`-r`/`-s` selects the right template.
22
+ - SemVer pre-release increment (`alpha.2` → `alpha.3`) and invalid tags.
23
+ - `getLatestTag`, GitHub permission/fetch, and `updateFileContent` stop release on error instead of continuing.
24
+ - Singleton stub constructor is private; GlotPress locale ids are sanitized.
25
+
26
+ ### Removed
27
+ - Laravel Mix / PHPCS / plugin boilerplate templates, `fs-extra`, and the `async` package.
28
+
7
29
  ## [1.0.28] - 2025-04-20
8
30
  ### Added
9
- - `pot` command to generate `.po` and `.mo` translation files.
31
+ - `pot` command to generate `.pot` translation files.
10
32
  - `translations` command to download translation files from GlotPress.
11
33
 
12
34
  ## [1.0.23] - 2025-04-15
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Shakeeb Ahmed
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
 
6
6
  [![npm version](https://img.shields.io/npm/v/wp-advads.svg)](https://www.npmjs.com/package/wp-advads)
7
- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
- ![Version](https://img.shields.io/badge/version-2.0.0-yellow.svg)
7
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
10
8
 
11
9
  <p align="center">
12
10
  <img src="https://img.icons8.com/nolan/256/wordpress.png"/>
@@ -37,6 +35,7 @@ Initializes a new project configuration file.
37
35
  npx wp-advads init
38
36
  ```
39
37
 
38
+ `wp.advads` lives in the nearest ancestor directory that already has that file. `init` creates it in the current directory.
40
39
 
41
40
  #### `release`
42
41
  Creates a new release for the plugin.
@@ -48,15 +47,15 @@ npx wp-advads release
48
47
  #### `class <classname> [options]`
49
48
  Creates a new PHP class file with optional templates.
50
49
  ```bash
51
- npx wp-advads class MyClass -h "Class Heading" -d "Description" -s
50
+ npx wp-advads class MyClass --heading "Class Heading" --description "Description" -s
52
51
  ```
53
52
 
54
53
  ##### Required Argument:
55
54
  - `<classname>` – The name of the class.
56
55
 
57
56
  ##### Optional Argument:
58
- - `-h <heading>` – File heading
59
- - `-d <description>` – File description
57
+ - `--heading <heading>` – File heading
58
+ - `--description <description>` – File description
60
59
  - `-i` – Initializer interface
61
60
  - `-g` – Integration interface
62
61
  - `-r` – REST interface
@@ -113,7 +112,7 @@ npx wp-advads css styles -h "Main CSS" -d "Plugin styles"
113
112
  - `-d <description>` – Description comment for the file.
114
113
 
115
114
  #### `pot`
116
- Generates `.po` and `.mo` translation files.
115
+ Generates a `.pot` translation template.
117
116
  ```bash
118
117
  npx wp-advads pot
119
118
  ```
@@ -129,6 +128,8 @@ A config file is required for all commands **except** init.
129
128
 
130
129
  If one is missing, you'll be prompted to create it with `wp-advads init`.
131
130
 
131
+ `class`, `view`, `updates`, `js`, and `css` will not overwrite an existing file unless you pass `--force`.
132
+
132
133
  ### 👤 Author
133
134
  Shakeeb Ahmed
134
135
  GitHub: [@meshakeeb](http://github.com/meshakeeb)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "wp-advads",
4
- "version": "1.0.33",
5
- "description": "Create a Advanced Ads wordPress plugin eco system.",
4
+ "version": "1.0.34",
5
+ "description": "Create an Advanced Ads WordPress plugin ecosystem.",
6
6
  "author": {
7
7
  "name": "Shakeeb Ahmed",
8
8
  "email": "me@shakeebahmed.com",
@@ -13,7 +13,8 @@
13
13
  "wp-advads": "src/app.js"
14
14
  },
15
15
  "scripts": {
16
- "start": "node src/app.js"
16
+ "start": "node src/app.js",
17
+ "test": "node --experimental-test-module-mocks --test"
17
18
  },
18
19
  "repository": {
19
20
  "type": "git",
@@ -25,15 +26,16 @@
25
26
  "generator"
26
27
  ],
27
28
  "license": "ISC",
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
28
32
  "bugs": {
29
- "url": "https://github.com/advanced-ads/npm-scaffolding/issues"
33
+ "url": "https://github.com/advanced-ads/wp-advads/issues"
30
34
  },
31
- "homepage": "https://github.com/advanced-ads/npm-scaffolding#readme",
35
+ "homepage": "https://github.com/advanced-ads/wp-advads#readme",
32
36
  "dependencies": {
33
- "async": "^3.2.6",
34
37
  "chalk": "^5.4.1",
35
38
  "commander": "^13.1.0",
36
- "fs-extra": "^11.3.0",
37
39
  "inquirer": "^12.5.2",
38
40
  "lodash": "^4.17.21",
39
41
  "log-symbols": "^7.0.0"
package/src/app.js CHANGED
@@ -5,6 +5,9 @@
5
5
  */
6
6
  import chalk from 'chalk'
7
7
  import { program } from 'commander'
8
+ import { readFileSync } from 'node:fs'
9
+ import { dirname, join } from 'node:path'
10
+ import { fileURLToPath } from 'node:url'
8
11
 
9
12
  /**
10
13
  * Commands
@@ -12,6 +15,10 @@ import { program } from 'commander'
12
15
  import * as commands from './commands/index.js'
13
16
  import { configFileExists, onNewLine } from './utilities/index.js'
14
17
 
18
+ const { version } = JSON.parse(
19
+ readFileSync( join( dirname( fileURLToPath( import.meta.url ) ), '../package.json' ), 'utf8' )
20
+ )
21
+
15
22
  /**
16
23
  * App
17
24
  */
@@ -19,7 +26,7 @@ const app = async () => {
19
26
  console.log(
20
27
  [
21
28
  chalk.hex('#FADC00').inverse.bold('Advanced Ads WordPress Plugin Toolkit'),
22
- chalk.white( 'v2.0.0' ),
29
+ chalk.white( 'v' + version ),
23
30
  chalk.dim( 'by Shakeeb Ahmed' )
24
31
  ].join(" ")
25
32
  );
@@ -31,7 +38,7 @@ const app = async () => {
31
38
  program
32
39
  .name('wp-advads')
33
40
  .description('CLI to Advanced Ads scaffolding utilities')
34
- .version('2.0.0')
41
+ .version(version)
35
42
  .hook('preAction', (thisCommand, actionCommand) => {
36
43
  if ( 'init' !== actionCommand.name() && ! configFileExists() ) {
37
44
  onNewLine(chalk.bgRed.white('Config file not found. Run `wp-advads init` to create a new config file.'));
@@ -52,12 +59,6 @@ const app = async () => {
52
59
  .description('Build the plugin/theme according to the config file')
53
60
  .action(commands.build);
54
61
 
55
- // Command: plugin
56
- // program
57
- // .command('plugin')
58
- // .description('Create a new plugin')
59
- // .action(commands.plugin);
60
-
61
62
  // Command: release
62
63
  program
63
64
  .command('release')
@@ -69,12 +70,13 @@ const app = async () => {
69
70
  .command('class')
70
71
  .description('Create a new class file')
71
72
  .argument('<classname>', 'Classname')
72
- .option('-h <heading>', 'Heading of the file')
73
- .option('-d <description>', 'Description of the file')
73
+ .option('--heading <heading>', 'Heading of the file')
74
+ .option('--description <description>', 'Description of the file')
74
75
  .option('-i', 'Initializer interface template')
75
76
  .option('-g', 'Integration interface template')
76
77
  .option('-r', 'Rest interface template')
77
78
  .option('-s', 'Singleton template')
79
+ .option('--force', 'Overwrite an existing file')
78
80
  .action(commands.classFile);
79
81
 
80
82
  // Command: view
@@ -83,6 +85,7 @@ const app = async () => {
83
85
  .description('Create a new view')
84
86
  .argument('<viewname>', 'name of the view')
85
87
  .argument('[heading]', 'Heading of the file')
88
+ .option('--force', 'Overwrite an existing file')
86
89
  .action(commands.views);
87
90
 
88
91
  // Command: updates
@@ -90,6 +93,7 @@ const app = async () => {
90
93
  .command('updates')
91
94
  .description('Updates for the plugin')
92
95
  .argument('<version>', 'version number')
96
+ .option('--force', 'Overwrite an existing file')
93
97
  .action(commands.updates);
94
98
 
95
99
  // Command: js
@@ -99,6 +103,7 @@ const app = async () => {
99
103
  .argument('<filename>', 'name of the file')
100
104
  .option('-h <heading>', 'Heading of the file')
101
105
  .option('-d <description>', 'Description of the file')
106
+ .option('--force', 'Overwrite an existing file')
102
107
  .action(commands.javascript);
103
108
 
104
109
  // Command: css
@@ -108,12 +113,13 @@ const app = async () => {
108
113
  .argument('<filename>', 'name of the file')
109
114
  .option('-h <heading>', 'Heading of the file')
110
115
  .option('-d <description>', 'Description of the file')
116
+ .option('--force', 'Overwrite an existing file')
111
117
  .action(commands.css);
112
118
 
113
119
  // Command: wp-pot
114
120
  program
115
121
  .command('pot')
116
- .description('Create po and mo files')
122
+ .description('Create a .pot file')
117
123
  .action(commands.wpPot);
118
124
 
119
125
  // Command: wp-glotpress
@@ -3,80 +3,93 @@
3
3
  */
4
4
  import fs from 'fs';
5
5
  import chalk from 'chalk'
6
- import { waterfall } from 'async'
7
6
  import logSymbols from 'log-symbols'
8
7
 
9
8
  /**
10
9
  * Node dependencies
11
10
  */
12
- import { pluginData } from './release.js';
13
11
  import wpPot from './wp-pot.js';
14
12
  import { heading, onSameLine, execCommand } from '../utilities/index.js'
15
13
 
16
- export default function wpBuild(nextProcess = null) {
14
+ export default function wpBuild(nextProcess = null, commitMessages = null) {
17
15
  heading('Building the plugin...')
18
16
  console.log('------------------------------------------------');
19
17
 
20
- waterfall(
21
- [
22
- (next) => {
23
- process.stdout.write('Clearing packages folder...')
24
- try {
25
- fs.rmSync( 'packages', { recursive: true, force: true } );
26
- onSameLine(`${logSymbols.success} Cleared packages folder`)
27
- } catch ( _ ) {}
28
- next();
29
- },
30
- (next) => {
31
- process.stdout.write('Installing PHP dependencies...')
32
-
33
- execCommand(
34
- 'composer install -o -a -n --no-dev --no-scripts',
35
- function() {
36
- onSameLine(`${logSymbols.success} Installed PHP dependencies`);
37
- process.stderr.write('Composer dumping....')
38
-
39
- execCommand('composer dump', function() {
40
- onSameLine(`${logSymbols.success} Composer updated`)
41
- pluginData.commitMessages.push('update 3rd party dependecies')
42
- next();
43
- })
44
- },
45
- {
46
- env: { ...process.env, COMPOSER_VENDOR_DIR: 'packages' },
47
- }
48
- );
49
-
50
- },
51
- (next) => {
52
- process.stdout.write('Building plugin resources...')
53
- execCommand( 'npx wp-scripts build', function() {
54
- onSameLine(`${logSymbols.success} Built plugin resources`);
55
- pluginData.commitMessages.push('Build plugin resources')
56
- next();
57
- });
58
- },
59
- (next) => {
60
- console.log('')
61
- wpPot(next);
62
- },
63
- ],
64
- ( err, results ) => {
65
- if (err) {
66
- console.log('');
67
- console.log( `${logSymbols.error} ${chalk.bold.red(`We failed somewhere! Work hard mate...`)}` )
68
- if (typeof nextProcess === 'function') {
69
- nextProcess(true);
70
- }
71
- return
72
- }
73
-
18
+ run( commitMessages )
19
+ .then( () => {
74
20
  if (typeof nextProcess === 'function') {
75
21
  nextProcess();
76
22
  } else {
77
23
  console.log('');
78
24
  console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
79
25
  }
80
- }
81
- );
26
+ } )
27
+ .catch( ( err ) => {
28
+ console.log('');
29
+ console.log( `${logSymbols.error} ${chalk.bold.red(`We failed somewhere! Work hard mate...`)}` )
30
+ if (typeof nextProcess === 'function') {
31
+ nextProcess(true);
32
+ }
33
+ } )
34
+ }
35
+
36
+ function run( commitMessages ) {
37
+ return ( async () => {
38
+ process.stdout.write('Clearing packages folder...')
39
+ try {
40
+ fs.rmSync( 'packages', { recursive: true, force: true } );
41
+ onSameLine(`${logSymbols.success} Cleared packages folder`)
42
+ } catch ( err ) {
43
+ onSameLine(`${logSymbols.error} ${err.message}`)
44
+ throw err
45
+ }
46
+
47
+ process.stdout.write('Installing PHP dependencies...')
48
+
49
+ const composerEnv = {
50
+ env: { ...process.env, COMPOSER_VENDOR_DIR: 'packages' },
51
+ }
52
+
53
+ await runExec( 'composer install -o -a -n --no-dev --no-scripts', composerEnv )
54
+ onSameLine(`${logSymbols.success} Installed PHP dependencies`);
55
+ process.stderr.write('Composer dumping....')
56
+
57
+ await runExec( 'composer dump', composerEnv )
58
+ onSameLine(`${logSymbols.success} Composer updated`)
59
+ commitMessages?.push( 'update 3rd party dependencies' )
60
+
61
+ process.stdout.write('Building plugin resources...')
62
+ let buildScript
63
+ try {
64
+ buildScript = JSON.parse( fs.readFileSync( 'package.json', 'utf8' ) ).scripts?.build
65
+ } catch {
66
+ buildScript = null
67
+ }
68
+
69
+ if ( ! buildScript ) {
70
+ onSameLine(`${logSymbols.warning} No package.json build script, skipping`)
71
+ } else {
72
+ await runExec( 'npm run build' )
73
+ onSameLine(`${logSymbols.success} Built plugin resources`);
74
+ commitMessages?.push( 'Build plugin resources' )
75
+ }
76
+
77
+ console.log('')
78
+ await new Promise( ( resolve, reject ) => {
79
+ wpPot( ( err ) => err ? reject( err ) : resolve() )
80
+ } )
81
+ } )()
82
+ }
83
+
84
+ function runExec( cmd, options ) {
85
+ return new Promise( ( resolve, reject ) => {
86
+ execCommand( cmd, ( stdout, error, stderr ) => {
87
+ if ( error ) {
88
+ onSameLine(`${logSymbols.error} ${stderr || error.message}`)
89
+ reject( error )
90
+ return
91
+ }
92
+ resolve( stdout )
93
+ }, options )
94
+ } )
82
95
  }
@@ -1,8 +1,3 @@
1
- /**
2
- * External Dependencies
3
- */
4
- import capitalize from 'lodash/capitalize.js';
5
-
6
1
  /**
7
2
  * Node Dependencies
8
3
  */
@@ -11,53 +6,52 @@ import path from 'path';
11
6
  /**
12
7
  * Internal Dependencies
13
8
  */
14
- import { getSetting, writeFile, filenameToHeading, heading, getProjectRoot, msgErrorTitle, getTemplateFile, compileTemplate, runCommand } from "../utilities/index.js";
9
+ import { getSetting, filenameToHeading, heading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
15
10
 
16
11
  function templateName(options) {
17
- const length = Object.keys(options).length
12
+ if ( options.i ) {
13
+ return 'class-initializer';
14
+ }
18
15
 
19
- if ( 0 === length ) {
20
- return 'class-empty';
16
+ if ( options.g ) {
17
+ return 'class-integration';
21
18
  }
22
19
 
23
- const hash = {
24
- 'i': 'class-initializer',
25
- 'g': 'class-integration',
26
- 'r': 'class-rest',
27
- 's': 'class-singleton',
20
+ if ( options.r ) {
21
+ return 'class-rest';
28
22
  }
29
- const has = Object.keys(options)[0]
30
23
 
31
- return hash[has] ?? 'class-empty';
24
+ if ( options.s ) {
25
+ return 'class-singleton';
26
+ }
27
+
28
+ return 'class-empty';
32
29
  }
33
30
 
34
31
  export default (classname, options) => {
35
32
  heading('Creating class file...')
36
33
  const {
37
- h: header = null,
38
- d: description = null,
34
+ heading: header = null,
35
+ description = null,
39
36
  } = options
40
37
 
41
- try {
42
- const template = templateName(options);
43
- const namespace = classname.split('\\');
44
- const paths = classname.toLowerCase().split('\\');
45
- const filename = paths.pop().replace(/_/g, '-') + '.php';
46
- const folder = path.join(getProjectRoot(), getSetting('paths.php'), paths.join('/'));;
47
-
48
- // Data
49
- const data = getSetting();
50
- data.heading = header || filenameToHeading(filename) + ' template file';
51
- data.description = description || 'Brief description of the styles in this file';
52
- data.className = namespace.pop();
53
- data.namespace = namespace.length > 0 ? '\\' + namespace.join('\\') : '';
54
-
55
- const content = compileTemplate(getTemplateFile(`files/${template}.php`), data);
56
- writeFile(folder, `class-${filename}`, content);
57
- runCommand( 'composer', [ 'dump' ], () => {} );
58
- }
59
- catch (err) {
60
- msgErrorTitle('We failed!!!');
61
- throw err;
62
- }
38
+ const template = templateName(options);
39
+ const namespace = classname.split('\\');
40
+ const paths = classname.toLowerCase().split('\\');
41
+ const filename = paths.pop().replace(/_/g, '-') + '.php';
42
+ const folder = path.join(getProjectRoot(), getSetting('paths.php'), paths.join('/'));
43
+
44
+ writeFromTemplate(
45
+ folder,
46
+ `class-${filename}`,
47
+ `files/${template}.php`,
48
+ {
49
+ ...getSetting(),
50
+ heading: header || filenameToHeading(filename) + ' template file',
51
+ description: description || 'Brief description of the styles in this file',
52
+ className: namespace.pop(),
53
+ namespace: namespace.length > 0 ? '\\' + namespace.join('\\') : '',
54
+ },
55
+ options.force
56
+ )
63
57
  }
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Node Dependencies
4
3
  */
@@ -7,7 +6,7 @@ import path from 'path';
7
6
  /**
8
7
  * Internal Dependencies
9
8
  */
10
- import { getSetting, writeFile, heading, filenameToHeading, getProjectRoot, msgErrorTitle, getTemplateFile, compileTemplate } from "../utilities/index.js";
9
+ import { getSetting, heading, filenameToHeading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
11
10
 
12
11
  export default (name, options) => {
13
12
  heading('Creating CSS file...')
@@ -16,21 +15,16 @@ export default (name, options) => {
16
15
  d: description = null,
17
16
  } = options
18
17
 
19
- try {
20
- const paths = name.toLowerCase().split('\\')
21
- const filename = paths.pop() + '.css';
22
- const folder = path.join(getProjectRoot(), getSetting('paths.css'), paths.join('/'));
23
-
24
- // Data
25
- const data = getSetting();
26
- data.heading = header || filenameToHeading(name) + ' styles.';
27
- data.description = description || 'Brief description of the styles in this file';
28
-
29
- const content = compileTemplate(getTemplateFile('files/stylesheet.css'), data);
30
- writeFile(folder, filename, content);
31
- }
32
- catch (err) {
33
- msgErrorTitle('We failed!!!');
34
- throw err;
35
- }
18
+ const dest = path.join( getProjectRoot(), getSetting( 'paths.css' ), name.toLowerCase().replaceAll( '\\', '/' ) ) + '.css'
19
+ writeFromTemplate(
20
+ path.dirname( dest ),
21
+ path.basename( dest ),
22
+ 'files/stylesheet.css',
23
+ {
24
+ ...getSetting(),
25
+ heading: header || filenameToHeading(name) + ' styles.',
26
+ description: description || 'Brief description of the styles in this file',
27
+ },
28
+ options.force
29
+ )
36
30
  }
@@ -2,13 +2,16 @@
2
2
  * External dependencies
3
3
  */
4
4
  import inquirer from 'inquirer'
5
- import kebabCase from 'lodash/kebabCase.js'
6
5
 
7
6
  /**
8
7
  * Node dependencies
9
8
  */
10
9
  import { getSetting, heading, saveConfig, msgSuccessTitle } from '../utilities/index.js'
11
10
 
11
+ function kebabCase( value ) {
12
+ return String( value ).toLowerCase().replace( /\s+/g, '-' )
13
+ }
14
+
12
15
  export default async () => {
13
16
  const questions = [
14
17
  // Product
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Node Dependencies
4
3
  */
@@ -7,7 +6,7 @@ import path from 'path';
7
6
  /**
8
7
  * Internal Dependencies
9
8
  */
10
- import { getSetting, writeFile, heading, filenameToHeading, getProjectRoot, msgErrorTitle, getTemplateFile, compileTemplate } from "../utilities/index.js";
9
+ import { getSetting, heading, filenameToHeading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
11
10
 
12
11
  export default (name, options) => {
13
12
  heading('Creating javascript file...')
@@ -16,21 +15,16 @@ export default (name, options) => {
16
15
  d: description = null,
17
16
  } = options
18
17
 
19
- try {
20
- const paths = name.toLowerCase().split('\\')
21
- const filename = paths.pop() + '.js';
22
- const folder = path.join(getProjectRoot(), getSetting('paths.javascript'), paths.join('/'));
23
-
24
- // Data
25
- const data = getSetting();
26
- data.heading = header || filenameToHeading(name) + ' module.';
27
- data.description = description || 'Description of the module';
28
-
29
- const content = compileTemplate(getTemplateFile('files/javascript.js'), data);
30
- writeFile(folder, filename, content);
31
- }
32
- catch (err) {
33
- msgErrorTitle('We failed!!!');
34
- throw err;
35
- }
18
+ const dest = path.join( getProjectRoot(), getSetting( 'paths.javascript' ), name.toLowerCase().replaceAll( '\\', '/' ) ) + '.js'
19
+ writeFromTemplate(
20
+ path.dirname( dest ),
21
+ path.basename( dest ),
22
+ 'files/javascript.js',
23
+ {
24
+ ...getSetting(),
25
+ heading: header || filenameToHeading(name) + ' module.',
26
+ description: description || 'Description of the module',
27
+ },
28
+ options.force
29
+ )
36
30
  }