@wp-typia/project-tools 0.22.4 → 0.22.6
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/dist/runtime/ai-feature-capability.js +20 -0
- package/dist/runtime/cli-add-block.js +16 -11
- package/dist/runtime/cli-add-collision.js +213 -136
- package/dist/runtime/cli-add-help.js +1 -1
- package/dist/runtime/cli-add-kind-ids.d.ts +11 -0
- package/dist/runtime/cli-add-kind-ids.js +20 -0
- package/dist/runtime/cli-add-types.d.ts +2 -8
- package/dist/runtime/cli-add-types.js +1 -17
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +3 -1
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +22 -5
- package/dist/runtime/cli-add-workspace-ability.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ability.js +5 -1
- package/dist/runtime/cli-add-workspace-admin-view-source.d.ts +7 -0
- package/dist/runtime/cli-add-workspace-admin-view-source.js +9 -10
- package/dist/runtime/cli-add-workspace-admin-view-types.d.ts +0 -2
- package/dist/runtime/cli-add-workspace-admin-view-types.js +0 -3
- package/dist/runtime/cli-add-workspace-ai-anchors.js +3 -24
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +14 -6
- package/dist/runtime/cli-add-workspace-assets.js +7 -50
- package/dist/runtime/cli-add-workspace-rest-anchors.js +3 -24
- package/dist/runtime/cli-doctor-workspace-bindings.js +2 -3
- package/dist/runtime/cli-doctor-workspace-blocks.js +2 -3
- package/dist/runtime/cli-doctor-workspace-features.js +6 -11
- package/dist/runtime/cli-doctor-workspace-shared.d.ts +8 -0
- package/dist/runtime/cli-doctor-workspace-shared.js +10 -0
- package/dist/runtime/cli-help.js +1 -1
- package/dist/runtime/cli-init-apply.d.ts +15 -0
- package/dist/runtime/cli-init-apply.js +99 -0
- package/dist/runtime/cli-init-package-json.d.ts +19 -0
- package/dist/runtime/cli-init-package-json.js +191 -0
- package/dist/runtime/cli-init-plan.d.ts +39 -0
- package/dist/runtime/cli-init-plan.js +375 -0
- package/dist/runtime/cli-init-templates.d.ts +27 -0
- package/dist/runtime/cli-init-templates.js +244 -0
- package/dist/runtime/cli-init-types.d.ts +84 -0
- package/dist/runtime/cli-init-types.js +3 -0
- package/dist/runtime/cli-init.d.ts +4 -100
- package/dist/runtime/cli-init.js +6 -878
- package/dist/runtime/fs-async.d.ts +28 -0
- package/dist/runtime/fs-async.js +53 -0
- package/dist/runtime/package-managers.js +1 -1
- package/dist/runtime/php-utils.d.ts +16 -0
- package/dist/runtime/php-utils.js +321 -1
- package/dist/runtime/scaffold-apply-utils.js +10 -20
- package/dist/runtime/scaffold-bootstrap.js +6 -8
- package/dist/runtime/scaffold-compatibility.d.ts +15 -3
- package/dist/runtime/scaffold-compatibility.js +42 -11
- package/dist/runtime/scaffold-documents.js +12 -0
- package/dist/runtime/scaffold-package-manager-files.js +4 -3
- package/dist/runtime/string-case.d.ts +5 -0
- package/dist/runtime/string-case.js +52 -2
- package/dist/runtime/template-source-cache.d.ts +19 -0
- package/dist/runtime/template-source-cache.js +164 -28
- package/dist/runtime/template-source-external.d.ts +7 -0
- package/dist/runtime/template-source-external.js +22 -5
- package/dist/runtime/template-source-normalization.d.ts +1 -1
- package/dist/runtime/template-source-normalization.js +12 -12
- package/dist/runtime/template-source-remote.d.ts +14 -0
- package/dist/runtime/template-source-remote.js +91 -15
- package/dist/runtime/template-source.js +35 -25
- package/dist/runtime/typia-llm.js +7 -0
- package/dist/runtime/version-floor.js +8 -2
- package/dist/runtime/workspace-inventory.d.ts +16 -14
- package/dist/runtime/workspace-inventory.js +310 -239
- package/package.json +6 -1
|
@@ -10,7 +10,7 @@ import { getWorkspaceBootstrapPath, patchFile, } from "./cli-add-shared.js";
|
|
|
10
10
|
import { appendPhpSnippetBeforeClosingTag, executeWorkspaceMutationPlan, insertPhpSnippetBeforeWorkspaceAnchors, } from "./cli-add-workspace-mutation.js";
|
|
11
11
|
import { updatePluginHeaderCompatibility, } from "./scaffold-compatibility.js";
|
|
12
12
|
import { DEFAULT_WORDPRESS_ABILITIES_VERSION, DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION, } from "./package-versions.js";
|
|
13
|
-
import { escapeRegex, findPhpFunctionRange, hasPhpFunctionDefinition, replacePhpFunctionDefinition, } from "./php-utils.js";
|
|
13
|
+
import { escapeRegex, findPhpFunctionRange, hasPhpFunctionCall, hasPhpFunctionDefinition, replacePhpFunctionDefinition, } from "./php-utils.js";
|
|
14
14
|
import { toPascalCase } from "./string-case.js";
|
|
15
15
|
function resolveManagedDependencyVersion(existingVersion, requiredVersion) {
|
|
16
16
|
if (!existingVersion) {
|
|
@@ -130,9 +130,18 @@ function ${enqueueFunctionName}() {
|
|
|
130
130
|
if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
|
|
131
131
|
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
|
|
132
132
|
}
|
|
133
|
-
else
|
|
134
|
-
nextSource
|
|
135
|
-
|
|
133
|
+
else {
|
|
134
|
+
const functionRange = findPhpFunctionRange(nextSource, enqueueFunctionName);
|
|
135
|
+
const functionSource = functionRange
|
|
136
|
+
? nextSource.slice(functionRange.start, functionRange.end)
|
|
137
|
+
: "";
|
|
138
|
+
if (!hasPhpFunctionCall(functionSource, "wp_enqueue_script_module")) {
|
|
139
|
+
const replacedSource = replacePhpFunctionDefinition(nextSource, enqueueFunctionName, enqueueFunction, { trimReplacementStart: true });
|
|
140
|
+
if (!replacedSource) {
|
|
141
|
+
throw new Error(`Unable to repair ${path.basename(bootstrapPath)} for ${enqueueFunctionName}.`);
|
|
142
|
+
}
|
|
143
|
+
nextSource = replacedSource;
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
146
|
if (!nextSource.includes(loadHook)) {
|
|
138
147
|
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, loadHook);
|
|
@@ -301,6 +310,7 @@ async function ensureAbilityWebpackAnchors(workspace) {
|
|
|
301
310
|
* Write generated workflow ability sources and patch shared workspace anchors.
|
|
302
311
|
*/
|
|
303
312
|
export async function scaffoldAbilityWorkspace({ abilitySlug, compatibilityPolicy, workspace, }) {
|
|
313
|
+
const compatibilityWarnings = [];
|
|
304
314
|
const blockConfigPath = path.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
305
315
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
306
316
|
const buildScriptPath = path.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
@@ -331,7 +341,11 @@ export async function scaffoldAbilityWorkspace({ abilitySlug, compatibilityPolic
|
|
|
331
341
|
await fsp.mkdir(abilityDir, { recursive: true });
|
|
332
342
|
await fsp.mkdir(path.dirname(phpFilePath), { recursive: true });
|
|
333
343
|
await ensureAbilityBootstrapAnchors(workspace);
|
|
334
|
-
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy
|
|
344
|
+
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy, {
|
|
345
|
+
onWarning: (warning) => {
|
|
346
|
+
compatibilityWarnings.push(warning);
|
|
347
|
+
},
|
|
348
|
+
}));
|
|
335
349
|
await ensureAbilityPackageScripts(workspace);
|
|
336
350
|
await ensureAbilitySyncProjectAnchors(workspace);
|
|
337
351
|
await ensureAbilityBuildScriptAnchors(workspace);
|
|
@@ -363,4 +377,7 @@ export async function scaffoldAbilityWorkspace({ abilitySlug, compatibilityPolic
|
|
|
363
377
|
});
|
|
364
378
|
},
|
|
365
379
|
});
|
|
380
|
+
return {
|
|
381
|
+
warnings: compatibilityWarnings,
|
|
382
|
+
};
|
|
366
383
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { type RunAddAbilityCommandOptions } from "./cli-add-shared.js";
|
|
2
2
|
/**
|
|
3
3
|
* Add one typed workflow ability scaffold to an official workspace project.
|
|
4
|
+
*
|
|
5
|
+
* @returns Generated ability metadata plus non-fatal scaffold warnings, such
|
|
6
|
+
* as repaired malformed existing plugin header floor values.
|
|
4
7
|
*/
|
|
5
8
|
export declare function runAddAbilityCommand({ abilityName, cwd, }: RunAddAbilityCommandOptions): Promise<{
|
|
6
9
|
abilitySlug: string;
|
|
7
10
|
projectDir: string;
|
|
11
|
+
warnings: string[];
|
|
8
12
|
}>;
|
|
@@ -5,6 +5,9 @@ import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
|
5
5
|
import { REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY, resolveScaffoldCompatibilityPolicy, } from "./scaffold-compatibility.js";
|
|
6
6
|
/**
|
|
7
7
|
* Add one typed workflow ability scaffold to an official workspace project.
|
|
8
|
+
*
|
|
9
|
+
* @returns Generated ability metadata plus non-fatal scaffold warnings, such
|
|
10
|
+
* as repaired malformed existing plugin header floor values.
|
|
8
11
|
*/
|
|
9
12
|
export async function runAddAbilityCommand({ abilityName, cwd = process.cwd(), }) {
|
|
10
13
|
const workspace = resolveWorkspaceProject(cwd);
|
|
@@ -12,7 +15,7 @@ export async function runAddAbilityCommand({ abilityName, cwd = process.cwd(), }
|
|
|
12
15
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
13
16
|
assertAbilityDoesNotExist(workspace.projectDir, abilitySlug, inventory);
|
|
14
17
|
const compatibilityPolicy = resolveScaffoldCompatibilityPolicy(REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY);
|
|
15
|
-
await scaffoldAbilityWorkspace({
|
|
18
|
+
const scaffoldResult = await scaffoldAbilityWorkspace({
|
|
16
19
|
abilitySlug,
|
|
17
20
|
compatibilityPolicy,
|
|
18
21
|
workspace,
|
|
@@ -20,5 +23,6 @@ export async function runAddAbilityCommand({ abilityName, cwd = process.cwd(), }
|
|
|
20
23
|
return {
|
|
21
24
|
abilitySlug,
|
|
22
25
|
projectDir: workspace.projectDir,
|
|
26
|
+
warnings: scaffoldResult.warnings,
|
|
23
27
|
};
|
|
24
28
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type AdminViewRestResource, type AdminViewSource } from './cli-add-workspace-admin-view-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Assert that admin-view package dependencies are available before file writes.
|
|
4
|
+
*
|
|
5
|
+
* This is a no-op while `@wp-typia/dataviews` is publicly available on npm.
|
|
6
|
+
* The exported seam is retained so future availability checks can stay
|
|
7
|
+
* centralized ahead of scaffold mutations.
|
|
8
|
+
*/
|
|
2
9
|
export declare function assertAdminViewPackageAvailability(): void;
|
|
3
10
|
export declare function parseAdminViewSource(source?: string): AdminViewSource | undefined;
|
|
4
11
|
export declare function resolveRestResourceSource(restResources: AdminViewRestResource[], source: AdminViewSource | undefined): AdminViewRestResource | undefined;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { assertValidGeneratedSlug } from './cli-add-shared.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { ADMIN_VIEW_CORE_DATA_ENTITY_KIND_IDS, ADMIN_VIEW_CORE_DATA_ENTITY_NAME_PATTERN, ADMIN_VIEW_CORE_DATA_ENTITY_SEGMENT_PATTERN, ADMIN_VIEW_CORE_DATA_SOURCE_KIND, ADMIN_VIEW_REST_SOURCE_KIND, ADMIN_VIEW_SOURCE_USAGE, isAdminViewCoreDataSource, isAdminViewRestResourceSource, } from './cli-add-workspace-admin-view-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Assert that admin-view package dependencies are available before file writes.
|
|
5
|
+
*
|
|
6
|
+
* This is a no-op while `@wp-typia/dataviews` is publicly available on npm.
|
|
7
|
+
* The exported seam is retained so future availability checks can stay
|
|
8
|
+
* centralized ahead of scaffold mutations.
|
|
9
|
+
*/
|
|
7
10
|
export function assertAdminViewPackageAvailability() {
|
|
8
|
-
|
|
9
|
-
ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, '`wp-typia add admin-view` is temporarily unavailable because `@wp-typia/dataviews` is not published to npm for public installs yet.');
|
|
11
|
+
return;
|
|
13
12
|
}
|
|
14
13
|
function assertValidCoreDataEntitySegment(label, value) {
|
|
15
14
|
const trimmed = value.trim();
|
|
@@ -10,8 +10,6 @@ export declare const ADMIN_VIEWS_ASSET = "build/admin-views/index.asset.php";
|
|
|
10
10
|
export declare const ADMIN_VIEWS_STYLE = "build/admin-views/style-index.css";
|
|
11
11
|
export declare const ADMIN_VIEWS_STYLE_RTL = "build/admin-views/style-index-rtl.css";
|
|
12
12
|
export declare const ADMIN_VIEWS_PHP_GLOB = "/inc/admin-views/*.php";
|
|
13
|
-
export declare const ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV = "WP_TYPIA_ALLOW_UNPUBLISHED_DATAVIEWS";
|
|
14
|
-
export declare const ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED = false;
|
|
15
13
|
export interface AdminViewRestResourceSource {
|
|
16
14
|
kind: typeof ADMIN_VIEW_REST_SOURCE_KIND;
|
|
17
15
|
slug: string;
|
|
@@ -12,9 +12,6 @@ export const ADMIN_VIEWS_ASSET = 'build/admin-views/index.asset.php';
|
|
|
12
12
|
export const ADMIN_VIEWS_STYLE = 'build/admin-views/style-index.css';
|
|
13
13
|
export const ADMIN_VIEWS_STYLE_RTL = 'build/admin-views/style-index-rtl.css';
|
|
14
14
|
export const ADMIN_VIEWS_PHP_GLOB = '/inc/admin-views/*.php';
|
|
15
|
-
export const ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV = 'WP_TYPIA_ALLOW_UNPUBLISHED_DATAVIEWS';
|
|
16
|
-
// Lift this gate in the same release that publishes @wp-typia/dataviews.
|
|
17
|
-
export const ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED = false;
|
|
18
15
|
export function isAdminViewCoreDataSource(source) {
|
|
19
16
|
return source?.kind === ADMIN_VIEW_CORE_DATA_SOURCE_KIND;
|
|
20
17
|
}
|
|
@@ -2,6 +2,7 @@ import { promises as fsp } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { getPackageVersions } from "./package-versions.js";
|
|
4
4
|
import { getWorkspaceBootstrapPath, patchFile, } from "./cli-add-shared.js";
|
|
5
|
+
import { appendPhpSnippetBeforeClosingTag, insertPhpSnippetBeforeWorkspaceAnchors, } from "./cli-add-workspace-mutation.js";
|
|
5
6
|
import { hasPhpFunctionDefinition } from "./php-utils.js";
|
|
6
7
|
const AI_FEATURE_SERVER_GLOB = "/inc/ai-features/*.php";
|
|
7
8
|
/**
|
|
@@ -21,30 +22,8 @@ function ${registerFunctionName}() {
|
|
|
21
22
|
\t}
|
|
22
23
|
}
|
|
23
24
|
`;
|
|
24
|
-
const insertionAnchors = [
|
|
25
|
-
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
26
|
-
/\?>\s*$/u,
|
|
27
|
-
];
|
|
28
|
-
const insertPhpSnippet = (snippet) => {
|
|
29
|
-
for (const anchor of insertionAnchors) {
|
|
30
|
-
const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
|
|
31
|
-
if (candidate !== nextSource) {
|
|
32
|
-
nextSource = candidate;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
37
|
-
};
|
|
38
|
-
const appendPhpSnippet = (snippet) => {
|
|
39
|
-
const closingTagPattern = /\?>\s*$/u;
|
|
40
|
-
if (closingTagPattern.test(nextSource)) {
|
|
41
|
-
nextSource = nextSource.replace(closingTagPattern, `${snippet}\n?>`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
45
|
-
};
|
|
46
25
|
if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
|
|
47
|
-
|
|
26
|
+
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
|
|
48
27
|
}
|
|
49
28
|
else if (!nextSource.includes(AI_FEATURE_SERVER_GLOB)) {
|
|
50
29
|
throw new Error([
|
|
@@ -54,7 +33,7 @@ function ${registerFunctionName}() {
|
|
|
54
33
|
].join(" "));
|
|
55
34
|
}
|
|
56
35
|
if (!nextSource.includes(registerHook)) {
|
|
57
|
-
|
|
36
|
+
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
|
|
58
37
|
}
|
|
59
38
|
return nextSource;
|
|
60
39
|
});
|
|
@@ -14,6 +14,7 @@ import { syncAiFeatureRestArtifacts, syncAiFeatureSchemaArtifact, } from "./ai-f
|
|
|
14
14
|
* Write generated AI feature sources and patch shared workspace anchors.
|
|
15
15
|
*/
|
|
16
16
|
export async function scaffoldAiFeatureWorkspace({ aiFeatureSlug, compatibilityPolicy, namespace, workspace, }) {
|
|
17
|
+
const compatibilityWarnings = [];
|
|
17
18
|
const blockConfigPath = path.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
18
19
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
19
20
|
const packageJsonPath = path.join(workspace.projectDir, "package.json");
|
|
@@ -40,7 +41,11 @@ export async function scaffoldAiFeatureWorkspace({ aiFeatureSlug, compatibilityP
|
|
|
40
41
|
await fsp.mkdir(aiFeatureDir, { recursive: true });
|
|
41
42
|
await fsp.mkdir(path.dirname(phpFilePath), { recursive: true });
|
|
42
43
|
await ensureAiFeatureBootstrapAnchors(workspace);
|
|
43
|
-
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy
|
|
44
|
+
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy, {
|
|
45
|
+
onWarning: (warning) => {
|
|
46
|
+
compatibilityWarnings.push(warning);
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
44
49
|
const packageScriptChanges = await ensureAiFeaturePackageScripts(workspace);
|
|
45
50
|
await ensureAiFeatureSyncProjectAnchors(workspace);
|
|
46
51
|
await ensureAiFeatureSyncRestAnchors(workspace);
|
|
@@ -76,11 +81,14 @@ export async function scaffoldAiFeatureWorkspace({ aiFeatureSlug, compatibilityP
|
|
|
76
81
|
transformSource: ensureBlockConfigCanAddRestManifests,
|
|
77
82
|
});
|
|
78
83
|
return {
|
|
79
|
-
warnings:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
warnings: [
|
|
85
|
+
...compatibilityWarnings,
|
|
86
|
+
...(packageScriptChanges.addedProjectToolsDependency
|
|
87
|
+
? [
|
|
88
|
+
"Added `@wp-typia/project-tools` to devDependencies for `sync-ai`. If this workspace was already installed, rerun your package manager install command before the first `wp-typia sync ai`.",
|
|
89
|
+
]
|
|
90
|
+
: []),
|
|
91
|
+
],
|
|
84
92
|
};
|
|
85
93
|
},
|
|
86
94
|
});
|
|
@@ -8,6 +8,7 @@ import { readWorkspaceInventory, appendWorkspaceInventoryEntries, } from "./work
|
|
|
8
8
|
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
9
9
|
import { findPhpFunctionRange, hasPhpFunctionDefinition, quotePhpString, replacePhpFunctionDefinition, } from "./php-utils.js";
|
|
10
10
|
import { assertBindingSourceDoesNotExist, assertEditorPluginDoesNotExist, assertPatternDoesNotExist, assertValidEditorPluginSlot, assertValidGeneratedSlug, getWorkspaceBootstrapPath, normalizeBlockSlug, patchFile, quoteTsString, resolveWorkspaceBlock, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
11
|
+
import { appendPhpSnippetBeforeClosingTag, insertPhpSnippetBeforeWorkspaceAnchors, } from "./cli-add-workspace-mutation.js";
|
|
11
12
|
import { normalizeOptionalCliString } from "./cli-validation.js";
|
|
12
13
|
const PATTERN_BOOTSTRAP_CATEGORY = "register_block_pattern_category";
|
|
13
14
|
const BINDING_SOURCE_SERVER_GLOB = "/src/bindings/*/server.php";
|
|
@@ -597,39 +598,17 @@ function ${bindingEditorEnqueueFunctionName}() {
|
|
|
597
598
|
\t);
|
|
598
599
|
}
|
|
599
600
|
`;
|
|
600
|
-
const insertionAnchors = [
|
|
601
|
-
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
602
|
-
/\?>\s*$/u,
|
|
603
|
-
];
|
|
604
|
-
const insertPhpSnippet = (snippet) => {
|
|
605
|
-
for (const anchor of insertionAnchors) {
|
|
606
|
-
const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
|
|
607
|
-
if (candidate !== nextSource) {
|
|
608
|
-
nextSource = candidate;
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
613
|
-
};
|
|
614
|
-
const appendPhpSnippet = (snippet) => {
|
|
615
|
-
const closingTagPattern = /\?>\s*$/u;
|
|
616
|
-
if (closingTagPattern.test(nextSource)) {
|
|
617
|
-
nextSource = nextSource.replace(closingTagPattern, `${snippet}\n?>`);
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
621
|
-
};
|
|
622
601
|
if (!hasPhpFunctionDefinition(nextSource, bindingRegistrationFunctionName)) {
|
|
623
|
-
|
|
602
|
+
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingRegistrationFunction);
|
|
624
603
|
}
|
|
625
604
|
if (!hasPhpFunctionDefinition(nextSource, bindingEditorEnqueueFunctionName)) {
|
|
626
|
-
|
|
605
|
+
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingEditorEnqueueFunction);
|
|
627
606
|
}
|
|
628
607
|
if (!nextSource.includes(bindingRegistrationHook)) {
|
|
629
|
-
|
|
608
|
+
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingRegistrationHook);
|
|
630
609
|
}
|
|
631
610
|
if (!nextSource.includes(bindingEditorEnqueueHook)) {
|
|
632
|
-
|
|
611
|
+
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingEditorEnqueueHook);
|
|
633
612
|
}
|
|
634
613
|
return nextSource;
|
|
635
614
|
});
|
|
@@ -679,30 +658,8 @@ function ${enqueueFunctionName}() {
|
|
|
679
658
|
\t}
|
|
680
659
|
}
|
|
681
660
|
`;
|
|
682
|
-
const insertionAnchors = [
|
|
683
|
-
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
684
|
-
/\?>\s*$/u,
|
|
685
|
-
];
|
|
686
|
-
const insertPhpSnippet = (snippet) => {
|
|
687
|
-
for (const anchor of insertionAnchors) {
|
|
688
|
-
const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
|
|
689
|
-
if (candidate !== nextSource) {
|
|
690
|
-
nextSource = candidate;
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
695
|
-
};
|
|
696
|
-
const appendPhpSnippet = (snippet) => {
|
|
697
|
-
const closingTagPattern = /\?>\s*$/u;
|
|
698
|
-
if (closingTagPattern.test(nextSource)) {
|
|
699
|
-
nextSource = nextSource.replace(closingTagPattern, `${snippet}\n?>`);
|
|
700
|
-
return;
|
|
701
|
-
}
|
|
702
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
703
|
-
};
|
|
704
661
|
if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
|
|
705
|
-
|
|
662
|
+
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
|
|
706
663
|
}
|
|
707
664
|
else {
|
|
708
665
|
const requiredReferences = [
|
|
@@ -726,7 +683,7 @@ function ${enqueueFunctionName}() {
|
|
|
726
683
|
}
|
|
727
684
|
}
|
|
728
685
|
if (!nextSource.includes(enqueueHook)) {
|
|
729
|
-
|
|
686
|
+
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, enqueueHook);
|
|
730
687
|
}
|
|
731
688
|
return nextSource;
|
|
732
689
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { getWorkspaceBootstrapPath, patchFile, } from "./cli-add-shared.js";
|
|
3
|
+
import { appendPhpSnippetBeforeClosingTag, insertPhpSnippetBeforeWorkspaceAnchors, } from "./cli-add-workspace-mutation.js";
|
|
3
4
|
import { hasPhpFunctionDefinition } from "./php-utils.js";
|
|
4
5
|
const REST_RESOURCE_SERVER_GLOB = "/inc/rest/*.php";
|
|
5
6
|
export async function ensureRestResourceBootstrapAnchors(workspace) {
|
|
@@ -16,30 +17,8 @@ function ${registerFunctionName}() {
|
|
|
16
17
|
\t}
|
|
17
18
|
}
|
|
18
19
|
`;
|
|
19
|
-
const insertionAnchors = [
|
|
20
|
-
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
21
|
-
/\?>\s*$/u,
|
|
22
|
-
];
|
|
23
|
-
const insertPhpSnippet = (snippet) => {
|
|
24
|
-
for (const anchor of insertionAnchors) {
|
|
25
|
-
const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
|
|
26
|
-
if (candidate !== nextSource) {
|
|
27
|
-
nextSource = candidate;
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
32
|
-
};
|
|
33
|
-
const appendPhpSnippet = (snippet) => {
|
|
34
|
-
const closingTagPattern = /\?>\s*$/u;
|
|
35
|
-
if (closingTagPattern.test(nextSource)) {
|
|
36
|
-
nextSource = nextSource.replace(closingTagPattern, `${snippet}\n?>`);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
40
|
-
};
|
|
41
20
|
if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
|
|
42
|
-
|
|
21
|
+
nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
|
|
43
22
|
}
|
|
44
23
|
else if (!nextSource.includes(REST_RESOURCE_SERVER_GLOB)) {
|
|
45
24
|
throw new Error([
|
|
@@ -49,7 +28,7 @@ function ${registerFunctionName}() {
|
|
|
49
28
|
].join(" "));
|
|
50
29
|
}
|
|
51
30
|
if (!nextSource.includes(registerHook)) {
|
|
52
|
-
|
|
31
|
+
nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
|
|
53
32
|
}
|
|
54
33
|
return nextSource;
|
|
55
34
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parseScaffoldBlockMetadata } from "@wp-typia/block-runtime/blocks";
|
|
4
|
-
import { checkExistingFiles, createDoctorCheck, WORKSPACE_BINDING_EDITOR_ASSET, WORKSPACE_BINDING_EDITOR_SCRIPT, WORKSPACE_BINDING_SERVER_GLOB, } from "./cli-doctor-workspace-shared.js";
|
|
4
|
+
import { checkExistingFiles, createDoctorCheck, resolveWorkspaceBootstrapPath, WORKSPACE_BINDING_EDITOR_ASSET, WORKSPACE_BINDING_EDITOR_SCRIPT, WORKSPACE_BINDING_SERVER_GLOB, } from "./cli-doctor-workspace-shared.js";
|
|
5
5
|
import { escapeRegex } from "./php-utils.js";
|
|
6
6
|
function checkWorkspaceBindingBootstrap(projectDir, packageName) {
|
|
7
|
-
const
|
|
8
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
7
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
9
8
|
if (!fs.existsSync(bootstrapPath)) {
|
|
10
9
|
return createDoctorCheck("Binding bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
11
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parseScaffoldBlockMetadata } from "@wp-typia/block-runtime/blocks";
|
|
4
|
-
import { checkExistingFiles, createDoctorCheck, WORKSPACE_FULL_BLOCK_NAME_PATTERN, WORKSPACE_GENERATED_BLOCK_ARTIFACTS, } from "./cli-doctor-workspace-shared.js";
|
|
4
|
+
import { checkExistingFiles, createDoctorCheck, resolveWorkspaceBootstrapPath, WORKSPACE_FULL_BLOCK_NAME_PATTERN, WORKSPACE_GENERATED_BLOCK_ARTIFACTS, } from "./cli-doctor-workspace-shared.js";
|
|
5
5
|
import { HOOKED_BLOCK_ANCHOR_PATTERN, HOOKED_BLOCK_POSITION_SET, } from "./hooked-blocks.js";
|
|
6
6
|
import { hasExecutablePattern, hasUncommentedPattern, maskTypeScriptCommentsAndLiterals, } from "./ts-source-masking.js";
|
|
7
7
|
const WORKSPACE_COLLECTION_IMPORT_LINE = "import '../../collection';";
|
|
@@ -306,8 +306,7 @@ function checkWorkspaceBlockIframeCompatibility(projectDir, blockSlug) {
|
|
|
306
306
|
];
|
|
307
307
|
}
|
|
308
308
|
function checkWorkspacePatternBootstrap(projectDir, packageName) {
|
|
309
|
-
const
|
|
310
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
309
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
311
310
|
if (!fs.existsSync(bootstrapPath)) {
|
|
312
311
|
return createDoctorCheck("Pattern bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
313
312
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { EDITOR_PLUGIN_SLOT_IDS, REST_RESOURCE_METHOD_IDS, REST_RESOURCE_NAMESPACE_PATTERN, resolveEditorPluginSlotAlias, } from "./cli-add-shared.js";
|
|
4
|
-
import { checkExistingFiles, createDoctorCheck, WORKSPACE_ABILITY_EDITOR_ASSET, WORKSPACE_ABILITY_EDITOR_SCRIPT, WORKSPACE_ABILITY_GLOB, WORKSPACE_ADMIN_VIEW_ASSET, WORKSPACE_ADMIN_VIEW_GLOB, WORKSPACE_ADMIN_VIEW_SCRIPT, WORKSPACE_ADMIN_VIEW_STYLE, WORKSPACE_AI_FEATURE_GLOB, WORKSPACE_EDITOR_PLUGIN_EDITOR_ASSET, WORKSPACE_EDITOR_PLUGIN_EDITOR_SCRIPT, WORKSPACE_EDITOR_PLUGIN_EDITOR_STYLE, WORKSPACE_REST_RESOURCE_GLOB, } from "./cli-doctor-workspace-shared.js";
|
|
4
|
+
import { checkExistingFiles, createDoctorCheck, resolveWorkspaceBootstrapPath, WORKSPACE_ABILITY_EDITOR_ASSET, WORKSPACE_ABILITY_EDITOR_SCRIPT, WORKSPACE_ABILITY_GLOB, WORKSPACE_ADMIN_VIEW_ASSET, WORKSPACE_ADMIN_VIEW_GLOB, WORKSPACE_ADMIN_VIEW_SCRIPT, WORKSPACE_ADMIN_VIEW_STYLE, WORKSPACE_AI_FEATURE_GLOB, WORKSPACE_EDITOR_PLUGIN_EDITOR_ASSET, WORKSPACE_EDITOR_PLUGIN_EDITOR_SCRIPT, WORKSPACE_EDITOR_PLUGIN_EDITOR_STYLE, WORKSPACE_REST_RESOURCE_GLOB, } from "./cli-doctor-workspace-shared.js";
|
|
5
5
|
import { escapeRegex } from "./php-utils.js";
|
|
6
6
|
function getWorkspaceRestResourceRequiredFiles(restResource) {
|
|
7
7
|
const schemaNames = new Set();
|
|
@@ -46,8 +46,7 @@ function checkWorkspaceRestResourceConfig(restResource) {
|
|
|
46
46
|
: "REST resource namespace or methods are invalid");
|
|
47
47
|
}
|
|
48
48
|
function checkWorkspaceRestResourceBootstrap(projectDir, packageName, phpPrefix) {
|
|
49
|
-
const
|
|
50
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
49
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
51
50
|
if (!fs.existsSync(bootstrapPath)) {
|
|
52
51
|
return createDoctorCheck("REST resource bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
53
52
|
}
|
|
@@ -93,8 +92,7 @@ function checkWorkspaceAbilityConfig(projectDir, ability) {
|
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
function checkWorkspaceAbilityBootstrap(projectDir, packageName, phpPrefix) {
|
|
96
|
-
const
|
|
97
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
95
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
98
96
|
if (!fs.existsSync(bootstrapPath)) {
|
|
99
97
|
return createDoctorCheck("Ability bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
100
98
|
}
|
|
@@ -169,8 +167,7 @@ function checkWorkspaceAiFeatureConfig(aiFeature) {
|
|
|
169
167
|
: "AI feature namespace is invalid");
|
|
170
168
|
}
|
|
171
169
|
function checkWorkspaceAiFeatureBootstrap(projectDir, packageName, phpPrefix) {
|
|
172
|
-
const
|
|
173
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
170
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
174
171
|
if (!fs.existsSync(bootstrapPath)) {
|
|
175
172
|
return createDoctorCheck("AI feature bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
176
173
|
}
|
|
@@ -204,8 +201,7 @@ function checkWorkspaceEditorPluginConfig(editorPlugin) {
|
|
|
204
201
|
: `Unsupported editor plugin slot "${editorPlugin.slot}". Expected one of: ${EDITOR_PLUGIN_SLOT_IDS.join(", ")} or legacy aliases PluginSidebar, PluginDocumentSettingPanel.`);
|
|
205
202
|
}
|
|
206
203
|
function checkWorkspaceEditorPluginBootstrap(projectDir, packageName, phpPrefix) {
|
|
207
|
-
const
|
|
208
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
204
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
209
205
|
if (!fs.existsSync(bootstrapPath)) {
|
|
210
206
|
return createDoctorCheck("Editor plugin bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
211
207
|
}
|
|
@@ -269,8 +265,7 @@ function checkWorkspaceAdminViewConfig(adminView, inventory) {
|
|
|
269
265
|
: "Admin view source must use rest-resource:<slug> with a list-capable REST resource or core-data:<postType|taxonomy>/<name>");
|
|
270
266
|
}
|
|
271
267
|
function checkWorkspaceAdminViewBootstrap(projectDir, packageName, phpPrefix) {
|
|
272
|
-
const
|
|
273
|
-
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
268
|
+
const bootstrapPath = resolveWorkspaceBootstrapPath(projectDir, packageName);
|
|
274
269
|
if (!fs.existsSync(bootstrapPath)) {
|
|
275
270
|
return createDoctorCheck("Admin view bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
276
271
|
}
|
|
@@ -58,6 +58,14 @@ export declare function createDoctorScopeCheck(status: DoctorCheck["status"], de
|
|
|
58
58
|
* @returns Relative PHP bootstrap filename for the workspace root.
|
|
59
59
|
*/
|
|
60
60
|
export declare function getWorkspaceBootstrapRelativePath(packageName: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve the expected workspace bootstrap file inside a project root.
|
|
63
|
+
*
|
|
64
|
+
* @param projectDir Absolute workspace root directory.
|
|
65
|
+
* @param packageName Package name used to derive the plugin bootstrap basename.
|
|
66
|
+
* @returns Absolute PHP bootstrap file path for the workspace root.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveWorkspaceBootstrapPath(projectDir: string, packageName: string): string;
|
|
61
69
|
/**
|
|
62
70
|
* Verify that every referenced relative file exists inside a workspace.
|
|
63
71
|
*
|
|
@@ -71,6 +71,16 @@ export function createDoctorScopeCheck(status, detail) {
|
|
|
71
71
|
export function getWorkspaceBootstrapRelativePath(packageName) {
|
|
72
72
|
return `${packageName.split("/").pop() ?? packageName}.php`;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the expected workspace bootstrap file inside a project root.
|
|
76
|
+
*
|
|
77
|
+
* @param projectDir Absolute workspace root directory.
|
|
78
|
+
* @param packageName Package name used to derive the plugin bootstrap basename.
|
|
79
|
+
* @returns Absolute PHP bootstrap file path for the workspace root.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveWorkspaceBootstrapPath(projectDir, packageName) {
|
|
82
|
+
return path.join(projectDir, getWorkspaceBootstrapRelativePath(packageName));
|
|
83
|
+
}
|
|
74
84
|
/**
|
|
75
85
|
* Verify that every referenced relative file exists inside a workspace.
|
|
76
86
|
*
|
package/dist/runtime/cli-help.js
CHANGED
|
@@ -52,7 +52,7 @@ Notes:
|
|
|
52
52
|
\`add admin-view\` scaffolds an opt-in DataViews-powered WordPress admin screen under \`src/admin-views/\`.
|
|
53
53
|
Pass \`--source rest-resource:<slug>\` to reuse a list-capable REST resource.
|
|
54
54
|
Pass \`--source core-data:postType/post\` or \`--source core-data:taxonomy/category\` to bind a WordPress-owned entity collection.
|
|
55
|
-
|
|
55
|
+
Generated admin-view workspaces add \`@wp-typia/dataviews\` and the needed WordPress DataViews packages as opt-in dependencies.
|
|
56
56
|
\`query-loop\` is create-only. Use \`wp-typia create <project-dir> --template query-loop\`; \`wp-typia add block\` accepts only basic, interactivity, persistence, and compound families.
|
|
57
57
|
\`add variation\` uses an existing workspace block from \`scripts/block-config.ts\`.
|
|
58
58
|
\`add style\` registers a Block Styles option for an existing generated block.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RetrofitInitPlan } from "./cli-init-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Apply the previewed retrofit init plan to disk.
|
|
4
|
+
*
|
|
5
|
+
* The command snapshots package.json and generated helper targets before
|
|
6
|
+
* writing, then rolls those files back automatically if any write fails.
|
|
7
|
+
*
|
|
8
|
+
* @param projectDir Project root that should receive the retrofit surface.
|
|
9
|
+
* @param options Optional package-manager override used for emitted scripts and
|
|
10
|
+
* follow-up guidance.
|
|
11
|
+
* @returns The applied retrofit init plan describing the persisted changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyInitPlan(projectDir: string, options?: {
|
|
14
|
+
packageManager?: string;
|
|
15
|
+
}): Promise<RetrofitInitPlan>;
|