@atlaskit/ads-cli 0.1.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.
- package/CHANGELOG.md +34 -0
- package/README.md +134 -0
- package/bin/ads-cli.js +40 -0
- package/compass.yml +25 -0
- package/dist/cjs/cli.js +488 -0
- package/dist/cjs/commands/definitions.js +713 -0
- package/dist/cjs/commands/get-command.js +19 -0
- package/dist/cjs/commands/import-tool-handler.js +57 -0
- package/dist/cjs/commands/run-tool.js +106 -0
- package/dist/cjs/commands/types.js +1 -0
- package/dist/cjs/envelope/create-error-envelope.js +27 -0
- package/dist/cjs/envelope/create-success-envelope.js +38 -0
- package/dist/cjs/envelope/types.js +1 -0
- package/dist/cjs/output/disambiguation.js +31 -0
- package/dist/cjs/output/format-component.js +99 -0
- package/dist/cjs/output/format-disambiguation.js +29 -0
- package/dist/cjs/output/format-doc-object.js +115 -0
- package/dist/cjs/output/format-grouped-results.js +55 -0
- package/dist/cjs/output/format-icon.js +49 -0
- package/dist/cjs/output/format-lint-rules.js +52 -0
- package/dist/cjs/output/format-results.js +158 -0
- package/dist/cjs/output/format-token.js +39 -0
- package/dist/cjs/output/parse-lint-rule-records.js +47 -0
- package/dist/cjs/output/write-human-error.js +20 -0
- package/dist/cjs/output/write-human-result.js +31 -0
- package/dist/cjs/output/write-json-envelope.js +20 -0
- package/dist/cjs/output/writer.js +32 -0
- package/dist/cjs/parse-args.js +106 -0
- package/dist/cjs/types.js +53 -0
- package/dist/es2019/cli.js +406 -0
- package/dist/es2019/commands/definitions.js +683 -0
- package/dist/es2019/commands/get-command.js +9 -0
- package/dist/es2019/commands/import-tool-handler.js +22 -0
- package/dist/es2019/commands/run-tool.js +73 -0
- package/dist/es2019/commands/types.js +0 -0
- package/dist/es2019/envelope/create-error-envelope.js +20 -0
- package/dist/es2019/envelope/create-success-envelope.js +31 -0
- package/dist/es2019/envelope/types.js +0 -0
- package/dist/es2019/output/disambiguation.js +21 -0
- package/dist/es2019/output/format-component.js +88 -0
- package/dist/es2019/output/format-disambiguation.js +22 -0
- package/dist/es2019/output/format-doc-object.js +94 -0
- package/dist/es2019/output/format-grouped-results.js +51 -0
- package/dist/es2019/output/format-icon.js +39 -0
- package/dist/es2019/output/format-lint-rules.js +43 -0
- package/dist/es2019/output/format-results.js +142 -0
- package/dist/es2019/output/format-token.js +31 -0
- package/dist/es2019/output/parse-lint-rule-records.js +41 -0
- package/dist/es2019/output/write-human-error.js +14 -0
- package/dist/es2019/output/write-human-result.js +25 -0
- package/dist/es2019/output/write-json-envelope.js +15 -0
- package/dist/es2019/output/writer.js +22 -0
- package/dist/es2019/parse-args.js +100 -0
- package/dist/es2019/types.js +47 -0
- package/dist/esm/cli.js +484 -0
- package/dist/esm/commands/definitions.js +708 -0
- package/dist/esm/commands/get-command.js +13 -0
- package/dist/esm/commands/import-tool-handler.js +42 -0
- package/dist/esm/commands/run-tool.js +99 -0
- package/dist/esm/commands/types.js +0 -0
- package/dist/esm/envelope/create-error-envelope.js +21 -0
- package/dist/esm/envelope/create-success-envelope.js +31 -0
- package/dist/esm/envelope/types.js +0 -0
- package/dist/esm/output/disambiguation.js +24 -0
- package/dist/esm/output/format-component.js +92 -0
- package/dist/esm/output/format-disambiguation.js +22 -0
- package/dist/esm/output/format-doc-object.js +108 -0
- package/dist/esm/output/format-grouped-results.js +50 -0
- package/dist/esm/output/format-icon.js +42 -0
- package/dist/esm/output/format-lint-rules.js +46 -0
- package/dist/esm/output/format-results.js +151 -0
- package/dist/esm/output/format-token.js +32 -0
- package/dist/esm/output/parse-lint-rule-records.js +41 -0
- package/dist/esm/output/write-human-error.js +13 -0
- package/dist/esm/output/write-human-result.js +24 -0
- package/dist/esm/output/write-json-envelope.js +14 -0
- package/dist/esm/output/writer.js +26 -0
- package/dist/esm/parse-args.js +100 -0
- package/dist/esm/types.js +47 -0
- package/dist/types/cli.d.ts +20 -0
- package/dist/types/commands/definitions.d.ts +19 -0
- package/dist/types/commands/get-command.d.ts +8 -0
- package/dist/types/commands/import-tool-handler.d.ts +14 -0
- package/dist/types/commands/run-tool.d.ts +37 -0
- package/dist/types/commands/types.d.ts +149 -0
- package/dist/types/envelope/create-error-envelope.d.ts +12 -0
- package/dist/types/envelope/create-success-envelope.d.ts +16 -0
- package/dist/types/envelope/types.d.ts +60 -0
- package/dist/types/output/disambiguation.d.ts +50 -0
- package/dist/types/output/format-component.d.ts +12 -0
- package/dist/types/output/format-disambiguation.d.ts +11 -0
- package/dist/types/output/format-doc-object.d.ts +15 -0
- package/dist/types/output/format-grouped-results.d.ts +14 -0
- package/dist/types/output/format-icon.d.ts +13 -0
- package/dist/types/output/format-lint-rules.d.ts +14 -0
- package/dist/types/output/format-results.d.ts +24 -0
- package/dist/types/output/format-token.d.ts +12 -0
- package/dist/types/output/parse-lint-rule-records.d.ts +26 -0
- package/dist/types/output/write-human-error.d.ts +11 -0
- package/dist/types/output/write-human-result.d.ts +14 -0
- package/dist/types/output/write-json-envelope.d.ts +14 -0
- package/dist/types/output/writer.d.ts +25 -0
- package/dist/types/parse-args.d.ts +29 -0
- package/dist/types/types.d.ts +53 -0
- package/index.js +31 -0
- package/package.json +30 -0
package/dist/cjs/cli.js
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.run = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _definitions = require("./commands/definitions");
|
|
12
|
+
var _getCommand = require("./commands/get-command");
|
|
13
|
+
var _importToolHandler = require("./commands/import-tool-handler");
|
|
14
|
+
var _runTool = require("./commands/run-tool");
|
|
15
|
+
var _createErrorEnvelope = require("./envelope/create-error-envelope");
|
|
16
|
+
var _createSuccessEnvelope = require("./envelope/create-success-envelope");
|
|
17
|
+
var _formatGroupedResults = require("./output/format-grouped-results");
|
|
18
|
+
var _formatResults = require("./output/format-results");
|
|
19
|
+
var _writeHumanError = require("./output/write-human-error");
|
|
20
|
+
var _writeHumanResult = require("./output/write-human-result");
|
|
21
|
+
var _writeJsonEnvelope = require("./output/write-json-envelope");
|
|
22
|
+
var _writer = require("./output/writer");
|
|
23
|
+
var _parseArgs2 = require("./parse-args");
|
|
24
|
+
var _types = require("./types");
|
|
25
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
26
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
27
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
28
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
|
30
|
+
* The ADS CLI entrypoint.
|
|
31
|
+
*
|
|
32
|
+
* `run(argv)` parses arguments, resolves the requested command from the shared
|
|
33
|
+
* {@link commands} registry, dispatches to the underlying `@atlaskit/ads-mcp/tools/*`
|
|
34
|
+
* handler, and formats the result (human-readable by default, JSON with `--json`).
|
|
35
|
+
*
|
|
36
|
+
* It never reimplements search ranking or bundles a dataset copy — all query logic lives in
|
|
37
|
+
* `@atlaskit/ads-mcp`, so the MCP server, the ADS skill, and this CLI stay in lock-step.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the CLI version from package.json. Kept in a function so a failure to read it never
|
|
41
|
+
* crashes the CLI (it falls back to `0.0.0`).
|
|
42
|
+
*/
|
|
43
|
+
var getVersion = function getVersion() {
|
|
44
|
+
try {
|
|
45
|
+
var _pkgJson$version;
|
|
46
|
+
// Read our own package.json at runtime via the package-name subpath. This mirrors
|
|
47
|
+
// the sibling `@atlaskit/ads-mcp` package and is depth-independent, so it resolves
|
|
48
|
+
// correctly in both the in-repo source layout (`src/cli`) and the published build
|
|
49
|
+
// (`dist/cjs/cli`). Requires the `./package.json` subpath in this package's exports.
|
|
50
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-var-requires -- this uses require because not all supported node versions use the same import assertions/attributes
|
|
51
|
+
var pkgJson = require('@atlaskit/ads-cli/package.json');
|
|
52
|
+
return (_pkgJson$version = pkgJson.version) !== null && _pkgJson$version !== void 0 ? _pkgJson$version : '0.0.0';
|
|
53
|
+
} catch (_unused) {
|
|
54
|
+
return '0.0.0';
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* One-line description of the CLI, shown at the top of `--help`.
|
|
60
|
+
*/
|
|
61
|
+
var CLI_DESCRIPTION = 'Query Atlassian Design System (ADS) structured content — components, tokens, icons, and guidelines — from the terminal.';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Build the top-level help text from the command registry so it can never drift from the
|
|
65
|
+
* runnable surface.
|
|
66
|
+
*/
|
|
67
|
+
var buildHelpText = function buildHelpText() {
|
|
68
|
+
// Width of the usage "gutter"; descriptions align to this column. Usages longer than the
|
|
69
|
+
// gutter wrap onto their own line with the description indented beneath, so a long usage
|
|
70
|
+
// (e.g. `docs`, which lists every topic) never produces a single 130-column line.
|
|
71
|
+
var gutter = 56;
|
|
72
|
+
var commandLines = _definitions.commands.map(function (command) {
|
|
73
|
+
if (command.usage.length <= gutter) {
|
|
74
|
+
return " ".concat(command.usage.padEnd(gutter), " ").concat(command.description);
|
|
75
|
+
}
|
|
76
|
+
// Long usage: print it on its own line(s), then the description indented beneath so the
|
|
77
|
+
// two stay visually associated instead of the description drifting far to the right.
|
|
78
|
+
var usageLines = command.usage.split(' | ').map(function (part, index) {
|
|
79
|
+
return index === 0 ? " ".concat(part) : " | ".concat(part);
|
|
80
|
+
}).join('\n');
|
|
81
|
+
return "".concat(usageLines, "\n ").concat(command.description);
|
|
82
|
+
}).join('\n');
|
|
83
|
+
return [CLI_DESCRIPTION, '', 'Usage', ' $ npx @atlaskit/ads-cli <command> [options]', '', 'Commands', commandLines, '', 'Global options', ' --json Emit a machine-readable JSON envelope on stdout.', ' --help, -h Show this help.', ' --version, -v Show the CLI version.', '', 'Examples', ' $ npx @atlaskit/ads-cli search button # unified: components, tokens & icons', ' $ npx @atlaskit/ads-cli search button --type component', ' $ npx @atlaskit/ads-cli component Button # detail for one component', ' $ npx @atlaskit/ads-cli token space.100 # detail for one token', ' $ npx @atlaskit/ads-cli icon --all # list every icon', ' $ npx @atlaskit/ads-cli docs spacing # foundations docs', ' $ npx @atlaskit/ads-cli docs a11y buttons # accessibility guidance', ' $ npx @atlaskit/ads-cli docs migration motion # migration guide'].join('\n');
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Execute a registry-backed command: resolve its tool + args, dispatch, and format output.
|
|
88
|
+
*/
|
|
89
|
+
var runRegistryCommand = /*#__PURE__*/function () {
|
|
90
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref) {
|
|
91
|
+
var _resolved$meta3;
|
|
92
|
+
var command, input, json, writer, resolved, _resolved$meta, results, _resolved$meta2;
|
|
93
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
94
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
command = _ref.command, input = _ref.input, json = _ref.json, writer = _ref.writer;
|
|
97
|
+
resolved = command.resolve(input); // A resolver returning `{ error }` indicates invalid input (a usage error).
|
|
98
|
+
if (!('error' in resolved)) {
|
|
99
|
+
_context2.next = 1;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
if (json) {
|
|
103
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
104
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
105
|
+
command: command.name,
|
|
106
|
+
code: 'USAGE_ERROR',
|
|
107
|
+
message: resolved.error
|
|
108
|
+
}),
|
|
109
|
+
writer: writer
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
(0, _writeHumanError.writeHumanError)({
|
|
113
|
+
message: resolved.error,
|
|
114
|
+
writer: writer
|
|
115
|
+
});
|
|
116
|
+
writer.err("Usage: ".concat(command.usage));
|
|
117
|
+
}
|
|
118
|
+
return _context2.abrupt("return", _types.ExitCode.UsageError);
|
|
119
|
+
case 1:
|
|
120
|
+
if (!('data' in resolved)) {
|
|
121
|
+
_context2.next = 2;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
return _context2.abrupt("return", renderSingleResult({
|
|
125
|
+
command: command,
|
|
126
|
+
input: input,
|
|
127
|
+
result: {
|
|
128
|
+
data: resolved.data,
|
|
129
|
+
isError: false
|
|
130
|
+
},
|
|
131
|
+
meta: (_resolved$meta = resolved.meta) !== null && _resolved$meta !== void 0 ? _resolved$meta : {},
|
|
132
|
+
json: json,
|
|
133
|
+
writer: writer
|
|
134
|
+
}));
|
|
135
|
+
case 2:
|
|
136
|
+
_context2.next = 3;
|
|
137
|
+
return Promise.all(resolved.tools.map( /*#__PURE__*/function () {
|
|
138
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(tool) {
|
|
139
|
+
var handler, _t, _t2;
|
|
140
|
+
return _regenerator.default.wrap(function (_context) {
|
|
141
|
+
while (1) switch (_context.prev = _context.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
_context.next = 1;
|
|
144
|
+
return (0, _importToolHandler.importToolHandler)({
|
|
145
|
+
importPath: tool.importPath,
|
|
146
|
+
handlerName: tool.handlerName
|
|
147
|
+
});
|
|
148
|
+
case 1:
|
|
149
|
+
handler = _context.sent;
|
|
150
|
+
_t = _objectSpread;
|
|
151
|
+
_t2 = {
|
|
152
|
+
key: tool.key
|
|
153
|
+
};
|
|
154
|
+
_context.next = 2;
|
|
155
|
+
return (0, _runTool.runTool)({
|
|
156
|
+
handler: handler,
|
|
157
|
+
args: tool.args
|
|
158
|
+
});
|
|
159
|
+
case 2:
|
|
160
|
+
return _context.abrupt("return", _t(_t2, _context.sent));
|
|
161
|
+
case 3:
|
|
162
|
+
case "end":
|
|
163
|
+
return _context.stop();
|
|
164
|
+
}
|
|
165
|
+
}, _callee);
|
|
166
|
+
}));
|
|
167
|
+
return function (_x2) {
|
|
168
|
+
return _ref3.apply(this, arguments);
|
|
169
|
+
};
|
|
170
|
+
}()));
|
|
171
|
+
case 3:
|
|
172
|
+
results = _context2.sent;
|
|
173
|
+
if (!resolved.grouped) {
|
|
174
|
+
_context2.next = 4;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
return _context2.abrupt("return", renderGroupedResult({
|
|
178
|
+
command: command,
|
|
179
|
+
input: input,
|
|
180
|
+
results: results,
|
|
181
|
+
meta: (_resolved$meta2 = resolved.meta) !== null && _resolved$meta2 !== void 0 ? _resolved$meta2 : {},
|
|
182
|
+
json: json,
|
|
183
|
+
writer: writer
|
|
184
|
+
}));
|
|
185
|
+
case 4:
|
|
186
|
+
return _context2.abrupt("return", renderSingleResult({
|
|
187
|
+
command: command,
|
|
188
|
+
input: input,
|
|
189
|
+
result: results[0],
|
|
190
|
+
meta: (_resolved$meta3 = resolved.meta) !== null && _resolved$meta3 !== void 0 ? _resolved$meta3 : {},
|
|
191
|
+
json: json,
|
|
192
|
+
writer: writer
|
|
193
|
+
}));
|
|
194
|
+
case 5:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context2.stop();
|
|
197
|
+
}
|
|
198
|
+
}, _callee2);
|
|
199
|
+
}));
|
|
200
|
+
return function runRegistryCommand(_x) {
|
|
201
|
+
return _ref2.apply(this, arguments);
|
|
202
|
+
};
|
|
203
|
+
}();
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Render a single-tool command result (the common case).
|
|
207
|
+
*/
|
|
208
|
+
var renderSingleResult = function renderSingleResult(_ref4) {
|
|
209
|
+
var _command$resultKind, _ref5, _command$formatHuman;
|
|
210
|
+
var command = _ref4.command,
|
|
211
|
+
input = _ref4.input,
|
|
212
|
+
result = _ref4.result,
|
|
213
|
+
meta = _ref4.meta,
|
|
214
|
+
json = _ref4.json,
|
|
215
|
+
writer = _ref4.writer;
|
|
216
|
+
var isError = result.isError;
|
|
217
|
+
|
|
218
|
+
// The ADS search tools return an `Error: No … found` text block when nothing matches.
|
|
219
|
+
if (isError) {
|
|
220
|
+
var message = typeof result.data === 'string' ? result.data.replace(/^Error:\s*/, '') : 'No results found.';
|
|
221
|
+
if (json) {
|
|
222
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
223
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
224
|
+
command: command.name,
|
|
225
|
+
code: 'NOT_FOUND',
|
|
226
|
+
message: message
|
|
227
|
+
}),
|
|
228
|
+
writer: writer
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
(0, _writeHumanError.writeHumanError)({
|
|
232
|
+
message: message,
|
|
233
|
+
writer: writer
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return _types.ExitCode.NotFound;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Some tools signal "no match" by returning an empty (or whitespace-only) string rather than
|
|
240
|
+
// an `Error:` block — e.g. `docs <term>` for an unknown foundation. Treat that as NOT_FOUND so
|
|
241
|
+
// the user gets a clear miss instead of a silent, empty, exit-0 response.
|
|
242
|
+
if (typeof result.data === 'string' && result.data.trim() === '') {
|
|
243
|
+
var _message = "No results found".concat(input.positionals.length > 0 ? " for \"".concat(input.positionals.join(' '), "\"") : '', ".");
|
|
244
|
+
if (json) {
|
|
245
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
246
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
247
|
+
command: command.name,
|
|
248
|
+
code: 'NOT_FOUND',
|
|
249
|
+
message: _message
|
|
250
|
+
}),
|
|
251
|
+
writer: writer
|
|
252
|
+
});
|
|
253
|
+
} else {
|
|
254
|
+
(0, _writeHumanError.writeHumanError)({
|
|
255
|
+
message: _message,
|
|
256
|
+
writer: writer
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return _types.ExitCode.NotFound;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Optional post-processing (e.g. exact-match vs disambiguation for item commands). Applied
|
|
263
|
+
// before both JSON and human rendering so the envelope and the terminal view stay in sync.
|
|
264
|
+
var data = command.transform ? command.transform({
|
|
265
|
+
data: result.data,
|
|
266
|
+
input: input
|
|
267
|
+
}) : result.data;
|
|
268
|
+
if (json) {
|
|
269
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
270
|
+
envelope: (0, _createSuccessEnvelope.createSuccessEnvelope)({
|
|
271
|
+
envelopeType: command.envelopeType(input),
|
|
272
|
+
command: command.name,
|
|
273
|
+
data: data,
|
|
274
|
+
meta: meta
|
|
275
|
+
}),
|
|
276
|
+
writer: writer
|
|
277
|
+
});
|
|
278
|
+
return _types.ExitCode.Ok;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Default (human) output, tried in order:
|
|
282
|
+
// 1. Compact per-row view when the command declares a result kind (search/list).
|
|
283
|
+
// 2. The command's own `formatHuman` renderer for rich single-object payloads
|
|
284
|
+
// (component docs, a11y/migration guides, lint-rule markdown).
|
|
285
|
+
// 3. The generic fallback: verbatim strings (e.g. foundations markdown) or pretty JSON.
|
|
286
|
+
// Each step returns `null` to defer to the next, so a raw JSON dump is only ever a last resort.
|
|
287
|
+
var resultKind = (_command$resultKind = command.resultKind) === null || _command$resultKind === void 0 ? void 0 : _command$resultKind.call(command, input);
|
|
288
|
+
var compact = resultKind ? (0, _formatResults.formatCompactResults)({
|
|
289
|
+
kind: resultKind,
|
|
290
|
+
data: data
|
|
291
|
+
}) : null;
|
|
292
|
+
var human = (_ref5 = compact !== null && compact !== void 0 ? compact : (_command$formatHuman = command.formatHuman) === null || _command$formatHuman === void 0 ? void 0 : _command$formatHuman.call(command, data)) !== null && _ref5 !== void 0 ? _ref5 : null;
|
|
293
|
+
if (human !== null) {
|
|
294
|
+
writer.out(human);
|
|
295
|
+
} else {
|
|
296
|
+
(0, _writeHumanResult.writeHumanResult)({
|
|
297
|
+
data: data,
|
|
298
|
+
writer: writer
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return _types.ExitCode.Ok;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Render a grouped (multi-tool) command result, e.g. unified `search`.
|
|
306
|
+
*
|
|
307
|
+
* Each sub-result is keyed by its {@link ToolCall.key}. A sub-search that finds nothing simply
|
|
308
|
+
* contributes an empty array; the command is only treated as NOT_FOUND when every group is empty.
|
|
309
|
+
*/
|
|
310
|
+
var renderGroupedResult = function renderGroupedResult(_ref6) {
|
|
311
|
+
var command = _ref6.command,
|
|
312
|
+
input = _ref6.input,
|
|
313
|
+
results = _ref6.results,
|
|
314
|
+
meta = _ref6.meta,
|
|
315
|
+
json = _ref6.json,
|
|
316
|
+
writer = _ref6.writer;
|
|
317
|
+
// Assemble `{ [key]: results }`, coercing "no matches" sub-results to empty arrays so one
|
|
318
|
+
// empty domain does not blank out the others.
|
|
319
|
+
var grouped = {};
|
|
320
|
+
var _iterator = _createForOfIteratorHelper(results),
|
|
321
|
+
_step;
|
|
322
|
+
try {
|
|
323
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
324
|
+
var _step$value = _step.value,
|
|
325
|
+
key = _step$value.key,
|
|
326
|
+
data = _step$value.data,
|
|
327
|
+
isError = _step$value.isError;
|
|
328
|
+
grouped[key] = isError || !Array.isArray(data) ? [] : data;
|
|
329
|
+
}
|
|
330
|
+
} catch (err) {
|
|
331
|
+
_iterator.e(err);
|
|
332
|
+
} finally {
|
|
333
|
+
_iterator.f();
|
|
334
|
+
}
|
|
335
|
+
var totalCount = Object.values(grouped).reduce(function (sum, arr) {
|
|
336
|
+
return sum + arr.length;
|
|
337
|
+
}, 0);
|
|
338
|
+
if (totalCount === 0) {
|
|
339
|
+
var message = 'No components, tokens, or icons found.';
|
|
340
|
+
if (json) {
|
|
341
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
342
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
343
|
+
command: command.name,
|
|
344
|
+
code: 'NOT_FOUND',
|
|
345
|
+
message: message
|
|
346
|
+
}),
|
|
347
|
+
writer: writer
|
|
348
|
+
});
|
|
349
|
+
} else {
|
|
350
|
+
(0, _writeHumanError.writeHumanError)({
|
|
351
|
+
message: message,
|
|
352
|
+
writer: writer
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return _types.ExitCode.NotFound;
|
|
356
|
+
}
|
|
357
|
+
if (json) {
|
|
358
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
359
|
+
envelope: (0, _createSuccessEnvelope.createSuccessEnvelope)({
|
|
360
|
+
envelopeType: command.envelopeType(input),
|
|
361
|
+
command: command.name,
|
|
362
|
+
// `data` for grouped commands is `{ components, tokens, icons }` (already counted
|
|
363
|
+
// per group), so `count` is the combined total across groups.
|
|
364
|
+
data: grouped,
|
|
365
|
+
meta: _objectSpread(_objectSpread({}, meta), {}, {
|
|
366
|
+
count: totalCount
|
|
367
|
+
})
|
|
368
|
+
}),
|
|
369
|
+
writer: writer
|
|
370
|
+
});
|
|
371
|
+
return _types.ExitCode.Ok;
|
|
372
|
+
}
|
|
373
|
+
writer.out((0, _formatGroupedResults.formatGroupedResults)({
|
|
374
|
+
groups: grouped,
|
|
375
|
+
totalCount: totalCount
|
|
376
|
+
}));
|
|
377
|
+
return _types.ExitCode.Ok;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Parse and execute a single CLI invocation.
|
|
382
|
+
*
|
|
383
|
+
* @param argv - Arguments after `node <script>` (i.e. `process.argv.slice(2)`).
|
|
384
|
+
* @param writer - Injectable output sink; defaults to console-backed stdout/stderr.
|
|
385
|
+
* @returns The process exit code. The bin wrapper maps this onto `process.exit`.
|
|
386
|
+
*/
|
|
387
|
+
var run = exports.run = /*#__PURE__*/function () {
|
|
388
|
+
var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
389
|
+
var argv,
|
|
390
|
+
writer,
|
|
391
|
+
_parseArgs,
|
|
392
|
+
command,
|
|
393
|
+
positionals,
|
|
394
|
+
flags,
|
|
395
|
+
json,
|
|
396
|
+
definition,
|
|
397
|
+
message,
|
|
398
|
+
_message2,
|
|
399
|
+
_args3 = arguments,
|
|
400
|
+
_t3;
|
|
401
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
402
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
403
|
+
case 0:
|
|
404
|
+
argv = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : process.argv.slice(2);
|
|
405
|
+
writer = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : _writer.defaultWriter;
|
|
406
|
+
_parseArgs = (0, _parseArgs2.parseArgs)(argv), command = _parseArgs.command, positionals = _parseArgs.positionals, flags = _parseArgs.flags;
|
|
407
|
+
json = flags.json === true; // `--version` / `-v` takes precedence and short-circuits.
|
|
408
|
+
if (!(flags.version === true)) {
|
|
409
|
+
_context3.next = 1;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
writer.out(getVersion());
|
|
413
|
+
return _context3.abrupt("return", _types.ExitCode.Ok);
|
|
414
|
+
case 1:
|
|
415
|
+
if (!(flags.help === true || command === undefined)) {
|
|
416
|
+
_context3.next = 2;
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
writer.out(buildHelpText());
|
|
420
|
+
return _context3.abrupt("return", command === undefined && flags.help !== true ? _types.ExitCode.UsageError : _types.ExitCode.Ok);
|
|
421
|
+
case 2:
|
|
422
|
+
definition = (0, _getCommand.getCommand)(command);
|
|
423
|
+
if (definition) {
|
|
424
|
+
_context3.next = 3;
|
|
425
|
+
break;
|
|
426
|
+
}
|
|
427
|
+
message = "Unknown command \"".concat(command, "\".");
|
|
428
|
+
if (json) {
|
|
429
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
430
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
431
|
+
command: command,
|
|
432
|
+
code: 'USAGE_ERROR',
|
|
433
|
+
message: message
|
|
434
|
+
}),
|
|
435
|
+
writer: writer
|
|
436
|
+
});
|
|
437
|
+
} else {
|
|
438
|
+
(0, _writeHumanError.writeHumanError)({
|
|
439
|
+
message: message,
|
|
440
|
+
writer: writer
|
|
441
|
+
});
|
|
442
|
+
writer.err('Run `ads-cli --help` to see available commands.');
|
|
443
|
+
}
|
|
444
|
+
return _context3.abrupt("return", _types.ExitCode.UsageError);
|
|
445
|
+
case 3:
|
|
446
|
+
_context3.prev = 3;
|
|
447
|
+
_context3.next = 4;
|
|
448
|
+
return runRegistryCommand({
|
|
449
|
+
command: definition,
|
|
450
|
+
input: {
|
|
451
|
+
positionals: positionals,
|
|
452
|
+
flags: flags
|
|
453
|
+
},
|
|
454
|
+
json: json,
|
|
455
|
+
writer: writer
|
|
456
|
+
});
|
|
457
|
+
case 4:
|
|
458
|
+
return _context3.abrupt("return", _context3.sent);
|
|
459
|
+
case 5:
|
|
460
|
+
_context3.prev = 5;
|
|
461
|
+
_t3 = _context3["catch"](3);
|
|
462
|
+
_message2 = _t3 instanceof Error ? _t3.message : String(_t3);
|
|
463
|
+
if (json) {
|
|
464
|
+
(0, _writeJsonEnvelope.writeJsonEnvelope)({
|
|
465
|
+
envelope: (0, _createErrorEnvelope.createErrorEnvelope)({
|
|
466
|
+
command: definition.name,
|
|
467
|
+
code: 'RUNTIME_ERROR',
|
|
468
|
+
message: _message2
|
|
469
|
+
}),
|
|
470
|
+
writer: writer
|
|
471
|
+
});
|
|
472
|
+
} else {
|
|
473
|
+
(0, _writeHumanError.writeHumanError)({
|
|
474
|
+
message: _message2,
|
|
475
|
+
writer: writer
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return _context3.abrupt("return", _types.ExitCode.RuntimeError);
|
|
479
|
+
case 6:
|
|
480
|
+
case "end":
|
|
481
|
+
return _context3.stop();
|
|
482
|
+
}
|
|
483
|
+
}, _callee3, null, [[3, 5]]);
|
|
484
|
+
}));
|
|
485
|
+
return function run() {
|
|
486
|
+
return _ref7.apply(this, arguments);
|
|
487
|
+
};
|
|
488
|
+
}();
|