@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,197 @@
|
|
|
1
|
+
import { promises as fsp } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { assertFullBlockName, resolveWorkspaceTargetBlockName, } from "./block-targets.js";
|
|
4
|
+
import { pathExists } from "./fs-async.js";
|
|
5
|
+
import { assertBlockTransformDoesNotExist, assertValidGeneratedSlug, normalizeBlockSlug, quoteTsString, resolveWorkspaceBlock, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
6
|
+
import { ensureWorkspaceRegistrationSettingsCall } from "./cli-add-workspace-registration-hooks.js";
|
|
7
|
+
import { appendWorkspaceInventoryEntries, readWorkspaceInventoryAsync, } from "./workspace-inventory.js";
|
|
8
|
+
import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
9
|
+
import { toSnakeCase, toTitleCase } from "./string-case.js";
|
|
10
|
+
const BLOCK_TRANSFORMS_IMPORT_LINE = "import { applyWorkspaceBlockTransforms } from './transforms';";
|
|
11
|
+
const BLOCK_TRANSFORMS_IMPORT_PATTERN = /^\s*import\s*\{\s*applyWorkspaceBlockTransforms\s*\}\s*from\s*["']\.\/transforms["']\s*;?\s*$/mu;
|
|
12
|
+
const BLOCK_TRANSFORMS_CALL_LINE = "applyWorkspaceBlockTransforms(registration.settings);";
|
|
13
|
+
const BLOCK_TRANSFORMS_CALL_PATTERN = /applyWorkspaceBlockTransforms\s*\(\s*registration\s*\.\s*settings\s*\)\s*;?/u;
|
|
14
|
+
function buildWorkspaceConstName(prefix, slug) {
|
|
15
|
+
return `workspace${prefix}_${toSnakeCase(slug)}`;
|
|
16
|
+
}
|
|
17
|
+
function buildBlockTransformConfigEntry(options) {
|
|
18
|
+
return [
|
|
19
|
+
"\t{",
|
|
20
|
+
`\t\tblock: ${quoteTsString(options.blockSlug)},`,
|
|
21
|
+
`\t\tfile: ${quoteTsString(`src/blocks/${options.blockSlug}/transforms/${options.transformSlug}.ts`)},`,
|
|
22
|
+
`\t\tfrom: ${quoteTsString(options.fromBlockName)},`,
|
|
23
|
+
`\t\tslug: ${quoteTsString(options.transformSlug)},`,
|
|
24
|
+
`\t\tto: ${quoteTsString(options.toBlockName)},`,
|
|
25
|
+
"\t},",
|
|
26
|
+
].join("\n");
|
|
27
|
+
}
|
|
28
|
+
function getBlockTransformConstBindings(transformSlugs) {
|
|
29
|
+
const seenConstNames = new Map();
|
|
30
|
+
return transformSlugs.map((transformSlug) => {
|
|
31
|
+
const constName = buildWorkspaceConstName("BlockTransform", transformSlug);
|
|
32
|
+
const previousSlug = seenConstNames.get(constName);
|
|
33
|
+
if (previousSlug && previousSlug !== transformSlug) {
|
|
34
|
+
throw new Error(`Transform slugs "${previousSlug}" and "${transformSlug}" generate the same registry identifier "${constName}". Rename one of the transforms.`);
|
|
35
|
+
}
|
|
36
|
+
seenConstNames.set(constName, transformSlug);
|
|
37
|
+
return { constName, transformSlug };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function buildBlockTransformSource(options) {
|
|
41
|
+
const transformTitle = toTitleCase(options.transformSlug);
|
|
42
|
+
const transformConstName = buildWorkspaceConstName("BlockTransform", options.transformSlug);
|
|
43
|
+
return `import { createBlock } from '@wordpress/blocks';
|
|
44
|
+
import { __ } from '@wordpress/i18n';
|
|
45
|
+
import metadata from '../block.json';
|
|
46
|
+
|
|
47
|
+
type TransformAttributes = Record<string, unknown>;
|
|
48
|
+
type TransformInnerBlock = ReturnType<typeof createBlock>;
|
|
49
|
+
|
|
50
|
+
function mapTransformAttributes(attributes: TransformAttributes): TransformAttributes {
|
|
51
|
+
\tconst content = attributes.content;
|
|
52
|
+
|
|
53
|
+
\treturn typeof content === 'string' ? { content } : {};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const ${transformConstName} = {
|
|
57
|
+
\ttype: 'block',
|
|
58
|
+
\tblocks: [${quoteTsString(options.fromBlockName)}],
|
|
59
|
+
\ttitle: __( ${quoteTsString(transformTitle)}, ${quoteTsString(options.textDomain)} ),
|
|
60
|
+
\ttransform: (
|
|
61
|
+
\t\tattributes: TransformAttributes,
|
|
62
|
+
\t\tinnerBlocks: TransformInnerBlock[] = [],
|
|
63
|
+
\t) => createBlock(metadata.name, mapTransformAttributes(attributes), innerBlocks),
|
|
64
|
+
} as const;
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
function buildBlockTransformIndexSource(transformSlugs) {
|
|
68
|
+
const transformBindings = getBlockTransformConstBindings(transformSlugs);
|
|
69
|
+
const importLines = transformBindings
|
|
70
|
+
.map(({ constName, transformSlug }) => `import { ${constName} } from './${transformSlug}';`)
|
|
71
|
+
.join("\n");
|
|
72
|
+
const transformConstNames = transformBindings
|
|
73
|
+
.map(({ constName }) => constName)
|
|
74
|
+
.join(",\n\t");
|
|
75
|
+
return `${importLines ? `${importLines}\n\n` : ""}type BlockSettingsWithTransforms = {
|
|
76
|
+
\ttransforms?: {
|
|
77
|
+
\t\tfrom?: unknown[];
|
|
78
|
+
\t\tto?: unknown[];
|
|
79
|
+
\t};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const WORKSPACE_BLOCK_TRANSFORMS = [
|
|
83
|
+
\t${transformConstNames}
|
|
84
|
+
\t// wp-typia add transform entries
|
|
85
|
+
] as const;
|
|
86
|
+
|
|
87
|
+
export function applyWorkspaceBlockTransforms(settings: BlockSettingsWithTransforms) {
|
|
88
|
+
\tconst transforms = settings.transforms ?? {};
|
|
89
|
+
|
|
90
|
+
\tsettings.transforms = {
|
|
91
|
+
\t\t...transforms,
|
|
92
|
+
\t\tfrom: [...(transforms.from ?? []), ...WORKSPACE_BLOCK_TRANSFORMS],
|
|
93
|
+
\t};
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
async function ensureBlockTransformRegistrationHook(blockIndexPath) {
|
|
98
|
+
await ensureWorkspaceRegistrationSettingsCall({
|
|
99
|
+
blockIndexPath,
|
|
100
|
+
callLine: BLOCK_TRANSFORMS_CALL_LINE,
|
|
101
|
+
callPattern: BLOCK_TRANSFORMS_CALL_PATTERN,
|
|
102
|
+
importLine: BLOCK_TRANSFORMS_IMPORT_LINE,
|
|
103
|
+
importPattern: BLOCK_TRANSFORMS_IMPORT_PATTERN,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async function writeBlockTransformRegistry(projectDir, blockSlug, transformSlug) {
|
|
107
|
+
const transformsDir = path.join(projectDir, "src", "blocks", blockSlug, "transforms");
|
|
108
|
+
const transformsIndexPath = path.join(transformsDir, "index.ts");
|
|
109
|
+
await fsp.mkdir(transformsDir, { recursive: true });
|
|
110
|
+
const existingTransformSlugs = (await fsp.readdir(transformsDir))
|
|
111
|
+
.filter((entry) => entry.endsWith(".ts") && entry !== "index.ts")
|
|
112
|
+
.map((entry) => entry.replace(/\.ts$/u, ""));
|
|
113
|
+
const nextTransformSlugs = Array.from(new Set([...existingTransformSlugs, transformSlug])).sort();
|
|
114
|
+
await fsp.writeFile(transformsIndexPath, buildBlockTransformIndexSource(nextTransformSlugs), "utf8");
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Add one block-to-block transform registration to an existing workspace block.
|
|
118
|
+
*
|
|
119
|
+
* @param options Command options for the block transform scaffold workflow.
|
|
120
|
+
* @param options.cwd Working directory used to resolve the nearest official workspace.
|
|
121
|
+
* Defaults to `process.cwd()`.
|
|
122
|
+
* @param options.fromBlockName Source block name for `--from`. This must be the
|
|
123
|
+
* full `namespace/block` form because transforms may originate from WordPress
|
|
124
|
+
* core or third-party blocks outside the workspace.
|
|
125
|
+
* @param options.toBlockName Target block for `--to`. A workspace block slug is
|
|
126
|
+
* resolved against the workspace namespace, while a full `namespace/block` name
|
|
127
|
+
* must still point at an existing workspace block.
|
|
128
|
+
* @param options.transformName Human-entered transform name that will be
|
|
129
|
+
* normalized and validated before files are written.
|
|
130
|
+
* @returns A promise that resolves with the normalized target `blockSlug`,
|
|
131
|
+
* resolved `fromBlockName`, resolved `toBlockName`, `transformSlug`, and owning
|
|
132
|
+
* `projectDir` after the transform module, transform registry, entrypoint hook,
|
|
133
|
+
* and inventory entry have been written successfully.
|
|
134
|
+
* @throws {Error} When the command is run outside an official workspace, when
|
|
135
|
+
* the target block is unknown, when `--from` is not a full block name, when
|
|
136
|
+
* `--to` uses a non-workspace namespace, when the target block entrypoint does
|
|
137
|
+
* not expose `registration.settings`, when the transform slug is invalid, or
|
|
138
|
+
* when a conflicting file or inventory entry already exists.
|
|
139
|
+
*/
|
|
140
|
+
export async function runAddBlockTransformCommand({ cwd = process.cwd(), fromBlockName, toBlockName, transformName, }) {
|
|
141
|
+
const workspace = resolveWorkspaceProject(cwd);
|
|
142
|
+
const transformSlug = assertValidGeneratedSlug("Transform name", normalizeBlockSlug(transformName), "wp-typia add transform <name> --from <namespace/block> --to <block-slug|namespace/block-slug>");
|
|
143
|
+
const resolvedFromBlockName = assertFullBlockName(fromBlockName, "--from");
|
|
144
|
+
const target = resolveWorkspaceTargetBlockName(toBlockName, workspace.workspace.namespace, "--to");
|
|
145
|
+
const inventory = await readWorkspaceInventoryAsync(workspace.projectDir);
|
|
146
|
+
resolveWorkspaceBlock(inventory, target.blockSlug);
|
|
147
|
+
assertBlockTransformDoesNotExist(workspace.projectDir, target.blockSlug, transformSlug, inventory);
|
|
148
|
+
const blockConfigPath = path.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
149
|
+
const blockIndexPath = path.join(workspace.projectDir, "src", "blocks", target.blockSlug, "index.tsx");
|
|
150
|
+
const transformsDir = path.join(workspace.projectDir, "src", "blocks", target.blockSlug, "transforms");
|
|
151
|
+
const transformFilePath = path.join(transformsDir, `${transformSlug}.ts`);
|
|
152
|
+
const transformsIndexPath = path.join(transformsDir, "index.ts");
|
|
153
|
+
const shouldRemoveTransformsDirOnRollback = !(await pathExists(transformsDir));
|
|
154
|
+
const mutationSnapshot = {
|
|
155
|
+
fileSources: await snapshotWorkspaceFiles([
|
|
156
|
+
blockConfigPath,
|
|
157
|
+
blockIndexPath,
|
|
158
|
+
transformsIndexPath,
|
|
159
|
+
]),
|
|
160
|
+
snapshotDirs: [],
|
|
161
|
+
targetPaths: [
|
|
162
|
+
transformFilePath,
|
|
163
|
+
...(shouldRemoveTransformsDirOnRollback ? [transformsDir] : []),
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
try {
|
|
167
|
+
await fsp.mkdir(transformsDir, { recursive: true });
|
|
168
|
+
await fsp.writeFile(transformFilePath, buildBlockTransformSource({
|
|
169
|
+
fromBlockName: resolvedFromBlockName,
|
|
170
|
+
textDomain: workspace.workspace.textDomain,
|
|
171
|
+
transformSlug,
|
|
172
|
+
}), "utf8");
|
|
173
|
+
await writeBlockTransformRegistry(workspace.projectDir, target.blockSlug, transformSlug);
|
|
174
|
+
await ensureBlockTransformRegistrationHook(blockIndexPath);
|
|
175
|
+
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
176
|
+
blockTransformEntries: [
|
|
177
|
+
buildBlockTransformConfigEntry({
|
|
178
|
+
blockSlug: target.blockSlug,
|
|
179
|
+
fromBlockName: resolvedFromBlockName,
|
|
180
|
+
toBlockName: target.blockName,
|
|
181
|
+
transformSlug,
|
|
182
|
+
}),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
blockSlug: target.blockSlug,
|
|
187
|
+
fromBlockName: resolvedFromBlockName,
|
|
188
|
+
projectDir: workspace.projectDir,
|
|
189
|
+
toBlockName: target.blockName,
|
|
190
|
+
transformSlug,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { pathExists } from "./fs-async.js";
|
|
4
4
|
import { assertContractDoesNotExist, assertValidGeneratedSlug, assertValidTypeScriptIdentifier, normalizeBlockSlug, } from "./cli-add-shared.js";
|
|
5
5
|
import { executeWorkspaceMutationPlan } from "./cli-add-workspace-mutation.js";
|
|
6
|
-
import { ensureContractSyncScriptAnchors } from "./cli-add-workspace-rest-anchors.js";
|
|
6
|
+
import { ensureContractSyncScriptAnchors, } from "./cli-add-workspace-rest-contract-sync-anchors.js";
|
|
7
7
|
import { buildContractConfigEntry, buildContractTypesSource, } from "./cli-add-workspace-contract-source-emitters.js";
|
|
8
8
|
import { syncStandaloneContractArtifacts } from "./contract-artifacts.js";
|
|
9
9
|
import { toPascalCase } from "./string-case.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RunAddCoreVariationCommandOptions } from "./cli-add-shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Add one editor-side variation registration for an existing core or external block.
|
|
4
|
+
*
|
|
5
|
+
* @param options Command options for the core-variation scaffold workflow.
|
|
6
|
+
* @param options.cwd Working directory used to resolve the nearest official workspace.
|
|
7
|
+
* Defaults to `process.cwd()`.
|
|
8
|
+
* @param options.targetBlockName Full `namespace/block` name that receives the variation.
|
|
9
|
+
* @param options.variationName Human-entered variation name normalized into the generated slug.
|
|
10
|
+
* @returns The normalized variation metadata and owning workspace directory.
|
|
11
|
+
* @throws {Error} When the command is run outside an official workspace, the
|
|
12
|
+
* target block name is not full `namespace/block` form, or the generated file
|
|
13
|
+
* already exists.
|
|
14
|
+
*/
|
|
15
|
+
export declare function runAddCoreVariationCommand({ cwd, targetBlockName, variationName, }: RunAddCoreVariationCommandOptions): Promise<{
|
|
16
|
+
projectDir: string;
|
|
17
|
+
targetBlockName: string;
|
|
18
|
+
variationFile: string;
|
|
19
|
+
variationSlug: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import fs, { promises as fsp } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { assertFullBlockName } from "./block-targets.js";
|
|
4
|
+
import { assertValidGeneratedSlug, normalizeBlockSlug, quoteTsString, rollbackWorkspaceMutation, snapshotWorkspaceFiles, } from "./cli-add-shared.js";
|
|
5
|
+
import { ensureEditorPluginBootstrapAnchors, ensureEditorPluginBuildScriptAnchors, ensureEditorPluginWebpackAnchors, resolveEditorPluginRegistryPath, writeEditorPluginRegistry, } from "./cli-add-workspace-editor-plugin.js";
|
|
6
|
+
import { pathExists } from "./fs-async.js";
|
|
7
|
+
import { toKebabCase, toPascalCase, toTitleCase } from "./string-case.js";
|
|
8
|
+
import { resolveWorkspaceProject } from "./workspace-project.js";
|
|
9
|
+
const CORE_VARIATIONS_EDITOR_PLUGIN_SLUG = "core-variations";
|
|
10
|
+
const CORE_VARIATION_USAGE = "wp-typia add core-variation <block-name> <name> or wp-typia add core-variation <name> --block <namespace/block>";
|
|
11
|
+
const CORE_VARIATION_SIMPLE_CONTAINER_BLOCKS = new Set([
|
|
12
|
+
"core/column",
|
|
13
|
+
"core/cover",
|
|
14
|
+
"core/group",
|
|
15
|
+
"core/media-text",
|
|
16
|
+
]);
|
|
17
|
+
function getCoreVariationRootDir(projectDir) {
|
|
18
|
+
return path.join(projectDir, "src", "editor-plugins", CORE_VARIATIONS_EDITOR_PLUGIN_SLUG);
|
|
19
|
+
}
|
|
20
|
+
function getCoreVariationBlockDir(projectDir, targetBlockName) {
|
|
21
|
+
const [namespace, blockSlug] = targetBlockName.split("/");
|
|
22
|
+
return path.join(getCoreVariationRootDir(projectDir), namespace ?? "", blockSlug ?? "");
|
|
23
|
+
}
|
|
24
|
+
function getCoreVariationFilePath(projectDir, targetBlockName, variationSlug) {
|
|
25
|
+
return path.join(getCoreVariationBlockDir(projectDir, targetBlockName), `${variationSlug}.ts`);
|
|
26
|
+
}
|
|
27
|
+
function getCoreVariationIndexPath(projectDir) {
|
|
28
|
+
return path.join(getCoreVariationRootDir(projectDir), "index.ts");
|
|
29
|
+
}
|
|
30
|
+
function buildCoreVariationIdentifier(targetBlockName, variationSlug) {
|
|
31
|
+
return toKebabCase(`${targetBlockName}-${variationSlug}`)
|
|
32
|
+
.split("-")
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join("_");
|
|
35
|
+
}
|
|
36
|
+
function buildCoreVariationConstName(targetBlockName, variationSlug) {
|
|
37
|
+
return `coreVariation_${buildCoreVariationIdentifier(targetBlockName, variationSlug)}`;
|
|
38
|
+
}
|
|
39
|
+
function buildCoreVariationBlockConstName(targetBlockName, variationSlug) {
|
|
40
|
+
return `${buildCoreVariationIdentifier(targetBlockName, variationSlug).toUpperCase()}_BLOCK_NAME`;
|
|
41
|
+
}
|
|
42
|
+
function buildCoreVariationAttributesTypeName(targetBlockName, variationSlug) {
|
|
43
|
+
return `${toPascalCase(`${targetBlockName}-${variationSlug}`)}Attributes`;
|
|
44
|
+
}
|
|
45
|
+
function buildCoreVariationAttributesConstName(targetBlockName, variationSlug) {
|
|
46
|
+
return `${buildCoreVariationIdentifier(targetBlockName, variationSlug)}Attributes`;
|
|
47
|
+
}
|
|
48
|
+
function buildCoreVariationInnerBlocksConstName(targetBlockName, variationSlug) {
|
|
49
|
+
return `${buildCoreVariationIdentifier(targetBlockName, variationSlug)}InnerBlocks`;
|
|
50
|
+
}
|
|
51
|
+
function buildCoreVariationImportPath(ref) {
|
|
52
|
+
return `./${ref.targetBlockName}/${ref.variationSlug}`;
|
|
53
|
+
}
|
|
54
|
+
function formatCoreVariationTitle(variationSlug) {
|
|
55
|
+
return toTitleCase(variationSlug);
|
|
56
|
+
}
|
|
57
|
+
function assertCoreVariationDoesNotExist(projectDir, targetBlockName, variationSlug) {
|
|
58
|
+
const variationFilePath = getCoreVariationFilePath(projectDir, targetBlockName, variationSlug);
|
|
59
|
+
if (fs.existsSync(variationFilePath)) {
|
|
60
|
+
throw new Error(`A core block variation already exists at ${path.relative(projectDir, variationFilePath)}. Choose a different name.`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function assertCoreVariationSlugIsNotRegistryIndex(variationSlug) {
|
|
64
|
+
if (variationSlug === "index") {
|
|
65
|
+
throw new Error("Core variation name must not normalize to `index`. Choose a different name so the variation module can be registered.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function buildCoreVariationInnerBlocksSource(options) {
|
|
69
|
+
if (options.targetBlockName === "core/columns") {
|
|
70
|
+
return `export const ${options.constName} = [
|
|
71
|
+
\t[
|
|
72
|
+
\t\t'core/column',
|
|
73
|
+
\t\t{},
|
|
74
|
+
\t\t[
|
|
75
|
+
\t\t\t[
|
|
76
|
+
\t\t\t\t'core/heading',
|
|
77
|
+
\t\t\t\t{
|
|
78
|
+
\t\t\t\t\tlevel: 2,
|
|
79
|
+
\t\t\t\t\tplaceholder: __( ${quoteTsString("Add a section heading")}, ${quoteTsString(options.textDomain)} ),
|
|
80
|
+
\t\t\t\t},
|
|
81
|
+
\t\t\t],
|
|
82
|
+
\t\t\t[
|
|
83
|
+
\t\t\t\t'core/paragraph',
|
|
84
|
+
\t\t\t\t{
|
|
85
|
+
\t\t\t\t\tplaceholder: __( ${quoteTsString("Add supporting copy")}, ${quoteTsString(options.textDomain)} ),
|
|
86
|
+
\t\t\t\t},
|
|
87
|
+
\t\t\t],
|
|
88
|
+
\t\t],
|
|
89
|
+
\t],
|
|
90
|
+
] satisfies BlockTemplate;`;
|
|
91
|
+
}
|
|
92
|
+
if (CORE_VARIATION_SIMPLE_CONTAINER_BLOCKS.has(options.targetBlockName)) {
|
|
93
|
+
return `export const ${options.constName} = [
|
|
94
|
+
\t[
|
|
95
|
+
\t\t'core/heading',
|
|
96
|
+
\t\t{
|
|
97
|
+
\t\t\tlevel: 2,
|
|
98
|
+
\t\t\tplaceholder: __( ${quoteTsString("Add a section heading")}, ${quoteTsString(options.textDomain)} ),
|
|
99
|
+
\t\t},
|
|
100
|
+
\t],
|
|
101
|
+
\t[
|
|
102
|
+
\t\t'core/paragraph',
|
|
103
|
+
\t\t{
|
|
104
|
+
\t\t\tplaceholder: __( ${quoteTsString("Add supporting copy")}, ${quoteTsString(options.textDomain)} ),
|
|
105
|
+
\t\t},
|
|
106
|
+
\t],
|
|
107
|
+
] satisfies BlockTemplate;`;
|
|
108
|
+
}
|
|
109
|
+
return `// Non-container core blocks can keep this empty or replace it with a
|
|
110
|
+
// block-supported InnerBlocks template when the target block accepts children.
|
|
111
|
+
export const ${options.constName} = [] satisfies BlockTemplate;`;
|
|
112
|
+
}
|
|
113
|
+
function buildCoreVariationSource(options) {
|
|
114
|
+
const attributesTypeName = buildCoreVariationAttributesTypeName(options.targetBlockName, options.variationSlug);
|
|
115
|
+
const blockConstName = buildCoreVariationBlockConstName(options.targetBlockName, options.variationSlug);
|
|
116
|
+
const attributesConstName = buildCoreVariationAttributesConstName(options.targetBlockName, options.variationSlug);
|
|
117
|
+
const innerBlocksConstName = buildCoreVariationInnerBlocksConstName(options.targetBlockName, options.variationSlug);
|
|
118
|
+
const variationConstName = buildCoreVariationConstName(options.targetBlockName, options.variationSlug);
|
|
119
|
+
const variationTitle = formatCoreVariationTitle(options.variationSlug);
|
|
120
|
+
const variationClassName = `is-${options.variationSlug}`;
|
|
121
|
+
return `import type {
|
|
122
|
+
\tBlockTemplate,
|
|
123
|
+
\tBlockVariation,
|
|
124
|
+
} from '@wp-typia/block-types/blocks/registration';
|
|
125
|
+
import { __ } from '@wordpress/i18n';
|
|
126
|
+
|
|
127
|
+
export const ${blockConstName} = ${quoteTsString(options.targetBlockName)};
|
|
128
|
+
|
|
129
|
+
export interface ${attributesTypeName} {
|
|
130
|
+
\tclassName?: string;
|
|
131
|
+
\tmetadata?: {
|
|
132
|
+
\t\tname?: string;
|
|
133
|
+
\t};
|
|
134
|
+
\t[key: string]: unknown;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const ${attributesConstName} = {
|
|
138
|
+
\tclassName: ${quoteTsString(variationClassName)},
|
|
139
|
+
\tmetadata: {
|
|
140
|
+
\t\tname: ${quoteTsString(variationTitle)},
|
|
141
|
+
\t},
|
|
142
|
+
} satisfies ${attributesTypeName};
|
|
143
|
+
|
|
144
|
+
${buildCoreVariationInnerBlocksSource({
|
|
145
|
+
constName: innerBlocksConstName,
|
|
146
|
+
targetBlockName: options.targetBlockName,
|
|
147
|
+
textDomain: options.textDomain,
|
|
148
|
+
})}
|
|
149
|
+
|
|
150
|
+
export const ${variationConstName} = {
|
|
151
|
+
\tname: ${quoteTsString(options.variationSlug)},
|
|
152
|
+
\ttitle: __( ${quoteTsString(variationTitle)}, ${quoteTsString(options.textDomain)} ),
|
|
153
|
+
\tdescription: __(
|
|
154
|
+
\t\t${quoteTsString(`A starter ${options.targetBlockName} variation for ${variationTitle}.`)},
|
|
155
|
+
\t\t${quoteTsString(options.textDomain)},
|
|
156
|
+
\t),
|
|
157
|
+
\tcategory: 'design',
|
|
158
|
+
\ticon: 'layout',
|
|
159
|
+
\tkeywords: [
|
|
160
|
+
\t\t__( ${quoteTsString("variation")}, ${quoteTsString(options.textDomain)} ),
|
|
161
|
+
\t\t__( ${quoteTsString(variationTitle)}, ${quoteTsString(options.textDomain)} ),
|
|
162
|
+
\t],
|
|
163
|
+
\tattributes: ${attributesConstName},
|
|
164
|
+
\tinnerBlocks: ${innerBlocksConstName},
|
|
165
|
+
\tisActive: ['className'],
|
|
166
|
+
\tscope: ['block', 'inserter', 'transform'],
|
|
167
|
+
} satisfies BlockVariation<${attributesTypeName}>;
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
async function readCoreVariationModuleRefs(coreVariationsDir) {
|
|
171
|
+
if (!(await pathExists(coreVariationsDir))) {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
const refs = [];
|
|
175
|
+
const namespaceEntries = await fsp.readdir(coreVariationsDir, {
|
|
176
|
+
withFileTypes: true,
|
|
177
|
+
});
|
|
178
|
+
for (const namespaceEntry of namespaceEntries) {
|
|
179
|
+
if (!namespaceEntry.isDirectory()) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const namespaceDir = path.join(coreVariationsDir, namespaceEntry.name);
|
|
183
|
+
const blockEntries = await fsp.readdir(namespaceDir, {
|
|
184
|
+
withFileTypes: true,
|
|
185
|
+
});
|
|
186
|
+
for (const blockEntry of blockEntries) {
|
|
187
|
+
if (!blockEntry.isDirectory()) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const blockDir = path.join(namespaceDir, blockEntry.name);
|
|
191
|
+
const variationEntries = await fsp.readdir(blockDir, {
|
|
192
|
+
withFileTypes: true,
|
|
193
|
+
});
|
|
194
|
+
for (const variationEntry of variationEntries) {
|
|
195
|
+
if (!variationEntry.isFile() || !variationEntry.name.endsWith(".ts")) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const variationSlug = variationEntry.name.replace(/\.ts$/u, "");
|
|
199
|
+
if (variationSlug === "index") {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
refs.push({
|
|
203
|
+
targetBlockName: `${namespaceEntry.name}/${blockEntry.name}`,
|
|
204
|
+
variationSlug,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return refs.sort((left, right) => {
|
|
210
|
+
const leftKey = `${left.targetBlockName}/${left.variationSlug}`;
|
|
211
|
+
const rightKey = `${right.targetBlockName}/${right.variationSlug}`;
|
|
212
|
+
return leftKey.localeCompare(rightKey);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function buildCoreVariationIndexSource(refs) {
|
|
216
|
+
const importLines = refs
|
|
217
|
+
.map((ref, index) => {
|
|
218
|
+
const blockConstName = buildCoreVariationBlockConstName(ref.targetBlockName, ref.variationSlug);
|
|
219
|
+
const variationConstName = buildCoreVariationConstName(ref.targetBlockName, ref.variationSlug);
|
|
220
|
+
return `import { ${blockConstName} as CORE_VARIATION_BLOCK_${index}, ${variationConstName} as coreVariationEntry${index} } from '${buildCoreVariationImportPath(ref)}';`;
|
|
221
|
+
})
|
|
222
|
+
.join("\n");
|
|
223
|
+
const entryLines = refs
|
|
224
|
+
.map((_, index) => {
|
|
225
|
+
return `\t{ blockName: CORE_VARIATION_BLOCK_${index}, variation: coreVariationEntry${index} },`;
|
|
226
|
+
})
|
|
227
|
+
.join("\n");
|
|
228
|
+
return `import { registerBlockVariation } from '@wordpress/blocks';
|
|
229
|
+
${importLines ? `\n${importLines}\n` : ""}
|
|
230
|
+
const WORKSPACE_CORE_VARIATIONS = [
|
|
231
|
+
${entryLines}
|
|
232
|
+
] as const;
|
|
233
|
+
|
|
234
|
+
export function registerWorkspaceCoreVariations() {
|
|
235
|
+
\tfor (const { blockName, variation } of WORKSPACE_CORE_VARIATIONS) {
|
|
236
|
+
\t\tregisterBlockVariation(blockName, variation);
|
|
237
|
+
\t}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
registerWorkspaceCoreVariations();
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
async function writeCoreVariationRegistry(projectDir, targetBlockName, textDomain, variationSlug) {
|
|
244
|
+
const coreVariationsDir = getCoreVariationRootDir(projectDir);
|
|
245
|
+
const targetBlockDir = getCoreVariationBlockDir(projectDir, targetBlockName);
|
|
246
|
+
const variationFilePath = getCoreVariationFilePath(projectDir, targetBlockName, variationSlug);
|
|
247
|
+
await fsp.mkdir(targetBlockDir, { recursive: true });
|
|
248
|
+
await fsp.writeFile(variationFilePath, buildCoreVariationSource({
|
|
249
|
+
targetBlockName,
|
|
250
|
+
textDomain,
|
|
251
|
+
variationSlug,
|
|
252
|
+
}), "utf8");
|
|
253
|
+
const refs = await readCoreVariationModuleRefs(coreVariationsDir);
|
|
254
|
+
await fsp.writeFile(getCoreVariationIndexPath(projectDir), buildCoreVariationIndexSource(refs), "utf8");
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Add one editor-side variation registration for an existing core or external block.
|
|
258
|
+
*
|
|
259
|
+
* @param options Command options for the core-variation scaffold workflow.
|
|
260
|
+
* @param options.cwd Working directory used to resolve the nearest official workspace.
|
|
261
|
+
* Defaults to `process.cwd()`.
|
|
262
|
+
* @param options.targetBlockName Full `namespace/block` name that receives the variation.
|
|
263
|
+
* @param options.variationName Human-entered variation name normalized into the generated slug.
|
|
264
|
+
* @returns The normalized variation metadata and owning workspace directory.
|
|
265
|
+
* @throws {Error} When the command is run outside an official workspace, the
|
|
266
|
+
* target block name is not full `namespace/block` form, or the generated file
|
|
267
|
+
* already exists.
|
|
268
|
+
*/
|
|
269
|
+
export async function runAddCoreVariationCommand({ cwd = process.cwd(), targetBlockName, variationName, }) {
|
|
270
|
+
const workspace = resolveWorkspaceProject(cwd);
|
|
271
|
+
const resolvedTargetBlockName = assertFullBlockName(targetBlockName, "core-variation target");
|
|
272
|
+
const variationSlug = assertValidGeneratedSlug("Core variation name", normalizeBlockSlug(variationName), CORE_VARIATION_USAGE);
|
|
273
|
+
assertCoreVariationSlugIsNotRegistryIndex(variationSlug);
|
|
274
|
+
assertCoreVariationDoesNotExist(workspace.projectDir, resolvedTargetBlockName, variationSlug);
|
|
275
|
+
const bootstrapPath = path.join(workspace.projectDir, `${workspace.packageName.split("/").pop() ?? workspace.packageName}.php`);
|
|
276
|
+
const buildScriptPath = path.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
277
|
+
const webpackConfigPath = path.join(workspace.projectDir, "webpack.config.js");
|
|
278
|
+
const editorPluginsIndexPath = await resolveEditorPluginRegistryPath(workspace.projectDir);
|
|
279
|
+
const coreVariationsDir = getCoreVariationRootDir(workspace.projectDir);
|
|
280
|
+
const targetNamespaceDir = path.join(coreVariationsDir, resolvedTargetBlockName.split("/")[0] ?? "");
|
|
281
|
+
const targetBlockDir = getCoreVariationBlockDir(workspace.projectDir, resolvedTargetBlockName);
|
|
282
|
+
const variationFilePath = getCoreVariationFilePath(workspace.projectDir, resolvedTargetBlockName, variationSlug);
|
|
283
|
+
const coreVariationsIndexPath = getCoreVariationIndexPath(workspace.projectDir);
|
|
284
|
+
const shouldRemoveCoreVariationsDir = !(await pathExists(coreVariationsDir));
|
|
285
|
+
const shouldRemoveTargetNamespaceDir = !shouldRemoveCoreVariationsDir && !(await pathExists(targetNamespaceDir));
|
|
286
|
+
const shouldRemoveTargetBlockDir = !shouldRemoveCoreVariationsDir &&
|
|
287
|
+
!shouldRemoveTargetNamespaceDir &&
|
|
288
|
+
!(await pathExists(targetBlockDir));
|
|
289
|
+
const mutationSnapshot = {
|
|
290
|
+
fileSources: await snapshotWorkspaceFiles([
|
|
291
|
+
bootstrapPath,
|
|
292
|
+
buildScriptPath,
|
|
293
|
+
editorPluginsIndexPath,
|
|
294
|
+
webpackConfigPath,
|
|
295
|
+
coreVariationsIndexPath,
|
|
296
|
+
]),
|
|
297
|
+
snapshotDirs: [],
|
|
298
|
+
targetPaths: [
|
|
299
|
+
variationFilePath,
|
|
300
|
+
...(shouldRemoveCoreVariationsDir ? [coreVariationsDir] : []),
|
|
301
|
+
...(shouldRemoveTargetNamespaceDir ? [targetNamespaceDir] : []),
|
|
302
|
+
...(shouldRemoveTargetBlockDir ? [targetBlockDir] : []),
|
|
303
|
+
],
|
|
304
|
+
};
|
|
305
|
+
try {
|
|
306
|
+
await ensureEditorPluginBootstrapAnchors(workspace);
|
|
307
|
+
await ensureEditorPluginBuildScriptAnchors(workspace);
|
|
308
|
+
await ensureEditorPluginWebpackAnchors(workspace);
|
|
309
|
+
await writeCoreVariationRegistry(workspace.projectDir, resolvedTargetBlockName, workspace.workspace.textDomain, variationSlug);
|
|
310
|
+
await writeEditorPluginRegistry(workspace.projectDir, CORE_VARIATIONS_EDITOR_PLUGIN_SLUG);
|
|
311
|
+
return {
|
|
312
|
+
projectDir: workspace.projectDir,
|
|
313
|
+
targetBlockName: resolvedTargetBlockName,
|
|
314
|
+
variationFile: path.relative(workspace.projectDir, variationFilePath),
|
|
315
|
+
variationSlug,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { WorkspaceProject } from "./workspace-project.js";
|
|
2
|
+
/**
|
|
3
|
+
* Ensures the workspace bootstrap enqueues the shared editor plugin bundle.
|
|
4
|
+
*
|
|
5
|
+
* @param workspace Official workspace metadata used to locate and patch the bootstrap file.
|
|
6
|
+
* @returns A promise that resolves after the bootstrap anchors are present.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ensureEditorPluginBootstrapAnchors(workspace: WorkspaceProject): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Ensures the workspace build script includes the shared editor plugin entry.
|
|
11
|
+
*
|
|
12
|
+
* @param workspace Official workspace metadata used to locate the build script.
|
|
13
|
+
* @returns A promise that resolves after the build script anchors are present.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ensureEditorPluginBuildScriptAnchors(workspace: WorkspaceProject): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Ensures the workspace webpack config builds the shared editor plugin entry.
|
|
18
|
+
*
|
|
19
|
+
* @param workspace Official workspace metadata used to locate the webpack config.
|
|
20
|
+
* @returns A promise that resolves after the webpack anchors are present.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureEditorPluginWebpackAnchors(workspace: WorkspaceProject): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the editor plugin registry path, preferring existing TypeScript or JavaScript registries.
|
|
25
|
+
*
|
|
26
|
+
* @param projectDir Workspace root directory to inspect.
|
|
27
|
+
* @returns A promise for the registry path to read or write.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveEditorPluginRegistryPath(projectDir: string): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Rewrites the shared editor plugin registry with the requested plugin slug included.
|
|
32
|
+
*
|
|
33
|
+
* @param projectDir Workspace root directory that owns `src/editor-plugins`.
|
|
34
|
+
* @param editorPluginSlug Editor plugin slug that must be imported by the registry.
|
|
35
|
+
* @returns A promise that resolves after the registry has been written.
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeEditorPluginRegistry(projectDir: string, editorPluginSlug: string): Promise<void>;
|