@kidd-cli/cli 0.3.0 → 0.3.1

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.
@@ -5,24 +5,89 @@ import { command } from "@kidd-cli/core";
5
5
  import { dirname, join } from "node:path";
6
6
  import { readManifest } from "@kidd-cli/utils/manifest";
7
7
  import { z } from "zod";
8
- import { attempt } from "@kidd-cli/utils/fp";
9
- //#region src/generated/template-versions.ts
8
+ import { existsSync, readFileSync } from "node:fs";
9
+ import { attempt, err, match, ok } from "@kidd-cli/utils/fp";
10
+ import { parse } from "yaml";
11
+ //#region src/lib/template-versions.ts
10
12
  /**
11
- * Zod version from the workspace catalog.
13
+ * Zod schema for the `catalog` field in `pnpm-workspace.yaml`.
14
+ *
15
+ * @private
16
+ */
17
+ const catalogSchema = z.object({ catalog: z.object({
18
+ tsdown: z.string(),
19
+ typescript: z.string(),
20
+ vitest: z.string(),
21
+ zod: z.string()
22
+ }) });
23
+ /**
24
+ * Known locations for `pnpm-workspace.yaml` relative to this module.
25
+ *
26
+ * - First path covers the built `dist/` layout (yaml copied to `dist/`).
27
+ * - Second path covers running from source `src/lib/` during development.
28
+ *
29
+ * @private
30
+ */
31
+ const CANDIDATE_PATHS = [join(import.meta.dirname, "..", "pnpm-workspace.yaml"), join(import.meta.dirname, "..", "..", "..", "..", "pnpm-workspace.yaml")];
32
+ /**
33
+ * Locate `pnpm-workspace.yaml` by checking known candidate paths.
34
+ *
35
+ * @returns The resolved path, or `null` when no candidate exists.
36
+ * @private
12
37
  */
13
- const ZOD_VERSION = "^4.3.6";
38
+ function findWorkspaceYaml() {
39
+ return CANDIDATE_PATHS.find(existsSync) ?? null;
40
+ }
14
41
  /**
15
- * TypeScript version from the workspace catalog.
42
+ * Range operator prefixes recognized in version strings.
43
+ *
44
+ * @private
16
45
  */
17
- const TYPESCRIPT_VERSION = "^5.9.3";
46
+ const RANGE_PREFIXES = [
47
+ "^",
48
+ "~",
49
+ ">",
50
+ "<",
51
+ "="
52
+ ];
18
53
  /**
19
- * Vitest version from the workspace catalog.
54
+ * Normalize a version string to always include a caret range prefix.
55
+ *
56
+ * If the version already starts with a range operator (`^`, `~`, `>`, `<`, `=`)
57
+ * it is returned as-is. Otherwise a `^` prefix is added.
58
+ *
59
+ * @param version - The raw version string from the catalog.
60
+ * @returns The version prefixed with `^` when no range operator is present.
20
61
  */
21
- const VITEST_VERSION = "^4.0.18";
62
+ function normalizeVersion(version) {
63
+ return match(RANGE_PREFIXES.some((prefix) => version.startsWith(prefix))).with(true, () => version).with(false, () => `^${version}`).exhaustive();
64
+ }
22
65
  /**
23
- * Tsdown version from the workspace catalog.
66
+ * Read template dependency versions from the workspace catalog (`pnpm-workspace.yaml`).
67
+ *
68
+ * Resolves the workspace file from known relative locations, parses the YAML,
69
+ * validates the structure with Zod, and returns normalized version strings
70
+ * suitable for scaffolding `package.json` files in new projects.
71
+ *
72
+ * @returns A `Result` tuple with the resolved versions or an error.
24
73
  */
