@ykdz/template 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/src/cli.d.ts.map +1 -0
  2. package/dist/{cli.js → src/cli.js} +77 -56
  3. package/dist/{declarations.d.ts → src/declarations.d.ts} +1 -2
  4. package/dist/src/declarations.d.ts.map +1 -0
  5. package/dist/{declarations.js → src/declarations.js} +2 -109
  6. package/dist/src/dependency-catalog.d.ts +10 -0
  7. package/dist/src/dependency-catalog.d.ts.map +1 -0
  8. package/dist/src/dependency-catalog.js +63 -0
  9. package/dist/{devcontainer.d.ts → src/devcontainer.d.ts} +1 -0
  10. package/dist/src/devcontainer.d.ts.map +1 -0
  11. package/dist/{devcontainer.js → src/devcontainer.js} +1 -0
  12. package/dist/src/editor-customization.d.ts +13 -0
  13. package/dist/src/editor-customization.d.ts.map +1 -0
  14. package/dist/src/editor-customization.js +101 -0
  15. package/dist/{generation-context.d.ts → src/generation-context.d.ts} +2 -2
  16. package/dist/src/generation-context.d.ts.map +1 -0
  17. package/dist/{module-graph.d.ts → src/module-graph.d.ts} +0 -14
  18. package/dist/src/module-graph.d.ts.map +1 -0
  19. package/dist/src/module-graph.js +48 -0
  20. package/dist/{next-step-instructions.d.ts → src/next-step-instructions.d.ts} +2 -3
  21. package/dist/src/next-step-instructions.d.ts.map +1 -0
  22. package/dist/{next-step-instructions.js → src/next-step-instructions.js} +14 -24
  23. package/dist/src/package-addition.d.ts.map +1 -0
  24. package/dist/src/package-addition.js +188 -0
  25. package/dist/src/preset-projection.d.ts +66 -0
  26. package/dist/src/preset-projection.d.ts.map +1 -0
  27. package/dist/src/preset-projection.js +7 -0
  28. package/dist/{project-github.d.ts → src/project-github.d.ts} +0 -7
  29. package/dist/src/project-github.d.ts.map +1 -0
  30. package/dist/{project-github.js → src/project-github.js} +3 -36
  31. package/dist/src/renderer.d.ts.map +1 -0
  32. package/dist/src/runtime-paths.d.ts +2 -0
  33. package/dist/src/runtime-paths.d.ts.map +1 -0
  34. package/dist/src/runtime-paths.js +11 -0
  35. package/dist/src/toolchain-resolution.d.ts.map +1 -0
  36. package/dist/{toolchain-resolution.js → src/toolchain-resolution.js} +1 -1
  37. package/dist/templates/hono-api/projection.d.ts +7 -0
  38. package/dist/templates/hono-api/projection.d.ts.map +1 -0
  39. package/dist/templates/hono-api/projection.js +377 -0
  40. package/dist/templates/projection-plans.d.ts +8 -0
  41. package/dist/templates/projection-plans.d.ts.map +1 -0
  42. package/dist/templates/projection-plans.js +94 -0
  43. package/dist/templates/registry.d.ts +8 -0
  44. package/dist/templates/registry.d.ts.map +1 -0
  45. package/dist/templates/registry.js +42 -0
  46. package/dist/templates/rust-bin/projection.d.ts +10 -0
  47. package/dist/templates/rust-bin/projection.d.ts.map +1 -0
  48. package/dist/templates/rust-bin/projection.js +282 -0
  49. package/dist/templates/ts-lib/projection.d.ts +7 -0
  50. package/dist/templates/ts-lib/projection.d.ts.map +1 -0
  51. package/dist/templates/ts-lib/projection.js +372 -0
  52. package/dist/templates/vue-app/projection.d.ts +7 -0
  53. package/dist/templates/vue-app/projection.d.ts.map +1 -0
  54. package/dist/templates/vue-app/projection.js +594 -0
  55. package/dist/templates/vue-hono-app/projection.d.ts +9 -0
  56. package/dist/templates/vue-hono-app/projection.d.ts.map +1 -0
  57. package/dist/{vue-hono-app.js → templates/vue-hono-app/projection.js} +250 -101
  58. package/package.json +29 -24
  59. package/pnpm-workspace.yaml +34 -0
  60. package/templates/hono-api/projection.ts +453 -0
  61. package/templates/projection-plans.ts +135 -0
  62. package/templates/registry.ts +59 -0
  63. package/templates/rust-bin/projection.ts +346 -0
  64. package/templates/ts-lib/projection.ts +454 -0
  65. package/templates/vue-app/projection.ts +687 -0
  66. package/templates/vue-app/test/e2e/app.spec.ts +4 -1
  67. package/templates/vue-hono-app/projection.ts +669 -0
  68. package/templates/vue-hono-app/web/test/e2e/app.spec.ts +4 -1
  69. package/dist/cli.d.ts.map +0 -1
  70. package/dist/declarations.d.ts.map +0 -1
  71. package/dist/devcontainer.d.ts.map +0 -1
  72. package/dist/generation-context.d.ts.map +0 -1
  73. package/dist/hono-api.d.ts +0 -3
  74. package/dist/hono-api.d.ts.map +0 -1
  75. package/dist/hono-api.js +0 -210
  76. package/dist/module-graph.d.ts.map +0 -1
  77. package/dist/module-graph.js +0 -187
  78. package/dist/next-step-instructions.d.ts.map +0 -1
  79. package/dist/package-addition.d.ts.map +0 -1
  80. package/dist/package-addition.js +0 -560
  81. package/dist/project-github.d.ts.map +0 -1
  82. package/dist/renderer.d.ts.map +0 -1
  83. package/dist/rust-bin.d.ts +0 -8
  84. package/dist/rust-bin.d.ts.map +0 -1
  85. package/dist/rust-bin.js +0 -208
  86. package/dist/toolchain-resolution.d.ts.map +0 -1
  87. package/dist/ts-lib.d.ts +0 -8
  88. package/dist/ts-lib.d.ts.map +0 -1
  89. package/dist/ts-lib.js +0 -214
  90. package/dist/vue-app.d.ts +0 -3
  91. package/dist/vue-app.d.ts.map +0 -1
  92. package/dist/vue-app.js +0 -301
  93. package/dist/vue-hono-app.d.ts +0 -7
  94. package/dist/vue-hono-app.d.ts.map +0 -1
  95. package/templates/shared/oxc/package.json +0 -18
  96. package/templates/shared/oxc/tsconfig.json +0 -11
  97. /package/dist/{cli.d.ts → src/cli.d.ts} +0 -0
  98. /package/dist/{generation-context.js → src/generation-context.js} +0 -0
  99. /package/dist/{package-addition.d.ts → src/package-addition.d.ts} +0 -0
  100. /package/dist/{renderer.d.ts → src/renderer.d.ts} +0 -0
  101. /package/dist/{renderer.js → src/renderer.js} +0 -0
  102. /package/dist/{toolchain-resolution.d.ts → src/toolchain-resolution.d.ts} +0 -0
