@ykdz/template 0.0.3 → 0.0.5

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 (95) hide show
  1. package/README.md +1 -1
  2. package/dist/src/cli.d.ts +0 -1
  3. package/dist/src/cli.js +26 -2
  4. package/dist/src/declarations.d.ts +38 -3
  5. package/dist/src/declarations.js +75 -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 +20 -2
  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-support.d.ts +5 -0
  19. package/dist/src/package-addition-support.js +4 -0
  20. package/dist/src/package-addition.d.ts +2 -1
  21. package/dist/src/package-addition.js +557 -55
  22. package/dist/src/package-linking.d.ts +55 -0
  23. package/dist/src/package-linking.js +116 -0
  24. package/dist/src/preset-projection.d.ts +4 -2
  25. package/dist/src/project-github.d.ts +3 -2
  26. package/dist/src/project-github.js +24 -6
  27. package/dist/src/renderer.d.ts +16 -2
  28. package/dist/src/renderer.js +96 -12
  29. package/dist/src/runtime-paths.d.ts +0 -1
  30. package/dist/src/template-boundary-check.d.ts +34 -0
  31. package/dist/src/template-boundary-check.js +448 -0
  32. package/dist/src/toolchain-resolution.d.ts +0 -1
  33. package/dist/templates/hono-api/projection.d.ts +2 -3
  34. package/dist/templates/hono-api/projection.js +258 -76
  35. package/dist/templates/projection-plans.d.ts +0 -1
  36. package/dist/templates/registry.d.ts +0 -1
  37. package/dist/templates/registry.js +5 -2
  38. package/dist/templates/rust-bin/projection.d.ts +2 -3
  39. package/dist/templates/rust-bin/projection.js +171 -53
  40. package/dist/templates/ts-lib/projection.d.ts +2 -3
  41. package/dist/templates/ts-lib/projection.js +251 -87
  42. package/dist/templates/vue-app/projection.d.ts +2 -3
  43. package/dist/templates/vue-app/projection.js +266 -94
  44. package/dist/templates/vue-hono-app/projection.d.ts +0 -1
  45. package/dist/templates/vue-hono-app/projection.js +232 -108
  46. package/package.json +10 -5
  47. package/pnpm-workspace.yaml +1 -0
  48. package/templates/hono-api/.github/dependabot.yml +13 -0
  49. package/templates/hono-api/src/server.ts +1 -1
  50. package/templates/hono-api/test/app.test.ts +1 -1
  51. package/templates/rust-bin/.github/dependabot.yml +18 -1
  52. package/templates/rust-bin/rust-toolchain.toml +3 -0
  53. package/templates/rust-bin/rustfmt.toml +2 -0
  54. package/templates/shared/devcontainer/browser-test.Dockerfile +2 -0
  55. package/templates/shared/devcontainer/node-pnpm.Dockerfile +6 -0
  56. package/templates/shared/devcontainer/rust.Dockerfile +16 -0
  57. package/templates/shared/editor-customization/capabilities.json +56 -0
  58. package/templates/ts-lib/.github/dependabot.yml +13 -0
  59. package/templates/ts-lib/src/index.ts +5 -1
  60. package/templates/ts-lib/src/name-schema.ts +3 -0
  61. package/templates/vue-app/.github/dependabot.yml +13 -0
  62. package/templates/vue-app/.github/workflows/check.yml +1 -1
  63. package/templates/vue-app/src/App.vue +1 -1
  64. package/templates/vue-app/test/app.test.ts +1 -1
  65. package/templates/vue-hono-app/.github/dependabot.yml +13 -0
  66. package/templates/vue-hono-app/web/src/App.vue +2 -2
  67. package/templates/vue-hono-app/web/test/app.test.ts +1 -1
  68. package/dist/src/cli.d.ts.map +0 -1
  69. package/dist/src/declarations.d.ts.map +0 -1
  70. package/dist/src/dependency-catalog.d.ts.map +0 -1
  71. package/dist/src/devcontainer.d.ts.map +0 -1
  72. package/dist/src/editor-customization.d.ts.map +0 -1
  73. package/dist/src/generation-context.d.ts.map +0 -1
  74. package/dist/src/module-graph.d.ts.map +0 -1
  75. package/dist/src/next-step-instructions.d.ts.map +0 -1
  76. package/dist/src/package-addition.d.ts.map +0 -1
  77. package/dist/src/preset-projection.d.ts.map +0 -1
  78. package/dist/src/project-github.d.ts.map +0 -1
  79. package/dist/src/renderer.d.ts.map +0 -1
  80. package/dist/src/runtime-paths.d.ts.map +0 -1
  81. package/dist/src/toolchain-resolution.d.ts.map +0 -1
  82. package/dist/templates/hono-api/projection.d.ts.map +0 -1
  83. package/dist/templates/projection-plans.d.ts.map +0 -1
  84. package/dist/templates/registry.d.ts.map +0 -1
  85. package/dist/templates/rust-bin/projection.d.ts.map +0 -1
  86. package/dist/templates/ts-lib/projection.d.ts.map +0 -1
  87. package/dist/templates/vue-app/projection.d.ts.map +0 -1
  88. package/dist/templates/vue-hono-app/projection.d.ts.map +0 -1
  89. package/templates/hono-api/projection.ts +0 -453
  90. package/templates/projection-plans.ts +0 -135
  91. package/templates/registry.ts +0 -59
  92. package/templates/rust-bin/projection.ts +0 -346
  93. package/templates/ts-lib/projection.ts +0 -454
  94. package/templates/vue-app/projection.ts +0 -687
  95. package/templates/vue-hono-app/projection.ts +0 -669
