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