wp-advads 1.0.33 → 1.0.35

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 +86 -66
  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
@@ -1,138 +1,158 @@
1
- # wp-advads Scaffolding Tool
2
-
3
-
4
-
1
+ # wp-advads
5
2
 
6
3
  [![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)
4
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
10
5
 
11
- <p align="center">
12
- <img src="https://img.icons8.com/nolan/256/wordpress.png"/>
13
- </p>
6
+ CLI scaffolding for an **existing** Advanced Ads WordPress plugin. It writes `wp.advads` and file stubs (`class`, `view`, `updates`, `js`, `css`). It does not generate a plugin from scratch.
14
7
 
15
- ## 📃 Introduction
8
+ Requires **Node.js 18+**. Created by [Shakeeb Ahmed](https://github.com/meshakeeb).
16
9
 
17
- CLI tools to streamline development tasks for the Advanced Ads WordPress plugin.
18
- Created by [Shakeeb Ahmed](https://github.com/meshakeeb)
10
+ ## Installation
19
11
 
20
- ## 📦 Installation
21
- Use via npx:
22
12
  ```bash
23
13
  npx wp-advads
24
14
  ```
25
15
 
26
- ## 🚀 Usage
27
- Run the CLI using:
28
16
  ```bash
29
17
  npx wp-advads <command> [options]
30
18
  ```
31
19
 
32
- ## 🔧 Commands
20
+ ## Config
21
+
22
+ Commands (except `init`) need a `wp.advads` file. The CLI uses the nearest ancestor that already has one. `init` writes `wp.advads` in the current directory.
23
+
24
+ If the file is missing, the CLI exits and tells you to run `wp-advads init`. It does not prompt.
25
+
26
+ ## Commands
33
27
 
34
28
  #### `init`
35
- Initializes a new project configuration file.
29
+
30
+ Creates `wp.advads` in the current directory.
31
+
36
32
  ```bash
37
33
  npx wp-advads init
38
34
  ```
39
35
 
36
+ #### `build`
37
+
38
+ Installs PHP dependencies into `packages/` (`COMPOSER_VENDOR_DIR=packages`), dumps the autoloader, runs `npm run build` when `package.json` has a `scripts.build`, then generates a `.pot`.
39
+
40
+ ```bash
41
+ npx wp-advads build
42
+ ```
43
+
44
+ Standalone `build` does not touch release git messages. During `release`, commit bullets are passed in explicitly.
40
45
 
41
46
  #### `release`
42
- Creates a new release for the plugin.
47
+
48
+ Bumps the version, changelog, translations, build, and git (explicit file list, hooks run). Stops on the first failed step.
49
+
43
50
  ```bash
44
51
  npx wp-advads release
45
52
  ```
46
53
 
47
-
48
54
  #### `class <classname> [options]`
49
- Creates a new PHP class file with optional templates.
55
+
56
+ Writes a PHP class under `paths.php`. Combine `--heading` with a template flag (`-i` / `-g` / `-r` / `-s`).
57
+
50
58
  ```bash
51
- npx wp-advads class MyClass -h "Class Heading" -d "Description" -s
59
+ npx wp-advads class MyClass --heading "Class Heading" --description "Description" -s
52
60
  ```
53
61
 
54
- ##### Required Argument:
55
- - `<classname>` – The name of the class.
62
+ - `<classname>` – Class name (namespaces with `\`, e.g. `Foo\Bar`)
63
+ - `--heading <heading>` – File heading
64
+ - `--description <description>` – File description
65
+ - `-i` – Initializer
66
+ - `-g` – Integration
67
+ - `-r` – REST
68
+ - `-s` – Singleton (`__construct` is private)
69
+ - `--force` – Overwrite if the file exists
56
70
 
57
- ##### Optional Argument:
58
- - `-h <heading>` – File heading
59
- - `-d <description>` – File description
60
- - `-i` – Initializer interface
61
- - `-g` – Integration interface
62
- - `-r` – REST interface
63
- - `-s` – Singleton class
71
+ #### `view <viewname> [heading]`
64
72
 
73
+ Writes a PHP view under `paths.views`. Nested names accept `/` or `\`.
65
74
 
66
- #### `view <viewname> [heading]`
67
- Creates a new view file (e.g. template partial).
68
75
  ```bash
69
76
  npx wp-advads view sidebar "Sidebar View"
77
+ npx wp-advads view admin/settings
70
78
  ```
71
79
 
72
- ##### Required Argument:
73
- - `<viewname>` – Name of the view file.
80
+ - `<viewname>` – View file name
81
+ - `[heading]` – Heading comment
82
+ - `--force` – Overwrite if the file exists
74
83
 
75
- ##### Optional Argument:
76
- - `[heading]` – A heading comment added to the view file.
84
+ #### `updates <version>`
77
85
 
86
+ Writes an upgrade file under `paths.updates`. `misc.prefix` from `wp.advads` is required (empty prefix is an error).
78
87
 
79
- #### `updates <version>`
80
- Creates update logic for the given plugin version.
81
88
  ```bash
82
89
  npx wp-advads updates 1.2.3
83
90
  ```
84
91
 
85
- ##### Required Argument:
86
- - `<version>` – Target version number (e.g. `1.2.0`)
92
+ - `<version>` – Target version (e.g. `1.2.3`)
93
+ - `--force` – Overwrite if the file exists
87
94
 
88
95
  #### `js <filename> [options]`
89
- Creates a new JavaScript file.
96
+
97
+ Writes a JavaScript file under `paths.javascript`. Nested names accept `/` or `\`.
98
+
90
99
  ```bash
91
100
  npx wp-advads js script -h "Main JS" -d "Handles the frontend logic"
92
101
  ```
93
102
 
94
- ##### Required Argument:
95
- - `<filename>` – Name of the JavaScript file (without extension).
103
+ - `<filename>` – Name without extension
104
+ - `-h <heading>` – Heading comment
105
+ - `-d <description>` – Description comment
106
+ - `--force` – Overwrite if the file exists
96
107
 
97
- ##### Optional Argument:
98
- - `-h <heading>` – Heading comment for the file.
99
- - `-d <description>` – Description comment for the file.
108
+ #### `css <filename> [options]`
100
109
 
110
+ Writes a CSS file under `paths.css`. Nested names accept `/` or `\`.
101
111
 
102
- #### `css <filename> [options]`
103
- Creates a new CSS file.
104
112
  ```bash
105
113
  npx wp-advads css styles -h "Main CSS" -d "Plugin styles"
106
114
  ```
107
115
 
108
- ##### Required Argument:
109
- - `<filename>` – Name of the CSS file (without extension).
110
-
111
- ##### Optional Argument:
112
- - `-h <heading>` – Heading comment for the file.
113
- - `-d <description>` – Description comment for the file.
116
+ - `<filename>` – Name without extension
117
+ - `-h <heading>` – Heading comment
118
+ - `-d <description>` – Description comment
119
+ - `--force` – Overwrite if the file exists
114
120
 
115
121
  #### `pot`
116
- Generates `.po` and `.mo` translation files.
122
+
123
+ Creates a `.pot` translation template (`wp i18n make-pot`).
124
+
117
125
  ```bash
118
126
  npx wp-advads pot
119
127
  ```
120
128
 
129
+ POT headers (`Last-Translator`, `Language-Team`) use `author.name` and `author.email` from `wp.advads`.
130
+
121
131
  #### `translations`
122
- Downloads translation files from GlotPress.
132
+
133
+ Downloads `.po` / `.mo` files from GlotPress into `glotpress.destination` (default `./languages/`). Locale ids must be `[a-zA-Z0-9_]+`; non-OK HTTP responses are skipped.
134
+
123
135
  ```bash
124
136
  npx wp-advads translations
125
137
  ```
126
138
 
127
- ### ⚠️ Notes
128
- A config file is required for all commands **except** init.
139
+ ## Notes
140
+
141
+ `class`, `view`, `updates`, `js`, and `css` will not overwrite an existing file unless you pass `--force`. Writes cannot escape the project root.
142
+
143
+ ## Tests
144
+
145
+ ```bash
146
+ npm test
147
+ ```
148
+
149
+ That runs `node --experimental-test-module-mocks --test`. Node 18+ is required (`engines.node`).
129
150
 
130
- If one is missing, you'll be prompted to create it with `wp-advads init`.
151
+ ## Author
131
152
 
132
- ### 👤 Author
133
- Shakeeb Ahmed
134
- GitHub: [@meshakeeb](http://github.com/meshakeeb)
153
+ Shakeeb Ahmed
154
+ GitHub: [@meshakeeb](https://github.com/meshakeeb)
135
155
 
136
- ### 📖 Changelog
156
+ ## Changelog
137
157
 
138
- [See the changelog file](./CHANGELOG.md)
158
+ [CHANGELOG.md](./CHANGELOG.md)
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.35",
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
  }