@@ -0,0 +1,454 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ import type {
6
+ BuiltInPreset,
7
+ ProjectBlueprint,
8
+ } from "../../src/declarations.js";
9
+ import { renderGeneratedPnpmWorkspaceYaml } from "../../src/dependency-catalog.js";
10
+ import { nodePnpmDevcontainer } from "../../src/devcontainer.js";
11
+ import { editorCustomizationForCapabilities } from "../../src/editor-customization.js";
12
+ import type { GenerationContext } from "../../src/generation-context.js";
13
+ import {
14
+ type CheckPlan,
15
+ type ComponentOwner,
16
+ type FixPlan,
17
+ renderFixCommand,
18
+ renderRootCheckCommand,
19
+ } from "../../src/module-graph.js";
20
+ import type {
21
+ PresetPackageAdditionOptions,
22
+ PresetPackageAdditionPlan,
23
+ PresetProjection,
24
+ PresetProjectionPlan,
25
+ } from "../../src/preset-projection.js";
26
+ import {
27
+ projectCheckWorkflow,
28
+ projectDependabotConfig,
29
+ type DependencyMaintenancePolicy,
30
+ } from "../../src/project-github.js";
31
+ import { renderNewProject, type RenderOperation } from "../../src/renderer.js";
32
+
33
+ const generatedBy = {
34
+ packageName: "@ykdz/template",
35
+ version: "0.0.0",
36
+ command: "template init --preset ts-lib",
37
+ };
38
+
39
+ export const tsLibPresetMetadata: BuiltInPreset = {
40
+ name: "ts-lib",
41
+ title: "TypeScript library",
42
+ description: "Strict TypeScript package with pnpm catalog tooling.",
43
+ generation: "supported",
44
+ supportedPackageManagers: ["pnpm"],
45
+ supportedProjectKinds: ["single-package"],
46
+ features: [
47
+ "pnpm-catalog",
48
+ "oxc-format-lint",
49
+ "strict-typescript",
50
+ "root-check",
51
+ "fix-command",
52
+ "devcontainer",
53
+ "github-actions",
54
+ "dependabot",
55
+ ],
56
+ };
57
+
58
+ const dependencyMaintenancePolicy: DependencyMaintenancePolicy = {
59
+ ecosystems: ["npm", "github-actions"],
60
+ interval: "weekly",
61
+ };
62
+
63
+ const tsLibPackageBoundary: ComponentOwner = {
64
+ kind: "package-boundary",
65
+ path: ".",
66
+ };
67
+
68
+ function planTsLibChecks(): CheckPlan {
69
+ return {
70
+ components: [
71
+ { kind: "typescript-typecheck", owner: tsLibPackageBoundary },
72
+ { kind: "oxc-lint", owner: tsLibPackageBoundary },
73
+ { kind: "oxc-format-check", owner: tsLibPackageBoundary },
74
+ ],
75
+ environmentNeeds: [],
76
+ };
77
+ }
78
+
79
+ function planTsLibFixes(): FixPlan {
80
+ return {
81
+ components: [
82
+ { kind: "oxc-format-write", owner: tsLibPackageBoundary },
83
+ { kind: "oxc-lint-fix", owner: tsLibPackageBoundary },
84
+ ],
85
+ };
86
+ }
87
+
88
+ export function tsLibBlueprint(): ProjectBlueprint {
89
+ return {
90
+ schemaVersion: 1,
91
+ preset: "ts-lib",
92
+ packageManager: "pnpm",
93
+ projectKind: "single-package",
94
+ features: [...tsLibPresetMetadata.features],
95
+ };
96
+ }
97
+
98
+ export function projectTsLibPackageScripts(): Record<string, string> {
99
+ const checkPlan = planTsLibChecks();
100
+ const fixPlan = planTsLibFixes();
101
+
102
+ return {
103
+ build: "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
104
+ check: renderRootCheckCommand(checkPlan),
105
+ fix: renderFixCommand(fixPlan),
106
+ "format:check": "oxfmt --check .",
107
+ "format:write": "oxfmt --write .",
108
+ lint: "oxlint . --deny-warnings",
109
+ "lint:fix": "oxlint . --fix --deny-warnings",
110
+ typecheck: "tsc -p tsconfig.json --noEmit",
111
+ };
112
+ }
113
+
114
+ function packageJson(
115
+ context: GenerationContext,
116
+ packageScripts: Record<string, string>,
117
+ ): Record<string, unknown> {
118
+ return {
119
+ name: context.projectName.value,
120
+ version: "0.0.0",
121
+ private: true,
122
+ files: ["dist"],
123
+ type: "module",
124
+ exports: {
125
+ ".": {
126
+ default: "./dist/index.js",
127
+ types: "./dist/index.d.ts",
128
+ },
129
+ },
130
+ scripts: packageScripts,
131
+ devDependencies: {
132
+ "@types/node": "catalog:",
133
+ oxfmt: "catalog:",
134
+ oxlint: "catalog:",
135
+ "tsc-alias": "catalog:",
136
+ typescript: "catalog:",
137
+ },
138
+ engines: {
139
+ node: context.toolchain.nodeLtsMajor.value,
140
+ },
141
+ packageManager: context.toolchain.packageManagerPin.value,
142
+ };
143
+ }
144
+
145
+ function generationRecord(context: GenerationContext): Record<string, unknown> {
146
+ return {
147
+ ...generatedBy,
148
+ toolchain: {
149
+ nodeLtsMajor: context.toolchain.nodeLtsMajor.value,
150
+ packageManagerPin: context.toolchain.packageManagerPin.value,
151
+ source: context.toolchain.source,
152
+ },
153
+ };
154
+ }
155
+
156
+ function operationsForTsLib(
157
+ context: GenerationContext,
158
+ packageScripts: Record<string, string>,
159
+ checkPlan: CheckPlan,
160
+ ): RenderOperation[] {
161
+ const editorCustomization = editorCustomizationForCapabilities([
162
+ "oxc-format-lint",
163
+ ]);
164
+
165
+ return [
166
+ {
167
+ kind: "writeJson",
168
+ to: "package.json",
169
+ value: packageJson(context, packageScripts),
170
+ multilineArrays: ["files"],
171
+ },
172
+ {
173
+ kind: "writeText",
174
+ to: "pnpm-workspace.yaml",
175
+ text: renderGeneratedPnpmWorkspaceYaml({
176
+ dependencies: [
177
+ "@types/node",
178
+ "oxfmt",
179
+ "oxlint",
180
+ "tsc-alias",
181
+ "typescript",
182
+ ],
183
+ }),
184
+ },
185
+ {
186
+ kind: "writeJson",
187
+ to: "tsconfig.json",
188
+ value: {
189
+ compilerOptions: {
190
+ declaration: true,
191
+ declarationMap: true,
192
+ module: "NodeNext",
193
+ moduleResolution: "NodeNext",
194
+ noEmitOnError: true,
195
+ outDir: "dist",
196
+ paths: {
197
+ "@/*": ["./src/*"],
198
+ },
199
+ rootDir: "src",
200
+ skipLibCheck: false,
201
+ strict: true,
202
+ target: "ES2022",
203
+ types: ["node"],
204
+ },
205
+ include: ["src/**/*.ts"],
206
+ },
207
+ },
208
+ {
209
+ kind: "copyFile",
210
+ sourceRoot: "sharedOxc",
211
+ from: "node/oxlint.config.ts",
212
+ to: "oxlint.config.ts",
213
+ },
214
+ {
215
+ kind: "copyFile",
216
+ sourceRoot: "sharedOxc",
217
+ from: "oxfmt.config.ts",
218
+ to: "oxfmt.config.ts",
219
+ },
220
+ {
221
+ kind: "writeText",
222
+ to: ".gitignore",
223
+ text: ["node_modules", "dist", ".env", ""].join("\n"),
224
+ },
225
+ {
226
+ kind: "copyFile",
227
+ from: "src/index.ts",
228
+ to: "src/index.ts",
229
+ },
230
+ {
231
+ kind: "writeJson",
232
+ to: ".project-kit/blueprint.json",
233
+ value: tsLibBlueprint(),
234
+ },
235
+ {
236
+ kind: "writeJson",
237
+ to: ".project-kit/generated-by.json",
238
+ value: generationRecord(context),
239
+ },
240
+ {
241
+ kind: "writeJson",
242
+ to: ".devcontainer/devcontainer.json",
243
+ value: nodePnpmDevcontainer({
244
+ name: `${context.projectName.value} development`,
245
+ nodeVersion: context.toolchain.nodeLtsMajor.value,
246
+ packageManagerPin: context.toolchain.packageManagerPin.value,
247
+ extensions: editorCustomization.extensions,
248
+ settings: editorCustomization.settings,
249
+ }),
250
+ },
251
+ {
252
+ kind: "writeJson",
253
+ to: ".vscode/extensions.json",
254
+ value: {
255
+ recommendations: editorCustomization.extensions,
256
+ },
257
+ multilineArrays: ["recommendations"],
258
+ },
259
+ {
260
+ kind: "writeJson",
261
+ to: ".vscode/settings.json",
262
+ value: editorCustomization.settings,
263
+ },
264
+ {
265
+ kind: "writeText",
266
+ to: ".github/workflows/check.yml",
267
+ text: projectCheckWorkflow({ checkPlan }),
268
+ },
269
+ {
270
+ kind: "writeText",
271
+ to: ".github/dependabot.yml",
272
+ text: projectDependabotConfig(dependencyMaintenancePolicy),
273
+ },
274
+ ];
275
+ }
276
+
277
+ function packageAdditionOperations(
278
+ packagePath: string,
279
+ packageName: string,
280
+ nodeVersion: string,
281
+ ): RenderOperation[] {
282
+ return [
283
+ {
284
+ kind: "writeJson",
285
+ to: `${packagePath}/package.json`,
286
+ value: {
287
+ name: packageName,
288
+ version: "0.0.0",
289
+ private: true,
290
+ files: ["dist"],
291
+ type: "module",
292
+ exports: {
293
+ ".": {
294
+ default: "./dist/index.js",
295
+ types: "./dist/index.d.ts",
296
+ },
297
+ },
298
+ scripts: projectTsLibPackageScripts(),
299
+ devDependencies: {
300
+ "@types/node": "catalog:",
301
+ oxfmt: "catalog:",
302
+ oxlint: "catalog:",
303
+ "tsc-alias": "catalog:",
304
+ typescript: "catalog:",
305
+ },
306
+ engines: {
307
+ node: nodeVersion,
308
+ },
309
+ },
310
+ multilineArrays: ["files"],
311
+ },
312
+ {
313
+ kind: "writeJson",
314
+ to: `${packagePath}/tsconfig.json`,
315
+ value: {
316
+ compilerOptions: {
317
+ composite: true,
318
+ declaration: true,
319
+ declarationMap: true,
320
+ module: "NodeNext",
321
+ moduleResolution: "NodeNext",
322
+ noEmitOnError: true,
323
+ outDir: "dist",
324
+ paths: {
325
+ "@/*": ["./src/*"],
326
+ },
327
+ rootDir: "src",
328
+ skipLibCheck: false,
329
+ strict: true,
330
+ target: "ES2022",
331
+ types: ["node"],
332
+ },
333
+ include: ["src/**/*.ts"],
334
+ },
335
+ },
336
+ {
337
+ kind: "copyFile",
338
+ sourceRoot: "sharedOxc",
339
+ from: "node/oxlint.config.ts",
340
+ to: `${packagePath}/oxlint.config.ts`,
341
+ },
342
+ {
343
+ kind: "copyFile",
344
+ sourceRoot: "sharedOxc",
345
+ from: "oxfmt.config.ts",
346
+ to: `${packagePath}/oxfmt.config.ts`,
347
+ },
348
+ {
349
+ kind: "copyFile",
350
+ from: "src/index.ts",
351
+ to: `${packagePath}/src/index.ts`,
352
+ },
353
+ ];
354
+ }
355
+
356
+ function packageAdditionPlan(
357
+ packageLeafName: string,
358
+ packageName: string,
359
+ nodeVersion: string,
360
+ ): PresetPackageAdditionPlan {
361
+ const packagePath = `packages/${packageLeafName}`;
362
+
363
+ return {
364
+ packagePath,
365
+ workspacePackageGlob: "packages/*",
366
+ rootTsconfigReferences: [`./${packagePath}/tsconfig.json`],
367
+ sourceRoot: templateSourceRoot(),
368
+ sourceRoots: { sharedOxc: sharedOxcSourceRoot() },
369
+ operations: packageAdditionOperations(
370
+ packagePath,
371
+ packageName,
372
+ nodeVersion,
373
+ ),
374
+ };
375
+ }
376
+
377
+ function templateSourceRoot(): string {
378
+ const projectionDir = path.dirname(fileURLToPath(import.meta.url));
379
+ const publishedTemplateRoot = path.join(
380
+ projectionDir,
381
+ "..",
382
+ "..",
383
+ "..",
384
+ "templates",
385
+ "ts-lib",
386
+ );
387
+
388
+ return existsSync(path.join(publishedTemplateRoot, "src", "index.ts"))
389
+ ? publishedTemplateRoot
390
+ : projectionDir;
391
+ }
392
+
393
+ function sharedOxcSourceRoot(): string {
394
+ const projectionDir = path.dirname(fileURLToPath(import.meta.url));
395
+ const publishedSharedRoot = path.join(
396
+ projectionDir,
397
+ "..",
398
+ "..",
399
+ "..",
400
+ "templates",
401
+ "shared",
402
+ "oxc",
403
+ );
404
+
405
+ return existsSync(path.join(publishedSharedRoot, "oxfmt.config.ts"))
406
+ ? publishedSharedRoot
407
+ : path.join(projectionDir, "..", "shared", "oxc");
408
+ }
409
+
410
+ export const tsLibPresetProjection: PresetProjection = {
411
+ metadata: tsLibPresetMetadata,
412
+ capabilities: {
413
+ packageAddition: {
414
+ planPackageAddition({
415
+ packageLeafName,
416
+ packageName,
417
+ nodeVersion,
418
+ }: PresetPackageAdditionOptions) {
419
+ return packageAdditionPlan(packageLeafName, packageName, nodeVersion);
420
+ },
421
+ },
422
+ },
423
+ blueprint: tsLibBlueprint,
424
+ project(context: GenerationContext): PresetProjectionPlan {
425
+ const checkPlan = planTsLibChecks();
426
+ const fixPlan = planTsLibFixes();
427
+ const packageScripts = projectTsLibPackageScripts();
428
+
429
+ return {
430
+ sourceRoot: templateSourceRoot(),
431
+ sourceRoots: { sharedOxc: sharedOxcSourceRoot() },
432
+ operations: operationsForTsLib(context, packageScripts, checkPlan),
433
+ checkPlan,
434
+ fixPlan,
435
+ dependencyMaintenancePolicy,
436
+ packageScripts,
437
+ capabilities: {
438
+ rootCheck: true,
439
+ fixCommand: true,
440
+ githubActions: true,
441
+ dependabot: true,
442
+ devcontainer: true,
443
+ },
444
+ };
445
+ },
446
+ async render({ targetDir, plan }): Promise<void> {
447
+ await renderNewProject({
448
+ sourceRoot: plan.sourceRoot,
449
+ sourceRoots: plan.sourceRoots,
450
+ targetRoot: targetDir,
451
+ operations: [...plan.operations],
452
+ });
453
+ },
454
+ };