@wp-typia/project-tools 0.23.1 → 0.24.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/built-in-block-non-ts-basic-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-basic-artifacts.js +84 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-compound-artifacts.js +36 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-compound-templates.js +453 -0
- package/dist/runtime/built-in-block-non-ts-family-artifacts.d.ts +8 -26
- package/dist/runtime/built-in-block-non-ts-family-artifacts.js +8 -1034
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-interactivity-artifacts.js +83 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.d.ts +9 -0
- package/dist/runtime/built-in-block-non-ts-persistence-artifacts.js +33 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.d.ts +23 -0
- package/dist/runtime/built-in-block-non-ts-persistence-templates.js +395 -0
- package/dist/runtime/cli-add-collision.js +8 -0
- package/dist/runtime/cli-add-help.js +10 -7
- package/dist/runtime/cli-add-kind-ids.d.ts +1 -1
- package/dist/runtime/cli-add-kind-ids.js +1 -0
- package/dist/runtime/cli-add-types.d.ts +28 -1
- package/dist/runtime/cli-add-types.js +2 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.d.ts +24 -0
- package/dist/runtime/cli-add-workspace-ability-anchors.js +294 -0
- package/dist/runtime/cli-add-workspace-ability-registry.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-ability-registry.js +51 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +1 -1
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +5 -311
- package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +1 -1
- package/dist/runtime/cli-add-workspace-ai-anchors.d.ts +4 -4
- package/dist/runtime/cli-add-workspace-ai-anchors.js +4 -232
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +4 -2
- package/dist/runtime/cli-add-workspace-ai-source-emitters.d.ts +1 -4
- package/dist/runtime/cli-add-workspace-ai-source-emitters.js +1 -145
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.d.ts +5 -0
- package/dist/runtime/cli-add-workspace-ai-sync-rest-anchors.js +236 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ai-sync-script-source.js +145 -0
- package/dist/runtime/cli-add-workspace-assets.d.ts +6 -63
- package/dist/runtime/cli-add-workspace-assets.js +6 -950
- package/dist/runtime/cli-add-workspace-binding-source-anchors.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-binding-source-anchors.js +112 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-binding-source-source-emitters.js +436 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-binding-source-types.js +1 -0
- package/dist/runtime/cli-add-workspace-binding-source.d.ts +40 -0
- package/dist/runtime/cli-add-workspace-binding-source.js +275 -0
- package/dist/runtime/cli-add-workspace-block-style.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-block-style.js +148 -0
- package/dist/runtime/cli-add-workspace-block-transform.d.ts +32 -0
- package/dist/runtime/cli-add-workspace-block-transform.js +197 -0
- package/dist/runtime/cli-add-workspace-contract.js +1 -1
- package/dist/runtime/cli-add-workspace-core-variation.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-core-variation.js +322 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.d.ts +37 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-anchors.js +206 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.d.ts +47 -0
- package/dist/runtime/cli-add-workspace-editor-plugin-source-emitters.js +219 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-editor-plugin.js +78 -0
- package/dist/runtime/cli-add-workspace-hooked-block.d.ts +23 -0
- package/dist/runtime/cli-add-workspace-hooked-block.js +57 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-integration-env-files.js +65 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.d.ts +38 -0
- package/dist/runtime/cli-add-workspace-integration-env-package-json.js +122 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.d.ts +44 -0
- package/dist/runtime/cli-add-workspace-integration-env-source-emitters.js +262 -0
- package/dist/runtime/cli-add-workspace-integration-env.js +5 -345
- package/dist/runtime/cli-add-workspace-pattern-anchors.d.ts +10 -0
- package/dist/runtime/cli-add-workspace-pattern-anchors.js +95 -0
- package/dist/runtime/cli-add-workspace-pattern-options.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-options.js +113 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.d.ts +20 -0
- package/dist/runtime/cli-add-workspace-pattern-source-emitters.js +57 -0
- package/dist/runtime/cli-add-workspace-pattern.d.ts +42 -0
- package/dist/runtime/cli-add-workspace-pattern.js +99 -0
- package/dist/runtime/cli-add-workspace-post-meta.js +1 -1
- package/dist/runtime/cli-add-workspace-registration-hooks.d.ts +50 -0
- package/dist/runtime/cli-add-workspace-registration-hooks.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-anchors.d.ts +6 -9
- package/dist/runtime/cli-add-workspace-rest-anchors.js +6 -466
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-bootstrap-anchors.js +108 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-contract-sync-anchors.js +142 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.d.ts +51 -0
- package/dist/runtime/cli-add-workspace-rest-generated-source-emitters.js +415 -0
- package/dist/runtime/cli-add-workspace-rest-generated.js +5 -3
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.d.ts +80 -0
- package/dist/runtime/cli-add-workspace-rest-manual-source-emitters.js +238 -0
- package/dist/runtime/cli-add-workspace-rest-manual.js +3 -16
- package/dist/runtime/cli-add-workspace-rest-php-templates.d.ts +1 -7
- package/dist/runtime/cli-add-workspace-rest-php-templates.js +3 -322
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.d.ts +33 -0
- package/dist/runtime/cli-add-workspace-rest-resource-php-routing-template.js +145 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.d.ts +9 -0
- package/dist/runtime/cli-add-workspace-rest-resource-sync-anchors.js +162 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.d.ts +7 -0
- package/dist/runtime/cli-add-workspace-rest-schema-helper-php-template.js +193 -0
- package/dist/runtime/cli-add-workspace-rest-source-emitters.d.ts +5 -99
- package/dist/runtime/cli-add-workspace-rest-source-emitters.js +5 -663
- package/dist/runtime/cli-add-workspace-rest-source-utils.d.ts +17 -0
- package/dist/runtime/cli-add-workspace-rest-source-utils.js +50 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.d.ts +56 -0
- package/dist/runtime/cli-add-workspace-rest-sync-script-shared.js +122 -0
- package/dist/runtime/cli-add-workspace-rest-types.d.ts +3 -3
- package/dist/runtime/cli-add-workspace-variation.d.ts +22 -0
- package/dist/runtime/cli-add-workspace-variation.js +162 -0
- package/dist/runtime/cli-add-workspace.d.ts +42 -107
- package/dist/runtime/cli-add-workspace.js +42 -674
- package/dist/runtime/cli-add.d.ts +3 -3
- package/dist/runtime/cli-add.js +2 -2
- package/dist/runtime/cli-core.d.ts +2 -1
- package/dist/runtime/cli-core.js +1 -1
- package/dist/runtime/cli-doctor-workspace-bindings.js +59 -0
- package/dist/runtime/cli-doctor-workspace-block-addons.js +33 -5
- package/dist/runtime/cli-doctor.d.ts +2 -0
- package/dist/runtime/cli-doctor.js +13 -2
- package/dist/runtime/cli-help.js +6 -4
- package/dist/runtime/index.d.ts +5 -2
- package/dist/runtime/index.js +4 -2
- package/dist/runtime/local-dev-presets.js +2 -1
- package/dist/runtime/package-versions.d.ts +1 -0
- package/dist/runtime/package-versions.js +10 -2
- package/dist/runtime/pattern-catalog.d.ts +122 -0
- package/dist/runtime/pattern-catalog.js +471 -0
- package/dist/runtime/post-meta-binding-fields.d.ts +46 -0
- package/dist/runtime/post-meta-binding-fields.js +135 -0
- package/dist/runtime/typia-llm-json-schema.d.ts +24 -0
- package/dist/runtime/typia-llm-json-schema.js +33 -0
- package/dist/runtime/typia-llm-openapi-constraints.d.ts +20 -0
- package/dist/runtime/typia-llm-openapi-constraints.js +254 -0
- package/dist/runtime/typia-llm-projection.d.ts +25 -0
- package/dist/runtime/typia-llm-projection.js +58 -0
- package/dist/runtime/typia-llm-render.d.ts +21 -0
- package/dist/runtime/typia-llm-render.js +252 -0
- package/dist/runtime/typia-llm-sync.d.ts +10 -0
- package/dist/runtime/typia-llm-sync.js +63 -0
- package/dist/runtime/typia-llm-types.d.ts +197 -0
- package/dist/runtime/typia-llm-types.js +1 -0
- package/dist/runtime/typia-llm.d.ts +9 -255
- package/dist/runtime/typia-llm.js +5 -634
- package/dist/runtime/workspace-inventory-mutations.js +13 -0
- package/dist/runtime/workspace-inventory-section-descriptors.js +9 -1
- package/dist/runtime/workspace-inventory-templates.d.ts +2 -2
- package/dist/runtime/workspace-inventory-templates.js +9 -1
- package/dist/runtime/workspace-inventory-types.d.ts +9 -1
- package/package.json +8 -3
- package/templates/_shared/compound/core/scripts/block-config.ts.mustache +22 -0
- package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +103 -2
- package/templates/_shared/compound/core/src/inner-blocks-templates.ts.mustache +13 -0
- package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +22 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RunAddPatternCommandOptions } from "./cli-add-shared.js";
|
|
2
|
+
import type { PatternCatalogScope } from "./pattern-catalog.js";
|
|
3
|
+
/**
|
|
4
|
+
* Add one PHP block pattern shell to an official workspace project.
|
|
5
|
+
*
|
|
6
|
+
* @param options Command options for the pattern scaffold workflow.
|
|
7
|
+
* @param options.catalogTitle Optional human-readable title. Defaults to the
|
|
8
|
+
* title-cased form of the normalized pattern slug.
|
|
9
|
+
* @param options.contentFile Optional safe relative project path directly
|
|
10
|
+
* under `src/patterns/` or one nested directory under `src/patterns/` for the
|
|
11
|
+
* generated PHP file. Defaults to `src/patterns/full/<slug>.php` or
|
|
12
|
+
* `src/patterns/sections/<slug>.php`.
|
|
13
|
+
* @param options.cwd Working directory used to resolve the nearest official workspace.
|
|
14
|
+
* Defaults to `process.cwd()`.
|
|
15
|
+
* @param options.patternName Human-entered pattern name that will be normalized
|
|
16
|
+
* and validated before files are written.
|
|
17
|
+
* @param options.patternScope Catalog scope (`full` or `section`). Defaults to `full`.
|
|
18
|
+
* @param options.sectionRole Section role slug. Required only when
|
|
19
|
+
* `patternScope` is `section`.
|
|
20
|
+
* @param options.tags Optional pattern tags as a comma-separated string or
|
|
21
|
+
* array. Tags are normalized, deduplicated, and sorted.
|
|
22
|
+
* @param options.thumbnailUrl Optional thumbnail URL or relative asset path
|
|
23
|
+
* recorded in the inventory entry.
|
|
24
|
+
* @returns A promise that resolves with the normalized `patternSlug`, owning
|
|
25
|
+
* `projectDir`, resolved `contentFile`, `patternScope`, `tags`, `title`, and
|
|
26
|
+
* optional `sectionRole` and `thumbnailUrl` after the pattern file and
|
|
27
|
+
* inventory entry have been written successfully.
|
|
28
|
+
* @throws {Error} When the command is run outside an official workspace, when
|
|
29
|
+
* the pattern slug, scope, section-role coupling, tag values, or content file
|
|
30
|
+
* path are invalid, or when a conflicting target file or inventory entry
|
|
31
|
+
* already exists.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runAddPatternCommand({ catalogTitle, contentFile, cwd, patternName, patternScope, sectionRole, tags, thumbnailUrl, }: RunAddPatternCommandOptions): Promise<{
|
|
34
|
+
contentFile: string;
|
|
35
|
+
patternSlug: string;
|
|
36
|
+
patternScope: PatternCatalogScope;
|
|
37
|
+
projectDir: string;
|
|
38
|
+
sectionRole?: string;
|
|
39
|
+
tags: string[];
|
|
40
|
+
title: string;
|
|
41
|
+
thumbnailUrl?: string;
|
|
42
|
+
}>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { promises as fsp } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { assertPatternDoesNotExist, assertValidGeneratedSlug, getWorkspaceBootstrapPath, normalizeBlockSlug, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
4
|
+
import { ensurePatternBootstrapAnchors } from "./cli-add-workspace-pattern-anchors.js";
|
|
5
|
+
import { resolvePatternCatalogOptions } from "./cli-add-workspace-pattern-options.js";
|
|
6
|
+
import { buildPatternConfigEntry, buildPatternSource, } from "./cli-add-workspace-pattern-source-emitters.js";
|
|
7
|
+
import { appendWorkspaceInventoryEntries, readWorkspaceInventoryAsync, } from "./workspace-inventory.js";
|
|
8
|
+
import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
9
|
+
/**
|
|
10
|
+
* Add one PHP block pattern shell to an official workspace project.
|
|
11
|
+
*
|
|
12
|
+
* @param options Command options for the pattern scaffold workflow.
|
|
13
|
+
* @param options.catalogTitle Optional human-readable title. Defaults to the
|
|
14
|
+
* title-cased form of the normalized pattern slug.
|
|
15
|
+
* @param options.contentFile Optional safe relative project path directly
|
|
16
|
+
* under `src/patterns/` or one nested directory under `src/patterns/` for the
|
|
17
|
+
* generated PHP file. Defaults to `src/patterns/full/<slug>.php` or
|
|
18
|
+
* `src/patterns/sections/<slug>.php`.
|
|
19
|
+
* @param options.cwd Working directory used to resolve the nearest official workspace.
|
|
20
|
+
* Defaults to `process.cwd()`.
|
|
21
|
+
* @param options.patternName Human-entered pattern name that will be normalized
|
|
22
|
+
* and validated before files are written.
|
|
23
|
+
* @param options.patternScope Catalog scope (`full` or `section`). Defaults to `full`.
|
|
24
|
+
* @param options.sectionRole Section role slug. Required only when
|
|
25
|
+
* `patternScope` is `section`.
|
|
26
|
+
* @param options.tags Optional pattern tags as a comma-separated string or
|
|
27
|
+
* array. Tags are normalized, deduplicated, and sorted.
|
|
28
|
+
* @param options.thumbnailUrl Optional thumbnail URL or relative asset path
|
|
29
|
+
* recorded in the inventory entry.
|
|
30
|
+
* @returns A promise that resolves with the normalized `patternSlug`, owning
|
|
31
|
+
* `projectDir`, resolved `contentFile`, `patternScope`, `tags`, `title`, and
|
|
32
|
+
* optional `sectionRole` and `thumbnailUrl` after the pattern file and
|
|
33
|
+
* inventory entry have been written successfully.
|
|
34
|
+
* @throws {Error} When the command is run outside an official workspace, when
|
|
35
|
+
* the pattern slug, scope, section-role coupling, tag values, or content file
|
|
36
|
+
* path are invalid, or when a conflicting target file or inventory entry
|
|
37
|
+
* already exists.
|
|
38
|
+
*/
|
|
39
|
+
export async function runAddPatternCommand({ catalogTitle, contentFile, cwd = process.cwd(), patternName, patternScope, sectionRole, tags, thumbnailUrl, }) {
|
|
40
|
+
const workspace = resolveWorkspaceProject(cwd);
|
|
41
|
+
const patternSlug = assertValidGeneratedSlug("Pattern name", normalizeBlockSlug(patternName), "wp-typia add pattern <name>");
|
|
42
|
+
const patternCatalogOptions = resolvePatternCatalogOptions(patternSlug, {
|
|
43
|
+
catalogTitle,
|
|
44
|
+
contentFile,
|
|
45
|
+
cwd,
|
|
46
|
+
patternName,
|
|
47
|
+
patternScope,
|
|
48
|
+
sectionRole,
|
|
49
|
+
tags,
|
|
50
|
+
thumbnailUrl,
|
|
51
|
+
});
|
|
52
|
+
const inventory = await readWorkspaceInventoryAsync(workspace.projectDir);
|
|
53
|
+
assertPatternDoesNotExist(workspace.projectDir, patternSlug, inventory);
|
|
54
|
+
const contentFilePath = path.join(workspace.projectDir, patternCatalogOptions.contentFile);
|
|
55
|
+
if (await fsp.stat(contentFilePath).then(() => true, (error) => {
|
|
56
|
+
if (error.code === "ENOENT") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
})) {
|
|
61
|
+
throw new Error(`A pattern already exists at ${patternCatalogOptions.contentFile}. Choose a different name.`);
|
|
62
|
+
}
|
|
63
|
+
const blockConfigPath = path.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
64
|
+
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
65
|
+
const patternFilePath = contentFilePath;
|
|
66
|
+
const mutationSnapshot = {
|
|
67
|
+
fileSources: await snapshotWorkspaceFiles([blockConfigPath, bootstrapPath]),
|
|
68
|
+
snapshotDirs: [],
|
|
69
|
+
targetPaths: [patternFilePath],
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
await fsp.mkdir(path.dirname(patternFilePath), { recursive: true });
|
|
73
|
+
await ensurePatternBootstrapAnchors(workspace);
|
|
74
|
+
await fsp.writeFile(patternFilePath, buildPatternSource(patternSlug, workspace.workspace.namespace, patternCatalogOptions.sectionRole, workspace.workspace.textDomain, patternCatalogOptions.title), "utf8");
|
|
75
|
+
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
76
|
+
patternEntries: [
|
|
77
|
+
buildPatternConfigEntry(patternSlug, patternCatalogOptions),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
contentFile: patternCatalogOptions.contentFile,
|
|
82
|
+
patternSlug,
|
|
83
|
+
patternScope: patternCatalogOptions.patternScope,
|
|
84
|
+
projectDir: workspace.projectDir,
|
|
85
|
+
...(patternCatalogOptions.sectionRole
|
|
86
|
+
? { sectionRole: patternCatalogOptions.sectionRole }
|
|
87
|
+
: {}),
|
|
88
|
+
tags: patternCatalogOptions.tags,
|
|
89
|
+
title: patternCatalogOptions.title,
|
|
90
|
+
...(patternCatalogOptions.thumbnailUrl
|
|
91
|
+
? { thumbnailUrl: patternCatalogOptions.thumbnailUrl }
|
|
92
|
+
: {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -2,7 +2,7 @@ import { promises as fsp } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pathExists } from "./fs-async.js";
|
|
4
4
|
import { assertPostMetaDoesNotExist, assertValidGeneratedSlug, assertValidPostMetaPostType, assertValidTypeScriptIdentifier, getWorkspaceBootstrapPath, normalizeBlockSlug, resolvePostMetaKey, } from "./cli-add-shared.js";
|
|
5
|
-
import { ensureContractSyncScriptAnchors } from "./cli-add-workspace-rest-anchors.js";
|
|
5
|
+
import { ensureContractSyncScriptAnchors, } from "./cli-add-workspace-rest-contract-sync-anchors.js";
|
|
6
6
|
import { ensurePostMetaBootstrapAnchors, ensurePostMetaSyncScriptAnchors, } from "./cli-add-workspace-post-meta-anchors.js";
|
|
7
7
|
import { buildPostMetaConfigEntry, buildPostMetaPhpSource, buildPostMetaReadmeSource, buildPostMetaTypesSource, } from "./cli-add-workspace-post-meta-source-emitters.js";
|
|
8
8
|
import { executeWorkspaceMutationPlan } from "./cli-add-workspace-mutation.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type SourceRange } from "./ts-source-masking.js";
|
|
2
|
+
/**
|
|
3
|
+
* Find the first executable call expression for a named function in source code.
|
|
4
|
+
*
|
|
5
|
+
* @param source TypeScript or JavaScript source text to scan.
|
|
6
|
+
* @param callName Function identifier to locate.
|
|
7
|
+
* @returns The source range for the first matching executable call, or
|
|
8
|
+
* `undefined` when the identifier is absent, commented, string-literal-only, or
|
|
9
|
+
* not followed by a call expression.
|
|
10
|
+
*/
|
|
11
|
+
export declare function findExecutableCallRange(source: string, callName: string): SourceRange | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure a block entrypoint imports and calls a workspace registration helper.
|
|
14
|
+
*
|
|
15
|
+
* @param options Entrypoint patch options.
|
|
16
|
+
* @param options.blockIndexPath Absolute path to the block entrypoint file.
|
|
17
|
+
* @param options.callLine Call expression line to insert when missing.
|
|
18
|
+
* @param options.callPattern Executable pattern used to detect an existing call.
|
|
19
|
+
* @param options.importLine Import line to prepend when missing.
|
|
20
|
+
* @param options.importPattern Uncommented import pattern used to avoid duplicates.
|
|
21
|
+
* @returns A promise that resolves after the entrypoint has been patched.
|
|
22
|
+
* @throws {Error} When the call cannot be injected or verified.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureWorkspaceEntrypointCall({ blockIndexPath, callLine, callPattern, importLine, importPattern, }: {
|
|
25
|
+
blockIndexPath: string;
|
|
26
|
+
callLine: string;
|
|
27
|
+
callPattern: RegExp;
|
|
28
|
+
importLine: string;
|
|
29
|
+
importPattern: RegExp;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Ensure a scaffold block registration settings hook is imported and called.
|
|
33
|
+
*
|
|
34
|
+
* @param options Registration settings patch options.
|
|
35
|
+
* @param options.blockIndexPath Absolute path to the block entrypoint file.
|
|
36
|
+
* @param options.callLine Settings mutation call to insert before registration.
|
|
37
|
+
* @param options.callPattern Executable pattern used to detect an existing call.
|
|
38
|
+
* @param options.importLine Import line to prepend when missing.
|
|
39
|
+
* @param options.importPattern Uncommented import pattern used to avoid duplicates.
|
|
40
|
+
* @returns A promise that resolves after the entrypoint has been patched.
|
|
41
|
+
* @throws {Error} When the entrypoint does not expose the expected
|
|
42
|
+
* `registerScaffoldBlockType(registration.name, registration.settings)` call.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureWorkspaceRegistrationSettingsCall({ blockIndexPath, callLine, callPattern, importLine, importPattern, }: {
|
|
45
|
+
blockIndexPath: string;
|
|
46
|
+
callLine: string;
|
|
47
|
+
callPattern: RegExp;
|
|
48
|
+
importLine: string;
|
|
49
|
+
importPattern: RegExp;
|
|
50
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { patchFile } from "./cli-add-shared.js";
|
|
3
|
+
import { findExecutablePatternMatch, hasExecutablePattern, hasUncommentedPattern, maskTypeScriptCommentsAndLiterals, } from "./ts-source-masking.js";
|
|
4
|
+
const SCAFFOLD_REGISTRATION_SETTINGS_CALL_PATTERN = /registerScaffoldBlockType\s*\(\s*registration\s*\.\s*name\s*,\s*registration\s*\.\s*settings\s*\)\s*;?/u;
|
|
5
|
+
function isIdentifierBoundary(source, index) {
|
|
6
|
+
if (index < 0 || index >= source.length) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return !/[A-Za-z0-9_$]/u.test(source[index] ?? "");
|
|
10
|
+
}
|
|
11
|
+
function skipWhitespace(source, index) {
|
|
12
|
+
let cursor = index;
|
|
13
|
+
while (cursor < source.length && /\s/u.test(source[cursor] ?? "")) {
|
|
14
|
+
cursor += 1;
|
|
15
|
+
}
|
|
16
|
+
return cursor;
|
|
17
|
+
}
|
|
18
|
+
function findMatchingDelimiterEnd(source, openIndex, openDelimiter, closeDelimiter) {
|
|
19
|
+
let depth = 0;
|
|
20
|
+
for (let index = openIndex; index < source.length; index += 1) {
|
|
21
|
+
const char = source[index];
|
|
22
|
+
if (char === openDelimiter) {
|
|
23
|
+
depth += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (char === closeDelimiter) {
|
|
27
|
+
depth -= 1;
|
|
28
|
+
if (depth === 0) {
|
|
29
|
+
return index + 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Find the first executable call expression for a named function in source code.
|
|
37
|
+
*
|
|
38
|
+
* @param source TypeScript or JavaScript source text to scan.
|
|
39
|
+
* @param callName Function identifier to locate.
|
|
40
|
+
* @returns The source range for the first matching executable call, or
|
|
41
|
+
* `undefined` when the identifier is absent, commented, string-literal-only, or
|
|
42
|
+
* not followed by a call expression.
|
|
43
|
+
*/
|
|
44
|
+
export function findExecutableCallRange(source, callName) {
|
|
45
|
+
const maskedSource = maskTypeScriptCommentsAndLiterals(source);
|
|
46
|
+
let searchIndex = 0;
|
|
47
|
+
while (searchIndex < maskedSource.length) {
|
|
48
|
+
const callNameIndex = maskedSource.indexOf(callName, searchIndex);
|
|
49
|
+
if (callNameIndex === -1) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const callNameEnd = callNameIndex + callName.length;
|
|
53
|
+
if (!isIdentifierBoundary(maskedSource, callNameIndex - 1) ||
|
|
54
|
+
!isIdentifierBoundary(maskedSource, callNameEnd)) {
|
|
55
|
+
searchIndex = callNameEnd;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
let cursor = skipWhitespace(maskedSource, callNameEnd);
|
|
59
|
+
if (maskedSource[cursor] === "<") {
|
|
60
|
+
const genericEnd = findMatchingDelimiterEnd(maskedSource, cursor, "<", ">");
|
|
61
|
+
if (genericEnd === undefined) {
|
|
62
|
+
searchIndex = callNameEnd;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
cursor = skipWhitespace(maskedSource, genericEnd);
|
|
66
|
+
}
|
|
67
|
+
if (maskedSource[cursor] !== "(") {
|
|
68
|
+
searchIndex = callNameEnd;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const callEnd = findMatchingDelimiterEnd(maskedSource, cursor, "(", ")");
|
|
72
|
+
if (callEnd === undefined) {
|
|
73
|
+
searchIndex = callNameEnd;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
let end = skipWhitespace(maskedSource, callEnd);
|
|
77
|
+
if (maskedSource[end] === ";") {
|
|
78
|
+
end += 1;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
end,
|
|
82
|
+
start: callNameIndex,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
function findBlockRegistrationCallRange(source) {
|
|
88
|
+
return (findExecutableCallRange(source, "registerScaffoldBlockType") ??
|
|
89
|
+
findExecutableCallRange(source, "registerBlockType"));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Ensure a block entrypoint imports and calls a workspace registration helper.
|
|
93
|
+
*
|
|
94
|
+
* @param options Entrypoint patch options.
|
|
95
|
+
* @param options.blockIndexPath Absolute path to the block entrypoint file.
|
|
96
|
+
* @param options.callLine Call expression line to insert when missing.
|
|
97
|
+
* @param options.callPattern Executable pattern used to detect an existing call.
|
|
98
|
+
* @param options.importLine Import line to prepend when missing.
|
|
99
|
+
* @param options.importPattern Uncommented import pattern used to avoid duplicates.
|
|
100
|
+
* @returns A promise that resolves after the entrypoint has been patched.
|
|
101
|
+
* @throws {Error} When the call cannot be injected or verified.
|
|
102
|
+
*/
|
|
103
|
+
export async function ensureWorkspaceEntrypointCall({ blockIndexPath, callLine, callPattern, importLine, importPattern, }) {
|
|
104
|
+
await patchFile(blockIndexPath, (source) => {
|
|
105
|
+
let nextSource = source;
|
|
106
|
+
if (!hasUncommentedPattern(nextSource, importPattern)) {
|
|
107
|
+
nextSource = `${importLine}\n${nextSource}`;
|
|
108
|
+
}
|
|
109
|
+
if (!hasExecutablePattern(nextSource, callPattern)) {
|
|
110
|
+
const callRange = findBlockRegistrationCallRange(nextSource);
|
|
111
|
+
if (callRange) {
|
|
112
|
+
nextSource = [
|
|
113
|
+
nextSource.slice(0, callRange.end),
|
|
114
|
+
`\n${callLine}\n`,
|
|
115
|
+
nextSource.slice(callRange.end),
|
|
116
|
+
].join("");
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
nextSource = `${nextSource.trimEnd()}\n\n${callLine}\n`;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!hasExecutablePattern(nextSource, callPattern)) {
|
|
123
|
+
throw new Error(`Unable to inject ${callLine} into ${path.basename(blockIndexPath)}.`);
|
|
124
|
+
}
|
|
125
|
+
return nextSource;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Ensure a scaffold block registration settings hook is imported and called.
|
|
130
|
+
*
|
|
131
|
+
* @param options Registration settings patch options.
|
|
132
|
+
* @param options.blockIndexPath Absolute path to the block entrypoint file.
|
|
133
|
+
* @param options.callLine Settings mutation call to insert before registration.
|
|
134
|
+
* @param options.callPattern Executable pattern used to detect an existing call.
|
|
135
|
+
* @param options.importLine Import line to prepend when missing.
|
|
136
|
+
* @param options.importPattern Uncommented import pattern used to avoid duplicates.
|
|
137
|
+
* @returns A promise that resolves after the entrypoint has been patched.
|
|
138
|
+
* @throws {Error} When the entrypoint does not expose the expected
|
|
139
|
+
* `registerScaffoldBlockType(registration.name, registration.settings)` call.
|
|
140
|
+
*/
|
|
141
|
+
export async function ensureWorkspaceRegistrationSettingsCall({ blockIndexPath, callLine, callPattern, importLine, importPattern, }) {
|
|
142
|
+
await patchFile(blockIndexPath, (source) => {
|
|
143
|
+
let nextSource = source;
|
|
144
|
+
if (!hasUncommentedPattern(nextSource, importPattern)) {
|
|
145
|
+
nextSource = `${importLine}\n${nextSource}`;
|
|
146
|
+
}
|
|
147
|
+
if (!hasExecutablePattern(nextSource, callPattern)) {
|
|
148
|
+
const callRange = findExecutablePatternMatch(nextSource, [
|
|
149
|
+
SCAFFOLD_REGISTRATION_SETTINGS_CALL_PATTERN,
|
|
150
|
+
]);
|
|
151
|
+
if (!callRange) {
|
|
152
|
+
throw new Error(`Unable to inject ${callLine} into ${path.basename(blockIndexPath)} because it does not expose a scaffold registration settings object.`);
|
|
153
|
+
}
|
|
154
|
+
nextSource = [
|
|
155
|
+
nextSource.slice(0, callRange.start),
|
|
156
|
+
`${callLine}\n`,
|
|
157
|
+
nextSource.slice(callRange.start),
|
|
158
|
+
].join("");
|
|
159
|
+
}
|
|
160
|
+
return nextSource;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { WorkspaceProject } from "./workspace-project.js";
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* Compatibility facade for REST workspace anchor patchers.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @throws When an existing loader does not reference `inc/rest-schema.php`.
|
|
4
|
+
* Keep the public runtime import path stable while bootstrap, contract sync,
|
|
5
|
+
* and REST resource sync patchers live in focused implementation modules.
|
|
8
6
|
*/
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export declare function ensureRestResourceSyncScriptAnchors(workspace: WorkspaceProject): Promise<void>;
|
|
7
|
+
export { ensureRestResourceBootstrapAnchors, ensureRestSchemaHelperBootstrapAnchors, } from "./cli-add-workspace-rest-bootstrap-anchors.js";
|
|
8
|
+
export { ensureContractSyncScriptAnchors, } from "./cli-add-workspace-rest-contract-sync-anchors.js";
|
|
9
|
+
export { ensureRestResourceSyncScriptAnchors, } from "./cli-add-workspace-rest-resource-sync-anchors.js";
|