@wp-typia/project-tools 0.16.11 → 0.16.12

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.
Files changed (101) hide show
  1. package/README.md +9 -3
  2. package/dist/runtime/built-in-block-artifact-documents.d.ts +3 -0
  3. package/dist/runtime/built-in-block-artifact-documents.js +2 -0
  4. package/dist/runtime/built-in-block-artifact-types.d.ts +51 -0
  5. package/dist/runtime/built-in-block-artifact-types.js +304 -0
  6. package/dist/runtime/built-in-block-artifacts.js +4 -803
  7. package/dist/runtime/built-in-block-attribute-emitters.d.ts +71 -0
  8. package/dist/runtime/built-in-block-attribute-emitters.js +176 -0
  9. package/dist/runtime/built-in-block-attribute-specs.d.ts +38 -0
  10. package/dist/runtime/built-in-block-attribute-specs.js +358 -0
  11. package/dist/runtime/built-in-block-code-templates/basic.d.ts +4 -0
  12. package/dist/runtime/built-in-block-code-templates/basic.js +249 -0
  13. package/dist/runtime/built-in-block-code-templates/compound-child.d.ts +4 -0
  14. package/dist/runtime/built-in-block-code-templates/compound-child.js +138 -0
  15. package/dist/runtime/built-in-block-code-templates/compound-parent.d.ts +6 -0
  16. package/dist/runtime/built-in-block-code-templates/compound-parent.js +227 -0
  17. package/dist/runtime/built-in-block-code-templates/compound-persistence.d.ts +4 -0
  18. package/dist/runtime/built-in-block-code-templates/compound-persistence.js +478 -0
  19. package/dist/runtime/built-in-block-code-templates/compound.d.ts +3 -0
  20. package/dist/runtime/built-in-block-code-templates/compound.js +3 -0
  21. package/dist/runtime/built-in-block-code-templates/interactivity.d.ts +5 -0
  22. package/dist/runtime/built-in-block-code-templates/interactivity.js +547 -0
  23. package/dist/runtime/built-in-block-code-templates/persistence.d.ts +5 -0
  24. package/dist/runtime/built-in-block-code-templates/persistence.js +550 -0
  25. package/dist/runtime/built-in-block-code-templates/shared.d.ts +16 -0
  26. package/dist/runtime/built-in-block-code-templates/shared.js +53 -0
  27. package/dist/runtime/built-in-block-code-templates.d.ts +5 -32
  28. package/dist/runtime/built-in-block-code-templates.js +5 -2230
  29. package/dist/runtime/cli-add-block-config.d.ts +6 -0
  30. package/dist/runtime/cli-add-block-config.js +143 -0
  31. package/dist/runtime/cli-add-block-legacy-validator.d.ts +4 -0
  32. package/dist/runtime/cli-add-block-legacy-validator.js +168 -0
  33. package/dist/runtime/cli-add-block.js +3 -301
  34. package/dist/runtime/cli-add-workspace-assets.d.ts +38 -0
  35. package/dist/runtime/cli-add-workspace-assets.js +399 -0
  36. package/dist/runtime/cli-add-workspace.d.ts +2 -38
  37. package/dist/runtime/cli-add-workspace.js +5 -396
  38. package/dist/runtime/cli-doctor-environment.d.ts +12 -0
  39. package/dist/runtime/cli-doctor-environment.js +123 -0
  40. package/dist/runtime/cli-doctor-workspace.d.ts +14 -0
  41. package/dist/runtime/cli-doctor-workspace.js +296 -0
  42. package/dist/runtime/cli-doctor.d.ts +4 -2
  43. package/dist/runtime/cli-doctor.js +10 -405
  44. package/dist/runtime/migration-command-surface.d.ts +67 -0
  45. package/dist/runtime/migration-command-surface.js +189 -0
  46. package/dist/runtime/migration-diff-rename.d.ts +13 -0
  47. package/dist/runtime/migration-diff-rename.js +192 -0
  48. package/dist/runtime/migration-diff-transform.d.ts +14 -0
  49. package/dist/runtime/migration-diff-transform.js +105 -0
  50. package/dist/runtime/migration-diff.js +12 -297
  51. package/dist/runtime/migration-generated-artifacts.d.ts +3 -0
  52. package/dist/runtime/migration-generated-artifacts.js +41 -0
  53. package/dist/runtime/migration-maintenance.d.ts +51 -0
  54. package/dist/runtime/migration-maintenance.js +380 -0
  55. package/dist/runtime/migration-planning.d.ts +23 -0
  56. package/dist/runtime/migration-planning.js +131 -0
  57. package/dist/runtime/migration-project-config-source.d.ts +6 -0
  58. package/dist/runtime/migration-project-config-source.js +424 -0
  59. package/dist/runtime/migration-project-layout-discovery.d.ts +61 -0
  60. package/dist/runtime/migration-project-layout-discovery.js +337 -0
  61. package/dist/runtime/migration-project-layout-paths.d.ts +135 -0
  62. package/dist/runtime/migration-project-layout-paths.js +288 -0
  63. package/dist/runtime/migration-project-layout.d.ts +3 -0
  64. package/dist/runtime/migration-project-layout.js +2 -0
  65. package/dist/runtime/migration-project-workspace.d.ts +47 -0
  66. package/dist/runtime/migration-project-workspace.js +212 -0
  67. package/dist/runtime/migration-project.d.ts +4 -94
  68. package/dist/runtime/migration-project.js +3 -1101
  69. package/dist/runtime/migration-render-diff-rule.d.ts +5 -0
  70. package/dist/runtime/migration-render-diff-rule.js +120 -0
  71. package/dist/runtime/migration-render-execution.d.ts +3 -0
  72. package/dist/runtime/migration-render-execution.js +428 -0
  73. package/dist/runtime/migration-render-generated.d.ts +27 -0
  74. package/dist/runtime/migration-render-generated.js +230 -0
  75. package/dist/runtime/migration-render-support.d.ts +3 -0
  76. package/dist/runtime/migration-render-support.js +16 -0
  77. package/dist/runtime/migration-render.d.ts +3 -33
  78. package/dist/runtime/migration-render.js +3 -789
  79. package/dist/runtime/migrations.d.ts +24 -118
  80. package/dist/runtime/migrations.js +12 -700
  81. package/dist/runtime/scaffold-bootstrap.d.ts +45 -0
  82. package/dist/runtime/scaffold-bootstrap.js +185 -0
  83. package/dist/runtime/scaffold-package-manager-files.d.ts +35 -0
  84. package/dist/runtime/scaffold-package-manager-files.js +79 -0
  85. package/dist/runtime/scaffold.d.ts +1 -12
  86. package/dist/runtime/scaffold.js +10 -393
  87. package/dist/runtime/template-source-contracts.d.ts +81 -0
  88. package/dist/runtime/template-source-contracts.js +1 -0
  89. package/dist/runtime/template-source-external.d.ts +21 -0
  90. package/dist/runtime/template-source-external.js +184 -0
  91. package/dist/runtime/template-source-locators.d.ts +4 -0
  92. package/dist/runtime/template-source-locators.js +72 -0
  93. package/dist/runtime/template-source-normalization.d.ts +7 -0
  94. package/dist/runtime/template-source-normalization.js +53 -0
  95. package/dist/runtime/template-source-remote.d.ts +23 -0
  96. package/dist/runtime/template-source-remote.js +336 -0
  97. package/dist/runtime/template-source-seeds.d.ts +12 -0
  98. package/dist/runtime/template-source-seeds.js +243 -0
  99. package/dist/runtime/template-source.d.ts +4 -86
  100. package/dist/runtime/template-source.js +9 -828
  101. package/package.json +4 -4
