@wp-typia/project-tools 0.22.2 → 0.22.3
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-code-templates/interactivity.d.ts +1 -1
- package/dist/runtime/built-in-block-code-templates/interactivity.js +4 -2
- package/dist/runtime/cli-add-shared.d.ts +49 -0
- package/dist/runtime/cli-add-shared.js +204 -71
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +5 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +392 -0
- package/dist/runtime/cli-add-workspace-ability-templates.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-ability-templates.js +500 -0
- package/dist/runtime/cli-add-workspace-ability-types.d.ts +27 -0
- package/dist/runtime/cli-add-workspace-ability-types.js +14 -0
- package/dist/runtime/cli-add-workspace-ability.js +12 -852
- package/dist/runtime/cli-add-workspace-ai-scaffold.d.ts +21 -0
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +91 -0
- package/dist/runtime/cli-add-workspace-ai-templates.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ai-templates.js +605 -0
- package/dist/runtime/cli-add-workspace-ai.js +15 -688
- package/dist/runtime/cli-add-workspace-assets.js +7 -4
- package/dist/runtime/cli-add-workspace.js +1 -19
- package/dist/runtime/cli-doctor-workspace-bindings.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-bindings.js +134 -0
- package/dist/runtime/cli-doctor-workspace-blocks.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-blocks.js +504 -0
- package/dist/runtime/cli-doctor-workspace-features.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features.js +383 -0
- package/dist/runtime/cli-doctor-workspace-package.d.ts +18 -0
- package/dist/runtime/cli-doctor-workspace-package.js +59 -0
- package/dist/runtime/cli-doctor-workspace-shared.d.ts +69 -0
- package/dist/runtime/cli-doctor-workspace-shared.js +87 -0
- package/dist/runtime/cli-doctor-workspace.js +25 -1062
- package/package.json +3 -3
|
@@ -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 { normalizeOptionalCliString } from "./cli-validation.js";
|
|
11
12
|
const PATTERN_BOOTSTRAP_CATEGORY = "register_block_pattern_category";
|
|
12
13
|
const BINDING_SOURCE_SERVER_GLOB = "/src/bindings/*/server.php";
|
|
13
14
|
const BINDING_SOURCE_EDITOR_SCRIPT = "build/bindings/index.js";
|
|
@@ -225,8 +226,10 @@ registerBlockBindingsSource( {
|
|
|
225
226
|
`;
|
|
226
227
|
}
|
|
227
228
|
function resolveBindingTarget(options, namespace) {
|
|
228
|
-
const
|
|
229
|
-
const
|
|
229
|
+
const blockName = normalizeOptionalCliString(options.blockName);
|
|
230
|
+
const attributeName = normalizeOptionalCliString(options.attributeName);
|
|
231
|
+
const hasBlock = blockName !== undefined;
|
|
232
|
+
const hasAttribute = attributeName !== undefined;
|
|
230
233
|
if (!hasBlock && !hasAttribute) {
|
|
231
234
|
return undefined;
|
|
232
235
|
}
|
|
@@ -234,8 +237,8 @@ function resolveBindingTarget(options, namespace) {
|
|
|
234
237
|
throw new Error("`wp-typia add binding-source` requires --block and --attribute to be provided together.");
|
|
235
238
|
}
|
|
236
239
|
return {
|
|
237
|
-
attributeName: assertValidBindingAttributeName(
|
|
238
|
-
blockSlug: resolveBindingTargetBlockSlug(
|
|
240
|
+
attributeName: assertValidBindingAttributeName(attributeName ?? ""),
|
|
241
|
+
blockSlug: resolveBindingTargetBlockSlug(blockName ?? "", namespace),
|
|
239
242
|
};
|
|
240
243
|
}
|
|
241
244
|
function formatBindingAttributeTypeMember(attributeName) {
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
5
5
|
import { appendWorkspaceInventoryEntries, readWorkspaceInventory } from "./workspace-inventory.js";
|
|
6
6
|
import { toKebabCase, toSnakeCase, toTitleCase } from "./string-case.js";
|
|
7
|
-
import { assertValidGeneratedSlug, assertValidHookAnchor, assertValidHookedBlockPosition, assertVariationDoesNotExist, getMutableBlockHooks, normalizeBlockSlug, patchFile, quoteTsString, readWorkspaceBlockJson, resolveWorkspaceBlock, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
7
|
+
import { assertBlockStyleDoesNotExist, assertBlockTransformDoesNotExist, assertValidGeneratedSlug, assertValidHookAnchor, assertValidHookedBlockPosition, assertVariationDoesNotExist, getMutableBlockHooks, normalizeBlockSlug, patchFile, quoteTsString, readWorkspaceBlockJson, resolveWorkspaceBlock, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
8
8
|
const VARIATIONS_IMPORT_LINE = "import { registerWorkspaceVariations } from './variations';";
|
|
9
9
|
const VARIATIONS_IMPORT_PATTERN = /^\s*import\s*\{\s*registerWorkspaceVariations\s*\}\s*from\s*["']\.\/variations["']\s*;?\s*$/mu;
|
|
10
10
|
const VARIATIONS_CALL_LINE = "registerWorkspaceVariations();";
|
|
@@ -488,24 +488,6 @@ async function writeBlockTransformRegistry(projectDir, blockSlug, transformSlug)
|
|
|
488
488
|
const nextTransformSlugs = Array.from(new Set([...existingTransformSlugs, transformSlug])).sort();
|
|
489
489
|
await fsp.writeFile(transformsIndexPath, buildBlockTransformIndexSource(nextTransformSlugs), "utf8");
|
|
490
490
|
}
|
|
491
|
-
function assertBlockStyleDoesNotExist(projectDir, blockSlug, styleSlug, inventory) {
|
|
492
|
-
const stylePath = path.join(projectDir, "src", "blocks", blockSlug, "styles", `${styleSlug}.ts`);
|
|
493
|
-
if (fs.existsSync(stylePath)) {
|
|
494
|
-
throw new Error(`A block style already exists at ${path.relative(projectDir, stylePath)}. Choose a different name.`);
|
|
495
|
-
}
|
|
496
|
-
if (inventory.blockStyles.some((entry) => entry.block === blockSlug && entry.slug === styleSlug)) {
|
|
497
|
-
throw new Error(`A block style inventory entry already exists for ${blockSlug}/${styleSlug}. Choose a different name.`);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function assertBlockTransformDoesNotExist(projectDir, blockSlug, transformSlug, inventory) {
|
|
501
|
-
const transformPath = path.join(projectDir, "src", "blocks", blockSlug, "transforms", `${transformSlug}.ts`);
|
|
502
|
-
if (fs.existsSync(transformPath)) {
|
|
503
|
-
throw new Error(`A block transform already exists at ${path.relative(projectDir, transformPath)}. Choose a different name.`);
|
|
504
|
-
}
|
|
505
|
-
if (inventory.blockTransforms.some((entry) => entry.block === blockSlug && entry.slug === transformSlug)) {
|
|
506
|
-
throw new Error(`A block transform inventory entry already exists for ${blockSlug}/${transformSlug}. Choose a different name.`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
491
|
function assertFullBlockName(blockName, flagName) {
|
|
510
492
|
const trimmed = blockName.trim();
|
|
511
493
|
if (!trimmed) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DoctorCheck } from "./cli-doctor.js";
|
|
2
|
+
import type { WorkspaceInventory } from "./workspace-inventory.js";
|
|
3
|
+
import type { WorkspaceProject } from "./workspace-project.js";
|
|
4
|
+
/**
|
|
5
|
+
* Collect workspace doctor checks for extracted binding-source diagnostics.
|
|
6
|
+
*
|
|
7
|
+
* @param workspace Resolved workspace metadata and filesystem paths.
|
|
8
|
+
* @param inventory Parsed workspace inventory from `scripts/block-config.ts`.
|
|
9
|
+
* @returns Ordered `DoctorCheck[]` rows for binding bootstrap, index, and target checks.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getWorkspaceBindingDoctorChecks(workspace: WorkspaceProject, inventory: WorkspaceInventory): DoctorCheck[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
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";
|
|
5
|
+
import { escapeRegex } from "./php-utils.js";
|
|
6
|
+
function checkWorkspaceBindingBootstrap(projectDir, packageName) {
|
|
7
|
+
const packageBaseName = packageName.split("/").pop() ?? packageName;
|
|
8
|
+
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
9
|
+
if (!fs.existsSync(bootstrapPath)) {
|
|
10
|
+
return createDoctorCheck("Binding bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
11
|
+
}
|
|
12
|
+
const source = fs.readFileSync(bootstrapPath, "utf8");
|
|
13
|
+
const hasServerGlob = source.includes(WORKSPACE_BINDING_SERVER_GLOB);
|
|
14
|
+
const hasEditorEnqueueHook = source.includes("enqueue_block_editor_assets");
|
|
15
|
+
const hasEditorScript = source.includes(WORKSPACE_BINDING_EDITOR_SCRIPT);
|
|
16
|
+
const hasEditorAsset = source.includes(WORKSPACE_BINDING_EDITOR_ASSET);
|
|
17
|
+
return createDoctorCheck("Binding bootstrap", hasServerGlob && hasEditorEnqueueHook && hasEditorScript && hasEditorAsset ? "pass" : "fail", hasServerGlob && hasEditorEnqueueHook && hasEditorScript && hasEditorAsset
|
|
18
|
+
? "Binding source PHP and editor bootstrap hooks are present"
|
|
19
|
+
: "Missing binding source PHP require glob or editor enqueue hook");
|
|
20
|
+
}
|
|
21
|
+
function checkWorkspaceBindingSourcesIndex(projectDir, bindingSources) {
|
|
22
|
+
const indexRelativePath = [path.join("src", "bindings", "index.ts"), path.join("src", "bindings", "index.js")].find((relativePath) => fs.existsSync(path.join(projectDir, relativePath)));
|
|
23
|
+
if (!indexRelativePath) {
|
|
24
|
+
return createDoctorCheck("Binding sources index", "fail", "Missing src/bindings/index.ts or src/bindings/index.js");
|
|
25
|
+
}
|
|
26
|
+
const indexPath = path.join(projectDir, indexRelativePath);
|
|
27
|
+
const source = fs.readFileSync(indexPath, "utf8");
|
|
28
|
+
const missingImports = bindingSources.filter((bindingSource) => !source.includes(`./${bindingSource.slug}/editor`));
|
|
29
|
+
return createDoctorCheck("Binding sources index", missingImports.length === 0 ? "pass" : "fail", missingImports.length === 0
|
|
30
|
+
? "Binding source editor registrations are aggregated"
|
|
31
|
+
: `Missing editor imports for: ${missingImports.map((entry) => entry.slug).join(", ")}`);
|
|
32
|
+
}
|
|
33
|
+
function checkWorkspaceBindingTarget(projectDir, workspace, registeredBlockSlugs, bindingSource) {
|
|
34
|
+
const hasBlock = bindingSource.block !== undefined;
|
|
35
|
+
const hasAttribute = bindingSource.attribute !== undefined;
|
|
36
|
+
if (!hasBlock && !hasAttribute) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
if (!bindingSource.block || !bindingSource.attribute) {
|
|
40
|
+
return createDoctorCheck(`Binding target ${bindingSource.slug}`, "fail", "Binding target entries must include both block and attribute.");
|
|
41
|
+
}
|
|
42
|
+
if (!registeredBlockSlugs.has(bindingSource.block)) {
|
|
43
|
+
return createDoctorCheck(`Binding target ${bindingSource.slug}`, "fail", `Binding target references unknown block "${bindingSource.block}".`);
|
|
44
|
+
}
|
|
45
|
+
const blockJsonRelativePath = path.join("src", "blocks", bindingSource.block, "block.json");
|
|
46
|
+
const blockJsonPath = path.join(projectDir, blockJsonRelativePath);
|
|
47
|
+
const issues = [];
|
|
48
|
+
try {
|
|
49
|
+
const blockJson = parseScaffoldBlockMetadata(JSON.parse(fs.readFileSync(blockJsonPath, "utf8")));
|
|
50
|
+
const attributes = blockJson.attributes;
|
|
51
|
+
if (!attributes || typeof attributes !== "object" || Array.isArray(attributes)) {
|
|
52
|
+
issues.push(`${blockJsonRelativePath} must define an attributes object`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const attributeConfig = attributes[bindingSource.attribute];
|
|
56
|
+
if (!attributeConfig ||
|
|
57
|
+
typeof attributeConfig !== "object" ||
|
|
58
|
+
Array.isArray(attributeConfig)) {
|
|
59
|
+
issues.push(`${blockJsonRelativePath} must declare attribute "${bindingSource.attribute}"`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
issues.push(error instanceof Error
|
|
65
|
+
? `Unable to read ${blockJsonRelativePath}: ${error.message}`
|
|
66
|
+
: `Unable to read ${blockJsonRelativePath}.`);
|
|
67
|
+
}
|
|
68
|
+
const serverPath = path.join(projectDir, bindingSource.serverFile);
|
|
69
|
+
if (fs.existsSync(serverPath)) {
|
|
70
|
+
const serverSource = fs.readFileSync(serverPath, "utf8");
|
|
71
|
+
const supportedAttributesFilter = `block_bindings_supported_attributes_${workspace.workspace.namespace}/${bindingSource.block}`;
|
|
72
|
+
if (!serverSource.includes(supportedAttributesFilter)) {
|
|
73
|
+
issues.push(`${bindingSource.serverFile} must register ${supportedAttributesFilter}`);
|
|
74
|
+
}
|
|
75
|
+
if (!new RegExp(`(['"])${escapeRegex(bindingSource.attribute)}\\1`, "u").test(serverSource)) {
|
|
76
|
+
issues.push(`${bindingSource.serverFile} must expose attribute "${bindingSource.attribute}"`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
issues.push(`Missing ${bindingSource.serverFile}`);
|
|
81
|
+
}
|
|
82
|
+
const editorPath = path.join(projectDir, bindingSource.editorFile);
|
|
83
|
+
if (fs.existsSync(editorPath)) {
|
|
84
|
+
const editorSource = fs.readFileSync(editorPath, "utf8");
|
|
85
|
+
const blockName = `${workspace.workspace.namespace}/${bindingSource.block}`;
|
|
86
|
+
const bindingSourceTargetMatch = editorSource.match(/export\s+const\s+BINDING_SOURCE_TARGET\s*=\s*\{([\s\S]*?)\}\s+as\s+const\s*;/u);
|
|
87
|
+
if (!bindingSourceTargetMatch) {
|
|
88
|
+
issues.push(`${bindingSource.editorFile} must export BINDING_SOURCE_TARGET`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const targetSource = bindingSourceTargetMatch[1] ?? "";
|
|
92
|
+
const attributePattern = new RegExp(`\\battribute\\s*:\\s*["']${escapeRegex(bindingSource.attribute)}["']`, "u");
|
|
93
|
+
const blockPattern = new RegExp(`\\bblock\\s*:\\s*["']${escapeRegex(blockName)}["']`, "u");
|
|
94
|
+
if (!attributePattern.test(targetSource)) {
|
|
95
|
+
issues.push(`${bindingSource.editorFile} must document target attribute "${bindingSource.attribute}"`);
|
|
96
|
+
}
|
|
97
|
+
if (!blockPattern.test(targetSource)) {
|
|
98
|
+
issues.push(`${bindingSource.editorFile} must document target block "${blockName}"`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
issues.push(`Missing ${bindingSource.editorFile}`);
|
|
104
|
+
}
|
|
105
|
+
return createDoctorCheck(`Binding target ${bindingSource.slug}`, issues.length === 0 ? "pass" : "fail", issues.length === 0
|
|
106
|
+
? `${bindingSource.block}.${bindingSource.attribute} is declared and supported`
|
|
107
|
+
: issues.join("; "));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Collect workspace doctor checks for extracted binding-source diagnostics.
|
|
111
|
+
*
|
|
112
|
+
* @param workspace Resolved workspace metadata and filesystem paths.
|
|
113
|
+
* @param inventory Parsed workspace inventory from `scripts/block-config.ts`.
|
|
114
|
+
* @returns Ordered `DoctorCheck[]` rows for binding bootstrap, index, and target checks.
|
|
115
|
+
*/
|
|
116
|
+
export function getWorkspaceBindingDoctorChecks(workspace, inventory) {
|
|
117
|
+
const checks = [];
|
|
118
|
+
if (inventory.bindingSources.length > 0) {
|
|
119
|
+
checks.push(checkWorkspaceBindingBootstrap(workspace.projectDir, workspace.packageName));
|
|
120
|
+
checks.push(checkWorkspaceBindingSourcesIndex(workspace.projectDir, inventory.bindingSources));
|
|
121
|
+
}
|
|
122
|
+
const registeredBlockSlugs = new Set(inventory.blocks.map((block) => block.slug));
|
|
123
|
+
for (const bindingSource of inventory.bindingSources) {
|
|
124
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Binding source ${bindingSource.slug}`, [
|
|
125
|
+
bindingSource.serverFile,
|
|
126
|
+
bindingSource.editorFile,
|
|
127
|
+
]));
|
|
128
|
+
const bindingTargetCheck = checkWorkspaceBindingTarget(workspace.projectDir, workspace, registeredBlockSlugs, bindingSource);
|
|
129
|
+
if (bindingTargetCheck) {
|
|
130
|
+
checks.push(bindingTargetCheck);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return checks;
|
|
134
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DoctorCheck } from "./cli-doctor.js";
|
|
2
|
+
import type { WorkspaceInventory } from "./workspace-inventory.js";
|
|
3
|
+
import type { WorkspaceProject } from "./workspace-project.js";
|
|
4
|
+
/**
|
|
5
|
+
* Collect block-, variation-, transform-, and pattern-related workspace doctor checks.
|
|
6
|
+
*
|
|
7
|
+
* @param workspace Resolved workspace metadata and filesystem paths.
|
|
8
|
+
* @param inventory Parsed workspace inventory from `scripts/block-config.ts`.
|
|
9
|
+
* @returns Ordered `DoctorCheck[]` rows for extracted block diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getWorkspaceBlockDoctorChecks(workspace: WorkspaceProject, inventory: WorkspaceInventory): DoctorCheck[];
|