@ykdz/template 0.0.1 → 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 (101) hide show
  1. package/dist/src/cli.d.ts.map +1 -0
  2. package/dist/{cli.js → src/cli.js} +126 -128
  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/src/devcontainer.d.ts +18 -0
  10. package/dist/src/devcontainer.d.ts.map +1 -0
  11. package/dist/src/devcontainer.js +24 -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/src/generation-context.d.ts +24 -0
  16. package/dist/src/generation-context.d.ts.map +1 -0
  17. package/dist/src/generation-context.js +12 -0
  18. package/dist/src/module-graph.d.ts +31 -0
  19. package/dist/src/module-graph.d.ts.map +1 -0
  20. package/dist/src/module-graph.js +48 -0
  21. package/dist/src/next-step-instructions.d.ts +21 -0
  22. package/dist/src/next-step-instructions.d.ts.map +1 -0
  23. package/dist/src/next-step-instructions.js +89 -0
  24. package/dist/src/package-addition.d.ts.map +1 -0
  25. package/dist/src/package-addition.js +188 -0
  26. package/dist/src/preset-projection.d.ts +66 -0
  27. package/dist/src/preset-projection.d.ts.map +1 -0
  28. package/dist/src/preset-projection.js +7 -0
  29. package/dist/src/project-github.d.ts +29 -0
  30. package/dist/src/project-github.d.ts.map +1 -0
  31. package/dist/src/project-github.js +63 -0
  32. package/dist/src/renderer.d.ts.map +1 -0
  33. package/dist/{renderer.js → src/renderer.js} +0 -3
  34. package/dist/src/runtime-paths.d.ts +2 -0
  35. package/dist/src/runtime-paths.d.ts.map +1 -0
  36. package/dist/src/runtime-paths.js +11 -0
  37. package/dist/src/toolchain-resolution.d.ts +35 -0
  38. package/dist/src/toolchain-resolution.d.ts.map +1 -0
  39. package/dist/src/toolchain-resolution.js +192 -0
  40. package/dist/templates/hono-api/projection.d.ts +7 -0
  41. package/dist/templates/hono-api/projection.d.ts.map +1 -0
  42. package/dist/templates/hono-api/projection.js +377 -0
  43. package/dist/templates/projection-plans.d.ts +8 -0
  44. package/dist/templates/projection-plans.d.ts.map +1 -0
  45. package/dist/templates/projection-plans.js +94 -0
  46. package/dist/templates/registry.d.ts +8 -0
  47. package/dist/templates/registry.d.ts.map +1 -0
  48. package/dist/templates/registry.js +42 -0
  49. package/dist/templates/rust-bin/projection.d.ts +10 -0
  50. package/dist/templates/rust-bin/projection.d.ts.map +1 -0
  51. package/dist/templates/rust-bin/projection.js +282 -0
  52. package/dist/templates/ts-lib/projection.d.ts +7 -0
  53. package/dist/templates/ts-lib/projection.d.ts.map +1 -0
  54. package/dist/templates/ts-lib/projection.js +372 -0
  55. package/dist/templates/vue-app/projection.d.ts +7 -0
  56. package/dist/templates/vue-app/projection.d.ts.map +1 -0
  57. package/dist/templates/vue-app/projection.js +594 -0
  58. package/dist/templates/vue-hono-app/projection.d.ts +9 -0
  59. package/dist/templates/vue-hono-app/projection.d.ts.map +1 -0
  60. package/dist/templates/vue-hono-app/projection.js +589 -0
  61. package/package.json +30 -24
  62. package/pnpm-workspace.yaml +34 -0
  63. package/templates/hono-api/projection.ts +453 -0
  64. package/templates/projection-plans.ts +135 -0
  65. package/templates/registry.ts +59 -0
  66. package/templates/rust-bin/.github/dependabot.yml +4 -0
  67. package/templates/rust-bin/.github/workflows/check.yml +6 -1
  68. package/templates/rust-bin/projection.ts +346 -0
  69. package/templates/ts-lib/projection.ts +454 -0
  70. package/templates/vue-app/projection.ts +687 -0
  71. package/templates/vue-app/test/e2e/app.spec.ts +4 -1
  72. package/templates/vue-hono-app/projection.ts +669 -0
  73. package/templates/vue-hono-app/web/test/e2e/app.spec.ts +4 -1
  74. package/dist/cli.d.ts.map +0 -1
  75. package/dist/declarations.d.ts.map +0 -1
  76. package/dist/hono-api.d.ts +0 -2
  77. package/dist/hono-api.d.ts.map +0 -1
  78. package/dist/hono-api.js +0 -208
  79. package/dist/package-addition.d.ts.map +0 -1
  80. package/dist/package-addition.js +0 -560
  81. package/dist/post-commands.d.ts +0 -40
  82. package/dist/post-commands.d.ts.map +0 -1
  83. package/dist/post-commands.js +0 -154
  84. package/dist/renderer.d.ts.map +0 -1
  85. package/dist/rust-bin.d.ts +0 -2
  86. package/dist/rust-bin.d.ts.map +0 -1
  87. package/dist/rust-bin.js +0 -174
  88. package/dist/ts-lib.d.ts +0 -2
  89. package/dist/ts-lib.d.ts.map +0 -1
  90. package/dist/ts-lib.js +0 -181
  91. package/dist/vue-app.d.ts +0 -2
  92. package/dist/vue-app.d.ts.map +0 -1
  93. package/dist/vue-app.js +0 -299
  94. package/dist/vue-hono-app.d.ts +0 -4
  95. package/dist/vue-hono-app.d.ts.map +0 -1
  96. package/dist/vue-hono-app.js +0 -436
  97. package/templates/shared/oxc/package.json +0 -18
  98. package/templates/shared/oxc/tsconfig.json +0 -11
  99. /package/dist/{cli.d.ts → src/cli.d.ts} +0 -0
  100. /package/dist/{package-addition.d.ts → src/package-addition.d.ts} +0 -0
  101. /package/dist/{renderer.d.ts → src/renderer.d.ts} +0 -0