25
- const TSDOWN_VERSION = "^0.21.1";
74
+ function readTemplateVersions() {
75
+ const yamlPath = findWorkspaceYaml();
76
+ if (yamlPath === null) return err(/* @__PURE__ */ new Error("Could not locate pnpm-workspace.yaml"));
77
+ const [readError, content] = attempt(() => readFileSync(yamlPath, "utf8"));
78
+ if (readError) return err(readError);
79
+ const [parseError, rawParsed] = attempt(() => parse(content));
80
+ if (parseError) return err(parseError);
81
+ const validation = catalogSchema.safeParse(rawParsed);
82
+ if (!validation.success) return err(/* @__PURE__ */ new Error(`Invalid pnpm-workspace.yaml catalog: ${validation.error.message}`));
83
+ const { catalog } = validation.data;
84
+ return ok(Object.freeze({
85
+ tsdownVersion: normalizeVersion(catalog.tsdown),
86
+ typescriptVersion: normalizeVersion(catalog.typescript),
87
+ vitestVersion: normalizeVersion(catalog.vitest),
88
+ zodVersion: normalizeVersion(catalog.zod)
89
+ }));
90
+ }
26
91
  //#endregion
27
92
  //#region src/commands/init.ts
28
93
  const initCommand = command({
@@ -45,6 +110,11 @@ const initCommand = command({
45
110
  const includeExample = await resolveIncludeExample(ctx);
46
111
  const includeConfig = await resolveIncludeConfig(ctx);
47
112
  ctx.spinner.start("Scaffolding project...");
113
+ const [versionsError, templateVersions] = readTemplateVersions();
114
+ if (versionsError) {
115
+ ctx.spinner.stop("Failed");
116
+ return ctx.fail(versionsError.message);
117
+ }
48
118
  const coreVersion = await resolveDependencyVersion("@kidd-cli/core");
49
119
  const cliVersion = await resolveSelfVersion();
50
120
  const [renderError, rendered] = await renderTemplate({
@@ -56,10 +126,7 @@ const initCommand = command({
56
126
  includeConfig,
57
127
  name: projectName,
58
128
  packageManager,
59
- tsdownVersion: TSDOWN_VERSION,
60
- typescriptVersion: TYPESCRIPT_VERSION,
61
- vitestVersion: VITEST_VERSION,
62
- zodVersion: ZOD_VERSION
129
+ ...templateVersions
63
130
  }
64
131
  });
65
132
  if (renderError) {
@@ -0,0 +1,15 @@
1
+ packages:
2
+ - packages/*
3
+ - examples/*
4
+
5
+ catalog:
6
+ '@types/node': ^25.5.0
7
+ '@vitest/coverage-v8': ^4.1.0
8
+ es-toolkit: ^1.45.1
9
+ liquidjs: ^10.25.0
10
+ ts-pattern: ^5.9.0
11
+ tsdown: 0.21.3
12
+ tsx: ^4.21.0
13
+ typescript: ^5.9.3
14
+ vitest: ^4.1.0
15
+ zod: ^4.3.6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidd-cli/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "DX companion CLI for the kidd framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -25,21 +25,21 @@
25
25
  "fs-extra": "^11.3.4",
26
26
  "liquidjs": "^10.25.0",
27
27
  "picocolors": "^1.1.1",
28
+ "yaml": "^2.8.2",
28
29
  "zod": "^4.3.6",
29
- "@kidd-cli/bundler": "0.2.0",
30
- "@kidd-cli/config": "0.1.4",
31
- "@kidd-cli/utils": "0.1.4",
32
- "@kidd-cli/core": "0.5.0"
30
+ "@kidd-cli/bundler": "0.2.1",
31
+ "@kidd-cli/config": "0.1.5",
32
+ "@kidd-cli/core": "0.5.1",
33
+ "@kidd-cli/utils": "0.1.4"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/fs-extra": "^11.0.4",
36
- "tsdown": "0.21.1",
37
+ "tsdown": "0.21.3",
37
38
  "typescript": "^5.9.3",
38
- "vitest": "^4.0.18",
39
- "yaml": "^2.8.0"
39
+ "vitest": "^4.1.0"
40
40
  },
41
41
  "scripts": {
42
- "build": "tsdown && mkdir -p dist/lib && cp -r src/lib/templates dist/lib/templates",
42
+ "build": "tsdown && mkdir -p dist/lib && cp -r src/lib/templates dist/lib/templates && cp ../../pnpm-workspace.yaml dist/pnpm-workspace.yaml",
43
43
  "typecheck": "tsgo --noEmit",
44
44
  "lint": "oxlint --ignore-pattern node_modules",
45
45
  "lint:fix": "oxlint --fix --ignore-pattern node_modules",