@ykdz/template 0.0.3 → 0.0.4

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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/src/cli.d.ts +0 -1
  3. package/dist/src/cli.js +14 -2
  4. package/dist/src/declarations.d.ts +2 -3
  5. package/dist/src/declarations.js +46 -36
  6. package/dist/src/dependency-catalog.d.ts +9 -1
  7. package/dist/src/dependency-catalog.js +69 -0
  8. package/dist/src/devcontainer.d.ts +49 -9
  9. package/dist/src/devcontainer.js +192 -14
  10. package/dist/src/editor-customization.d.ts +0 -1
  11. package/dist/src/editor-customization.js +54 -47
  12. package/dist/src/generation-context.d.ts +0 -1
  13. package/dist/src/generation-context.js +4 -1
  14. package/dist/src/module-graph.d.ts +8 -5
  15. package/dist/src/module-graph.js +10 -0
  16. package/dist/src/next-step-instructions.d.ts +0 -1
  17. package/dist/src/next-step-instructions.js +35 -0
  18. package/dist/src/package-addition.d.ts +1 -1
  19. package/dist/src/package-addition.js +170 -15
  20. package/dist/src/preset-projection.d.ts +1 -1
  21. package/dist/src/project-github.d.ts +3 -2
  22. package/dist/src/project-github.js +24 -6
  23. package/dist/src/renderer.d.ts +16 -2
  24. package/dist/src/renderer.js +95 -12
  25. package/dist/src/runtime-paths.d.ts +0 -1
  26. package/dist/src/template-boundary-check.d.ts +34 -0
  27. package/dist/src/template-boundary-check.js +448 -0
  28. package/dist/src/toolchain-resolution.d.ts +0 -1
  29. package/dist/templates/hono-api/projection.d.ts +2 -3
  30. package/dist/templates/hono-api/projection.js +230 -69
  31. package/dist/templates/projection-plans.d.ts +0 -1
  32. package/dist/templates/registry.d.ts +0 -1
  33. package/dist/templates/registry.js +2 -2
  34. package/dist/templates/rust-bin/projection.d.ts +2 -3
  35. package/dist/templates/rust-bin/projection.js +161 -53
  36. package/dist/templates/ts-lib/projection.d.ts +2 -3
  37. package/dist/templates/ts-lib/projection.js +215 -64
  38. package/dist/templates/vue-app/projection.d.ts +2 -3
  39. package/dist/templates/vue-app/projection.js +246 -83
  40. package/dist/templates/vue-hono-app/projection.d.ts +0 -1
  41. package/dist/templates/vue-hono-app/projection.js +191 -87
  42. package/package.json +10 -5
  43. package/pnpm-workspace.yaml +1 -0
  44. package/templates/hono-api/.github/dependabot.yml +13 -0
  45. package/templates/rust-bin/.github/dependabot.yml +18 -1
  46. package/templates/rust-bin/rust-toolchain.toml +3 -0
  47. package/templates/rust-bin/rustfmt.toml +2 -0
  48. package/templates/shared/devcontainer/browser-test.Dockerfile +2 -0
  49. package/templates/shared/devcontainer/node-pnpm.Dockerfile +6 -0
  50. package/templates/shared/devcontainer/rust.Dockerfile +16 -0
  51. package/templates/shared/editor-customization/capabilities.json +56 -0
  52. package/templates/ts-lib/.github/dependabot.yml +13 -0
  53. package/templates/ts-lib/src/index.ts +5 -1
  54. package/templates/vue-app/.github/dependabot.yml +13 -0
  55. package/templates/vue-app/.github/workflows/check.yml +1 -1
  56. package/templates/vue-hono-app/.github/dependabot.yml +13 -0
  57. package/dist/src/cli.d.ts.map +0 -1
  58. package/dist/src/declarations.d.ts.map +0 -1
  59. package/dist/src/dependency-catalog.d.ts.map +0 -1
  60. package/dist/src/devcontainer.d.ts.map +0 -1
  61. package/dist/src/editor-customization.d.ts.map +0 -1
  62. package/dist/src/generation-context.d.ts.map +0 -1
  63. package/dist/src/module-graph.d.ts.map +0 -1
  64. package/dist/src/next-step-instructions.d.ts.map +0 -1
  65. package/dist/src/package-addition.d.ts.map +0 -1
  66. package/dist/src/preset-projection.d.ts.map +0 -1
  67. package/dist/src/project-github.d.ts.map +0 -1
  68. package/dist/src/renderer.d.ts.map +0 -1
  69. package/dist/src/runtime-paths.d.ts.map +0 -1
  70. package/dist/src/toolchain-resolution.d.ts.map +0 -1
  71. package/dist/templates/hono-api/projection.d.ts.map +0 -1
  72. package/dist/templates/projection-plans.d.ts.map +0 -1
  73. package/dist/templates/registry.d.ts.map +0 -1
  74. package/dist/templates/rust-bin/projection.d.ts.map +0 -1
  75. package/dist/templates/ts-lib/projection.d.ts.map +0 -1
  76. package/dist/templates/vue-app/projection.d.ts.map +0 -1
  77. package/dist/templates/vue-hono-app/projection.d.ts.map +0 -1
  78. package/templates/hono-api/projection.ts +0 -453
  79. package/templates/projection-plans.ts +0 -135
  80. package/templates/registry.ts +0 -59
  81. package/templates/rust-bin/projection.ts +0 -346
  82. package/templates/ts-lib/projection.ts +0 -454
  83. package/templates/vue-app/projection.ts +0 -687
  84. package/templates/vue-hono-app/projection.ts +0 -669