@@ -0,0 +1,346 @@
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 { devcontainerNodeFeature } from "../../src/devcontainer.js";
10
+ import { editorCustomizationForCapabilities } from "../../src/editor-customization.js";
11
+ import type { GenerationContext } from "../../src/generation-context.js";
12
+ import {
13
+ type CheckPlan,
14
+ type ComponentOwner,
15
+ type FixPlan,
16
+ renderFixCommand,
17
+ renderRootCheckCommand,
18
+ } from "../../src/module-graph.js";
19
+ import type {
20
+ PresetProjection,
21
+ PresetProjectionPlan,
22
+ } from "../../src/preset-projection.js";
23
+ import {
24
+ projectCheckWorkflow,
25
+ projectDependabotConfig,
26
+ type DependencyMaintenancePolicy,
27
+ } from "../../src/project-github.js";
28
+ import { renderNewProject, type RenderOperation } from "../../src/renderer.js";
29
+
30
+ const generatedBy = {
31
+ packageName: "@ykdz/template",
32
+ version: "0.0.0",
33
+ command: "template init --preset rust-bin",
34
+ };
35
+
36
+ export const rustBinPresetMetadata: BuiltInPreset = {
37
+ name: "rust-bin",
38
+ title: "Rust binary",
39
+ description:
40
+ "Single-package Rust native binary with rustfmt, clippy, and cargo tests.",
41
+ generation: "supported",
42
+ supportedPackageManagers: ["pnpm"],
43
+ supportedProjectKinds: ["single-package"],
44
+ features: [
45
+ "root-check",
46
+ "fix-command",
47
+ "devcontainer",
48
+ "github-actions",
49
+ "dependabot",
50
+ "rustfmt-clippy",
51
+ "cargo-test",
52
+ ],
53
+ };
54
+
55
+ const dependencyMaintenancePolicy: DependencyMaintenancePolicy = {
56
+ ecosystems: ["npm", "cargo", "github-actions"],
57
+ interval: "weekly",
58
+ };
59
+
60
+ const rustPackageBoundary: ComponentOwner = {
61
+ kind: "package-boundary",
62
+ path: ".",
63
+ };
64
+
65
+ function cargoPackageNameFromProjectName(projectName: string): string {
66
+ const slug = projectName
67
+ .normalize("NFKD")
68
+ .replace(/[\u0300-\u036f]/g, "")
69
+ .toLowerCase()
70
+ .replace(/[^a-z0-9]+/g, "-")
71
+ .replace(/^-+|-+$/g, "");
72
+
73
+ return slug || "rust-bin";
74
+ }
75
+
76
+ export function planRustBinChecks(): CheckPlan {
77
+ return {
78
+ components: [
79
+ { kind: "rustfmt-check", owner: rustPackageBoundary },
80
+ { kind: "cargo-clippy", owner: rustPackageBoundary },
81
+ { kind: "cargo-test", owner: rustPackageBoundary },
82
+ ],
83
+ environmentNeeds: [],
84
+ };
85
+ }
86
+
87
+ export function planRustBinFixes(): FixPlan {
88
+ return {
89
+ components: [{ kind: "rustfmt-write", owner: rustPackageBoundary }],
90
+ };
91
+ }
92
+
93
+ export function rustBinBlueprint(): ProjectBlueprint {
94
+ return {
95
+ schemaVersion: 1,
96
+ preset: "rust-bin",
97
+ packageManager: "pnpm",
98
+ projectKind: "single-package",
99
+ features: [...rustBinPresetMetadata.features],
100
+ };
101
+ }
102
+
103
+ export function projectRustBinPackageScripts(): Record<string, string> {
104
+ return {
105
+ check: renderRootCheckCommand(planRustBinChecks()),
106
+ fix: renderFixCommand(planRustBinFixes()),
107
+ };
108
+ }
109
+
110
+ function cargoToml(projectName: string): string {
111
+ return [
112
+ "[package]",
113
+ `name = "${projectName}"`,
114
+ 'version = "0.1.0"',
115
+ 'edition = "2024"',
116
+ "",
117
+ "[dependencies]",
118
+ "",
119
+ "[lints]",
120
+ "workspace = true",
121
+ "",
122
+ "[workspace]",
123
+ 'members = ["."]',
124
+ 'resolver = "3"',
125
+ "",
126
+ "[workspace.lints.rust]",
127
+ 'unsafe_code = "forbid"',
128
+ "",
129
+ "[workspace.lints.clippy]",
130
+ 'all = "deny"',
131
+ 'pedantic = "deny"',
132
+ 'nursery = "deny"',
133
+ "",
134
+ "[profile.release]",
135
+ 'strip = "symbols"',
136
+ 'lto = "thin"',
137
+ "codegen-units = 1",
138
+ "",
139
+ ].join("\n");
140
+ }
141
+
142
+ function cargoLock(projectName: string): string {
143
+ return [
144
+ "# This file is automatically @generated by Cargo.",
145
+ "# It is not intended for manual editing.",
146
+ "version = 4",
147
+ "",
148
+ "[[package]]",
149
+ `name = "${projectName}"`,
150
+ 'version = "0.1.0"',
151
+ "",
152
+ ].join("\n");
153
+ }
154
+
155
+ function packageJson(
156
+ context: GenerationContext,
157
+ projectName: string,
158
+ packageScripts: Record<string, string>,
159
+ ): Record<string, unknown> {
160
+ return {
161
+ name: projectName,
162
+ version: "0.0.0",
163
+ private: true,
164
+ scripts: packageScripts,
165
+ engines: {
166
+ node: context.toolchain.nodeLtsMajor.value,
167
+ },
168
+ packageManager: context.toolchain.packageManagerPin.value,
169
+ };
170
+ }
171
+
172
+ function generationRecord(context: GenerationContext): Record<string, unknown> {
173
+ return {
174
+ ...generatedBy,
175
+ toolchain: {
176
+ nodeLtsMajor: context.toolchain.nodeLtsMajor.value,
177
+ packageManagerPin: context.toolchain.packageManagerPin.value,
178
+ source: context.toolchain.source,
179
+ },
180
+ };
181
+ }
182
+
183
+ function operationsForRustBin(
184
+ context: GenerationContext,
185
+ projectName: string,
186
+ packageScripts: Record<string, string>,
187
+ checkPlan: CheckPlan,
188
+ ): RenderOperation[] {
189
+ const editorCustomization = editorCustomizationForCapabilities([
190
+ "rust-tooling",
191
+ ]);
192
+
193
+ return [
194
+ {
195
+ kind: "writeJson",
196
+ to: "package.json",
197
+ value: packageJson(context, projectName, packageScripts),
198
+ },
199
+ {
200
+ kind: "writeText",
201
+ to: "pnpm-workspace.yaml",
202
+ text: ["packages:", " - .", ""].join("\n"),
203
+ },
204
+ {
205
+ kind: "writeText",
206
+ to: "Cargo.toml",
207
+ text: cargoToml(projectName),
208
+ },
209
+ {
210
+ kind: "writeText",
211
+ to: "Cargo.lock",
212
+ text: cargoLock(projectName),
213
+ },
214
+ {
215
+ kind: "writeText",
216
+ to: "rustfmt.toml",
217
+ text: ['edition = "2024"', "max_width = 100", ""].join("\n"),
218
+ },
219
+ {
220
+ kind: "writeText",
221
+ to: ".gitignore",
222
+ text: ["target", ".env", ""].join("\n"),
223
+ },
224
+ {
225
+ kind: "copyFile",
226
+ from: "src/main.rs",
227
+ to: "src/main.rs",
228
+ },
229
+ {
230
+ kind: "writeJson",
231
+ to: ".project-kit/blueprint.json",
232
+ value: rustBinBlueprint(),
233
+ },
234
+ {
235
+ kind: "writeJson",
236
+ to: ".project-kit/generated-by.json",
237
+ value: generationRecord(context),
238
+ },
239
+ {
240
+ kind: "writeJson",
241
+ to: ".devcontainer/devcontainer.json",
242
+ value: {
243
+ name: `${projectName} Rust development`,
244
+ image: "mcr.microsoft.com/devcontainers/rust:1",
245
+ features: devcontainerNodeFeature({
246
+ nodeVersion: context.toolchain.nodeLtsMajor.value,
247
+ packageManagerPin: context.toolchain.packageManagerPin.value,
248
+ }),
249
+ mounts: [
250
+ "source=${localWorkspaceFolderBasename}-cargo-registry,target=/usr/local/cargo/registry,type=volume",
251
+ "source=${localWorkspaceFolderBasename}-cargo-git,target=/usr/local/cargo/git,type=volume",
252
+ "source=${localWorkspaceFolderBasename}-target,target=${containerWorkspaceFolder}/target,type=volume",
253
+ ],
254
+ customizations: {
255
+ vscode: {
256
+ extensions: editorCustomization.extensions,
257
+ settings: editorCustomization.settings,
258
+ },
259
+ },
260
+ },
261
+ },
262
+ {
263
+ kind: "writeJson",
264
+ to: ".vscode/extensions.json",
265
+ value: {
266
+ recommendations: editorCustomization.extensions,
267
+ },
268
+ },
269
+ {
270
+ kind: "writeJson",
271
+ to: ".vscode/settings.json",
272
+ value: editorCustomization.settings,
273
+ },
274
+ {
275
+ kind: "writeText",
276
+ to: ".github/workflows/check.yml",
277
+ text: projectCheckWorkflow({
278
+ checkPlan,
279
+ environmentPreparation: { rustToolchain: true },
280
+ }),
281
+ },
282
+ {
283
+ kind: "writeText",
284
+ to: ".github/dependabot.yml",
285
+ text: projectDependabotConfig(dependencyMaintenancePolicy),
286
+ },
287
+ ];
288
+ }
289
+
290
+ function templateSourceRoot(): string {
291
+ const projectionDir = path.dirname(fileURLToPath(import.meta.url));
292
+ const publishedTemplateRoot = path.join(
293
+ projectionDir,
294
+ "..",
295
+ "..",
296
+ "..",
297
+ "templates",
298
+ "rust-bin",
299
+ );
300
+
301
+ return existsSync(path.join(publishedTemplateRoot, "src", "main.rs"))
302
+ ? publishedTemplateRoot
303
+ : projectionDir;
304
+ }
305
+
306
+ export const rustBinPresetProjection: PresetProjection = {
307
+ metadata: rustBinPresetMetadata,
308
+ blueprint: rustBinBlueprint,
309
+ project(context: GenerationContext): PresetProjectionPlan {
310
+ const checkPlan = planRustBinChecks();
311
+ const fixPlan = planRustBinFixes();
312
+ const packageScripts = projectRustBinPackageScripts();
313
+ const projectName = cargoPackageNameFromProjectName(
314
+ context.projectName.value,
315
+ );
316
+
317
+ return {
318
+ sourceRoot: templateSourceRoot(),
319
+ operations: operationsForRustBin(
320
+ context,
321
+ projectName,
322
+ packageScripts,
323
+ checkPlan,
324
+ ),
325
+ checkPlan,
326
+ fixPlan,
327
+ dependencyMaintenancePolicy,
328
+ packageScripts,
329
+ capabilities: {
330
+ rootCheck: true,
331
+ fixCommand: true,
332
+ githubActions: true,
333
+ dependabot: true,
334
+ devcontainer: true,
335
+ },
336
+ };
337
+ },
338
+ async render({ targetDir, plan }): Promise<void> {
339
+ await renderNewProject({
340
+ sourceRoot: plan.sourceRoot,
341
+ sourceRoots: plan.sourceRoots,
342
+ targetRoot: targetDir,
343
+ operations: [...plan.operations],
344
+ });
345
+ },
346
+ };