@wp-typia/project-tools 0.20.1 → 0.21.0
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/cli-add-block.js +1 -1
- package/dist/runtime/cli-add-shared.d.ts +73 -5
- package/dist/runtime/cli-add-shared.js +58 -11
- package/dist/runtime/cli-add-workspace-ability.js +11 -57
- package/dist/runtime/cli-add-workspace-admin-view.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-admin-view.js +872 -0
- package/dist/runtime/cli-add-workspace-ai-anchors.js +2 -5
- package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +0 -4
- package/dist/runtime/cli-add-workspace-ai-source-emitters.js +7 -17
- package/dist/runtime/cli-add-workspace-ai.js +4 -6
- package/dist/runtime/cli-add-workspace-assets.d.ts +13 -5
- package/dist/runtime/cli-add-workspace-assets.js +290 -106
- package/dist/runtime/cli-add-workspace-rest-anchors.js +2 -5
- package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +0 -1
- package/dist/runtime/cli-add-workspace-rest-source-emitters.js +7 -14
- package/dist/runtime/cli-add-workspace-rest.js +4 -6
- package/dist/runtime/cli-add-workspace.d.ts +58 -1
- package/dist/runtime/cli-add-workspace.js +588 -18
- package/dist/runtime/cli-add.d.ts +1 -1
- package/dist/runtime/cli-add.js +1 -1
- package/dist/runtime/cli-core.d.ts +8 -5
- package/dist/runtime/cli-core.js +7 -4
- package/dist/runtime/cli-diagnostics.d.ts +84 -1
- package/dist/runtime/cli-diagnostics.js +90 -3
- package/dist/runtime/cli-doctor-workspace.js +552 -13
- package/dist/runtime/cli-doctor.d.ts +4 -2
- package/dist/runtime/cli-doctor.js +2 -1
- package/dist/runtime/cli-help.js +19 -9
- package/dist/runtime/cli-init.d.ts +67 -3
- package/dist/runtime/cli-init.js +603 -64
- package/dist/runtime/cli-validation.js +4 -3
- package/dist/runtime/index.d.ts +9 -4
- package/dist/runtime/index.js +7 -3
- package/dist/runtime/package-json-types.d.ts +12 -0
- package/dist/runtime/package-json-types.js +1 -0
- package/dist/runtime/package-versions.d.ts +17 -2
- package/dist/runtime/package-versions.js +46 -1
- package/dist/runtime/php-utils.d.ts +16 -0
- package/dist/runtime/php-utils.js +59 -0
- package/dist/runtime/scaffold-answer-resolution.js +35 -10
- package/dist/runtime/scaffold-apply-utils.d.ts +2 -3
- package/dist/runtime/scaffold-apply-utils.js +3 -43
- package/dist/runtime/template-source-cache.d.ts +112 -0
- package/dist/runtime/template-source-cache.js +434 -0
- package/dist/runtime/template-source-seeds.js +333 -53
- package/dist/runtime/workspace-inventory.d.ts +43 -2
- package/dist/runtime/workspace-inventory.js +138 -5
- package/package.json +2 -2
|
@@ -2,10 +2,8 @@ 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 { hasPhpFunctionDefinition } from "./php-utils.js";
|
|
5
6
|
const AI_FEATURE_SERVER_GLOB = "/inc/ai-features/*.php";
|
|
6
|
-
function escapeRegex(value) {
|
|
7
|
-
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
8
|
-
}
|
|
9
7
|
/**
|
|
10
8
|
* Patch the workspace bootstrap file so it loads generated AI feature PHP modules.
|
|
11
9
|
*/
|
|
@@ -27,7 +25,6 @@ function ${registerFunctionName}() {
|
|
|
27
25
|
/add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
|
|
28
26
|
/\?>\s*$/u,
|
|
29
27
|
];
|
|
30
|
-
const hasPhpFunctionDefinition = (functionName) => new RegExp(`function\\s+${escapeRegex(functionName)}\\s*\\(`, "u").test(nextSource);
|
|
31
28
|
const insertPhpSnippet = (snippet) => {
|
|
32
29
|
for (const anchor of insertionAnchors) {
|
|
33
30
|
const candidate = nextSource.replace(anchor, (match) => `${snippet}\n${match}`);
|
|
@@ -46,7 +43,7 @@ function ${registerFunctionName}() {
|
|
|
46
43
|
}
|
|
47
44
|
nextSource = `${nextSource.trimEnd()}\n${snippet}\n`;
|
|
48
45
|
};
|
|
49
|
-
if (!hasPhpFunctionDefinition(registerFunctionName)) {
|
|
46
|
+
if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
|
|
50
47
|
insertPhpSnippet(registerFunction);
|
|
51
48
|
}
|
|
52
49
|
else if (!nextSource.includes(AI_FEATURE_SERVER_GLOB)) {
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert an AI feature slug into the PascalCase identifier used by generated types.
|
|
3
|
-
*/
|
|
4
|
-
export declare function toPascalCaseFromAiFeatureSlug(slug: string): string;
|
|
5
1
|
/**
|
|
6
2
|
* Build the workspace inventory entry written into `scripts/block-config.ts` for one AI feature.
|
|
7
3
|
*/
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { quoteTsString } from "./cli-add-shared.js";
|
|
2
2
|
import { buildAiFeatureEndpointManifest } from "./ai-feature-artifacts.js";
|
|
3
3
|
import { OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY, renderScaffoldCompatibilityConfig, resolveScaffoldCompatibilityPolicy, } from "./scaffold-compatibility.js";
|
|
4
|
-
import { toTitleCase } from "./string-case.js";
|
|
5
|
-
/**
|
|
6
|
-
* Convert an AI feature slug into the PascalCase identifier used by generated types.
|
|
7
|
-
*/
|
|
8
|
-
export function toPascalCaseFromAiFeatureSlug(slug) {
|
|
9
|
-
return normalizeBlockSlug(slug)
|
|
10
|
-
.split("-")
|
|
11
|
-
.filter(Boolean)
|
|
12
|
-
.map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
|
|
13
|
-
.join("");
|
|
14
|
-
}
|
|
4
|
+
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
15
5
|
function indentMultiline(source, prefix) {
|
|
16
6
|
return source
|
|
17
7
|
.split("\n")
|
|
@@ -22,7 +12,7 @@ function indentMultiline(source, prefix) {
|
|
|
22
12
|
* Build the workspace inventory entry written into `scripts/block-config.ts` for one AI feature.
|
|
23
13
|
*/
|
|
24
14
|
export function buildAiFeatureConfigEntry(aiFeatureSlug, namespace) {
|
|
25
|
-
const pascalCase =
|
|
15
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
26
16
|
const title = toTitleCase(aiFeatureSlug);
|
|
27
17
|
const compatibilityPolicy = resolveScaffoldCompatibilityPolicy(OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY);
|
|
28
18
|
const manifest = buildAiFeatureEndpointManifest({
|
|
@@ -54,7 +44,7 @@ export function buildAiFeatureConfigEntry(aiFeatureSlug, namespace) {
|
|
|
54
44
|
* Generate TypeScript request, response, and telemetry contracts for an AI feature scaffold.
|
|
55
45
|
*/
|
|
56
46
|
export function buildAiFeatureTypesSource(aiFeatureSlug) {
|
|
57
|
-
const pascalCase =
|
|
47
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
58
48
|
return `import { tags } from 'typia';
|
|
59
49
|
|
|
60
50
|
export interface ${pascalCase}AiFeatureRequest {
|
|
@@ -95,7 +85,7 @@ export interface ${pascalCase}AiFeatureResponse {
|
|
|
95
85
|
* Generate runtime validators for the AI feature request/result/response contracts.
|
|
96
86
|
*/
|
|
97
87
|
export function buildAiFeatureValidatorsSource(aiFeatureSlug) {
|
|
98
|
-
const pascalCase =
|
|
88
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
99
89
|
return `import typia from 'typia';
|
|
100
90
|
|
|
101
91
|
import { toValidationResult } from '@wp-typia/rest';
|
|
@@ -129,7 +119,7 @@ export const apiValidators = {
|
|
|
129
119
|
* Generate the typed client wrapper that calls the scaffolded AI feature endpoint.
|
|
130
120
|
*/
|
|
131
121
|
export function buildAiFeatureApiSource(aiFeatureSlug) {
|
|
132
|
-
const pascalCase =
|
|
122
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
133
123
|
return `import {
|
|
134
124
|
\tcallEndpoint,
|
|
135
125
|
\tresolveRestRouteUrl,
|
|
@@ -187,7 +177,7 @@ export function runAiFeature( request: ${pascalCase}AiFeatureRequest ) {
|
|
|
187
177
|
* Generate React endpoint-mutation hooks for the scaffolded AI feature client wrapper.
|
|
188
178
|
*/
|
|
189
179
|
export function buildAiFeatureDataSource(aiFeatureSlug) {
|
|
190
|
-
const pascalCase =
|
|
180
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
191
181
|
return `import {
|
|
192
182
|
\tuseEndpointMutation,
|
|
193
183
|
\ttype UseEndpointMutationOptions,
|
|
@@ -2,16 +2,14 @@ import { promises as fsp } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { assertAiFeatureDoesNotExist, assertValidGeneratedSlug, getWorkspaceBootstrapPath, normalizeBlockSlug, patchFile, resolveRestResourceNamespace, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
4
4
|
import { ensureBlockConfigCanAddRestManifests } from "./cli-add-block-legacy-validator.js";
|
|
5
|
-
import { buildAiFeatureConfigEntry, buildAiFeatureDataSource, buildAiFeatureSyncScriptSource, buildAiFeatureTypesSource, buildAiFeatureValidatorsSource, buildAiFeatureApiSource,
|
|
5
|
+
import { buildAiFeatureConfigEntry, buildAiFeatureDataSource, buildAiFeatureSyncScriptSource, buildAiFeatureTypesSource, buildAiFeatureValidatorsSource, buildAiFeatureApiSource, } from "./cli-add-workspace-ai-source-emitters.js";
|
|
6
6
|
import { ensureAiFeatureBootstrapAnchors, ensureAiFeaturePackageScripts, ensureAiFeatureSyncProjectAnchors, ensureAiFeatureSyncRestAnchors, } from "./cli-add-workspace-ai-anchors.js";
|
|
7
7
|
import { syncAiFeatureRestArtifacts, syncAiFeatureSchemaArtifact, } from "./ai-feature-artifacts.js";
|
|
8
8
|
import { appendWorkspaceInventoryEntries, readWorkspaceInventory } from "./workspace-inventory.js";
|
|
9
9
|
import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
10
10
|
import { OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY, resolveScaffoldCompatibilityPolicy, updatePluginHeaderCompatibility, } from "./scaffold-compatibility.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
return `'${value.replace(/\\/gu, "\\\\").replace(/'/gu, "\\'")}'`;
|
|
14
|
-
}
|
|
11
|
+
import { quotePhpString } from "./php-utils.js";
|
|
12
|
+
import { toPascalCase, toTitleCase } from "./string-case.js";
|
|
15
13
|
function buildAiFeaturePhpSource(aiFeatureSlug, namespace, phpPrefix, textDomain) {
|
|
16
14
|
const aiFeatureTitle = toTitleCase(aiFeatureSlug);
|
|
17
15
|
const aiFeaturePhpId = aiFeatureSlug.replace(/-/g, "_");
|
|
@@ -441,7 +439,7 @@ export async function runAddAiFeatureCommand({ aiFeatureName, cwd = process.cwd(
|
|
|
441
439
|
await fsp.writeFile(apiFilePath, buildAiFeatureApiSource(aiFeatureSlug), "utf8");
|
|
442
440
|
await fsp.writeFile(dataFilePath, buildAiFeatureDataSource(aiFeatureSlug), "utf8");
|
|
443
441
|
await fsp.writeFile(phpFilePath, buildAiFeaturePhpSource(aiFeatureSlug, resolvedNamespace, workspace.workspace.phpPrefix, workspace.workspace.textDomain), "utf8");
|
|
444
|
-
const pascalCase =
|
|
442
|
+
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
445
443
|
await syncAiFeatureRestArtifacts({
|
|
446
444
|
clientFile: `src/ai-features/${aiFeatureSlug}/api-client.ts`,
|
|
447
445
|
outputDir: path.join("src", "ai-features", aiFeatureSlug),
|
|
@@ -7,7 +7,7 @@ import { type RunAddBindingSourceCommandOptions, type RunAddEditorPluginCommandO
|
|
|
7
7
|
* Defaults to `process.cwd()`.
|
|
8
8
|
* @param options.editorPluginName Human-entered editor-plugin name that will be
|
|
9
9
|
* normalized and validated before files are written.
|
|
10
|
-
* @param options.slot Optional editor plugin shell slot. Defaults to `
|
|
10
|
+
* @param options.slot Optional editor plugin shell slot. Defaults to `sidebar`.
|
|
11
11
|
* @returns A promise that resolves with the normalized `editorPluginSlug`, chosen
|
|
12
12
|
* `slot`, and owning `projectDir` after the scaffold files and inventory entry
|
|
13
13
|
* are written successfully.
|
|
@@ -42,17 +42,25 @@ export declare function runAddPatternCommand({ cwd, patternName, }: RunAddPatter
|
|
|
42
42
|
* Add one block binding source scaffold to an official workspace project.
|
|
43
43
|
*
|
|
44
44
|
* @param options Command options for the binding-source scaffold workflow.
|
|
45
|
+
* @param options.attributeName Optional generated block attribute to declare as
|
|
46
|
+
* bindable. Must be provided together with `blockName`.
|
|
47
|
+
* @param options.blockName Optional generated block slug or full block name to
|
|
48
|
+
* receive the bindable attribute wiring. Must be provided together with
|
|
49
|
+
* `attributeName`.
|
|
45
50
|
* @param options.bindingSourceName Human-entered binding source name that will
|
|
46
51
|
* be normalized and validated before files are written.
|
|
47
52
|
* @param options.cwd Working directory used to resolve the nearest official
|
|
48
53
|
* workspace. Defaults to `process.cwd()`.
|
|
49
54
|
* @returns A promise that resolves with the normalized `bindingSourceSlug` and
|
|
50
|
-
* owning `projectDir` after the server/editor files
|
|
51
|
-
* been written successfully.
|
|
55
|
+
* owning `projectDir` after the server/editor files, optional target block
|
|
56
|
+
* metadata, and inventory entry have been written successfully.
|
|
52
57
|
* @throws {Error} When the command is run outside an official workspace, when
|
|
53
|
-
* the slug is invalid,
|
|
58
|
+
* the slug is invalid, when a binding target is incomplete or unknown, or when
|
|
59
|
+
* a conflicting file or inventory entry exists.
|
|
54
60
|
*/
|
|
55
|
-
export declare function runAddBindingSourceCommand({ bindingSourceName, cwd, }: RunAddBindingSourceCommandOptions): Promise<{
|
|
61
|
+
export declare function runAddBindingSourceCommand({ attributeName, bindingSourceName, blockName, cwd, }: RunAddBindingSourceCommandOptions): Promise<{
|
|
62
|
+
attributeName?: string;
|
|
56
63
|
bindingSourceSlug: string;
|
|
64
|
+
blockSlug?: string;
|
|
57
65
|
projectDir: string;
|
|
58
66
|
}>;
|