@jskit-ai/jskit-cli 0.2.31 → 0.2.33

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/jskit-cli",
3
- "version": "0.2.31",
3
+ "version": "0.2.33",
4
4
  "description": "Bundle and package orchestration CLI for JSKIT apps.",
5
5
  "type": "module",
6
6
  "files": [
@@ -20,8 +20,8 @@
20
20
  "test": "node --test"
21
21
  },
22
22
  "dependencies": {
23
- "@jskit-ai/jskit-catalog": "0.1.31",
24
- "@jskit-ai/kernel": "0.1.23"
23
+ "@jskit-ai/jskit-catalog": "0.1.33",
24
+ "@jskit-ai/kernel": "0.1.25"
25
25
  },
26
26
  "engines": {
27
27
  "node": "20.x"
@@ -95,6 +95,76 @@ function normalizeSubcommandOptionNames(rawOptionNames = []) {
95
95
  return rows;
96
96
  }
97
97
 
98
+ function normalizeHelpExampleRows(rawRows = []) {
99
+ const rows = [];
100
+
101
+ for (const rawRow of ensureArray(rawRows)) {
102
+ if (typeof rawRow === "string") {
103
+ const lines = String(rawRow)
104
+ .split(/\r?\n/u)
105
+ .map((value) => value.replace(/[ \t]+$/u, ""))
106
+ .filter((value) => value.trim().length > 0);
107
+ if (lines.length < 1) {
108
+ continue;
109
+ }
110
+ rows.push(Object.freeze({
111
+ label: "",
112
+ lines
113
+ }));
114
+ continue;
115
+ }
116
+
117
+ const row = ensureObject(rawRow);
118
+ const label = String(row.label || "").trim();
119
+ const commandLines = String(row.command || "")
120
+ .split(/\r?\n/u)
121
+ .map((value) => value.replace(/[ \t]+$/u, ""))
122
+ .filter((value) => value.trim().length > 0);
123
+ const explicitLines = ensureArray(row.lines)
124
+ .map((value) => String(value || "").replace(/[ \t]+$/u, ""))
125
+ .filter((value) => value.trim().length > 0);
126
+ const lines = explicitLines.length > 0 ? explicitLines : commandLines;
127
+ if (lines.length < 1) {
128
+ continue;
129
+ }
130
+ rows.push(Object.freeze({
131
+ label,
132
+ lines
133
+ }));
134
+ }
135
+
136
+ return rows;
137
+ }
138
+
139
+ function appendHelpExamples(lines = [], exampleRows = []) {
140
+ const examples = ensureArray(exampleRows);
141
+ if (examples.length < 1) {
142
+ return;
143
+ }
144
+
145
+ lines.push("");
146
+ lines.push(`Examples (${examples.length}):`);
147
+ for (const example of examples) {
148
+ const label = String(example?.label || "").trim();
149
+ if (label) {
150
+ lines.push(`- ${label}`);
151
+ for (const commandLine of ensureArray(example?.lines)) {
152
+ lines.push(` ${commandLine}`);
153
+ }
154
+ continue;
155
+ }
156
+
157
+ const commandLines = ensureArray(example?.lines);
158
+ if (commandLines.length < 1) {
159
+ continue;
160
+ }
161
+ lines.push(`- ${commandLines[0]}`);
162
+ for (const commandLine of commandLines.slice(1)) {
163
+ lines.push(` ${commandLine}`);
164
+ }
165
+ }
166
+ }
167
+
98
168
  function resolveGeneratorSubcommandMetadata(packageEntry = {}) {
99
169
  const descriptor = ensureObject(packageEntry?.descriptor);
100
170
  const metadata = ensureObject(descriptor.metadata);
@@ -126,7 +196,8 @@ function resolveGeneratorSubcommandMetadata(packageEntry = {}) {
126
196
  description: String(definition.description || "").trim(),
127
197
  positionalArgs: normalizeSubcommandPositionalArgRows(definition.positionalArgs),
128
198
  optionNames,
129
- requiredOptionNames
199
+ requiredOptionNames,
200
+ examples: normalizeHelpExampleRows(definition.examples)
130
201
  }));
131
202
  }
132
203
 
@@ -359,6 +430,7 @@ function renderGeneratePackageHelp({
359
430
  const summary = resolvePackageSummary(packageEntry);
360
431
  const optionRows = buildPackageOptionRows(packageEntry);
361
432
  const generatorMetadata = resolveGeneratorSubcommandMetadata(packageEntry);
433
+ const primarySubcommandRow = ensureArray(generatorMetadata.subcommands).find((row) => row.primary) || null;
362
434
  const preferredId = toShortPackageId(packageId) || packageId;
363
435
  const usage = Object.freeze([
364
436
  `jskit generate ${preferredId} help`,
@@ -380,6 +452,7 @@ function renderGeneratePackageHelp({
380
452
  usage,
381
453
  primarySubcommand: generatorMetadata.primarySubcommand || "",
382
454
  subcommands: generatorMetadata.subcommands,
455
+ primarySubcommandExamples: ensureArray(primarySubcommandRow?.examples),
383
456
  options: optionRows
384
457
  }, null, 2)}\n`);
385
458
  return;
@@ -409,9 +482,10 @@ function renderGeneratePackageHelp({
409
482
  lines.push(`- ${subcommand.name}${primarySuffix}${descriptionSuffix}`);
410
483
  }
411
484
  lines.push("- Use subcommand help for details: jskit generate <generatorId> <subcommand> help");
412
- lines.push("");
413
485
  }
414
486
 
487
+ appendHelpExamples(lines, primarySubcommandRow?.examples);
488
+ lines.push("");
415
489
  lines.push(`Options (${optionRows.length}):`);
416
490
  if (optionRows.length > 0) {
417
491
  for (const optionRow of optionRows) {
@@ -478,6 +552,7 @@ function renderGenerateSubcommandHelp({
478
552
  primary: subcommandRow.primary,
479
553
  description: effectiveDescription,
480
554
  positionalArgs,
555
+ examples: ensureArray(subcommandRow.examples),
481
556
  options: subcommandOptionRows
482
557
  },
483
558
  usage
@@ -520,6 +595,7 @@ function renderGenerateSubcommandHelp({
520
595
  } else {
521
596
  lines.push("- No inline options.");
522
597
  }
598
+ appendHelpExamples(lines, subcommandRow.examples);
523
599
  if (hasRequiredWithDefaults) {
524
600
  lines.push("");
525
601
  lines.push("Note: required options with defaults are auto-filled when omitted.");