@kidd-cli/cli 0.1.4 → 0.2.0

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.
@@ -41,7 +41,8 @@ const buildCommand = command({
41
41
  ctx.logger.note(formatBuildNote({
42
42
  cwd,
43
43
  entryFile: buildOutput.entryFile,
44
- outDir: buildOutput.outDir
44
+ outDir: buildOutput.outDir,
45
+ version: buildOutput.version
45
46
  }), "Bundle");
46
47
  return;
47
48
  }
@@ -63,7 +64,8 @@ const buildCommand = command({
63
64
  ctx.logger.note(formatBuildNote({
64
65
  cwd,
65
66
  entryFile: buildOutput.entryFile,
66
- outDir: buildOutput.outDir
67
+ outDir: buildOutput.outDir,
68
+ version: buildOutput.version
67
69
  }), "Bundle");
68
70
  ctx.logger.note(formatBinariesNote({
69
71
  binaries: compileOutput.binaries,
@@ -133,7 +135,22 @@ function resolveExistingCompile(value) {
133
135
  * @returns A formatted string with entry and output directory.
134
136
  */
135
137
  function formatBuildNote(params) {
136
- return [`entry ${relative(params.cwd, params.entryFile)}`, `output ${relative(params.cwd, params.outDir)}`].join("\n");
138
+ return [
139
+ `entry ${relative(params.cwd, params.entryFile)}`,
140
+ `output ${relative(params.cwd, params.outDir)}`,
141
+ ...formatVersionLine(params.version)
142
+ ].join("\n");
143
+ }
144
+ /**
145
+ * Format a version line for the build note, if a version is available.
146
+ *
147
+ * @private
148
+ * @param version - The version string, or undefined.
149
+ * @returns A single-element array with the formatted line, or an empty array.
150
+ */
151
+ function formatVersionLine(version) {
152
+ if (!version) return [];
153
+ return [`version ${version}`];
137
154
  }
138
155
  /**
139
156
  * Format compiled binaries into an aligned, multi-line string for display.
@@ -43,21 +43,79 @@ async function resolveSubcommands(commands) {
43
43
  /**
44
44
  * Recursively build a sorted tree of entries from a CommandMap.
45
45
  *
46
+ * Commands listed in the order array appear first in the specified order;
47
+ * omitted commands fall back to alphabetical sort.
48
+ *
46
49
  * @private
47
50
  * @param commandMap - The map of command names to Command objects.
51
+ * @param order - Optional array of command names defining display order.
48
52
  * @returns A sorted array of TreeEntry nodes.
49
53
  */
50
- async function buildTree(commandMap) {
51
- const entries = Object.entries(commandMap).toSorted(([a], [b]) => a.localeCompare(b));
54
+ async function buildTree(commandMap, order) {
55
+ const entries = sortEntries({
56
+ entries: Object.entries(commandMap),
57
+ order
58
+ });
52
59
  return Promise.all(entries.map(async ([name, cmd]) => {
53
60
  return {
54
- children: await buildTree(await resolveSubcommands(cmd.commands)),
61
+ children: await buildTree(await resolveSubcommands(cmd.commands), cmd.order),
55
62
  description: cmd.description ?? "",
56
63
  name
57
64
  };
58
65
  }));
59
66
  }
60
67
  /**
68
+ * Sort command entries with ordered names first (in specified order),
69
+ * remaining names alphabetically.
70
+ *
71
+ * Validates the order array against available command names and logs a
72
+ * warning for unknown or duplicate entries rather than failing silently.
73
+ *
74
+ * @private
75
+ * @param params - The command entries and optional order array.
76
+ * @returns Sorted array of entries.
77
+ */
78
+ function sortEntries(params) {
79
+ const { entries, order } = params;
80
+ if (!order || order.length === 0) return entries.toSorted(([a], [b]) => a.localeCompare(b));
81
+ const validOrder = validateOrder({
82
+ commandNames: entries.map(([name]) => name),
83
+ order
84
+ });
85
+ const entryMap = new Map(entries);
86
+ const orderedSet = new Set(validOrder);
87
+ const ordered = validOrder.filter((name) => entryMap.has(name)).map((name) => [name, entryMap.get(name)]);
88
+ const remaining = entries.filter(([name]) => !orderedSet.has(name)).toSorted(([a], [b]) => a.localeCompare(b));
89
+ return [...ordered, ...remaining];
90
+ }
91
+ /**
92
+ * Validate the order array by filtering out unknown and duplicate names.
93
+ *
94
+ * Logs warnings for invalid entries so developers see the mismatch
95
+ * during `kidd commands` introspection, matching the runtime behaviour.
96
+ *
97
+ * @private
98
+ * @param params - The order array and available command names.
99
+ * @returns A deduplicated array of valid order names.
100
+ */
101
+ function validateOrder(params) {
102
+ const { commandNames, order } = params;
103
+ const nameSet = new Set(commandNames);
104
+ const seen = /* @__PURE__ */ new Set();
105
+ return order.filter((name) => {
106
+ if (seen.has(name)) {
107
+ console.warn(`Warning: duplicate command name "${name}" in order array`);
108
+ return false;
109
+ }
110
+ seen.add(name);
111
+ if (!nameSet.has(name)) {
112
+ console.warn(`Warning: unknown command "${name}" in order array`);
113
+ return false;
114
+ }
115
+ return true;
116
+ });
117
+ }
118
+ /**
61
119
  * Render a tree of entries into an ASCII tree string.
62
120
  *
63
121
  * @private
package/dist/index.mjs CHANGED
@@ -31,6 +31,7 @@ const manifest = await loadCLIManifest(import.meta.dirname);
31
31
  await cli({
32
32
  commands: `${import.meta.dirname}/commands`,
33
33
  description: manifest.description,
34
+ help: { header: `${manifest.name} v${manifest.version}` },
34
35
  name: manifest.name,
35
36
  version: manifest.version
36
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidd-cli/cli",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "DX companion CLI for the kidd framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -26,10 +26,10 @@
26
26
  "liquidjs": "^10.25.0",
27
27
  "picocolors": "^1.1.1",
28
28
  "zod": "^4.3.6",
29
- "@kidd-cli/bundler": "0.1.3",
30
- "@kidd-cli/config": "0.1.3",
31
- "@kidd-cli/core": "0.3.0",
32
- "@kidd-cli/utils": "0.1.3"
29
+ "@kidd-cli/bundler": "0.2.0",
30
+ "@kidd-cli/config": "0.1.4",
31
+ "@kidd-cli/core": "0.4.0",
32
+ "@kidd-cli/utils": "0.1.4"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/fs-extra": "^11.0.4",