@codigodoleo/wp-kit 5.0.0 → 5.0.2
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.
- package/lib/prompts/index.js +1 -1
- package/lib/utils/logger.js +1 -1
- package/modules/blank-theme/index.js +28 -9
- package/modules/blank-theme/templates/functions.php.hbs +21 -15
- package/modules/mu-plugin/index.js +28 -8
- package/modules/mu-plugin/prompts.js +18 -2
- package/modules/mu-plugin/templates/acorn/app/Providers/CoreServiceProvider.php.hbs +1 -1
- package/modules/sage/templates/theme/style.css.hbs +12 -20
- package/package.json +1 -1
- package/templates/.gitignore.hbs +8 -3
- package/templates/README.md.hbs +1 -1
- package/modules/mu-plugin/templates/acorn/resources/.gitkeep +0 -0
- package/modules/mu-plugin/templates/acorn/storage/framework/cache/.gitkeep +0 -0
- package/modules/mu-plugin/templates/acorn/storage/framework/sessions/.gitkeep +0 -0
- package/modules/mu-plugin/templates/acorn/storage/framework/views/.gitkeep +0 -0
package/lib/prompts/index.js
CHANGED
|
@@ -123,7 +123,7 @@ export async function runPrompts({ defaults = false } = {}) {
|
|
|
123
123
|
type: 'input',
|
|
124
124
|
name: 'projectDescription',
|
|
125
125
|
message: 'Project description:',
|
|
126
|
-
default: 'Generated with wp-
|
|
126
|
+
default: 'Generated with wp-kit',
|
|
127
127
|
},
|
|
128
128
|
{
|
|
129
129
|
type: 'input',
|
package/lib/utils/logger.js
CHANGED
|
@@ -18,7 +18,7 @@ export const color = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Prints a formatted message with prefix [wp
|
|
21
|
+
* Prints a formatted message with prefix [leo-wp] and optional color
|
|
22
22
|
* @param {Function} colorFn - Chalk color function (e.g. color.green)
|
|
23
23
|
* @param {string} message - The message to print
|
|
24
24
|
*/
|
|
@@ -4,11 +4,35 @@ import fs from 'fs-extra';
|
|
|
4
4
|
|
|
5
5
|
import { log, color } from '../../lib/utils/logger.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Derive an UPPER_SNAKE constant prefix from a kebab/snake theme slug
|
|
9
|
+
* so the scaffolded functions.php compiles. PHP `define()` keys can
|
|
10
|
+
* contain hyphens, but bare-name references (`MY_NAME_VERSION`) cannot
|
|
11
|
+
* — those parse as subtraction.
|
|
12
|
+
*
|
|
13
|
+
* acme-theme -> ACME_THEME
|
|
14
|
+
* my-site-theme -> MY_SITE_THEME
|
|
15
|
+
* wp-futrading-theme -> WP_FUTRADING_THEME
|
|
16
|
+
*/
|
|
17
|
+
function toConstantPrefix(slug) {
|
|
18
|
+
return slug
|
|
19
|
+
.split(/[-_]/)
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.map((segment) => segment.toUpperCase())
|
|
22
|
+
.join('_');
|
|
23
|
+
}
|
|
24
|
+
|
|
7
25
|
export async function setupModule(context, generator) {
|
|
8
26
|
const themeName = context.blank_theme_name || `${context.projectName}-theme`;
|
|
9
27
|
const themeDir = `content/themes/${themeName}`;
|
|
10
28
|
const absoluteThemeDir = path.join(generator.cwd, themeDir);
|
|
11
29
|
|
|
30
|
+
const themeContext = {
|
|
31
|
+
...context,
|
|
32
|
+
blank_theme_name: themeName,
|
|
33
|
+
blank_theme_constant_prefix: toConstantPrefix(themeName),
|
|
34
|
+
};
|
|
35
|
+
|
|
12
36
|
log(color.blue, `[blank-theme] 📂 Scaffolding blank theme: ${themeDir}`);
|
|
13
37
|
|
|
14
38
|
// 1. Ensure directories exist
|
|
@@ -17,27 +41,22 @@ export async function setupModule(context, generator) {
|
|
|
17
41
|
await fs.ensureDir(path.join(absoluteThemeDir, 'php'));
|
|
18
42
|
|
|
19
43
|
// 2. Generate static files
|
|
20
|
-
await generator.generateFile(
|
|
21
|
-
'style.css',
|
|
22
|
-
{ ...context, blank_theme_name: themeName },
|
|
23
|
-
'blank-theme',
|
|
24
|
-
`${themeDir}/style.css`
|
|
25
|
-
);
|
|
44
|
+
await generator.generateFile('style.css', themeContext, 'blank-theme', `${themeDir}/style.css`);
|
|
26
45
|
await generator.generateFile(
|
|
27
46
|
'functions.php',
|
|
28
|
-
|
|
47
|
+
themeContext,
|
|
29
48
|
'blank-theme',
|
|
30
49
|
`${themeDir}/functions.php`
|
|
31
50
|
);
|
|
32
51
|
await generator.generateFile(
|
|
33
52
|
'vite.config.js',
|
|
34
|
-
|
|
53
|
+
themeContext,
|
|
35
54
|
'blank-theme',
|
|
36
55
|
`${themeDir}/vite.config.js`
|
|
37
56
|
);
|
|
38
57
|
await generator.generateFile(
|
|
39
58
|
'package.json',
|
|
40
|
-
|
|
59
|
+
themeContext,
|
|
41
60
|
'blank-theme',
|
|
42
61
|
`${themeDir}/package.json`
|
|
43
62
|
);
|
|
@@ -5,42 +5,48 @@
|
|
|
5
5
|
* @package {{blank_theme_name}}
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
if (! defined('ABSPATH')) {
|
|
9
11
|
exit;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
define('{{
|
|
13
|
-
define('{{
|
|
14
|
-
define('{{
|
|
14
|
+
define('{{blank_theme_constant_prefix}}_VERSION', '{{projectVersion}}');
|
|
15
|
+
define('{{blank_theme_constant_prefix}}_DIR', get_template_directory());
|
|
16
|
+
define('{{blank_theme_constant_prefix}}_URI', get_template_directory_uri());
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
* Enqueue Vite-compiled assets.
|
|
19
|
+
* Enqueue Vite-compiled assets when the manifest exists.
|
|
18
20
|
*/
|
|
19
|
-
add_action('wp_enqueue_scripts', function () {
|
|
20
|
-
$
|
|
21
|
+
add_action('wp_enqueue_scripts', static function (): void {
|
|
22
|
+
$manifest_path = {{blank_theme_constant_prefix}}_DIR . '/dist/.vite/manifest.json';
|
|
21
23
|
|
|
22
|
-
if (!file_exists($
|
|
24
|
+
if (! file_exists($manifest_path)) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
$
|
|
28
|
+
$manifest = json_decode((string) file_get_contents($manifest_path), true);
|
|
29
|
+
|
|
30
|
+
if (! is_array($manifest)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
27
33
|
|
|
28
|
-
if (isset($
|
|
34
|
+
if (isset($manifest['src/js/app.js']['file'])) {
|
|
29
35
|
wp_enqueue_script(
|
|
30
36
|
'{{blank_theme_name}}-app',
|
|
31
|
-
{{
|
|
37
|
+
{{blank_theme_constant_prefix}}_URI . '/dist/' . $manifest['src/js/app.js']['file'],
|
|
32
38
|
[],
|
|
33
|
-
|
|
39
|
+
{{blank_theme_constant_prefix}}_VERSION,
|
|
34
40
|
true
|
|
35
41
|
);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
if (isset($
|
|
44
|
+
if (isset($manifest['src/scss/app.scss']['file'])) {
|
|
39
45
|
wp_enqueue_style(
|
|
40
46
|
'{{blank_theme_name}}-app',
|
|
41
|
-
{{
|
|
47
|
+
{{blank_theme_constant_prefix}}_URI . '/dist/' . $manifest['src/scss/app.scss']['file'],
|
|
42
48
|
[],
|
|
43
|
-
|
|
49
|
+
{{blank_theme_constant_prefix}}_VERSION
|
|
44
50
|
);
|
|
45
51
|
}
|
|
46
52
|
});
|
|
@@ -35,7 +35,23 @@ function toConstantPrefix(slug) {
|
|
|
35
35
|
|
|
36
36
|
export async function setupModule(context, generator) {
|
|
37
37
|
const pluginName = context.mu_plugin_name || `${context.projectName}-core`;
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
// Sage and an Acorn-flavored MU plugin cannot coexist: both call
|
|
40
|
+
// `Application::configure()->boot()` and the second wins with a
|
|
41
|
+
// clobbered container that drops half its providers (most visibly
|
|
42
|
+
// `view`). The prompts module already hides `mu_plugin_acorn` when
|
|
43
|
+
// Sage is selected, but we also defend at scaffold time so non-
|
|
44
|
+
// interactive paths (env-var driven, --defaults) cannot drift into
|
|
45
|
+
// the broken state.
|
|
46
|
+
const hasSage = (context.selectedContentModules || []).includes('sage');
|
|
47
|
+
if (hasSage && context.mu_plugin_acorn === true) {
|
|
48
|
+
log(
|
|
49
|
+
color.orange,
|
|
50
|
+
'[mu-plugin] ⚠️ Sage is also selected — forcing the minimal (non-Acorn) flavor to avoid a competing Application singleton. If you want the MU plugin to own Acorn, regenerate the project with the `blank-theme` module instead of `sage`.'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const useAcorn = !hasSage && context.mu_plugin_acorn !== false;
|
|
54
|
+
|
|
39
55
|
const pluginDir = `content/mu-plugins/${pluginName}`;
|
|
40
56
|
const absolutePluginDir = path.join(generator.cwd, pluginDir);
|
|
41
57
|
|
|
@@ -82,7 +98,7 @@ export async function setupModule(context, generator) {
|
|
|
82
98
|
* config/app/storage/resources layout, and four documented gotcha fixes
|
|
83
99
|
* baked into the plugin entry file.
|
|
84
100
|
*/
|
|
85
|
-
async function scaffoldAcorn(context, generator, pluginDir,
|
|
101
|
+
async function scaffoldAcorn(context, generator, pluginDir, absolutePluginDir) {
|
|
86
102
|
const { mu_plugin_name: pluginName } = context;
|
|
87
103
|
|
|
88
104
|
// Bedrock Autoloader bootstrap (lives at the mu-plugins root, NOT inside
|
|
@@ -139,7 +155,15 @@ async function scaffoldAcorn(context, generator, pluginDir, _absolutePluginDir)
|
|
|
139
155
|
);
|
|
140
156
|
|
|
141
157
|
// Storage and resources scaffolding (.gitkeep markers committed; runtime
|
|
142
|
-
// contents are ignored via .gitignore
|
|
158
|
+
// contents are ignored via the plugin's own .gitignore).
|
|
159
|
+
//
|
|
160
|
+
// We write the markers directly with fs.ensureFile instead of copying
|
|
161
|
+
// .gitkeep templates because shipping placeholder .gitkeep files is
|
|
162
|
+
// brittle: this repo's own .gitignore has a top-level `logs` rule
|
|
163
|
+
// (Node convention) which silently dropped storage/logs/.gitkeep from
|
|
164
|
+
// the v5.0.0 npm tarball and broke scaffolds at runtime. Writing the
|
|
165
|
+
// marker on the consumer side bypasses both this repo's .gitignore
|
|
166
|
+
// and any future similar trap.
|
|
143
167
|
for (const subdir of [
|
|
144
168
|
'storage/framework/cache',
|
|
145
169
|
'storage/framework/views',
|
|
@@ -147,11 +171,7 @@ async function scaffoldAcorn(context, generator, pluginDir, _absolutePluginDir)
|
|
|
147
171
|
'storage/logs',
|
|
148
172
|
'resources',
|
|
149
173
|
]) {
|
|
150
|
-
await
|
|
151
|
-
`templates/acorn/${subdir}/.gitkeep`,
|
|
152
|
-
'mu-plugin',
|
|
153
|
-
`${pluginDir}/${subdir}/.gitkeep`
|
|
154
|
-
);
|
|
174
|
+
await fs.ensureFile(path.join(absolutePluginDir, subdir, '.gitkeep'));
|
|
155
175
|
}
|
|
156
176
|
}
|
|
157
177
|
|
|
@@ -7,11 +7,27 @@ export default [
|
|
|
7
7
|
when: (answers) => answers.selectedContentModules?.includes('mu-plugin'),
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
|
+
// Acorn-flavored MU plugin and Sage cannot both boot Acorn in the same
|
|
11
|
+
// project — two `Application::configure()->boot()` calls produce
|
|
12
|
+
// competing singletons that clobber providers (View, in particular)
|
|
13
|
+
// and cascade into runtime fatals. The convention this kit enforces:
|
|
14
|
+
//
|
|
15
|
+
// - Sage selected: MU plugin stays minimal (no Acorn), and Sage
|
|
16
|
+
// owns the single Acorn Application.
|
|
17
|
+
// - Sage NOT selected: MU plugin can opt into the Acorn flavor and
|
|
18
|
+
// become the project's Acorn Application host. The recommended
|
|
19
|
+
// theme companion is then the `blank-theme` module.
|
|
20
|
+
//
|
|
21
|
+
// We suppress the prompt entirely when Sage is also selected. The
|
|
22
|
+
// generator (`modules/mu-plugin/index.js`) also defends against this
|
|
23
|
+
// case at scaffold time.
|
|
10
24
|
type: 'confirm',
|
|
11
25
|
name: 'mu_plugin_acorn',
|
|
12
|
-
message: 'MU Plugin: bootstrap with Roots Acorn (
|
|
26
|
+
message: 'MU Plugin: bootstrap with Roots Acorn (project becomes the Acorn host)?',
|
|
13
27
|
default: true,
|
|
14
|
-
when: (answers) =>
|
|
28
|
+
when: (answers) =>
|
|
29
|
+
answers.selectedContentModules?.includes('mu-plugin') &&
|
|
30
|
+
!answers.selectedContentModules?.includes('sage'),
|
|
15
31
|
},
|
|
16
32
|
{
|
|
17
33
|
type: 'confirm',
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
/*
|
|
2
|
-
{{projectName}}
|
|
3
|
-
Theme URI:
|
|
4
|
-
{{
|
|
5
|
-
|
|
6
|
-
{{
|
|
7
|
-
|
|
8
|
-
{{
|
|
9
|
-
|
|
10
|
-
{{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Text Domain:
|
|
14
|
-
{{projectName}}
|
|
15
|
-
License: MIT License License URI:
|
|
16
|
-
{{gitRepository}}/blob/main/LICENSE Requires PHP:
|
|
17
|
-
{{phpVersion}}
|
|
18
|
-
Requires at least:
|
|
19
|
-
{{wpCoreVersion}}
|
|
20
|
-
*/
|
|
1
|
+
/*
|
|
2
|
+
Theme Name: {{projectName}}
|
|
3
|
+
Theme URI: {{gitRepository}}
|
|
4
|
+
Description: {{projectDescription}}
|
|
5
|
+
Version: {{projectVersion}}
|
|
6
|
+
Author: {{author}}
|
|
7
|
+
Author URI: {{gitRepository}}
|
|
8
|
+
Text Domain: {{projectName}}
|
|
9
|
+
License: UNLICENSED
|
|
10
|
+
Requires PHP: {{phpVersion}}
|
|
11
|
+
Requires at least: {{wpCoreVersion}}
|
|
12
|
+
*/
|
package/package.json
CHANGED
package/templates/.gitignore.hbs
CHANGED
|
@@ -16,9 +16,13 @@ content/languages/*
|
|
|
16
16
|
!content/languages/.gitkeep
|
|
17
17
|
content/mu-plugins/*
|
|
18
18
|
!content/mu-plugins/.gitkeep
|
|
19
|
+
{{#if enable_mu_plugin}}!content/mu-plugins/{{mu_plugin_name}}
|
|
20
|
+
{{#if mu_plugin_acorn}}!content/mu-plugins/bedrock-autoloader.php
|
|
21
|
+
{{/if}}{{/if}}
|
|
19
22
|
|
|
20
23
|
# Theme{{#if enable_sage}}
|
|
21
|
-
!content/themes/{{projectName}}{{/if}}
|
|
24
|
+
!content/themes/{{projectName}}{{/if}}{{#if enable_blank_theme}}
|
|
25
|
+
!content/themes/{{blank_theme_name}}{{/if}}
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
# Composer
|
|
@@ -48,9 +52,10 @@ yarn-error.log*
|
|
|
48
52
|
ehthumbs.db
|
|
49
53
|
Thumbs.db
|
|
50
54
|
|
|
51
|
-
# Logs
|
|
55
|
+
# Logs (anchor `logs/` to project root so nested storage/logs/ in the
|
|
56
|
+
# MU plugin and Sage theme is not silently dropped from commits)
|
|
52
57
|
*.log
|
|
53
|
-
logs/
|
|
58
|
+
/logs/
|
|
54
59
|
|
|
55
60
|
# Temporary files
|
|
56
61
|
*.tmp
|
package/templates/README.md.hbs
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|