@@ -1,10 +1,11 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- import { devcontainerNodeFeature } from "../../src/devcontainer.js";
4
+ import { collectGeneratedManifestCatalogDependencies, renderGeneratedPnpmWorkspaceYaml, } from "../../src/dependency-catalog.js";
5
+ import { dockerfileFirstRustPnpmDevcontainer, nodePnpmToolLayer, rustToolLayer, } from "../../src/devcontainer.js";
5
6
  import { editorCustomizationForCapabilities } from "../../src/editor-customization.js";
6
7
  import { renderFixCommand, renderRootCheckCommand, } from "../../src/module-graph.js";
7
- import { projectCheckWorkflow, projectDependabotConfig, } from "../../src/project-github.js";
8
+ import { PackageAdditionSupport } from "../../src/package-addition-support.js";
8
9
  import { renderNewProject } from "../../src/renderer.js";
9
10
  const generatedBy = {
10
11
  packageName: "@ykdz/template",
@@ -14,10 +15,11 @@ const generatedBy = {
14
15
  export const rustBinPresetMetadata = {
15
16
  name: "rust-bin",
16
17
  title: "Rust binary",
17
- description: "Single-package Rust native binary with rustfmt, clippy, and cargo tests.",
18
+ description: "Rust native binary workspace with rustfmt, clippy, and cargo tests.",
18
19
  generation: "supported",
19
20
  supportedPackageManagers: ["pnpm"],
20
- supportedProjectKinds: ["single-package"],
21
+ supportedProjectKinds: ["multi-package"],
22
+ packageAdditionSupport: PackageAdditionSupport.Unsupported,
21
23
  features: [
22
24
  "root-check",
23
25
  "fix-command",
@@ -28,14 +30,14 @@ export const rustBinPresetMetadata = {
28
30
  "cargo-test",
29
31
  ],
30
32
  };
31
- const dependencyMaintenancePolicy = {
32
- ecosystems: ["npm", "cargo", "github-actions"],
33
- interval: "weekly",
34
- };
35
33
  const rustPackageBoundary = {
36
34
  kind: "package-boundary",
37
35
  path: ".",
38
36
  };
37
+ const rustWorkspacePackageBoundary = {
38
+ kind: "package-boundary",
39
+ path: "packages/*",
40
+ };
39
41
  function cargoPackageNameFromProjectName(projectName) {
40
42
  const slug = projectName
41
43
  .normalize("NFKD")
@@ -45,6 +47,24 @@ function cargoPackageNameFromProjectName(projectName) {
45
47
  .replace(/^-+|-+$/g, "");
46
48
  return slug || "rust-bin";
47
49
  }
50
+ function projectNameFromDir(targetDir) {
51
+ return path.basename(path.resolve(targetDir));
52
+ }
53
+ function rustWorkspacePackageName(projectName) {
54
+ return `${cargoPackageNameFromProjectName(projectName)}-native`;
55
+ }
56
+ function rustWorkspacePackagePath(projectName) {
57
+ return `packages/${cargoPackageNameFromProjectName(projectName)}`;
58
+ }
59
+ function rustDependencyMaintenancePolicy(projectName) {
60
+ return {
61
+ ecosystems: ["npm", "cargo", "github-actions", "docker", "rust-toolchain"],
62
+ directories: {
63
+ cargo: `/${rustWorkspacePackagePath(projectName)}`,
64
+ },
65
+ interval: "weekly",
66
+ };
67
+ }
48
68
  export function planRustBinChecks() {
49
69
  return {
50
70
  components: [
@@ -55,18 +75,40 @@ export function planRustBinChecks() {
55
75
  environmentNeeds: [],
56
76
  };
57
77
  }
78
+ function planRustBinRootChecks() {
79
+ return {
80
+ components: [
81
+ { kind: "turbo-package-check", owner: rustWorkspacePackageBoundary },
82
+ ],
83
+ environmentNeeds: [],
84
+ };
85
+ }
58
86
  export function planRustBinFixes() {
59
87
  return {
60
88
  components: [{ kind: "rustfmt-write", owner: rustPackageBoundary }],
61
89
  };
62
90
  }
63
- export function rustBinBlueprint() {
91
+ function planRustBinRootFixes() {
92
+ return {
93
+ components: [
94
+ { kind: "turbo-package-fix", owner: rustWorkspacePackageBoundary },
95
+ ],
96
+ };
97
+ }
98
+ export function rustBinBlueprint(options = { targetDir: process.cwd() }) {
99
+ const projectName = projectNameFromDir(options.targetDir);
64
100
  return {
65
101
  schemaVersion: 1,
66
102
  preset: "rust-bin",
67
103
  packageManager: "pnpm",
68
- projectKind: "single-package",
104
+ projectKind: "multi-package",
69
105
  features: [...rustBinPresetMetadata.features],
106
+ packages: [
107
+ {
108
+ name: rustWorkspacePackageName(projectName),
109
+ path: rustWorkspacePackagePath(projectName),
110
+ },
111
+ ],
70
112
  };
71
113
  }
72
114
  export function projectRustBinPackageScripts() {
@@ -75,6 +117,12 @@ export function projectRustBinPackageScripts() {
75
117
  fix: renderFixCommand(planRustBinFixes()),
76
118
  };
77
119
  }
120
+ function projectRustBinRootPackageScripts() {
121
+ return {
122
+ check: renderRootCheckCommand(planRustBinRootChecks()),
123
+ fix: renderFixCommand(planRustBinRootFixes()),
124
+ };
125
+ }
78
126
  function cargoToml(projectName) {
79
127
  return [
80
128
  "[package]",
@@ -124,12 +172,26 @@ function packageJson(context, projectName, packageScripts) {
124
172
  version: "0.0.0",
125
173
  private: true,
126
174
  scripts: packageScripts,
175
+ devDependencies: {
176
+ turbo: "catalog:",
177
+ },
127
178
  engines: {
128
179
  node: context.toolchain.nodeLtsMajor.value,
129
180
  },
130
181
  packageManager: context.toolchain.packageManagerPin.value,
131
182
  };
132
183
  }
184
+ function rustWorkspacePackageJson(context, projectName) {
185
+ return {
186
+ name: rustWorkspacePackageName(projectName),
187
+ version: "0.0.0",
188
+ private: true,
189
+ scripts: projectRustBinPackageScripts(),
190
+ engines: {
191
+ node: context.toolchain.nodeLtsMajor.value,
192
+ },
193
+ };
194
+ }
133
195
  function generationRecord(context) {
134
196
  return {
135
197
  ...generatedBy,
@@ -140,78 +202,121 @@ function generationRecord(context) {
140
202
  },
141
203
  };
142
204
  }
143
- function operationsForRustBin(context, projectName, packageScripts, checkPlan) {
205
+ function operationsForRustBin(context, devcontainerName, projectName, packageScripts, checkPlan) {
144
206
  const editorCustomization = editorCustomizationForCapabilities([
145
207
  "rust-tooling",
146
208
  ]);
209
+ const rustLayer = rustToolLayer();
210
+ const developmentContainer = dockerfileFirstRustPnpmDevcontainer({
211
+ name: devcontainerName,
212
+ nodeLayer: nodePnpmToolLayer({
213
+ nodeVersion: context.toolchain.nodeLtsMajor.value,
214
+ packageManagerPin: context.toolchain.packageManagerPin.value,
215
+ }),
216
+ rustLayer,
217
+ extensions: editorCustomization.extensions,
218
+ settings: editorCustomization.settings,
219
+ });
220
+ const dockerfileOperation = developmentContainer.dockerfileOperation;
221
+ if (dockerfileOperation === undefined) {
222
+ throw new Error("Rust Development Container Dockerfile must use fragments.");
223
+ }
224
+ const workspacePackagePath = rustWorkspacePackagePath(projectName);
225
+ const rootManifest = packageJson(context, projectName, packageScripts);
226
+ const packageManifest = rustWorkspacePackageJson(context, projectName);
227
+ const dependencyMaintenancePolicy = rustDependencyMaintenancePolicy(projectName);
147
228
  return [
148
229
  {
149
230
  kind: "writeJson",
150
231
  to: "package.json",
151
- value: packageJson(context, projectName, packageScripts),
232
+ value: rootManifest,
152
233
  },
153
234
  {
154
235
  kind: "writeText",
155
236
  to: "pnpm-workspace.yaml",
156
- text: ["packages:", " - .", ""].join("\n"),
237
+ text: renderGeneratedPnpmWorkspaceYaml({
238
+ packages: ["packages/*"],
239
+ dependencies: collectGeneratedManifestCatalogDependencies([
240
+ rootManifest,
241
+ packageManifest,
242
+ ]),
243
+ }),
244
+ },
245
+ {
246
+ kind: "writeJson",
247
+ to: "turbo.json",
248
+ value: {
249
+ tasks: {
250
+ check: {},
251
+ fix: {
252
+ cache: false,
253
+ },
254
+ },
255
+ },
256
+ },
257
+ {
258
+ kind: "writeJson",
259
+ to: `${workspacePackagePath}/package.json`,
260
+ value: packageManifest,
157
261
  },
158
262
  {
159
263
  kind: "writeText",
160
- to: "Cargo.toml",
264
+ to: `${workspacePackagePath}/Cargo.toml`,
161
265
  text: cargoToml(projectName),
162
266
  },
163
267
  {
164
268
  kind: "writeText",
165
- to: "Cargo.lock",
269
+ to: `${workspacePackagePath}/Cargo.lock`,
166
270
  text: cargoLock(projectName),
167
271
  },
168
272
  {
169
- kind: "writeText",
170
- to: "rustfmt.toml",
171
- text: ['edition = "2024"', "max_width = 100", ""].join("\n"),
273
+ kind: "copyFile",
274
+ from: "rustfmt.toml",
275
+ to: `${workspacePackagePath}/rustfmt.toml`,
276
+ },
277
+ {
278
+ kind: "writeTextTemplate",
279
+ from: "rust-toolchain.toml",
280
+ to: "rust-toolchain.toml",
281
+ replacements: {
282
+ RUST_TOOLCHAIN: rustLayer.toolchain,
283
+ },
172
284
  },
173
285
  {
174
286
  kind: "writeText",
175
287
  to: ".gitignore",
176
- text: ["target", ".env", ""].join("\n"),
288
+ text: [
289
+ "target",
290
+ "node_modules",
291
+ "dist",
292
+ ".env",
293
+ ".template/",
294
+ ".pnpm-store/",
295
+ "",
296
+ ].join("\n"),
177
297
  },
178
298
  {
179
299
  kind: "copyFile",
180
300
  from: "src/main.rs",
181
- to: "src/main.rs",
301
+ to: `${workspacePackagePath}/src/main.rs`,
182
302
  },
183
303
  {
184
304
  kind: "writeJson",
185
- to: ".project-kit/blueprint.json",
186
- value: rustBinBlueprint(),
305
+ to: ".template/blueprint.json",
306
+ value: context.blueprint,
187
307
  },
188
308
  {
189
309
  kind: "writeJson",
190
- to: ".project-kit/generated-by.json",
310
+ to: ".template/generated-by.json",
191
311
  value: generationRecord(context),
192
312
  },
193
313
  {
194
314
  kind: "writeJson",
195
315
  to: ".devcontainer/devcontainer.json",
196
- value: {
197
- name: `${projectName} Rust development`,
198
- image: "mcr.microsoft.com/devcontainers/rust:1",
199
- features: devcontainerNodeFeature({
200
- nodeVersion: context.toolchain.nodeLtsMajor.value,
201
- packageManagerPin: context.toolchain.packageManagerPin.value,
202
- }),
203
- mounts: [
204
- "source=${localWorkspaceFolderBasename}-cargo-registry,target=/usr/local/cargo/registry,type=volume",
205
- "source=${localWorkspaceFolderBasename}-cargo-git,target=/usr/local/cargo/git,type=volume",
206
- "source=${localWorkspaceFolderBasename}-target,target=${containerWorkspaceFolder}/target,type=volume",
207
- ],
208
- customizations: {
209
- vscode: {
210
- extensions: editorCustomization.extensions,
211
- settings: editorCustomization.settings,
212
- },
213
- },
214
- },
316
+ value: developmentContainer.devcontainer,
317
+ },
318
+ {
319
+ ...dockerfileOperation,
215
320
  },
216
321
  {
217
322
  kind: "writeJson",
@@ -226,17 +331,18 @@ function operationsForRustBin(context, projectName, packageScripts, checkPlan) {
226
331
  value: editorCustomization.settings,
227
332
  },
228
333
  {
229
- kind: "writeText",
334
+ kind: "copyFile",
335
+ from: ".github/workflows/check.yml",
230
336
  to: ".github/workflows/check.yml",
231
- text: projectCheckWorkflow({
232
- checkPlan,
233
- environmentPreparation: { rustToolchain: true },
234
- }),
235
337
  },
236
338
  {
237
- kind: "writeText",
339
+ kind: "writeTextTemplate",
340
+ from: ".github/dependabot.yml",
238
341
  to: ".github/dependabot.yml",
239
- text: projectDependabotConfig(dependencyMaintenancePolicy),
342
+ replacements: {
343
+ CARGO_PACKAGE_DIRECTORY: dependencyMaintenancePolicy.directories?.cargo ??
344
+ `/${workspacePackagePath}`,
345
+ },
240
346
  },
241
347
  ];
242
348
  }
@@ -247,17 +353,29 @@ function templateSourceRoot() {
247
353
  ? publishedTemplateRoot
248
354
  : projectionDir;
249
355
  }
356
+ function sharedDevcontainerSourceRoot() {
357
+ const projectionDir = path.dirname(fileURLToPath(import.meta.url));
358
+ const publishedSharedRoot = path.join(projectionDir, "..", "..", "..", "templates", "shared", "devcontainer");
359
+ return existsSync(path.join(publishedSharedRoot, "node-pnpm.Dockerfile"))
360
+ ? publishedSharedRoot
361
+ : path.join(projectionDir, "..", "shared", "devcontainer");
362
+ }
250
363
  export const rustBinPresetProjection = {
251
364
  metadata: rustBinPresetMetadata,
252
365
  blueprint: rustBinBlueprint,
253
366
  project(context) {
254
- const checkPlan = planRustBinChecks();
255
- const fixPlan = planRustBinFixes();
256
- const packageScripts = projectRustBinPackageScripts();
367
+ const checkPlan = planRustBinRootChecks();
368
+ const fixPlan = planRustBinRootFixes();
369
+ const packageScripts = projectRustBinRootPackageScripts();
257
370
  const projectName = cargoPackageNameFromProjectName(context.projectName.value);
371
+ const devcontainerName = context.projectName.value;
372
+ const dependencyMaintenancePolicy = rustDependencyMaintenancePolicy(projectName);
258
373
  return {
259
374
  sourceRoot: templateSourceRoot(),
260
- operations: operationsForRustBin(context, projectName, packageScripts, checkPlan),
375
+ sourceRoots: {
376
+ sharedDevcontainer: sharedDevcontainerSourceRoot(),
377
+ },
378
+ operations: operationsForRustBin(context, devcontainerName, projectName, packageScripts, checkPlan),
261
379
  checkPlan,
262
380
  fixPlan,
263
381
  dependencyMaintenancePolicy,
@@ -1,7 +1,6 @@
1
1
  import type { BuiltInPreset, ProjectBlueprint } from "../../src/declarations.js";
2
- import type { PresetProjection } from "../../src/preset-projection.js";
2
+ import type { PresetBlueprintOptions, PresetProjection } from "../../src/preset-projection.js";
3
3
  export declare const tsLibPresetMetadata: BuiltInPreset;
4
- export declare function tsLibBlueprint(): ProjectBlueprint;
4
+ export declare function tsLibBlueprint(options?: PresetBlueprintOptions): ProjectBlueprint;
5
5
  export declare function projectTsLibPackageScripts(): Record<string, string>;
6
6
  export declare const tsLibPresetProjection: PresetProjection;
7
- //# sourceMappingURL=projection.d.ts.map