@@ -1,135 +0,0 @@
1
- import type {
2
- CheckComponent,
3
- CheckEnvironmentNeed,
4
- CheckPlan,
5
- ComponentOwner,
6
- FixComponent,
7
- FixPlan,
8
- } from "../src/module-graph.js";
9
-
10
- const rootPackageBoundary: ComponentOwner = {
11
- kind: "package-boundary",
12
- path: ".",
13
- };
14
-
15
- const apiPackageBoundary: ComponentOwner = {
16
- kind: "package-boundary",
17
- path: "apps/api",
18
- };
19
-
20
- const webPackageBoundary: ComponentOwner = {
21
- kind: "package-boundary",
22
- path: "apps/web",
23
- };
24
-
25
- export type NodeCheckPlanTarget =
26
- | "hono-api"
27
- | "vue-app"
28
- | "vue-hono-root"
29
- | "vue-hono-api"
30
- | "vue-hono-web";
31
-
32
- export type NodeFixPlanTarget =
33
- | "hono-api"
34
- | "vue-app"
35
- | "vue-hono-root"
36
- | "vue-hono-api"
37
- | "vue-hono-web";
38
-
39
- function honoApiCheckComponents(owner: ComponentOwner): CheckComponent[] {
40
- return [
41
- { kind: "oxc-format-check", owner },
42
- { kind: "oxc-lint", owner },
43
- { kind: "typescript-typecheck", owner },
44
- { kind: "build", owner },
45
- { kind: "unit-test", owner },
46
- ];
47
- }
48
-
49
- function vueAppCheckComponents(owner: ComponentOwner): CheckComponent[] {
50
- return [
51
- { kind: "oxc-format-check", owner },
52
- { kind: "oxc-lint", owner },
53
- { kind: "typescript-typecheck", owner },
54
- { kind: "build", owner },
55
- { kind: "unit-test", owner },
56
- { kind: "e2e-test", owner },
57
- ];
58
- }
59
-
60
- function nodeFixComponents(owner: ComponentOwner): FixComponent[] {
61
- return [
62
- { kind: "oxc-format-write", owner },
63
- { kind: "oxc-lint-fix", owner },
64
- ];
65
- }
66
-
67
- export function selectNodeCheckComponents(
68
- target: NodeCheckPlanTarget,
69
- ): CheckComponent[] {
70
- switch (target) {
71
- case "hono-api":
72
- return honoApiCheckComponents(rootPackageBoundary);
73
- case "vue-app":
74
- return vueAppCheckComponents(rootPackageBoundary);
75
- case "vue-hono-root":
76
- return [{ kind: "turbo-check", owner: rootPackageBoundary }];
77
- case "vue-hono-api":
78
- return honoApiCheckComponents(apiPackageBoundary);
79
- case "vue-hono-web":
80
- return vueAppCheckComponents(webPackageBoundary);
81
- }
82
- }
83
-
84
- export function selectNodeFixComponents(
85
- target: NodeFixPlanTarget,
86
- ): FixComponent[] {
87
- switch (target) {
88
- case "hono-api":
89
- case "vue-app":
90
- return nodeFixComponents(rootPackageBoundary);
91
- case "vue-hono-root":
92
- return [{ kind: "turbo-fix", owner: rootPackageBoundary }];
93
- case "vue-hono-api":
94
- return nodeFixComponents(apiPackageBoundary);
95
- case "vue-hono-web":
96
- return nodeFixComponents(webPackageBoundary);
97
- }
98
- }
99
-
100
- function checkEnvironmentNeeds(
101
- target: NodeCheckPlanTarget,
102
- ): CheckEnvironmentNeed[] {
103
- if (target === "vue-app") {
104
- return [
105
- {
106
- kind: "playwright-browser-assets",
107
- browser: "chromium",
108
- owner: rootPackageBoundary,
109
- },
110
- ];
111
- }
112
-
113
- if (target === "vue-hono-root" || target === "vue-hono-web") {
114
- return [
115
- {
116
- kind: "playwright-browser-assets",
117
- browser: "chromium",
118
- owner: webPackageBoundary,
119
- },
120
- ];
121
- }
122
-
123
- return [];
124
- }
125
-
126
- export function planNodeChecks(target: NodeCheckPlanTarget): CheckPlan {
127
- return {
128
- components: selectNodeCheckComponents(target),
129
- environmentNeeds: checkEnvironmentNeeds(target),
130
- };
131
- }
132
-
133
- export function planNodeFixes(target: NodeFixPlanTarget): FixPlan {
134
- return { components: selectNodeFixComponents(target) };
135
- }
@@ -1,59 +0,0 @@
1
- import type { BuiltInPreset } from "../src/declarations.js";
2
- import type { GenerationContext } from "../src/generation-context.js";
3
- import type {
4
- PresetProjection,
5
- PresetProjectionPlan,
6
- } from "../src/preset-projection.js";
7
- import { honoApiPresetProjection } from "./hono-api/projection.js";
8
- import { rustBinPresetProjection } from "./rust-bin/projection.js";
9
- import { tsLibPresetProjection } from "./ts-lib/projection.js";
10
- import { vueAppPresetProjection } from "./vue-app/projection.js";
11
- import { vueHonoAppPresetProjection } from "./vue-hono-app/projection.js";
12
-
13
- const futurePresetMetadata = [
14
- {
15
- name: "ts-app",
16
- title: "TypeScript application",
17
- description: "Future application preset metadata.",
18
- generation: "future",
19
- supportedPackageManagers: ["pnpm"],
20
- supportedProjectKinds: ["single-package"],
21
- features: [],
22
- },
23
- {
24
- name: "node-cli",
25
- title: "Node.js CLI",
26
- description: "Future command-line preset metadata.",
27
- generation: "future",
28
- supportedPackageManagers: ["pnpm"],
29
- supportedProjectKinds: ["single-package"],
30
- features: [],
31
- },
32
- ] satisfies readonly BuiltInPreset[];
33
-
34
- export const builtInPresetProjections: readonly PresetProjection[] = [
35
- tsLibPresetProjection,
36
- honoApiPresetProjection,
37
- vueAppPresetProjection,
38
- vueHonoAppPresetProjection,
39
- rustBinPresetProjection,
40
- ];
41
-
42
- export const builtInPresetMetadata: readonly BuiltInPreset[] = [
43
- ...builtInPresetProjections.map((projection) => projection.metadata),
44
- ...futurePresetMetadata,
45
- ];
46
-
47
- export function findBuiltInPresetProjection(
48
- name: string,
49
- ): PresetProjection | undefined {
50
- return builtInPresetProjections.find(
51
- (projection) => projection.metadata.name === name,
52
- );
53
- }
54
-
55
- export function projectPresetThroughRegistry(
56
- context: GenerationContext,
57
- ): PresetProjectionPlan | undefined {
58
- return findBuiltInPresetProjection(context.preset)?.project(context);
59
- }
@@ -1,346 +0,0 @@
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
- };