@@ -0,0 +1,12 @@
1
+ import type { RemoteTemplateLocator, SeedSource } from './template-source-contracts.js';
2
+ export declare function isOfficialWorkspaceTemplateSeed(seed: SeedSource): boolean;
3
+ export declare function assertNoSymlinks(sourceDir: string): Promise<void>;
4
+ /**
5
+ * Resolves a template locator into a local seed source directory.
6
+ *
7
+ * @param locator Remote template locator describing a local path, GitHub source, or npm package.
8
+ * @param cwd Current working directory used to resolve local template paths.
9
+ * @returns A local seed source containing the resolved root and block directory, plus optional cleanup.
10
+ * @throws When the locator is invalid, the source cannot be fetched, or filesystem validation fails.
11
+ */
12
+ export declare function resolveTemplateSeed(locator: RemoteTemplateLocator, cwd: string): Promise<SeedSource>;
@@ -0,0 +1,243 @@
1
+ import fs from 'node:fs';
2
+ import { promises as fsp } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { execFileSync } from 'node:child_process';
7
+ import semver from 'semver';
8
+ import { x as extractTarball } from 'tar';
9
+ import { OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE, PROJECT_TOOLS_PACKAGE_ROOT, } from './template-registry.js';
10
+ import { isPlainObject } from './object-utils.js';
11
+ function selectRegistryVersion(metadata, locator) {
12
+ const distTags = isPlainObject(metadata['dist-tags'])
13
+ ? metadata['dist-tags']
14
+ : {};
15
+ const versions = isPlainObject(metadata.versions) ? metadata.versions : {};
16
+ const versionKeys = Object.keys(versions);
17
+ if (locator.type === 'version') {
18
+ if (!versions[locator.fetchSpec]) {
19
+ throw new Error(`npm template package version not found: ${locator.raw}`);
20
+ }
21
+ return locator.fetchSpec;
22
+ }
23
+ if (locator.type === 'tag') {
24
+ const taggedVersion = distTags[locator.fetchSpec];
25
+ if (typeof taggedVersion !== 'string') {
26
+ throw new Error(`npm template package tag not found: ${locator.raw}`);
27
+ }
28
+ return taggedVersion;
29
+ }
30
+ const range = locator.fetchSpec.trim().length > 0 ? locator.fetchSpec : '*';
31
+ const matchedVersion = semver.maxSatisfying(versionKeys, range);
32
+ if (matchedVersion) {
33
+ return matchedVersion;
34
+ }
35
+ if (locator.fetchSpec.trim().length > 0) {
36
+ throw new Error(`Unable to resolve npm template version for ${locator.raw}. Requested "${locator.fetchSpec}" but available versions are: ${versionKeys.join(', ') || '(none)'}.`);
37
+ }
38
+ const latestVersion = distTags.latest;
39
+ if (typeof latestVersion === 'string' && versions[latestVersion]) {
40
+ return latestVersion;
41
+ }
42
+ throw new Error(`Unable to resolve a published npm template version for ${locator.raw}.`);
43
+ }
44
+ async function fetchNpmTemplateSource(locator) {
45
+ const registryBase = (process.env.NPM_CONFIG_REGISTRY ?? 'https://registry.npmjs.org').replace(/\/$/, '');
46
+ const metadataResponse = await fetch(`${registryBase}/${encodeURIComponent(locator.name)}`);
47
+ if (!metadataResponse.ok) {
48
+ throw new Error(`Failed to fetch npm template metadata for ${locator.raw}: ${metadataResponse.status}`);
49
+ }
50
+ const metadata = (await metadataResponse.json());
51
+ const resolvedVersion = selectRegistryVersion(metadata, locator);
52
+ const versions = isPlainObject(metadata.versions) ? metadata.versions : {};
53
+ const versionMetadata = versions[resolvedVersion];
54
+ if (!isPlainObject(versionMetadata) || !isPlainObject(versionMetadata.dist)) {
55
+ throw new Error(`npm template metadata is missing dist information for ${locator.raw}@${resolvedVersion}.`);
56
+ }
57
+ const tarballUrl = versionMetadata.dist.tarball;
58
+ if (typeof tarballUrl !== 'string' || tarballUrl.length === 0) {
59
+ throw new Error(`npm template metadata is missing tarball URL for ${locator.raw}@${resolvedVersion}.`);
60
+ }
61
+ const tempRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'wp-typia-template-source-'));
62
+ const cleanup = async () => {
63
+ await fsp.rm(tempRoot, { force: true, recursive: true });
64
+ };
65
+ try {
66
+ const tarballResponse = await fetch(tarballUrl);
67
+ if (!tarballResponse.ok) {
68
+ throw new Error(`Failed to download npm template tarball for ${locator.raw}: ${tarballResponse.status}`);
69
+ }
70
+ const tarballPath = path.join(tempRoot, 'template.tgz');
71
+ const unpackDir = path.join(tempRoot, 'source');
72
+ await fsp.mkdir(unpackDir, { recursive: true });
73
+ await fsp.writeFile(tarballPath, Buffer.from(await tarballResponse.arrayBuffer()));
74
+ await extractTarball({
75
+ cwd: unpackDir,
76
+ file: tarballPath,
77
+ strip: 1,
78
+ });
79
+ await assertNoSymlinks(unpackDir);
80
+ return {
81
+ blockDir: unpackDir,
82
+ cleanup,
83
+ rootDir: unpackDir,
84
+ };
85
+ }
86
+ catch (error) {
87
+ await cleanup();
88
+ throw error;
89
+ }
90
+ }
91
+ /**
92
+ * Resolve a locally installed npm template package from the caller workspace.
93
+ *
94
+ * Bare package ids are preferred here so monorepo and offline workflows can
95
+ * use an already-installed template without forcing a registry fetch.
96
+ */
97
+ function resolveInstalledNpmTemplateSource(locator, cwd) {
98
+ if (locator.rawSpec !== '' && locator.rawSpec !== '*') {
99
+ return null;
100
+ }
101
+ const workspacePackagesRoot = path.resolve(PROJECT_TOOLS_PACKAGE_ROOT, '..');
102
+ if (fs.existsSync(workspacePackagesRoot)) {
103
+ for (const entry of fs.readdirSync(workspacePackagesRoot, {
104
+ withFileTypes: true,
105
+ })) {
106
+ if (!entry.isDirectory()) {
107
+ continue;
108
+ }
109
+ const packageDir = path.join(workspacePackagesRoot, entry.name);
110
+ const packageJsonPath = path.join(packageDir, 'package.json');
111
+ if (!fs.existsSync(packageJsonPath)) {
112
+ continue;
113
+ }
114
+ const manifest = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
115
+ if (manifest.name === locator.name) {
116
+ return {
117
+ blockDir: packageDir,
118
+ rootDir: packageDir,
119
+ };
120
+ }
121
+ }
122
+ }
123
+ const workspaceRequire = createRequire(path.join(path.resolve(cwd), '__wp_typia_template_resolver__.cjs'));
124
+ try {
125
+ const packageJsonPath = fs.realpathSync(workspaceRequire.resolve(`${locator.name}/package.json`));
126
+ const sourceDir = path.dirname(packageJsonPath);
127
+ return {
128
+ blockDir: sourceDir,
129
+ rootDir: sourceDir,
130
+ };
131
+ }
132
+ catch (error) {
133
+ const errorCode = typeof error === 'object' && error !== null && 'code' in error
134
+ ? String(error.code)
135
+ : '';
136
+ if (errorCode === 'MODULE_NOT_FOUND' ||
137
+ errorCode === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
138
+ for (const basePath of workspaceRequire.resolve.paths(locator.name) ??
139
+ []) {
140
+ const packageJsonPath = path.join(basePath, locator.name, 'package.json');
141
+ if (!fs.existsSync(packageJsonPath)) {
142
+ continue;
143
+ }
144
+ const sourceDir = path.dirname(fs.realpathSync(packageJsonPath));
145
+ return {
146
+ blockDir: sourceDir,
147
+ rootDir: sourceDir,
148
+ };
149
+ }
150
+ return null;
151
+ }
152
+ throw error;
153
+ }
154
+ }
155
+ export function isOfficialWorkspaceTemplateSeed(seed) {
156
+ const packageJsonPath = path.join(seed.rootDir, 'package.json');
157
+ if (!fs.existsSync(packageJsonPath)) {
158
+ return false;
159
+ }
160
+ try {
161
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
162
+ return packageJson.name === OFFICIAL_WORKSPACE_TEMPLATE_PACKAGE;
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ }
168
+ export async function assertNoSymlinks(sourceDir) {
169
+ const stats = await fsp.lstat(sourceDir);
170
+ if (stats.isSymbolicLink()) {
171
+ throw new Error(`Template sources may not include symbolic links: ${sourceDir}`);
172
+ }
173
+ if (!stats.isDirectory()) {
174
+ return;
175
+ }
176
+ for (const entry of await fsp.readdir(sourceDir)) {
177
+ await assertNoSymlinks(path.join(sourceDir, entry));
178
+ }
179
+ }
180
+ async function resolveGitHubTemplateSource(locator) {
181
+ const remoteRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'wp-typia-template-source-'));
182
+ const cleanup = async () => {
183
+ await fsp.rm(remoteRoot, { force: true, recursive: true });
184
+ };
185
+ const checkoutDir = path.join(remoteRoot, 'source');
186
+ try {
187
+ const args = ['clone', '--depth', '1'];
188
+ if (locator.ref) {
189
+ args.push('--branch', locator.ref);
190
+ }
191
+ args.push(`https://github.com/${locator.owner}/${locator.repo}.git`, checkoutDir);
192
+ execFileSync('git', args, { stdio: 'ignore' });
193
+ const sourceDir = path.resolve(checkoutDir, locator.sourcePath);
194
+ const relativeSourceDir = path.relative(checkoutDir, sourceDir);
195
+ if (relativeSourceDir.startsWith('..') ||
196
+ path.isAbsolute(relativeSourceDir)) {
197
+ throw new Error('GitHub template path must stay within the cloned repository.');
198
+ }
199
+ if (!fs.existsSync(sourceDir)) {
200
+ throw new Error(`GitHub template path does not exist: ${locator.sourcePath}`);
201
+ }
202
+ await assertNoSymlinks(sourceDir);
203
+ return {
204
+ blockDir: sourceDir,
205
+ cleanup,
206
+ rootDir: sourceDir,
207
+ };
208
+ }
209
+ catch (error) {
210
+ await cleanup();
211
+ throw error;
212
+ }
213
+ }
214
+ /**
215
+ * Resolves a template locator into a local seed source directory.
216
+ *
217
+ * @param locator Remote template locator describing a local path, GitHub source, or npm package.
218
+ * @param cwd Current working directory used to resolve local template paths.
219
+ * @returns A local seed source containing the resolved root and block directory, plus optional cleanup.
220
+ * @throws When the locator is invalid, the source cannot be fetched, or filesystem validation fails.
221
+ */
222
+ export async function resolveTemplateSeed(locator, cwd) {
223
+ if (locator.kind === 'path') {
224
+ const sourceDir = path.resolve(cwd, locator.templatePath);
225
+ if (!fs.existsSync(sourceDir)) {
226
+ throw new Error(`Template path does not exist: ${sourceDir}`);
227
+ }
228
+ await assertNoSymlinks(sourceDir);
229
+ return {
230
+ blockDir: sourceDir,
231
+ rootDir: sourceDir,
232
+ };
233
+ }
234
+ if (locator.kind === 'github') {
235
+ return resolveGitHubTemplateSource(locator.locator);
236
+ }
237
+ const installedSource = resolveInstalledNpmTemplateSource(locator.locator, cwd);
238
+ if (installedSource) {
239
+ await assertNoSymlinks(installedSource.blockDir);
240
+ return installedSource;
241
+ }
242
+ return fetchNpmTemplateSource(locator.locator);
243
+ }
@@ -1,89 +1,7 @@
1
- import { type UnknownRecord } from './object-utils.js';
2
- type TemplateSourceFormat = 'wp-typia' | 'create-block-external' | 'create-block-subset';
3
- /**
4
- * Public template variables exposed to external template seeds before wp-typia
5
- * normalizes them into a scaffold project.
6
- */
7
- export interface TemplateVariableContext extends UnknownRecord {
8
- /** Version string for `@wp-typia/api-client` used in generated dependencies. */
9
- apiClientPackageVersion: string;
10
- /** Version string for `@wp-typia/block-runtime` used in generated dependencies. */
11
- blockRuntimePackageVersion: string;
12
- /** Version string for `@wp-typia/block-types` used in generated dependencies. */
13
- blockTypesPackageVersion: string;
14
- /** PascalCase block type name derived from the scaffold slug. */
15
- pascalCase: string;
16
- /** Snake_case PHP symbol prefix used for generated functions, constants, and keys. */
17
- phpPrefix: string;
18
- /** Human-readable block title. */
19
- title: string;
20
- /** Human-readable project or block description. */
21
- description: string;
22
- /** Keyword string derived from the slug for generated block metadata. */
23
- keyword: string;
24
- /** Block namespace used in generated block names such as `namespace/slug`. */
25
- namespace: string;
26
- /** Kebab-case scaffold slug used for package names, paths, and block slugs. */
27
- slug: string;
28
- /** Kebab-case text domain used for generated i18n strings and plugin headers. */
29
- textDomain: string;
30
- }
31
- export interface ResolvedTemplateSource {
32
- id: string;
33
- defaultCategory: string;
34
- description: string;
35
- features: string[];
36
- format: TemplateSourceFormat;
37
- isOfficialWorkspaceTemplate?: boolean;
38
- templateDir: string;
39
- cleanup?: () => Promise<void>;
40
- selectedVariant?: string | null;
41
- warnings?: string[];
42
- }
43
- interface GitHubTemplateLocator {
44
- owner: string;
45
- repo: string;
46
- ref: string | null;
47
- sourcePath: string;
48
- }
49
- interface NpmTemplateLocator {
50
- fetchSpec: string;
51
- name: string;
52
- raw: string;
53
- rawSpec: string;
54
- type: string;
55
- }
56
- interface SeedSource {
57
- assetsDir?: string;
58
- blockDir: string;
59
- cleanup?: () => Promise<void>;
60
- rootDir: string;
61
- selectedVariant?: string | null;
62
- warnings?: string[];
63
- }
64
- type RemoteTemplateLocator = {
65
- kind: 'github';
66
- locator: GitHubTemplateLocator;
67
- } | {
68
- kind: 'npm';
69
- locator: NpmTemplateLocator;
70
- } | {
71
- kind: 'path';
72
- templatePath: string;
73
- };
74
- export declare function parseGitHubTemplateLocator(templateId: string): GitHubTemplateLocator | null;
75
- export declare function parseNpmTemplateLocator(templateId: string): NpmTemplateLocator | null;
76
- export declare function parseTemplateLocator(templateId: string): RemoteTemplateLocator;
77
- /**
78
- * Resolves a template locator into a local seed source directory.
79
- *
80
- * @param locator Remote template locator describing a local path, GitHub source, or npm package.
81
- * @param cwd Current working directory used to resolve local template paths.
82
- * @returns A local seed source containing the resolved root and block directory, plus optional cleanup.
83
- * @throws When the locator is invalid, the source cannot be fetched, or filesystem validation fails.
84
- */
85
- export declare function resolveTemplateSeed(locator: RemoteTemplateLocator, cwd: string): Promise<SeedSource>;
1
+ import type { ResolvedTemplateSource } from './template-source-contracts.js';
2
+ export type { GitHubTemplateLocator, NpmTemplateLocator, RemoteTemplateLocator, ResolvedTemplateSource, TemplateSourceFormat, TemplateVariableContext, } from './template-source-contracts.js';
3
+ export { parseGitHubTemplateLocator, parseNpmTemplateLocator, parseTemplateLocator, } from './template-source-locators.js';
4
+ export { resolveTemplateSeed } from './template-source-seeds.js';
86
5
  export declare function resolveTemplateSource(templateId: string, cwd: string, variables: {
87
6
  [key: string]: string;
88
7
  }, variant?: string): Promise<ResolvedTemplateSource>;
89
- export {};