wp-typia 0.22.0 → 0.22.1
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-bunli/.bunli/commands.gen.js +655 -520
- package/dist-bunli/{cli-ktp869eh.js → cli-0p8wz4a4.js} +36 -23
- package/dist-bunli/{cli-39er8888.js → cli-1sm60g1z.js} +19 -2
- package/dist-bunli/{cli-j180bk07.js → cli-5md428hf.js} +6 -2
- package/dist-bunli/{cli-1w5vkye4.js → cli-886tjd8m.js} +6 -6
- package/dist-bunli/{cli-add-kjhghdqq.js → cli-add-5z3wpzkh.js} +283 -264
- package/dist-bunli/{cli-doctor-p3jxvn0k.js → cli-doctor-jd7qyr5s.js} +1 -1
- package/dist-bunli/{cli-init-djhwr245.js → cli-init-10nktmme.js} +2 -2
- package/dist-bunli/{cli-scaffold-376yw891.js → cli-scaffold-837x3xsv.js} +4 -4
- package/dist-bunli/{cli-e623rs7g.js → cli-yzmkz95r.js} +1 -1
- package/dist-bunli/cli.js +2 -2
- package/dist-bunli/{command-list-jt1a1w7r.js → command-list-tgyxdhb0.js} +184 -127
- package/dist-bunli/{migrations-nwas5bwt.js → migrations-x3a9t9yf.js} +2 -2
- package/dist-bunli/node-cli.js +287 -197
- package/package.json +2 -2
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
scaffoldProject,
|
|
21
21
|
syncPersistenceRestArtifacts,
|
|
22
22
|
updatePluginHeaderCompatibility
|
|
23
|
-
} from "./cli-
|
|
23
|
+
} from "./cli-886tjd8m.js";
|
|
24
24
|
import {
|
|
25
25
|
DEFAULT_WORDPRESS_ABILITIES_VERSION,
|
|
26
26
|
DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION,
|
|
@@ -28,11 +28,12 @@ import {
|
|
|
28
28
|
DEFAULT_WORDPRESS_DATAVIEWS_VERSION,
|
|
29
29
|
DEFAULT_WORDPRESS_DATA_VERSION,
|
|
30
30
|
DEFAULT_WP_TYPIA_DATAVIEWS_VERSION,
|
|
31
|
-
getPackageVersions
|
|
32
|
-
|
|
31
|
+
getPackageVersions,
|
|
32
|
+
resolveManagedPackageVersionRange
|
|
33
|
+
} from "./cli-1sm60g1z.js";
|
|
33
34
|
import {
|
|
34
35
|
snapshotProjectVersion
|
|
35
|
-
} from "./cli-
|
|
36
|
+
} from "./cli-yzmkz95r.js";
|
|
36
37
|
import {
|
|
37
38
|
ensureMigrationDirectories,
|
|
38
39
|
parseMigrationConfig,
|
|
@@ -45,7 +46,6 @@ import {
|
|
|
45
46
|
} from "./cli-sj5mtyzj.js";
|
|
46
47
|
import"./cli-10pe4mf8.js";
|
|
47
48
|
import {
|
|
48
|
-
PROJECT_TOOLS_PACKAGE_ROOT,
|
|
49
49
|
SHARED_WORKSPACE_TEMPLATE_ROOT
|
|
50
50
|
} from "./cli-tke8twkn.js";
|
|
51
51
|
import {
|
|
@@ -89,11 +89,12 @@ import {
|
|
|
89
89
|
resolveWorkspaceBlock,
|
|
90
90
|
rollbackWorkspaceMutation,
|
|
91
91
|
snapshotWorkspaceFiles,
|
|
92
|
+
toCamelCase,
|
|
92
93
|
toKebabCase,
|
|
93
94
|
toPascalCase,
|
|
94
95
|
toSnakeCase,
|
|
95
96
|
toTitleCase
|
|
96
|
-
} from "./cli-
|
|
97
|
+
} from "./cli-5md428hf.js";
|
|
97
98
|
import {
|
|
98
99
|
createManagedTempRoot
|
|
99
100
|
} from "./cli-t73q5aqz.js";
|
|
@@ -781,16 +782,15 @@ async function runAddBlockCommand({
|
|
|
781
782
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace.ts
|
|
782
783
|
import fs6 from "fs";
|
|
783
784
|
import { promises as fsp9 } from "fs";
|
|
784
|
-
import
|
|
785
|
+
import path14 from "path";
|
|
785
786
|
|
|
786
|
-
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view.ts
|
|
787
|
-
import fs3 from "fs";
|
|
788
|
-
import { promises as fsp3 } from "fs";
|
|
789
|
-
import { createRequire } from "module";
|
|
790
|
-
import path4 from "path";
|
|
787
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-types.ts
|
|
791
788
|
var ADMIN_VIEW_REST_SOURCE_KIND = "rest-resource";
|
|
792
789
|
var ADMIN_VIEW_CORE_DATA_SOURCE_KIND = "core-data";
|
|
793
|
-
var ADMIN_VIEW_CORE_DATA_ENTITY_KIND_IDS = [
|
|
790
|
+
var ADMIN_VIEW_CORE_DATA_ENTITY_KIND_IDS = [
|
|
791
|
+
"postType",
|
|
792
|
+
"taxonomy"
|
|
793
|
+
];
|
|
794
794
|
var ADMIN_VIEW_CORE_DATA_ENTITY_SEGMENT_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/u;
|
|
795
795
|
var ADMIN_VIEW_CORE_DATA_ENTITY_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]*$/u;
|
|
796
796
|
var ADMIN_VIEW_SOURCE_USAGE = "wp-typia add admin-view <name> --source <rest-resource:slug|core-data:kind/name>";
|
|
@@ -801,28 +801,20 @@ var ADMIN_VIEWS_STYLE_RTL = "build/admin-views/style-index-rtl.css";
|
|
|
801
801
|
var ADMIN_VIEWS_PHP_GLOB = "/inc/admin-views/*.php";
|
|
802
802
|
var ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV = "WP_TYPIA_ALLOW_UNPUBLISHED_DATAVIEWS";
|
|
803
803
|
var ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED = false;
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
const pascalCase = toPascalCase(input);
|
|
807
|
-
return `${pascalCase.charAt(0).toLowerCase()}${pascalCase.slice(1)}`;
|
|
804
|
+
function isAdminViewCoreDataSource(source) {
|
|
805
|
+
return source?.kind === ADMIN_VIEW_CORE_DATA_SOURCE_KIND;
|
|
808
806
|
}
|
|
809
|
-
function
|
|
810
|
-
|
|
811
|
-
if (!trimmed || trimmed.startsWith("workspace:")) {
|
|
812
|
-
return fallback;
|
|
813
|
-
}
|
|
814
|
-
return /^[~^<>=]/u.test(trimmed) ? trimmed : `^${trimmed}`;
|
|
807
|
+
function isAdminViewRestResourceSource(source) {
|
|
808
|
+
return source?.kind === ADMIN_VIEW_REST_SOURCE_KIND;
|
|
815
809
|
}
|
|
816
|
-
function
|
|
817
|
-
|
|
818
|
-
return
|
|
819
|
-
} catch {
|
|
820
|
-
return;
|
|
810
|
+
function formatAdminViewSourceLocator(source) {
|
|
811
|
+
if (isAdminViewCoreDataSource(source)) {
|
|
812
|
+
return `${source.kind}:${source.entityKind}/${source.entityName}`;
|
|
821
813
|
}
|
|
814
|
+
return `${source.kind}:${source.slug}`;
|
|
822
815
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
}
|
|
816
|
+
|
|
817
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-source.ts
|
|
826
818
|
function isAdminViewUnpublishedDataViewsOverrideEnabled() {
|
|
827
819
|
return process.env[ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV]?.trim() === "1";
|
|
828
820
|
}
|
|
@@ -832,36 +824,6 @@ function assertAdminViewPackageAvailability() {
|
|
|
832
824
|
}
|
|
833
825
|
throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, "`wp-typia add admin-view` is temporarily unavailable because `@wp-typia/dataviews` is not published to npm for public installs yet.");
|
|
834
826
|
}
|
|
835
|
-
function detectJsonIndent(source) {
|
|
836
|
-
const indentMatch = /\n([ \t]+)"/u.exec(source);
|
|
837
|
-
return indentMatch?.[1] ?? 2;
|
|
838
|
-
}
|
|
839
|
-
function resolvePackageVersionRange(packageName, fallback, workspacePackageDirName) {
|
|
840
|
-
if (workspacePackageDirName) {
|
|
841
|
-
const workspaceVersion = readPackageManifestVersion(path4.join(PROJECT_TOOLS_PACKAGE_ROOT, "..", workspacePackageDirName, "package.json"));
|
|
842
|
-
if (workspaceVersion) {
|
|
843
|
-
return normalizeVersionRange(workspaceVersion, fallback);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
try {
|
|
847
|
-
return normalizeVersionRange(readPackageManifestVersion(require2.resolve(`${packageName}/package.json`)), fallback);
|
|
848
|
-
} catch {
|
|
849
|
-
return fallback;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
function getAdminViewRelativeModuleSpecifier(adminViewSlug, workspaceFile) {
|
|
853
|
-
const adminViewDir = `src/admin-views/${adminViewSlug}`;
|
|
854
|
-
const normalizedFile = workspaceFile.replace(/\\/gu, "/");
|
|
855
|
-
const modulePath = normalizedFile.replace(/\.[cm]?[jt]sx?$/u, "");
|
|
856
|
-
const relativeModulePath = path4.posix.relative(adminViewDir, modulePath);
|
|
857
|
-
return relativeModulePath.startsWith(".") ? relativeModulePath : `./${relativeModulePath}`;
|
|
858
|
-
}
|
|
859
|
-
function isAdminViewCoreDataSource(source) {
|
|
860
|
-
return source?.kind === ADMIN_VIEW_CORE_DATA_SOURCE_KIND;
|
|
861
|
-
}
|
|
862
|
-
function isAdminViewRestResourceSource(source) {
|
|
863
|
-
return source?.kind === ADMIN_VIEW_REST_SOURCE_KIND;
|
|
864
|
-
}
|
|
865
827
|
function assertValidCoreDataEntitySegment(label, value) {
|
|
866
828
|
const trimmed = value.trim();
|
|
867
829
|
if (!trimmed) {
|
|
@@ -889,12 +851,6 @@ function assertValidCoreDataEntityKind(value) {
|
|
|
889
851
|
}
|
|
890
852
|
return normalized;
|
|
891
853
|
}
|
|
892
|
-
function formatAdminViewSourceLocator(source) {
|
|
893
|
-
if (isAdminViewCoreDataSource(source)) {
|
|
894
|
-
return `${source.kind}:${source.entityKind}/${source.entityName}`;
|
|
895
|
-
}
|
|
896
|
-
return `${source.kind}:${source.slug}`;
|
|
897
|
-
}
|
|
898
854
|
function parseAdminViewSource(source) {
|
|
899
855
|
const trimmed = source?.trim();
|
|
900
856
|
if (!trimmed) {
|
|
@@ -938,6 +894,24 @@ function resolveRestResourceSource(restResources, source) {
|
|
|
938
894
|
}
|
|
939
895
|
return restResource;
|
|
940
896
|
}
|
|
897
|
+
function resolveAdminViewCoreDataSource(source) {
|
|
898
|
+
return isAdminViewCoreDataSource(source) ? source : undefined;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-scaffold.ts
|
|
902
|
+
import fs3 from "fs";
|
|
903
|
+
import { promises as fsp3 } from "fs";
|
|
904
|
+
import path5 from "path";
|
|
905
|
+
|
|
906
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-templates.ts
|
|
907
|
+
import path4 from "path";
|
|
908
|
+
function getAdminViewRelativeModuleSpecifier(adminViewSlug, workspaceFile) {
|
|
909
|
+
const adminViewDir = `src/admin-views/${adminViewSlug}`;
|
|
910
|
+
const normalizedFile = workspaceFile.replace(/\\/gu, "/");
|
|
911
|
+
const modulePath = normalizedFile.replace(/\.[cm]?[jt]sx?$/u, "");
|
|
912
|
+
const relativeModulePath = path4.posix.relative(adminViewDir, modulePath);
|
|
913
|
+
return relativeModulePath.startsWith(".") ? relativeModulePath : `./${relativeModulePath}`;
|
|
914
|
+
}
|
|
941
915
|
function buildAdminViewConfigEntry(adminViewSlug, source) {
|
|
942
916
|
return [
|
|
943
917
|
"\t{",
|
|
@@ -1070,8 +1044,8 @@ function buildAdminViewConfigSource(adminViewSlug, textDomain, source, restResou
|
|
|
1070
1044
|
const camelName = toCamelCase(adminViewSlug);
|
|
1071
1045
|
const itemTypeName = `${pascalName}AdminViewItem`;
|
|
1072
1046
|
const dataViewsName = `${camelName}AdminDataViews`;
|
|
1073
|
-
const isCoreDataSource = source
|
|
1074
|
-
const isTaxonomyCoreDataSource = source
|
|
1047
|
+
const isCoreDataSource = isAdminViewCoreDataSource(source);
|
|
1048
|
+
const isTaxonomyCoreDataSource = isAdminViewCoreDataSource(source) && source.entityKind === "taxonomy";
|
|
1075
1049
|
const defaultViewFields = restResource ? "['id']" : isTaxonomyCoreDataSource ? "['name', 'slug', 'count']" : isCoreDataSource ? "['title', 'slug', 'status', 'updatedAt']" : "['title', 'status', 'updatedAt']";
|
|
1076
1050
|
const searchEnabled = restResource ? "false" : "true";
|
|
1077
1051
|
const titleFieldSource = restResource ? "" : isTaxonomyCoreDataSource ? ` titleField: 'name',
|
|
@@ -1887,12 +1861,31 @@ add_action( 'admin_menu', '${registerFunctionName}' );
|
|
|
1887
1861
|
add_action( 'admin_enqueue_scripts', '${enqueueFunctionName}' );
|
|
1888
1862
|
`;
|
|
1889
1863
|
}
|
|
1864
|
+
|
|
1865
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-scaffold.ts
|
|
1866
|
+
function detectJsonIndent(source) {
|
|
1867
|
+
const indentMatch = /\n([ \t]+)"/u.exec(source);
|
|
1868
|
+
return indentMatch?.[1] ?? 2;
|
|
1869
|
+
}
|
|
1890
1870
|
async function ensureAdminViewPackageDependencies(workspace, adminViewSource) {
|
|
1891
|
-
const packageJsonPath =
|
|
1892
|
-
const wpTypiaDataViewsVersion =
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1871
|
+
const packageJsonPath = path5.join(workspace.projectDir, "package.json");
|
|
1872
|
+
const wpTypiaDataViewsVersion = resolveManagedPackageVersionRange({
|
|
1873
|
+
fallback: DEFAULT_WP_TYPIA_DATAVIEWS_VERSION,
|
|
1874
|
+
packageName: "@wp-typia/dataviews",
|
|
1875
|
+
workspacePackageDirName: "wp-typia-dataviews"
|
|
1876
|
+
});
|
|
1877
|
+
const wordpressDataViewsVersion = resolveManagedPackageVersionRange({
|
|
1878
|
+
fallback: DEFAULT_WORDPRESS_DATAVIEWS_VERSION,
|
|
1879
|
+
packageName: "@wordpress/dataviews"
|
|
1880
|
+
});
|
|
1881
|
+
const wordpressCoreDataVersion = resolveManagedPackageVersionRange({
|
|
1882
|
+
fallback: DEFAULT_WORDPRESS_CORE_DATA_VERSION,
|
|
1883
|
+
packageName: "@wordpress/core-data"
|
|
1884
|
+
});
|
|
1885
|
+
const wordpressDataVersion = resolveManagedPackageVersionRange({
|
|
1886
|
+
fallback: DEFAULT_WORDPRESS_DATA_VERSION,
|
|
1887
|
+
packageName: "@wordpress/data"
|
|
1888
|
+
});
|
|
1896
1889
|
await patchFile(packageJsonPath, (source) => {
|
|
1897
1890
|
const packageJson = JSON.parse(source);
|
|
1898
1891
|
const coreDataDependencies = isAdminViewCoreDataSource(adminViewSource) ? {
|
|
@@ -1923,6 +1916,7 @@ async function ensureAdminViewBootstrapAnchors(workspace) {
|
|
|
1923
1916
|
let nextSource = source;
|
|
1924
1917
|
const loadFunctionName = `${workspace.workspace.phpPrefix}_load_admin_views`;
|
|
1925
1918
|
const loadHook = `add_action( 'plugins_loaded', '${loadFunctionName}' );`;
|
|
1919
|
+
const loadHookPattern = new RegExp(`add_action\\(\\s*['"]plugins_loaded['"]\\s*,\\s*['"]${loadFunctionName}['"]\\s*\\)\\s*;`, "u");
|
|
1926
1920
|
const loadFunction = `
|
|
1927
1921
|
|
|
1928
1922
|
function ${loadFunctionName}() {
|
|
@@ -1967,19 +1961,19 @@ ${snippet}
|
|
|
1967
1961
|
if (!functionSource.includes(ADMIN_VIEWS_PHP_GLOB)) {
|
|
1968
1962
|
const replacedSource = replacePhpFunctionDefinition(nextSource, loadFunctionName, loadFunction);
|
|
1969
1963
|
if (!replacedSource) {
|
|
1970
|
-
throw new Error(`Unable to repair ${
|
|
1964
|
+
throw new Error(`Unable to repair ${path5.basename(bootstrapPath)} for ${loadFunctionName}.`);
|
|
1971
1965
|
}
|
|
1972
1966
|
nextSource = replacedSource;
|
|
1973
1967
|
}
|
|
1974
1968
|
}
|
|
1975
|
-
if (!
|
|
1969
|
+
if (!loadHookPattern.test(nextSource)) {
|
|
1976
1970
|
appendPhpSnippet(loadHook);
|
|
1977
1971
|
}
|
|
1978
1972
|
return nextSource;
|
|
1979
1973
|
});
|
|
1980
1974
|
}
|
|
1981
1975
|
async function ensureAdminViewBuildScriptAnchors(workspace) {
|
|
1982
|
-
const buildScriptPath =
|
|
1976
|
+
const buildScriptPath = path5.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
1983
1977
|
await patchFile(buildScriptPath, (source) => {
|
|
1984
1978
|
if (/['"]src\/admin-views\/index\.(?:ts|js)['"]/u.test(source)) {
|
|
1985
1979
|
return source;
|
|
@@ -2003,11 +1997,11 @@ async function ensureAdminViewBuildScriptAnchors(workspace) {
|
|
|
2003
1997
|
if (nextSource !== source) {
|
|
2004
1998
|
return nextSource;
|
|
2005
1999
|
}
|
|
2006
|
-
throw new Error(`Unable to update ${
|
|
2000
|
+
throw new Error(`Unable to update ${path5.relative(workspace.projectDir, buildScriptPath)} for admin view shared entries.`);
|
|
2007
2001
|
});
|
|
2008
2002
|
}
|
|
2009
2003
|
async function ensureAdminViewWebpackAnchors(workspace) {
|
|
2010
|
-
const webpackConfigPath =
|
|
2004
|
+
const webpackConfigPath = path5.join(workspace.projectDir, "webpack.config.js");
|
|
2011
2005
|
await patchFile(webpackConfigPath, (source) => {
|
|
2012
2006
|
if (/['"]admin-views\/index['"]/u.test(source)) {
|
|
2013
2007
|
return source;
|
|
@@ -2048,17 +2042,17 @@ async function ensureAdminViewWebpackAnchors(workspace) {
|
|
|
2048
2042
|
}`;
|
|
2049
2043
|
nextSource = source.replace(legacySharedEntriesBlockPattern, nextSharedEntriesBlock);
|
|
2050
2044
|
if (nextSource === source) {
|
|
2051
|
-
throw new Error(`Unable to update ${
|
|
2045
|
+
throw new Error(`Unable to update ${path5.relative(workspace.projectDir, webpackConfigPath)} for admin view shared entries.`);
|
|
2052
2046
|
}
|
|
2053
2047
|
return nextSource;
|
|
2054
2048
|
});
|
|
2055
2049
|
}
|
|
2056
2050
|
function resolveAdminViewRegistryPath(projectDir) {
|
|
2057
|
-
const adminViewsDir =
|
|
2051
|
+
const adminViewsDir = path5.join(projectDir, "src", "admin-views");
|
|
2058
2052
|
return [
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
].find((candidatePath) => fs3.existsSync(candidatePath)) ??
|
|
2053
|
+
path5.join(adminViewsDir, "index.ts"),
|
|
2054
|
+
path5.join(adminViewsDir, "index.js")
|
|
2055
|
+
].find((candidatePath) => fs3.existsSync(candidatePath)) ?? path5.join(adminViewsDir, "index.ts");
|
|
2062
2056
|
}
|
|
2063
2057
|
function readAdminViewRegistrySlugs(registryPath) {
|
|
2064
2058
|
if (!fs3.existsSync(registryPath)) {
|
|
@@ -2068,35 +2062,34 @@ function readAdminViewRegistrySlugs(registryPath) {
|
|
|
2068
2062
|
return Array.from(source.matchAll(/^\s*import\s+['"]\.\/([^/'"]+)(?:\/index(?:\.[cm]?[jt]sx?)?)?['"];?\s*$/gmu)).map((match) => match[1]);
|
|
2069
2063
|
}
|
|
2070
2064
|
async function writeAdminViewRegistry(projectDir, adminViewSlug) {
|
|
2071
|
-
const adminViewsDir =
|
|
2065
|
+
const adminViewsDir = path5.join(projectDir, "src", "admin-views");
|
|
2072
2066
|
const registryPath = resolveAdminViewRegistryPath(projectDir);
|
|
2073
2067
|
await fsp3.mkdir(adminViewsDir, { recursive: true });
|
|
2074
2068
|
const existingAdminViewSlugs = readWorkspaceInventory(projectDir).adminViews.map((entry) => entry.slug);
|
|
2075
2069
|
const existingRegistrySlugs = readAdminViewRegistrySlugs(registryPath);
|
|
2076
|
-
const nextAdminViewSlugs = Array.from(new Set([
|
|
2070
|
+
const nextAdminViewSlugs = Array.from(new Set([
|
|
2071
|
+
...existingAdminViewSlugs,
|
|
2072
|
+
...existingRegistrySlugs,
|
|
2073
|
+
adminViewSlug
|
|
2074
|
+
])).sort();
|
|
2077
2075
|
await fsp3.writeFile(registryPath, buildAdminViewRegistrySource(nextAdminViewSlugs), "utf8");
|
|
2078
2076
|
}
|
|
2079
|
-
async function
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
const
|
|
2088
|
-
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
2089
|
-
const restResource = resolveRestResourceSource(inventory.restResources, parsedSource);
|
|
2090
|
-
const coreDataSource = isAdminViewCoreDataSource(parsedSource) ? parsedSource : undefined;
|
|
2091
|
-
assertAdminViewDoesNotExist(workspace.projectDir, adminViewSlug, inventory);
|
|
2092
|
-
const blockConfigPath = path4.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
2077
|
+
async function scaffoldAdminViewWorkspace(options) {
|
|
2078
|
+
const {
|
|
2079
|
+
adminViewSlug,
|
|
2080
|
+
coreDataSource,
|
|
2081
|
+
parsedSource,
|
|
2082
|
+
restResource,
|
|
2083
|
+
workspace
|
|
2084
|
+
} = options;
|
|
2085
|
+
const blockConfigPath = path5.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
2093
2086
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
2094
|
-
const buildScriptPath =
|
|
2095
|
-
const packageJsonPath =
|
|
2096
|
-
const webpackConfigPath =
|
|
2087
|
+
const buildScriptPath = path5.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
2088
|
+
const packageJsonPath = path5.join(workspace.projectDir, "package.json");
|
|
2089
|
+
const webpackConfigPath = path5.join(workspace.projectDir, "webpack.config.js");
|
|
2097
2090
|
const adminViewsIndexPath = resolveAdminViewRegistryPath(workspace.projectDir);
|
|
2098
|
-
const adminViewDir =
|
|
2099
|
-
const adminViewPhpPath =
|
|
2091
|
+
const adminViewDir = path5.join(workspace.projectDir, "src", "admin-views", adminViewSlug);
|
|
2092
|
+
const adminViewPhpPath = path5.join(workspace.projectDir, "inc", "admin-views", `${adminViewSlug}.php`);
|
|
2100
2093
|
const mutationSnapshot = {
|
|
2101
2094
|
fileSources: await snapshotWorkspaceFiles([
|
|
2102
2095
|
adminViewsIndexPath,
|
|
@@ -2111,37 +2104,63 @@ async function runAddAdminViewCommand({
|
|
|
2111
2104
|
};
|
|
2112
2105
|
try {
|
|
2113
2106
|
await fsp3.mkdir(adminViewDir, { recursive: true });
|
|
2114
|
-
await fsp3.mkdir(
|
|
2107
|
+
await fsp3.mkdir(path5.dirname(adminViewPhpPath), { recursive: true });
|
|
2115
2108
|
await ensureAdminViewPackageDependencies(workspace, parsedSource);
|
|
2116
2109
|
await ensureAdminViewBootstrapAnchors(workspace);
|
|
2117
2110
|
await ensureAdminViewBuildScriptAnchors(workspace);
|
|
2118
2111
|
await ensureAdminViewWebpackAnchors(workspace);
|
|
2119
|
-
await fsp3.writeFile(
|
|
2120
|
-
await fsp3.writeFile(
|
|
2121
|
-
await fsp3.writeFile(
|
|
2122
|
-
await fsp3.writeFile(
|
|
2123
|
-
await fsp3.writeFile(
|
|
2124
|
-
await fsp3.writeFile(
|
|
2112
|
+
await fsp3.writeFile(path5.join(adminViewDir, "types.ts"), buildAdminViewTypesSource(adminViewSlug, restResource, coreDataSource), "utf8");
|
|
2113
|
+
await fsp3.writeFile(path5.join(adminViewDir, "config.ts"), buildAdminViewConfigSource(adminViewSlug, workspace.workspace.textDomain, parsedSource, restResource), "utf8");
|
|
2114
|
+
await fsp3.writeFile(path5.join(adminViewDir, "data.ts"), coreDataSource ? buildCoreDataAdminViewDataSource(adminViewSlug, coreDataSource) : restResource ? buildRestAdminViewDataSource(adminViewSlug, restResource) : buildDefaultAdminViewDataSource(adminViewSlug), "utf8");
|
|
2115
|
+
await fsp3.writeFile(path5.join(adminViewDir, "Screen.tsx"), coreDataSource ? buildCoreDataAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain) : buildAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain), "utf8");
|
|
2116
|
+
await fsp3.writeFile(path5.join(adminViewDir, "index.tsx"), buildAdminViewEntrySource(adminViewSlug), "utf8");
|
|
2117
|
+
await fsp3.writeFile(path5.join(adminViewDir, "style.scss"), buildAdminViewStyleSource(), "utf8");
|
|
2125
2118
|
await fsp3.writeFile(adminViewPhpPath, buildAdminViewPhpSource(adminViewSlug, workspace), "utf8");
|
|
2126
2119
|
await writeAdminViewRegistry(workspace.projectDir, adminViewSlug);
|
|
2127
2120
|
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
2128
|
-
adminViewEntries: [
|
|
2121
|
+
adminViewEntries: [
|
|
2122
|
+
buildAdminViewConfigEntry(adminViewSlug, parsedSource)
|
|
2123
|
+
]
|
|
2129
2124
|
});
|
|
2130
|
-
return {
|
|
2131
|
-
adminViewSlug,
|
|
2132
|
-
projectDir: workspace.projectDir,
|
|
2133
|
-
source: parsedSource ? formatAdminViewSourceLocator(parsedSource) : undefined
|
|
2134
|
-
};
|
|
2135
2125
|
} catch (error) {
|
|
2136
2126
|
await rollbackWorkspaceMutation(mutationSnapshot);
|
|
2137
2127
|
throw error;
|
|
2138
2128
|
}
|
|
2139
2129
|
}
|
|
2130
|
+
|
|
2131
|
+
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view.ts
|
|
2132
|
+
var ADD_ADMIN_VIEW_USAGE = "wp-typia add admin-view <name> [--source <rest-resource:slug|core-data:kind/name>]";
|
|
2133
|
+
async function runAddAdminViewCommand({
|
|
2134
|
+
adminViewName,
|
|
2135
|
+
cwd = process.cwd(),
|
|
2136
|
+
source
|
|
2137
|
+
}) {
|
|
2138
|
+
const workspace = resolveWorkspaceProject(cwd);
|
|
2139
|
+
assertAdminViewPackageAvailability();
|
|
2140
|
+
const adminViewSlug = assertValidGeneratedSlug("Admin view name", normalizeBlockSlug(adminViewName), ADD_ADMIN_VIEW_USAGE);
|
|
2141
|
+
const parsedSource = parseAdminViewSource(source);
|
|
2142
|
+
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
2143
|
+
const restResource = resolveRestResourceSource(inventory.restResources, parsedSource);
|
|
2144
|
+
const coreDataSource = resolveAdminViewCoreDataSource(parsedSource);
|
|
2145
|
+
assertAdminViewDoesNotExist(workspace.projectDir, adminViewSlug, inventory);
|
|
2146
|
+
await scaffoldAdminViewWorkspace({
|
|
2147
|
+
adminViewSlug,
|
|
2148
|
+
coreDataSource,
|
|
2149
|
+
parsedSource,
|
|
2150
|
+
restResource,
|
|
2151
|
+
workspace
|
|
2152
|
+
});
|
|
2153
|
+
return {
|
|
2154
|
+
adminViewSlug,
|
|
2155
|
+
projectDir: workspace.projectDir,
|
|
2156
|
+
source: parsedSource ? formatAdminViewSourceLocator(parsedSource) : undefined
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2140
2159
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-assets.ts
|
|
2141
2160
|
var import_typescript = __toESM(require_typescript(), 1);
|
|
2142
2161
|
import fs4 from "fs";
|
|
2143
2162
|
import { promises as fsp4 } from "fs";
|
|
2144
|
-
import
|
|
2163
|
+
import path6 from "path";
|
|
2145
2164
|
import {
|
|
2146
2165
|
syncBlockMetadata as syncBlockMetadata2
|
|
2147
2166
|
} from "@wp-typia/block-runtime/metadata-core";
|
|
@@ -2425,7 +2444,7 @@ async function ensureBindingTargetBlockAttributeType(projectDir, block, target)
|
|
|
2425
2444
|
if (!block.attributeTypeName) {
|
|
2426
2445
|
throw new Error(`Workspace block "${block.slug}" must include attributeTypeName in scripts/block-config.ts before it can receive binding-source targets.`);
|
|
2427
2446
|
}
|
|
2428
|
-
const typesPath =
|
|
2447
|
+
const typesPath = path6.join(projectDir, block.typesFile);
|
|
2429
2448
|
const source = await fsp4.readFile(typesPath, "utf8");
|
|
2430
2449
|
const targetInterface = getInterfaceDeclaration(source, block.attributeTypeName);
|
|
2431
2450
|
if (!targetInterface) {
|
|
@@ -2437,10 +2456,10 @@ async function ensureBindingTargetBlockAttributeType(projectDir, block, target)
|
|
|
2437
2456
|
await fsp4.writeFile(typesPath, nextSource, "utf8");
|
|
2438
2457
|
}
|
|
2439
2458
|
await syncBlockMetadata2({
|
|
2440
|
-
blockJsonFile:
|
|
2441
|
-
jsonSchemaFile:
|
|
2442
|
-
manifestFile:
|
|
2443
|
-
openApiFile:
|
|
2459
|
+
blockJsonFile: path6.join("src", "blocks", block.slug, "block.json"),
|
|
2460
|
+
jsonSchemaFile: path6.join("src", "blocks", block.slug, "typia.schema.json"),
|
|
2461
|
+
manifestFile: path6.join("src", "blocks", block.slug, "typia.manifest.json"),
|
|
2462
|
+
openApiFile: path6.join("src", "blocks", block.slug, "typia.openapi.json"),
|
|
2444
2463
|
projectRoot: projectDir,
|
|
2445
2464
|
sourceTypeName: block.attributeTypeName,
|
|
2446
2465
|
typesFile: block.typesFile
|
|
@@ -2679,7 +2698,7 @@ ${patternFunctions}
|
|
|
2679
2698
|
}
|
|
2680
2699
|
}
|
|
2681
2700
|
if (!nextSource.includes(patternCategoryFunctionName) || !nextSource.includes(patternRegistrationFunctionName)) {
|
|
2682
|
-
throw new Error(`Unable to inject pattern bootstrap functions into ${
|
|
2701
|
+
throw new Error(`Unable to inject pattern bootstrap functions into ${path6.basename(bootstrapPath)}.`);
|
|
2683
2702
|
}
|
|
2684
2703
|
if (!nextSource.includes(patternCategoryHook)) {
|
|
2685
2704
|
nextSource = `${nextSource.trimEnd()}
|
|
@@ -2867,7 +2886,7 @@ ${snippet}
|
|
|
2867
2886
|
if (missingReferences.length > 0) {
|
|
2868
2887
|
const replacedSource = replacePhpFunctionDefinition(nextSource, enqueueFunctionName, enqueueFunction);
|
|
2869
2888
|
if (!replacedSource) {
|
|
2870
|
-
throw new Error(`Unable to repair ${
|
|
2889
|
+
throw new Error(`Unable to repair ${path6.basename(bootstrapPath)} for ${enqueueFunctionName}.`);
|
|
2871
2890
|
}
|
|
2872
2891
|
nextSource = replacedSource;
|
|
2873
2892
|
}
|
|
@@ -2879,7 +2898,7 @@ ${snippet}
|
|
|
2879
2898
|
});
|
|
2880
2899
|
}
|
|
2881
2900
|
async function ensureEditorPluginBuildScriptAnchors(workspace) {
|
|
2882
|
-
const buildScriptPath =
|
|
2901
|
+
const buildScriptPath = path6.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
2883
2902
|
await patchFile(buildScriptPath, (source) => {
|
|
2884
2903
|
if (/['"]src\/editor-plugins\/index\.(?:ts|js)['"]/u.test(source)) {
|
|
2885
2904
|
return source;
|
|
@@ -2892,13 +2911,13 @@ async function ensureEditorPluginBuildScriptAnchors(workspace) {
|
|
|
2892
2911
|
'src/editor-plugins/index.js',
|
|
2893
2912
|
]`);
|
|
2894
2913
|
if (nextSource === source) {
|
|
2895
|
-
throw new Error(`Unable to update ${
|
|
2914
|
+
throw new Error(`Unable to update ${path6.relative(workspace.projectDir, buildScriptPath)} for editor plugin shared entries.`);
|
|
2896
2915
|
}
|
|
2897
2916
|
return nextSource;
|
|
2898
2917
|
});
|
|
2899
2918
|
}
|
|
2900
2919
|
async function ensureEditorPluginWebpackAnchors(workspace) {
|
|
2901
|
-
const webpackConfigPath =
|
|
2920
|
+
const webpackConfigPath = path6.join(workspace.projectDir, "webpack.config.js");
|
|
2902
2921
|
await patchFile(webpackConfigPath, (source) => {
|
|
2903
2922
|
if (/['"]editor-plugins\/index['"]/u.test(source)) {
|
|
2904
2923
|
return source;
|
|
@@ -2926,17 +2945,17 @@ async function ensureEditorPluginWebpackAnchors(workspace) {
|
|
|
2926
2945
|
}`;
|
|
2927
2946
|
const nextSource = source.replace(legacySharedEntriesBlockPattern, nextSharedEntriesBlock);
|
|
2928
2947
|
if (nextSource === source) {
|
|
2929
|
-
throw new Error(`Unable to update ${
|
|
2948
|
+
throw new Error(`Unable to update ${path6.relative(workspace.projectDir, webpackConfigPath)} for editor plugin shared entries.`);
|
|
2930
2949
|
}
|
|
2931
2950
|
return nextSource;
|
|
2932
2951
|
});
|
|
2933
2952
|
}
|
|
2934
2953
|
function resolveBindingSourceRegistryPath(projectDir) {
|
|
2935
|
-
const bindingsDir =
|
|
2936
|
-
return [
|
|
2954
|
+
const bindingsDir = path6.join(projectDir, "src", "bindings");
|
|
2955
|
+
return [path6.join(bindingsDir, "index.ts"), path6.join(bindingsDir, "index.js")].find((candidatePath) => fs4.existsSync(candidatePath)) ?? path6.join(bindingsDir, "index.ts");
|
|
2937
2956
|
}
|
|
2938
2957
|
async function writeBindingSourceRegistry(projectDir, bindingSourceSlug) {
|
|
2939
|
-
const bindingsDir =
|
|
2958
|
+
const bindingsDir = path6.join(projectDir, "src", "bindings");
|
|
2940
2959
|
const bindingsIndexPath = resolveBindingSourceRegistryPath(projectDir);
|
|
2941
2960
|
await fsp4.mkdir(bindingsDir, { recursive: true });
|
|
2942
2961
|
const existingBindingSourceSlugs = fs4.readdirSync(bindingsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
@@ -2944,11 +2963,11 @@ async function writeBindingSourceRegistry(projectDir, bindingSourceSlug) {
|
|
|
2944
2963
|
await fsp4.writeFile(bindingsIndexPath, buildBindingSourceIndexSource(nextBindingSourceSlugs), "utf8");
|
|
2945
2964
|
}
|
|
2946
2965
|
function resolveEditorPluginRegistryPath(projectDir) {
|
|
2947
|
-
const editorPluginsDir =
|
|
2966
|
+
const editorPluginsDir = path6.join(projectDir, "src", "editor-plugins");
|
|
2948
2967
|
return [
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
].find((candidatePath) => fs4.existsSync(candidatePath)) ??
|
|
2968
|
+
path6.join(editorPluginsDir, "index.ts"),
|
|
2969
|
+
path6.join(editorPluginsDir, "index.js")
|
|
2970
|
+
].find((candidatePath) => fs4.existsSync(candidatePath)) ?? path6.join(editorPluginsDir, "index.ts");
|
|
2952
2971
|
}
|
|
2953
2972
|
function readEditorPluginRegistrySlugs(registryPath) {
|
|
2954
2973
|
if (!fs4.existsSync(registryPath)) {
|
|
@@ -2958,7 +2977,7 @@ function readEditorPluginRegistrySlugs(registryPath) {
|
|
|
2958
2977
|
return Array.from(source.matchAll(/^\s*import\s+['"]\.\/([^/'"]+)(?:\/index(?:\.[cm]?[jt]sx?)?)?['"];?\s*$/gmu)).map((match) => match[1]);
|
|
2959
2978
|
}
|
|
2960
2979
|
async function writeEditorPluginRegistry(projectDir, editorPluginSlug) {
|
|
2961
|
-
const editorPluginsDir =
|
|
2980
|
+
const editorPluginsDir = path6.join(projectDir, "src", "editor-plugins");
|
|
2962
2981
|
const registryPath = resolveEditorPluginRegistryPath(projectDir);
|
|
2963
2982
|
await fsp4.mkdir(editorPluginsDir, { recursive: true });
|
|
2964
2983
|
const existingEditorPluginSlugs = readWorkspaceInventory(projectDir).editorPlugins.map((entry) => entry.slug);
|
|
@@ -2976,17 +2995,17 @@ async function runAddEditorPluginCommand({
|
|
|
2976
2995
|
const resolvedSlot = assertValidEditorPluginSlot(slot);
|
|
2977
2996
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
2978
2997
|
assertEditorPluginDoesNotExist(workspace.projectDir, editorPluginSlug, inventory);
|
|
2979
|
-
const blockConfigPath =
|
|
2998
|
+
const blockConfigPath = path6.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
2980
2999
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
2981
|
-
const buildScriptPath =
|
|
3000
|
+
const buildScriptPath = path6.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
2982
3001
|
const editorPluginsIndexPath = resolveEditorPluginRegistryPath(workspace.projectDir);
|
|
2983
|
-
const webpackConfigPath =
|
|
2984
|
-
const editorPluginDir =
|
|
2985
|
-
const entryFilePath =
|
|
2986
|
-
const surfaceFilePath =
|
|
2987
|
-
const dataFilePath =
|
|
2988
|
-
const typesFilePath =
|
|
2989
|
-
const styleFilePath =
|
|
3002
|
+
const webpackConfigPath = path6.join(workspace.projectDir, "webpack.config.js");
|
|
3003
|
+
const editorPluginDir = path6.join(workspace.projectDir, "src", "editor-plugins", editorPluginSlug);
|
|
3004
|
+
const entryFilePath = path6.join(editorPluginDir, "index.tsx");
|
|
3005
|
+
const surfaceFilePath = path6.join(editorPluginDir, "Surface.tsx");
|
|
3006
|
+
const dataFilePath = path6.join(editorPluginDir, "data.ts");
|
|
3007
|
+
const typesFilePath = path6.join(editorPluginDir, "types.ts");
|
|
3008
|
+
const styleFilePath = path6.join(editorPluginDir, "style.scss");
|
|
2990
3009
|
const mutationSnapshot = {
|
|
2991
3010
|
fileSources: await snapshotWorkspaceFiles([
|
|
2992
3011
|
blockConfigPath,
|
|
@@ -3032,16 +3051,16 @@ async function runAddPatternCommand({
|
|
|
3032
3051
|
const patternSlug = assertValidGeneratedSlug("Pattern name", normalizeBlockSlug(patternName), "wp-typia add pattern <name>");
|
|
3033
3052
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
3034
3053
|
assertPatternDoesNotExist(workspace.projectDir, patternSlug, inventory);
|
|
3035
|
-
const blockConfigPath =
|
|
3054
|
+
const blockConfigPath = path6.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
3036
3055
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
3037
|
-
const patternFilePath =
|
|
3056
|
+
const patternFilePath = path6.join(workspace.projectDir, "src", "patterns", `${patternSlug}.php`);
|
|
3038
3057
|
const mutationSnapshot = {
|
|
3039
3058
|
fileSources: await snapshotWorkspaceFiles([blockConfigPath, bootstrapPath]),
|
|
3040
3059
|
snapshotDirs: [],
|
|
3041
3060
|
targetPaths: [patternFilePath]
|
|
3042
3061
|
};
|
|
3043
3062
|
try {
|
|
3044
|
-
await fsp4.mkdir(
|
|
3063
|
+
await fsp4.mkdir(path6.dirname(patternFilePath), { recursive: true });
|
|
3045
3064
|
await ensurePatternBootstrapAnchors(workspace);
|
|
3046
3065
|
await fsp4.writeFile(patternFilePath, buildPatternSource(patternSlug, workspace.workspace.namespace, workspace.workspace.textDomain), "utf8");
|
|
3047
3066
|
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
@@ -3071,18 +3090,18 @@ async function runAddBindingSourceCommand({
|
|
|
3071
3090
|
blockName
|
|
3072
3091
|
}, workspace.workspace.namespace);
|
|
3073
3092
|
const targetBlock = target ? resolveWorkspaceBlock(inventory, target.blockSlug) : undefined;
|
|
3074
|
-
const blockConfigPath =
|
|
3093
|
+
const blockConfigPath = path6.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
3075
3094
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
3076
3095
|
const bindingsIndexPath = resolveBindingSourceRegistryPath(workspace.projectDir);
|
|
3077
|
-
const bindingSourceDir =
|
|
3078
|
-
const serverFilePath =
|
|
3079
|
-
const editorFilePath =
|
|
3080
|
-
const blockJsonPath = target ?
|
|
3096
|
+
const bindingSourceDir = path6.join(workspace.projectDir, "src", "bindings", bindingSourceSlug);
|
|
3097
|
+
const serverFilePath = path6.join(bindingSourceDir, "server.php");
|
|
3098
|
+
const editorFilePath = path6.join(bindingSourceDir, "editor.ts");
|
|
3099
|
+
const blockJsonPath = target ? path6.join(workspace.projectDir, "src", "blocks", target.blockSlug, "block.json") : undefined;
|
|
3081
3100
|
const targetGeneratedMetadataPaths = target ? [
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3101
|
+
path6.join(workspace.projectDir, "src", "blocks", target.blockSlug, "typia.manifest.json"),
|
|
3102
|
+
path6.join(workspace.projectDir, "src", "blocks", target.blockSlug, "typia.openapi.json"),
|
|
3103
|
+
path6.join(workspace.projectDir, "src", "blocks", target.blockSlug, "typia.schema.json"),
|
|
3104
|
+
path6.join(workspace.projectDir, "src", "blocks", target.blockSlug, "typia-validator.php")
|
|
3086
3105
|
] : [];
|
|
3087
3106
|
const mutationSnapshot = {
|
|
3088
3107
|
fileSources: await snapshotWorkspaceFiles([
|
|
@@ -3090,7 +3109,7 @@ async function runAddBindingSourceCommand({
|
|
|
3090
3109
|
bootstrapPath,
|
|
3091
3110
|
bindingsIndexPath,
|
|
3092
3111
|
...blockJsonPath ? [blockJsonPath] : [],
|
|
3093
|
-
...targetBlock ? [
|
|
3112
|
+
...targetBlock ? [path6.join(workspace.projectDir, targetBlock.typesFile)] : [],
|
|
3094
3113
|
...targetGeneratedMetadataPaths
|
|
3095
3114
|
]),
|
|
3096
3115
|
snapshotDirs: [],
|
|
@@ -3120,10 +3139,10 @@ async function runAddBindingSourceCommand({
|
|
|
3120
3139
|
}
|
|
3121
3140
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-rest.ts
|
|
3122
3141
|
import { promises as fsp5 } from "fs";
|
|
3123
|
-
import
|
|
3142
|
+
import path9 from "path";
|
|
3124
3143
|
|
|
3125
3144
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-rest-anchors.ts
|
|
3126
|
-
import
|
|
3145
|
+
import path7 from "path";
|
|
3127
3146
|
var REST_RESOURCE_SERVER_GLOB = "/inc/rest/*.php";
|
|
3128
3147
|
async function ensureRestResourceBootstrapAnchors(workspace) {
|
|
3129
3148
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
@@ -3171,7 +3190,7 @@ ${snippet}
|
|
|
3171
3190
|
insertPhpSnippet(registerFunction);
|
|
3172
3191
|
} else if (!nextSource.includes(REST_RESOURCE_SERVER_GLOB)) {
|
|
3173
3192
|
throw new Error([
|
|
3174
|
-
`Unable to patch ${
|
|
3193
|
+
`Unable to patch ${path7.basename(bootstrapPath)} in ensureRestResourceBootstrapAnchors.`,
|
|
3175
3194
|
`The existing ${registerFunctionName}() definition does not include ${REST_RESOURCE_SERVER_GLOB}.`,
|
|
3176
3195
|
"Restore the generated bootstrap shape or wire the REST resource loader manually before retrying."
|
|
3177
3196
|
].join(" "));
|
|
@@ -3185,7 +3204,7 @@ ${snippet}
|
|
|
3185
3204
|
function assertSyncRestAnchor(nextSource, target, anchorDescription, hasAnchor, syncRestScriptPath) {
|
|
3186
3205
|
if (!nextSource.includes(target) && !hasAnchor) {
|
|
3187
3206
|
throw new Error([
|
|
3188
|
-
`ensureRestResourceSyncScriptAnchors could not patch ${
|
|
3207
|
+
`ensureRestResourceSyncScriptAnchors could not patch ${path7.basename(syncRestScriptPath)}.`,
|
|
3189
3208
|
`Missing expected ${anchorDescription} anchor in scripts/sync-rest-contracts.ts.`,
|
|
3190
3209
|
"Restore the generated template or add the REST_RESOURCES wiring manually before retrying."
|
|
3191
3210
|
].join(" "));
|
|
@@ -3200,7 +3219,7 @@ function replaceRequiredSyncRestSource(nextSource, target, anchor, replacement,
|
|
|
3200
3219
|
return nextSource.replace(anchor, replacement);
|
|
3201
3220
|
}
|
|
3202
3221
|
async function ensureRestResourceSyncScriptAnchors(workspace) {
|
|
3203
|
-
const syncRestScriptPath =
|
|
3222
|
+
const syncRestScriptPath = path7.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
|
|
3204
3223
|
await patchFile(syncRestScriptPath, (source) => {
|
|
3205
3224
|
let nextSource = source;
|
|
3206
3225
|
const importAnchor = "import { BLOCKS, type WorkspaceBlockConfig } from './block-config';";
|
|
@@ -3318,7 +3337,7 @@ async function ensureRestResourceSyncScriptAnchors(workspace) {
|
|
|
3318
3337
|
}
|
|
3319
3338
|
|
|
3320
3339
|
// ../wp-typia-project-tools/src/runtime/rest-resource-artifacts.ts
|
|
3321
|
-
import
|
|
3340
|
+
import path8 from "path";
|
|
3322
3341
|
import {
|
|
3323
3342
|
defineEndpointManifest,
|
|
3324
3343
|
syncEndpointClient,
|
|
@@ -3454,8 +3473,8 @@ async function syncRestResourceArtifacts({
|
|
|
3454
3473
|
const manifest = buildRestResourceEndpointManifest(variables, methods);
|
|
3455
3474
|
for (const [baseName, contract] of Object.entries(manifest.contracts)) {
|
|
3456
3475
|
await syncTypeSchemas({
|
|
3457
|
-
jsonSchemaFile:
|
|
3458
|
-
openApiFile:
|
|
3476
|
+
jsonSchemaFile: path8.join(outputDir, "api-schemas", `${baseName}.schema.json`),
|
|
3477
|
+
openApiFile: path8.join(outputDir, "api-schemas", `${baseName}.openapi.json`),
|
|
3459
3478
|
projectRoot: projectDir,
|
|
3460
3479
|
sourceTypeName: contract.sourceTypeName,
|
|
3461
3480
|
typesFile
|
|
@@ -3463,7 +3482,7 @@ async function syncRestResourceArtifacts({
|
|
|
3463
3482
|
}
|
|
3464
3483
|
await syncRestOpenApi({
|
|
3465
3484
|
manifest,
|
|
3466
|
-
openApiFile:
|
|
3485
|
+
openApiFile: path8.join(outputDir, "api.openapi.json"),
|
|
3467
3486
|
projectRoot: projectDir,
|
|
3468
3487
|
typesFile
|
|
3469
3488
|
});
|
|
@@ -4288,15 +4307,15 @@ async function runAddRestResourceCommand({
|
|
|
4288
4307
|
const resolvedNamespace = resolveRestResourceNamespace(workspace.workspace.namespace, namespace);
|
|
4289
4308
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
4290
4309
|
assertRestResourceDoesNotExist(workspace.projectDir, restResourceSlug, inventory);
|
|
4291
|
-
const blockConfigPath =
|
|
4310
|
+
const blockConfigPath = path9.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
4292
4311
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
4293
|
-
const syncRestScriptPath =
|
|
4294
|
-
const restResourceDir =
|
|
4295
|
-
const typesFilePath =
|
|
4296
|
-
const validatorsFilePath =
|
|
4297
|
-
const apiFilePath =
|
|
4298
|
-
const dataFilePath =
|
|
4299
|
-
const phpFilePath =
|
|
4312
|
+
const syncRestScriptPath = path9.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
|
|
4313
|
+
const restResourceDir = path9.join(workspace.projectDir, "src", "rest", restResourceSlug);
|
|
4314
|
+
const typesFilePath = path9.join(restResourceDir, "api-types.ts");
|
|
4315
|
+
const validatorsFilePath = path9.join(restResourceDir, "api-validators.ts");
|
|
4316
|
+
const apiFilePath = path9.join(restResourceDir, "api.ts");
|
|
4317
|
+
const dataFilePath = path9.join(restResourceDir, "data.ts");
|
|
4318
|
+
const phpFilePath = path9.join(workspace.projectDir, "inc", "rest", `${restResourceSlug}.php`);
|
|
4300
4319
|
const mutationSnapshot = {
|
|
4301
4320
|
fileSources: await snapshotWorkspaceFiles([
|
|
4302
4321
|
blockConfigPath,
|
|
@@ -4308,7 +4327,7 @@ async function runAddRestResourceCommand({
|
|
|
4308
4327
|
};
|
|
4309
4328
|
try {
|
|
4310
4329
|
await fsp5.mkdir(restResourceDir, { recursive: true });
|
|
4311
|
-
await fsp5.mkdir(
|
|
4330
|
+
await fsp5.mkdir(path9.dirname(phpFilePath), { recursive: true });
|
|
4312
4331
|
await ensureRestResourceBootstrapAnchors(workspace);
|
|
4313
4332
|
await ensureRestResourceSyncScriptAnchors(workspace);
|
|
4314
4333
|
await fsp5.writeFile(typesFilePath, buildRestResourceTypesSource(restResourceSlug, resolvedMethods), "utf8");
|
|
@@ -4351,7 +4370,7 @@ async function runAddRestResourceCommand({
|
|
|
4351
4370
|
var import_semver = __toESM(require_semver(), 1);
|
|
4352
4371
|
import fs5 from "fs";
|
|
4353
4372
|
import { promises as fsp6 } from "fs";
|
|
4354
|
-
import
|
|
4373
|
+
import path10 from "path";
|
|
4355
4374
|
import { syncTypeSchemas as syncTypeSchemas2 } from "@wp-typia/block-runtime/metadata-core";
|
|
4356
4375
|
var ABILITY_SERVER_GLOB = "/inc/abilities/*.php";
|
|
4357
4376
|
var ABILITY_EDITOR_SCRIPT = "build/abilities/index.js";
|
|
@@ -4836,8 +4855,8 @@ function buildAbilityRegistrySource(abilitySlugs) {
|
|
|
4836
4855
|
`);
|
|
4837
4856
|
}
|
|
4838
4857
|
function resolveAbilityRegistryPath(projectDir) {
|
|
4839
|
-
const abilitiesDir =
|
|
4840
|
-
return [
|
|
4858
|
+
const abilitiesDir = path10.join(projectDir, "src", "abilities");
|
|
4859
|
+
return [path10.join(abilitiesDir, "index.ts"), path10.join(abilitiesDir, "index.js")].find((candidatePath) => fs5.existsSync(candidatePath)) ?? path10.join(abilitiesDir, "index.ts");
|
|
4841
4860
|
}
|
|
4842
4861
|
function readAbilityRegistrySlugs(registryPath) {
|
|
4843
4862
|
if (!fs5.existsSync(registryPath)) {
|
|
@@ -4847,7 +4866,7 @@ function readAbilityRegistrySlugs(registryPath) {
|
|
|
4847
4866
|
return Array.from(source.matchAll(/^\s*export\s+\*\s+from\s+['"]\.\/([^/'"]+)\/client['"];?\s*$/gmu)).map((match) => match[1]);
|
|
4848
4867
|
}
|
|
4849
4868
|
async function writeAbilityRegistry(projectDir, abilitySlug) {
|
|
4850
|
-
const abilitiesDir =
|
|
4869
|
+
const abilitiesDir = path10.join(projectDir, "src", "abilities");
|
|
4851
4870
|
const registryPath = resolveAbilityRegistryPath(projectDir);
|
|
4852
4871
|
await fsp6.mkdir(abilitiesDir, { recursive: true });
|
|
4853
4872
|
const existingAbilitySlugs = readWorkspaceInventory(projectDir).abilities.map((entry) => entry.slug);
|
|
@@ -4979,7 +4998,7 @@ ${snippet}
|
|
|
4979
4998
|
});
|
|
4980
4999
|
}
|
|
4981
5000
|
async function ensureAbilityPackageScripts(workspace) {
|
|
4982
|
-
const packageJsonPath =
|
|
5001
|
+
const packageJsonPath = path10.join(workspace.projectDir, "package.json");
|
|
4983
5002
|
const packageJson = JSON.parse(await fsp6.readFile(packageJsonPath, "utf8"));
|
|
4984
5003
|
const nextScripts = {
|
|
4985
5004
|
...packageJson.scripts ?? {},
|
|
@@ -4999,7 +5018,7 @@ async function ensureAbilityPackageScripts(workspace) {
|
|
|
4999
5018
|
`, "utf8");
|
|
5000
5019
|
}
|
|
5001
5020
|
async function ensureAbilitySyncProjectAnchors(workspace) {
|
|
5002
|
-
const syncProjectScriptPath =
|
|
5021
|
+
const syncProjectScriptPath = path10.join(workspace.projectDir, "scripts", "sync-project.ts");
|
|
5003
5022
|
await patchFile(syncProjectScriptPath, (source) => {
|
|
5004
5023
|
let nextSource = source;
|
|
5005
5024
|
const syncRestConst = "const syncRestScriptPath = path.join( 'scripts', 'sync-rest-contracts.ts' );";
|
|
@@ -5014,7 +5033,7 @@ async function ensureAbilitySyncProjectAnchors(workspace) {
|
|
|
5014
5033
|
if (!nextSource.includes(syncAbilitiesConst)) {
|
|
5015
5034
|
if (!nextSource.includes(syncRestConst)) {
|
|
5016
5035
|
throw new Error([
|
|
5017
|
-
`ensureAbilitySyncProjectAnchors could not patch ${
|
|
5036
|
+
`ensureAbilitySyncProjectAnchors could not patch ${path10.basename(syncProjectScriptPath)}.`,
|
|
5018
5037
|
"Missing the expected sync-rest script constant in scripts/sync-project.ts.",
|
|
5019
5038
|
"Restore the generated template or wire sync-abilities manually before retrying."
|
|
5020
5039
|
].join(" "));
|
|
@@ -5025,7 +5044,7 @@ ${syncAbilitiesConst}`);
|
|
|
5025
5044
|
if (!nextSource.includes("runSyncScript( syncAbilitiesScriptPath, options );")) {
|
|
5026
5045
|
if (!syncRestBlockPattern.test(nextSource)) {
|
|
5027
5046
|
throw new Error([
|
|
5028
|
-
`ensureAbilitySyncProjectAnchors could not patch ${
|
|
5047
|
+
`ensureAbilitySyncProjectAnchors could not patch ${path10.basename(syncProjectScriptPath)}.`,
|
|
5029
5048
|
"Missing the expected sync-rest invocation block in scripts/sync-project.ts.",
|
|
5030
5049
|
"Restore the generated template or wire sync-abilities manually before retrying."
|
|
5031
5050
|
].join(" "));
|
|
@@ -5038,7 +5057,7 @@ ${syncAbilitiesBlock}`);
|
|
|
5038
5057
|
});
|
|
5039
5058
|
}
|
|
5040
5059
|
async function ensureAbilityBuildScriptAnchors(workspace) {
|
|
5041
|
-
const buildScriptPath =
|
|
5060
|
+
const buildScriptPath = path10.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
5042
5061
|
await patchFile(buildScriptPath, (source) => {
|
|
5043
5062
|
let nextSource = source;
|
|
5044
5063
|
if (/['"]src\/abilities\/index\.(?:ts|js)['"]/u.test(nextSource)) {
|
|
@@ -5048,7 +5067,7 @@ async function ensureAbilityBuildScriptAnchors(workspace) {
|
|
|
5048
5067
|
const match = nextSource.match(sharedEntriesPattern);
|
|
5049
5068
|
if (!match || !match[2].includes("src/bindings/index.ts") || !match[2].includes("src/editor-plugins/index.ts")) {
|
|
5050
5069
|
throw new Error([
|
|
5051
|
-
`ensureAbilityBuildScriptAnchors could not patch ${
|
|
5070
|
+
`ensureAbilityBuildScriptAnchors could not patch ${path10.basename(buildScriptPath)}.`,
|
|
5052
5071
|
"Missing the expected shared editor entries array in scripts/build-workspace.mjs.",
|
|
5053
5072
|
"Restore the generated template or wire abilities/index manually before retrying."
|
|
5054
5073
|
].join(" "));
|
|
@@ -5065,7 +5084,7 @@ async function ensureAbilityBuildScriptAnchors(workspace) {
|
|
|
5065
5084
|
});
|
|
5066
5085
|
}
|
|
5067
5086
|
async function ensureAbilityWebpackAnchors(workspace) {
|
|
5068
|
-
const webpackConfigPath =
|
|
5087
|
+
const webpackConfigPath = path10.join(workspace.projectDir, "webpack.config.js");
|
|
5069
5088
|
await patchFile(webpackConfigPath, (source) => {
|
|
5070
5089
|
if (/['"]abilities\/index['"]/u.test(source)) {
|
|
5071
5090
|
return source;
|
|
@@ -5096,7 +5115,7 @@ $2`);
|
|
|
5096
5115
|
const match = source.match(sharedEntriesPattern);
|
|
5097
5116
|
if (!match || !match[1].includes("bindings/index") || !match[1].includes("editor-plugins/index")) {
|
|
5098
5117
|
throw new Error([
|
|
5099
|
-
`ensureAbilityWebpackAnchors could not patch ${
|
|
5118
|
+
`ensureAbilityWebpackAnchors could not patch ${path10.basename(webpackConfigPath)}.`,
|
|
5100
5119
|
"Missing the expected shared editor entries block in webpack.config.js.",
|
|
5101
5120
|
"Restore the generated template or wire abilities/index manually before retrying."
|
|
5102
5121
|
].join(" "));
|
|
@@ -5126,20 +5145,20 @@ async function runAddAbilityCommand({
|
|
|
5126
5145
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
5127
5146
|
assertAbilityDoesNotExist(workspace.projectDir, abilitySlug, inventory);
|
|
5128
5147
|
const compatibilityPolicy = resolveScaffoldCompatibilityPolicy(REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY);
|
|
5129
|
-
const blockConfigPath =
|
|
5148
|
+
const blockConfigPath = path10.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
5130
5149
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
5131
|
-
const buildScriptPath =
|
|
5132
|
-
const packageJsonPath =
|
|
5133
|
-
const syncAbilitiesScriptPath =
|
|
5134
|
-
const syncProjectScriptPath =
|
|
5135
|
-
const webpackConfigPath =
|
|
5150
|
+
const buildScriptPath = path10.join(workspace.projectDir, "scripts", "build-workspace.mjs");
|
|
5151
|
+
const packageJsonPath = path10.join(workspace.projectDir, "package.json");
|
|
5152
|
+
const syncAbilitiesScriptPath = path10.join(workspace.projectDir, "scripts", "sync-abilities.ts");
|
|
5153
|
+
const syncProjectScriptPath = path10.join(workspace.projectDir, "scripts", "sync-project.ts");
|
|
5154
|
+
const webpackConfigPath = path10.join(workspace.projectDir, "webpack.config.js");
|
|
5136
5155
|
const abilitiesIndexPath = resolveAbilityRegistryPath(workspace.projectDir);
|
|
5137
|
-
const abilityDir =
|
|
5138
|
-
const configFilePath =
|
|
5139
|
-
const typesFilePath =
|
|
5140
|
-
const dataFilePath =
|
|
5141
|
-
const clientFilePath =
|
|
5142
|
-
const phpFilePath =
|
|
5156
|
+
const abilityDir = path10.join(workspace.projectDir, "src", "abilities", abilitySlug);
|
|
5157
|
+
const configFilePath = path10.join(abilityDir, "ability.config.json");
|
|
5158
|
+
const typesFilePath = path10.join(abilityDir, "types.ts");
|
|
5159
|
+
const dataFilePath = path10.join(abilityDir, "data.ts");
|
|
5160
|
+
const clientFilePath = path10.join(abilityDir, "client.ts");
|
|
5161
|
+
const phpFilePath = path10.join(workspace.projectDir, "inc", "abilities", `${abilitySlug}.php`);
|
|
5143
5162
|
const mutationSnapshot = {
|
|
5144
5163
|
fileSources: await snapshotWorkspaceFiles([
|
|
5145
5164
|
blockConfigPath,
|
|
@@ -5156,7 +5175,7 @@ async function runAddAbilityCommand({
|
|
|
5156
5175
|
};
|
|
5157
5176
|
try {
|
|
5158
5177
|
await fsp6.mkdir(abilityDir, { recursive: true });
|
|
5159
|
-
await fsp6.mkdir(
|
|
5178
|
+
await fsp6.mkdir(path10.dirname(phpFilePath), { recursive: true });
|
|
5160
5179
|
await ensureAbilityBootstrapAnchors(workspace);
|
|
5161
5180
|
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
|
|
5162
5181
|
await ensureAbilityPackageScripts(workspace);
|
|
@@ -5197,11 +5216,11 @@ async function runAddAbilityCommand({
|
|
|
5197
5216
|
}
|
|
5198
5217
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-ai.ts
|
|
5199
5218
|
import { promises as fsp8 } from "fs";
|
|
5200
|
-
import
|
|
5219
|
+
import path13 from "path";
|
|
5201
5220
|
|
|
5202
5221
|
// ../wp-typia-project-tools/src/runtime/ai-feature-artifacts.ts
|
|
5203
5222
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
5204
|
-
import
|
|
5223
|
+
import path11 from "path";
|
|
5205
5224
|
import {
|
|
5206
5225
|
defineEndpointManifest as defineEndpointManifest2,
|
|
5207
5226
|
syncEndpointClient as syncEndpointClient2,
|
|
@@ -5227,7 +5246,7 @@ function normalizeGeneratedArtifactContent(content) {
|
|
|
5227
5246
|
}
|
|
5228
5247
|
async function reconcileGeneratedArtifact(options) {
|
|
5229
5248
|
if (!options.check) {
|
|
5230
|
-
await mkdir(
|
|
5249
|
+
await mkdir(path11.dirname(options.filePath), {
|
|
5231
5250
|
recursive: true
|
|
5232
5251
|
});
|
|
5233
5252
|
await writeFile(options.filePath, options.content, "utf8");
|
|
@@ -5299,8 +5318,8 @@ async function syncAiFeatureRestArtifacts({
|
|
|
5299
5318
|
const manifest = buildAiFeatureEndpointManifest(variables);
|
|
5300
5319
|
for (const [baseName, contract] of Object.entries(manifest.contracts)) {
|
|
5301
5320
|
await syncTypeSchemas3({
|
|
5302
|
-
jsonSchemaFile:
|
|
5303
|
-
openApiFile:
|
|
5321
|
+
jsonSchemaFile: path11.join(outputDir, "api-schemas", `${baseName}.schema.json`),
|
|
5322
|
+
openApiFile: path11.join(outputDir, "api-schemas", `${baseName}.openapi.json`),
|
|
5304
5323
|
projectRoot: projectDir,
|
|
5305
5324
|
sourceTypeName: contract.sourceTypeName,
|
|
5306
5325
|
typesFile
|
|
@@ -5308,7 +5327,7 @@ async function syncAiFeatureRestArtifacts({
|
|
|
5308
5327
|
}
|
|
5309
5328
|
await syncRestOpenApi2({
|
|
5310
5329
|
manifest,
|
|
5311
|
-
openApiFile:
|
|
5330
|
+
openApiFile: path11.join(outputDir, "api.openapi.json"),
|
|
5312
5331
|
projectRoot: projectDir,
|
|
5313
5332
|
typesFile
|
|
5314
5333
|
}, executionOptions);
|
|
@@ -5326,19 +5345,19 @@ async function syncAiFeatureSchemaArtifact({
|
|
|
5326
5345
|
outputDir,
|
|
5327
5346
|
projectDir
|
|
5328
5347
|
}) {
|
|
5329
|
-
const sourceSchemaPath =
|
|
5348
|
+
const sourceSchemaPath = path11.join(projectDir, outputDir, "api-schemas", "feature-result.schema.json");
|
|
5330
5349
|
const responseSchema = assertJsonObject(JSON.parse(await readFile(sourceSchemaPath, "utf8")), sourceSchemaPath);
|
|
5331
5350
|
const aiSchema = projectWordPressAiSchema(responseSchema);
|
|
5332
5351
|
await reconcileGeneratedArtifact({
|
|
5333
5352
|
check,
|
|
5334
5353
|
content: `${JSON.stringify(aiSchema, null, 2)}
|
|
5335
5354
|
`,
|
|
5336
|
-
filePath:
|
|
5355
|
+
filePath: path11.join(projectDir, aiSchemaFile),
|
|
5337
5356
|
label: "AI feature schema"
|
|
5338
5357
|
});
|
|
5339
5358
|
return {
|
|
5340
5359
|
aiSchema,
|
|
5341
|
-
aiSchemaPath:
|
|
5360
|
+
aiSchemaPath: path11.join(projectDir, aiSchemaFile),
|
|
5342
5361
|
check,
|
|
5343
5362
|
sourceSchemaPath
|
|
5344
5363
|
};
|
|
@@ -5662,7 +5681,7 @@ main().catch( ( error ) => {
|
|
|
5662
5681
|
|
|
5663
5682
|
// ../wp-typia-project-tools/src/runtime/cli-add-workspace-ai-anchors.ts
|
|
5664
5683
|
import { promises as fsp7 } from "fs";
|
|
5665
|
-
import
|
|
5684
|
+
import path12 from "path";
|
|
5666
5685
|
var AI_FEATURE_SERVER_GLOB = "/inc/ai-features/*.php";
|
|
5667
5686
|
async function ensureAiFeatureBootstrapAnchors(workspace) {
|
|
5668
5687
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
@@ -5710,7 +5729,7 @@ ${snippet}
|
|
|
5710
5729
|
insertPhpSnippet(registerFunction);
|
|
5711
5730
|
} else if (!nextSource.includes(AI_FEATURE_SERVER_GLOB)) {
|
|
5712
5731
|
throw new Error([
|
|
5713
|
-
`Unable to patch ${
|
|
5732
|
+
`Unable to patch ${path12.basename(bootstrapPath)} in ensureAiFeatureBootstrapAnchors.`,
|
|
5714
5733
|
`The existing ${registerFunctionName}() definition does not include ${AI_FEATURE_SERVER_GLOB}.`,
|
|
5715
5734
|
"Restore the generated bootstrap shape or wire the AI feature loader manually before retrying."
|
|
5716
5735
|
].join(" "));
|
|
@@ -5722,7 +5741,7 @@ ${snippet}
|
|
|
5722
5741
|
});
|
|
5723
5742
|
}
|
|
5724
5743
|
async function ensureAiFeaturePackageScripts(workspace) {
|
|
5725
|
-
const packageJsonPath =
|
|
5744
|
+
const packageJsonPath = path12.join(workspace.projectDir, "package.json");
|
|
5726
5745
|
const packageJson = JSON.parse(await fsp7.readFile(packageJsonPath, "utf8"));
|
|
5727
5746
|
const nextScripts = {
|
|
5728
5747
|
...packageJson.scripts ?? {},
|
|
@@ -5750,7 +5769,7 @@ async function ensureAiFeaturePackageScripts(workspace) {
|
|
|
5750
5769
|
};
|
|
5751
5770
|
}
|
|
5752
5771
|
async function ensureAiFeatureSyncProjectAnchors(workspace) {
|
|
5753
|
-
const syncProjectScriptPath =
|
|
5772
|
+
const syncProjectScriptPath = path12.join(workspace.projectDir, "scripts", "sync-project.ts");
|
|
5754
5773
|
await patchFile(syncProjectScriptPath, (source) => {
|
|
5755
5774
|
let nextSource = source;
|
|
5756
5775
|
const syncRestConst = "const syncRestScriptPath = path.join( 'scripts', 'sync-rest-contracts.ts' );";
|
|
@@ -5765,7 +5784,7 @@ async function ensureAiFeatureSyncProjectAnchors(workspace) {
|
|
|
5765
5784
|
if (!nextSource.includes(syncAiConst)) {
|
|
5766
5785
|
if (!nextSource.includes(syncRestConst)) {
|
|
5767
5786
|
throw new Error([
|
|
5768
|
-
`ensureAiFeatureSyncProjectAnchors could not patch ${
|
|
5787
|
+
`ensureAiFeatureSyncProjectAnchors could not patch ${path12.basename(syncProjectScriptPath)}.`,
|
|
5769
5788
|
"Missing the expected sync-rest script constant in scripts/sync-project.ts.",
|
|
5770
5789
|
"Restore the generated template or wire sync-ai manually before retrying."
|
|
5771
5790
|
].join(" "));
|
|
@@ -5776,7 +5795,7 @@ ${syncAiConst}`);
|
|
|
5776
5795
|
if (!nextSource.includes("runSyncScript( syncAiScriptPath, options );")) {
|
|
5777
5796
|
if (!syncRestBlockPattern.test(nextSource)) {
|
|
5778
5797
|
throw new Error([
|
|
5779
|
-
`ensureAiFeatureSyncProjectAnchors could not patch ${
|
|
5798
|
+
`ensureAiFeatureSyncProjectAnchors could not patch ${path12.basename(syncProjectScriptPath)}.`,
|
|
5780
5799
|
"Missing the expected sync-rest invocation block in scripts/sync-project.ts.",
|
|
5781
5800
|
"Restore the generated template or wire sync-ai manually before retrying."
|
|
5782
5801
|
].join(" "));
|
|
@@ -5791,7 +5810,7 @@ ${syncAiBlock}`);
|
|
|
5791
5810
|
function assertSyncRestAnchor2(nextSource, target, anchorDescription, hasAnchor, syncRestScriptPath) {
|
|
5792
5811
|
if (!nextSource.includes(target) && !hasAnchor) {
|
|
5793
5812
|
throw new Error([
|
|
5794
|
-
`ensureAiFeatureSyncRestAnchors could not patch ${
|
|
5813
|
+
`ensureAiFeatureSyncRestAnchors could not patch ${path12.basename(syncRestScriptPath)}.`,
|
|
5795
5814
|
`Missing expected ${anchorDescription} anchor in scripts/sync-rest-contracts.ts.`,
|
|
5796
5815
|
"Restore the generated template or add the AI feature wiring manually before retrying."
|
|
5797
5816
|
].join(" "));
|
|
@@ -5806,7 +5825,7 @@ function replaceRequiredSyncRestSource2(nextSource, target, anchor, replacement,
|
|
|
5806
5825
|
return nextSource.replace(anchor, replacement);
|
|
5807
5826
|
}
|
|
5808
5827
|
async function ensureAiFeatureSyncRestAnchors(workspace) {
|
|
5809
|
-
const syncRestScriptPath =
|
|
5828
|
+
const syncRestScriptPath = path12.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
|
|
5810
5829
|
await patchFile(syncRestScriptPath, (source) => {
|
|
5811
5830
|
let nextSource = source;
|
|
5812
5831
|
const importAnchor = [
|
|
@@ -6323,18 +6342,18 @@ async function runAddAiFeatureCommand({
|
|
|
6323
6342
|
const compatibilityPolicy = resolveScaffoldCompatibilityPolicy(OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY);
|
|
6324
6343
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
6325
6344
|
assertAiFeatureDoesNotExist(workspace.projectDir, aiFeatureSlug, inventory);
|
|
6326
|
-
const blockConfigPath =
|
|
6345
|
+
const blockConfigPath = path13.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
6327
6346
|
const bootstrapPath = getWorkspaceBootstrapPath(workspace);
|
|
6328
|
-
const packageJsonPath =
|
|
6329
|
-
const syncAiScriptPath =
|
|
6330
|
-
const syncProjectScriptPath =
|
|
6331
|
-
const syncRestScriptPath =
|
|
6332
|
-
const aiFeatureDir =
|
|
6333
|
-
const typesFilePath =
|
|
6334
|
-
const validatorsFilePath =
|
|
6335
|
-
const apiFilePath =
|
|
6336
|
-
const dataFilePath =
|
|
6337
|
-
const phpFilePath =
|
|
6347
|
+
const packageJsonPath = path13.join(workspace.projectDir, "package.json");
|
|
6348
|
+
const syncAiScriptPath = path13.join(workspace.projectDir, "scripts", "sync-ai-features.ts");
|
|
6349
|
+
const syncProjectScriptPath = path13.join(workspace.projectDir, "scripts", "sync-project.ts");
|
|
6350
|
+
const syncRestScriptPath = path13.join(workspace.projectDir, "scripts", "sync-rest-contracts.ts");
|
|
6351
|
+
const aiFeatureDir = path13.join(workspace.projectDir, "src", "ai-features", aiFeatureSlug);
|
|
6352
|
+
const typesFilePath = path13.join(aiFeatureDir, "api-types.ts");
|
|
6353
|
+
const validatorsFilePath = path13.join(aiFeatureDir, "api-validators.ts");
|
|
6354
|
+
const apiFilePath = path13.join(aiFeatureDir, "api.ts");
|
|
6355
|
+
const dataFilePath = path13.join(aiFeatureDir, "data.ts");
|
|
6356
|
+
const phpFilePath = path13.join(workspace.projectDir, "inc", "ai-features", `${aiFeatureSlug}.php`);
|
|
6338
6357
|
const mutationSnapshot = {
|
|
6339
6358
|
fileSources: await snapshotWorkspaceFiles([
|
|
6340
6359
|
blockConfigPath,
|
|
@@ -6349,7 +6368,7 @@ async function runAddAiFeatureCommand({
|
|
|
6349
6368
|
};
|
|
6350
6369
|
try {
|
|
6351
6370
|
await fsp8.mkdir(aiFeatureDir, { recursive: true });
|
|
6352
|
-
await fsp8.mkdir(
|
|
6371
|
+
await fsp8.mkdir(path13.dirname(phpFilePath), { recursive: true });
|
|
6353
6372
|
await ensureAiFeatureBootstrapAnchors(workspace);
|
|
6354
6373
|
await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
|
|
6355
6374
|
const packageScriptChanges = await ensureAiFeaturePackageScripts(workspace);
|
|
@@ -6364,7 +6383,7 @@ async function runAddAiFeatureCommand({
|
|
|
6364
6383
|
const pascalCase = toPascalCase(aiFeatureSlug);
|
|
6365
6384
|
await syncAiFeatureRestArtifacts({
|
|
6366
6385
|
clientFile: `src/ai-features/${aiFeatureSlug}/api-client.ts`,
|
|
6367
|
-
outputDir:
|
|
6386
|
+
outputDir: path13.join("src", "ai-features", aiFeatureSlug),
|
|
6368
6387
|
projectDir: workspace.projectDir,
|
|
6369
6388
|
typesFile: `src/ai-features/${aiFeatureSlug}/api-types.ts`,
|
|
6370
6389
|
validatorsFile: `src/ai-features/${aiFeatureSlug}/api-validators.ts`,
|
|
@@ -6377,7 +6396,7 @@ async function runAddAiFeatureCommand({
|
|
|
6377
6396
|
});
|
|
6378
6397
|
await syncAiFeatureSchemaArtifact({
|
|
6379
6398
|
aiSchemaFile: `src/ai-features/${aiFeatureSlug}/ai-schemas/feature-result.ai.schema.json`,
|
|
6380
|
-
outputDir:
|
|
6399
|
+
outputDir: path13.join("src", "ai-features", aiFeatureSlug),
|
|
6381
6400
|
projectDir: workspace.projectDir
|
|
6382
6401
|
});
|
|
6383
6402
|
await appendWorkspaceInventoryEntries(workspace.projectDir, {
|
|
@@ -6798,7 +6817,7 @@ ${VARIATIONS_CALL_LINE}
|
|
|
6798
6817
|
}
|
|
6799
6818
|
}
|
|
6800
6819
|
if (!hasExecutablePattern(nextSource, VARIATIONS_CALL_PATTERN)) {
|
|
6801
|
-
throw new Error(`Unable to inject ${VARIATIONS_CALL_LINE} into ${
|
|
6820
|
+
throw new Error(`Unable to inject ${VARIATIONS_CALL_LINE} into ${path14.basename(blockIndexPath)}.`);
|
|
6802
6821
|
}
|
|
6803
6822
|
return nextSource;
|
|
6804
6823
|
});
|
|
@@ -6828,7 +6847,7 @@ ${BLOCK_STYLES_CALL_LINE}
|
|
|
6828
6847
|
}
|
|
6829
6848
|
}
|
|
6830
6849
|
if (!hasExecutablePattern(nextSource, BLOCK_STYLES_CALL_PATTERN)) {
|
|
6831
|
-
throw new Error(`Unable to inject ${BLOCK_STYLES_CALL_LINE} into ${
|
|
6850
|
+
throw new Error(`Unable to inject ${BLOCK_STYLES_CALL_LINE} into ${path14.basename(blockIndexPath)}.`);
|
|
6832
6851
|
}
|
|
6833
6852
|
return nextSource;
|
|
6834
6853
|
});
|
|
@@ -6845,7 +6864,7 @@ ${nextSource}`;
|
|
|
6845
6864
|
SCAFFOLD_REGISTRATION_SETTINGS_CALL_PATTERN
|
|
6846
6865
|
]);
|
|
6847
6866
|
if (!callRange) {
|
|
6848
|
-
throw new Error(`Unable to inject ${BLOCK_TRANSFORMS_CALL_LINE} into ${
|
|
6867
|
+
throw new Error(`Unable to inject ${BLOCK_TRANSFORMS_CALL_LINE} into ${path14.basename(blockIndexPath)} because it does not expose a scaffold registration settings object.`);
|
|
6849
6868
|
}
|
|
6850
6869
|
nextSource = [
|
|
6851
6870
|
nextSource.slice(0, callRange.start),
|
|
@@ -6858,42 +6877,42 @@ ${nextSource}`;
|
|
|
6858
6877
|
});
|
|
6859
6878
|
}
|
|
6860
6879
|
async function writeVariationRegistry(projectDir, blockSlug, variationSlug) {
|
|
6861
|
-
const variationsDir =
|
|
6862
|
-
const variationsIndexPath =
|
|
6880
|
+
const variationsDir = path14.join(projectDir, "src", "blocks", blockSlug, "variations");
|
|
6881
|
+
const variationsIndexPath = path14.join(variationsDir, "index.ts");
|
|
6863
6882
|
await fsp9.mkdir(variationsDir, { recursive: true });
|
|
6864
6883
|
const existingVariationSlugs = fs6.readdirSync(variationsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
|
|
6865
6884
|
const nextVariationSlugs = Array.from(new Set([...existingVariationSlugs, variationSlug])).sort();
|
|
6866
6885
|
await fsp9.writeFile(variationsIndexPath, buildVariationIndexSource(nextVariationSlugs), "utf8");
|
|
6867
6886
|
}
|
|
6868
6887
|
async function writeBlockStyleRegistry(projectDir, blockSlug, styleSlug) {
|
|
6869
|
-
const stylesDir =
|
|
6870
|
-
const stylesIndexPath =
|
|
6888
|
+
const stylesDir = path14.join(projectDir, "src", "blocks", blockSlug, "styles");
|
|
6889
|
+
const stylesIndexPath = path14.join(stylesDir, "index.ts");
|
|
6871
6890
|
await fsp9.mkdir(stylesDir, { recursive: true });
|
|
6872
6891
|
const existingStyleSlugs = fs6.readdirSync(stylesDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
|
|
6873
6892
|
const nextStyleSlugs = Array.from(new Set([...existingStyleSlugs, styleSlug])).sort();
|
|
6874
6893
|
await fsp9.writeFile(stylesIndexPath, buildBlockStyleIndexSource(nextStyleSlugs), "utf8");
|
|
6875
6894
|
}
|
|
6876
6895
|
async function writeBlockTransformRegistry(projectDir, blockSlug, transformSlug) {
|
|
6877
|
-
const transformsDir =
|
|
6878
|
-
const transformsIndexPath =
|
|
6896
|
+
const transformsDir = path14.join(projectDir, "src", "blocks", blockSlug, "transforms");
|
|
6897
|
+
const transformsIndexPath = path14.join(transformsDir, "index.ts");
|
|
6879
6898
|
await fsp9.mkdir(transformsDir, { recursive: true });
|
|
6880
6899
|
const existingTransformSlugs = fs6.readdirSync(transformsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
|
|
6881
6900
|
const nextTransformSlugs = Array.from(new Set([...existingTransformSlugs, transformSlug])).sort();
|
|
6882
6901
|
await fsp9.writeFile(transformsIndexPath, buildBlockTransformIndexSource(nextTransformSlugs), "utf8");
|
|
6883
6902
|
}
|
|
6884
6903
|
function assertBlockStyleDoesNotExist(projectDir, blockSlug, styleSlug, inventory) {
|
|
6885
|
-
const stylePath =
|
|
6904
|
+
const stylePath = path14.join(projectDir, "src", "blocks", blockSlug, "styles", `${styleSlug}.ts`);
|
|
6886
6905
|
if (fs6.existsSync(stylePath)) {
|
|
6887
|
-
throw new Error(`A block style already exists at ${
|
|
6906
|
+
throw new Error(`A block style already exists at ${path14.relative(projectDir, stylePath)}. Choose a different name.`);
|
|
6888
6907
|
}
|
|
6889
6908
|
if (inventory.blockStyles.some((entry) => entry.block === blockSlug && entry.slug === styleSlug)) {
|
|
6890
6909
|
throw new Error(`A block style inventory entry already exists for ${blockSlug}/${styleSlug}. Choose a different name.`);
|
|
6891
6910
|
}
|
|
6892
6911
|
}
|
|
6893
6912
|
function assertBlockTransformDoesNotExist(projectDir, blockSlug, transformSlug, inventory) {
|
|
6894
|
-
const transformPath =
|
|
6913
|
+
const transformPath = path14.join(projectDir, "src", "blocks", blockSlug, "transforms", `${transformSlug}.ts`);
|
|
6895
6914
|
if (fs6.existsSync(transformPath)) {
|
|
6896
|
-
throw new Error(`A block transform already exists at ${
|
|
6915
|
+
throw new Error(`A block transform already exists at ${path14.relative(projectDir, transformPath)}. Choose a different name.`);
|
|
6897
6916
|
}
|
|
6898
6917
|
if (inventory.blockTransforms.some((entry) => entry.block === blockSlug && entry.slug === transformSlug)) {
|
|
6899
6918
|
throw new Error(`A block transform inventory entry already exists for ${blockSlug}/${transformSlug}. Choose a different name.`);
|
|
@@ -6939,11 +6958,11 @@ async function runAddVariationCommand({
|
|
|
6939
6958
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
6940
6959
|
resolveWorkspaceBlock(inventory, blockSlug);
|
|
6941
6960
|
assertVariationDoesNotExist(workspace.projectDir, blockSlug, variationSlug, inventory);
|
|
6942
|
-
const blockConfigPath =
|
|
6943
|
-
const blockIndexPath =
|
|
6944
|
-
const variationsDir =
|
|
6945
|
-
const variationFilePath =
|
|
6946
|
-
const variationsIndexPath =
|
|
6961
|
+
const blockConfigPath = path14.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
6962
|
+
const blockIndexPath = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "index.tsx");
|
|
6963
|
+
const variationsDir = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "variations");
|
|
6964
|
+
const variationFilePath = path14.join(variationsDir, `${variationSlug}.ts`);
|
|
6965
|
+
const variationsIndexPath = path14.join(variationsDir, "index.ts");
|
|
6947
6966
|
const shouldRemoveVariationsDirOnRollback = !fs6.existsSync(variationsDir);
|
|
6948
6967
|
const mutationSnapshot = {
|
|
6949
6968
|
fileSources: await snapshotWorkspaceFiles([
|
|
@@ -6986,11 +7005,11 @@ async function runAddBlockStyleCommand({
|
|
|
6986
7005
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
6987
7006
|
resolveWorkspaceBlock(inventory, blockSlug);
|
|
6988
7007
|
assertBlockStyleDoesNotExist(workspace.projectDir, blockSlug, styleSlug, inventory);
|
|
6989
|
-
const blockConfigPath =
|
|
6990
|
-
const blockIndexPath =
|
|
6991
|
-
const stylesDir =
|
|
6992
|
-
const styleFilePath =
|
|
6993
|
-
const stylesIndexPath =
|
|
7008
|
+
const blockConfigPath = path14.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
7009
|
+
const blockIndexPath = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "index.tsx");
|
|
7010
|
+
const stylesDir = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "styles");
|
|
7011
|
+
const styleFilePath = path14.join(stylesDir, `${styleSlug}.ts`);
|
|
7012
|
+
const stylesIndexPath = path14.join(stylesDir, "index.ts");
|
|
6994
7013
|
const shouldRemoveStylesDirOnRollback = !fs6.existsSync(stylesDir);
|
|
6995
7014
|
const mutationSnapshot = {
|
|
6996
7015
|
fileSources: await snapshotWorkspaceFiles([
|
|
@@ -7035,11 +7054,11 @@ async function runAddBlockTransformCommand({
|
|
|
7035
7054
|
const inventory = readWorkspaceInventory(workspace.projectDir);
|
|
7036
7055
|
resolveWorkspaceBlock(inventory, target.blockSlug);
|
|
7037
7056
|
assertBlockTransformDoesNotExist(workspace.projectDir, target.blockSlug, transformSlug, inventory);
|
|
7038
|
-
const blockConfigPath =
|
|
7039
|
-
const blockIndexPath =
|
|
7040
|
-
const transformsDir =
|
|
7041
|
-
const transformFilePath =
|
|
7042
|
-
const transformsIndexPath =
|
|
7057
|
+
const blockConfigPath = path14.join(workspace.projectDir, "scripts", "block-config.ts");
|
|
7058
|
+
const blockIndexPath = path14.join(workspace.projectDir, "src", "blocks", target.blockSlug, "index.tsx");
|
|
7059
|
+
const transformsDir = path14.join(workspace.projectDir, "src", "blocks", target.blockSlug, "transforms");
|
|
7060
|
+
const transformFilePath = path14.join(transformsDir, `${transformSlug}.ts`);
|
|
7061
|
+
const transformsIndexPath = path14.join(transformsDir, "index.ts");
|
|
7043
7062
|
const shouldRemoveTransformsDirOnRollback = !fs6.existsSync(transformsDir);
|
|
7044
7063
|
const mutationSnapshot = {
|
|
7045
7064
|
fileSources: await snapshotWorkspaceFiles([
|
|
@@ -7101,7 +7120,7 @@ async function runAddHookedBlockCommand({
|
|
|
7101
7120
|
throw new Error("`wp-typia add hooked-block` cannot hook a block relative to its own block name.");
|
|
7102
7121
|
}
|
|
7103
7122
|
const { blockJson, blockJsonPath } = readWorkspaceBlockJson(workspace.projectDir, blockSlug);
|
|
7104
|
-
const blockJsonRelativePath =
|
|
7123
|
+
const blockJsonRelativePath = path14.relative(workspace.projectDir, blockJsonPath);
|
|
7105
7124
|
const blockHooks = getMutableBlockHooks(blockJson, blockJsonRelativePath);
|
|
7106
7125
|
if (Object.prototype.hasOwnProperty.call(blockHooks, resolvedAnchorBlockName)) {
|
|
7107
7126
|
throw new Error(`${blockJsonRelativePath} already defines a blockHooks entry for "${resolvedAnchorBlockName}".`);
|
|
@@ -7146,4 +7165,4 @@ export {
|
|
|
7146
7165
|
ADD_BLOCK_TEMPLATE_IDS
|
|
7147
7166
|
};
|
|
7148
7167
|
|
|
7149
|
-
//# debugId=
|
|
7168
|
+
//# debugId=DE205F0F5620636264756E2164756E21
|