@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.
Files changed (106) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +134 -0
  3. package/bin/ads-cli.js +40 -0
  4. package/compass.yml +25 -0
  5. package/dist/cjs/cli.js +488 -0
  6. package/dist/cjs/commands/definitions.js +713 -0
  7. package/dist/cjs/commands/get-command.js +19 -0
  8. package/dist/cjs/commands/import-tool-handler.js +57 -0
  9. package/dist/cjs/commands/run-tool.js +106 -0
  10. package/dist/cjs/commands/types.js +1 -0
  11. package/dist/cjs/envelope/create-error-envelope.js +27 -0
  12. package/dist/cjs/envelope/create-success-envelope.js +38 -0
  13. package/dist/cjs/envelope/types.js +1 -0
  14. package/dist/cjs/output/disambiguation.js +31 -0
  15. package/dist/cjs/output/format-component.js +99 -0
  16. package/dist/cjs/output/format-disambiguation.js +29 -0
  17. package/dist/cjs/output/format-doc-object.js +115 -0
  18. package/dist/cjs/output/format-grouped-results.js +55 -0
  19. package/dist/cjs/output/format-icon.js +49 -0
  20. package/dist/cjs/output/format-lint-rules.js +52 -0
  21. package/dist/cjs/output/format-results.js +158 -0
  22. package/dist/cjs/output/format-token.js +39 -0
  23. package/dist/cjs/output/parse-lint-rule-records.js +47 -0
  24. package/dist/cjs/output/write-human-error.js +20 -0
  25. package/dist/cjs/output/write-human-result.js +31 -0
  26. package/dist/cjs/output/write-json-envelope.js +20 -0
  27. package/dist/cjs/output/writer.js +32 -0
  28. package/dist/cjs/parse-args.js +106 -0
  29. package/dist/cjs/types.js +53 -0
  30. package/dist/es2019/cli.js +406 -0
  31. package/dist/es2019/commands/definitions.js +683 -0
  32. package/dist/es2019/commands/get-command.js +9 -0
  33. package/dist/es2019/commands/import-tool-handler.js +22 -0
  34. package/dist/es2019/commands/run-tool.js +73 -0
  35. package/dist/es2019/commands/types.js +0 -0
  36. package/dist/es2019/envelope/create-error-envelope.js +20 -0
  37. package/dist/es2019/envelope/create-success-envelope.js +31 -0
  38. package/dist/es2019/envelope/types.js +0 -0
  39. package/dist/es2019/output/disambiguation.js +21 -0
  40. package/dist/es2019/output/format-component.js +88 -0
  41. package/dist/es2019/output/format-disambiguation.js +22 -0
  42. package/dist/es2019/output/format-doc-object.js +94 -0
  43. package/dist/es2019/output/format-grouped-results.js +51 -0
  44. package/dist/es2019/output/format-icon.js +39 -0
  45. package/dist/es2019/output/format-lint-rules.js +43 -0
  46. package/dist/es2019/output/format-results.js +142 -0
  47. package/dist/es2019/output/format-token.js +31 -0
  48. package/dist/es2019/output/parse-lint-rule-records.js +41 -0
  49. package/dist/es2019/output/write-human-error.js +14 -0
  50. package/dist/es2019/output/write-human-result.js +25 -0
  51. package/dist/es2019/output/write-json-envelope.js +15 -0
  52. package/dist/es2019/output/writer.js +22 -0
  53. package/dist/es2019/parse-args.js +100 -0
  54. package/dist/es2019/types.js +47 -0
  55. package/dist/esm/cli.js +484 -0
  56. package/dist/esm/commands/definitions.js +708 -0
  57. package/dist/esm/commands/get-command.js +13 -0
  58. package/dist/esm/commands/import-tool-handler.js +42 -0
  59. package/dist/esm/commands/run-tool.js +99 -0
  60. package/dist/esm/commands/types.js +0 -0
  61. package/dist/esm/envelope/create-error-envelope.js +21 -0
  62. package/dist/esm/envelope/create-success-envelope.js +31 -0
  63. package/dist/esm/envelope/types.js +0 -0
  64. package/dist/esm/output/disambiguation.js +24 -0
  65. package/dist/esm/output/format-component.js +92 -0
  66. package/dist/esm/output/format-disambiguation.js +22 -0
  67. package/dist/esm/output/format-doc-object.js +108 -0
  68. package/dist/esm/output/format-grouped-results.js +50 -0
  69. package/dist/esm/output/format-icon.js +42 -0
  70. package/dist/esm/output/format-lint-rules.js +46 -0
  71. package/dist/esm/output/format-results.js +151 -0
  72. package/dist/esm/output/format-token.js +32 -0
  73. package/dist/esm/output/parse-lint-rule-records.js +41 -0
  74. package/dist/esm/output/write-human-error.js +13 -0
  75. package/dist/esm/output/write-human-result.js +24 -0
  76. package/dist/esm/output/write-json-envelope.js +14 -0
  77. package/dist/esm/output/writer.js +26 -0
  78. package/dist/esm/parse-args.js +100 -0
  79. package/dist/esm/types.js +47 -0
  80. package/dist/types/cli.d.ts +20 -0
  81. package/dist/types/commands/definitions.d.ts +19 -0
  82. package/dist/types/commands/get-command.d.ts +8 -0
  83. package/dist/types/commands/import-tool-handler.d.ts +14 -0
  84. package/dist/types/commands/run-tool.d.ts +37 -0
  85. package/dist/types/commands/types.d.ts +149 -0
  86. package/dist/types/envelope/create-error-envelope.d.ts +12 -0
  87. package/dist/types/envelope/create-success-envelope.d.ts +16 -0
  88. package/dist/types/envelope/types.d.ts +60 -0
  89. package/dist/types/output/disambiguation.d.ts +50 -0
  90. package/dist/types/output/format-component.d.ts +12 -0
  91. package/dist/types/output/format-disambiguation.d.ts +11 -0
  92. package/dist/types/output/format-doc-object.d.ts +15 -0
  93. package/dist/types/output/format-grouped-results.d.ts +14 -0
  94. package/dist/types/output/format-icon.d.ts +13 -0
  95. package/dist/types/output/format-lint-rules.d.ts +14 -0
  96. package/dist/types/output/format-results.d.ts +24 -0
  97. package/dist/types/output/format-token.d.ts +12 -0
  98. package/dist/types/output/parse-lint-rule-records.d.ts +26 -0
  99. package/dist/types/output/write-human-error.d.ts +11 -0
  100. package/dist/types/output/write-human-result.d.ts +14 -0
  101. package/dist/types/output/write-json-envelope.d.ts +14 -0
  102. package/dist/types/output/writer.d.ts +25 -0
  103. package/dist/types/parse-args.d.ts +29 -0
  104. package/dist/types/types.d.ts +53 -0
  105. package/index.js +31 -0
  106. package/package.json +30 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCommand = void 0;
7
+ var _definitions = require("./definitions");
8
+ /**
9
+ * Look up a command definition by name.
10
+ */
11
+
12
+ /**
13
+ * Look up a command definition by name. Returns `undefined` for unknown commands.
14
+ */
15
+ var getCommand = exports.getCommand = function getCommand(name) {
16
+ return _definitions.commands.find(function (command) {
17
+ return command.name === name;
18
+ });
19
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.importToolHandler = void 0;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
12
+ function _tsRewriteRelativeImportExtensions(t, e) { return "string" == typeof t && /^\.\.?\//.test(t) ? t.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+)?)\.([cm]?)ts$/i, function (t, s, r, n, o) { return s ? e ? ".jsx" : ".js" : !r || n && o ? r + n + "." + o.toLowerCase() + "js" : t; }) : t; }
13
+ /**
14
+ * Dynamic-import indirection used to load an ADS MCP tool handler by subpath.
15
+ */
16
+
17
+ /**
18
+ * Load an ADS MCP tool handler by subpath.
19
+ *
20
+ * Exposed as a single function so tests can mock it and assert which tool a command
21
+ * dispatched to, and so the dynamic `import()` lives in exactly one place.
22
+ */
23
+ var importToolHandler = exports.importToolHandler = /*#__PURE__*/function () {
24
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
25
+ var importPath, handlerName, mod, handler;
26
+ return _regenerator.default.wrap(function (_context) {
27
+ while (1) switch (_context.prev = _context.next) {
28
+ case 0:
29
+ importPath = _ref.importPath, handlerName = _ref.handlerName;
30
+ _context.next = 1;
31
+ return function (specifier) {
32
+ return new Promise(function (r) {
33
+ return r("".concat(specifier));
34
+ }).then(function (s) {
35
+ return _interopRequireWildcard(require(s));
36
+ });
37
+ }( /* webpackChunkName: "@atlaskit-internal_ads-cli-tool" */_tsRewriteRelativeImportExtensions(importPath));
38
+ case 1:
39
+ mod = _context.sent;
40
+ handler = mod[handlerName];
41
+ if (!(typeof handler !== 'function')) {
42
+ _context.next = 2;
43
+ break;
44
+ }
45
+ throw new Error("Tool handler \"".concat(handlerName, "\" not found in \"").concat(importPath, "\"."));
46
+ case 2:
47
+ return _context.abrupt("return", handler);
48
+ case 3:
49
+ case "end":
50
+ return _context.stop();
51
+ }
52
+ }, _callee);
53
+ }));
54
+ return function importToolHandler(_x) {
55
+ return _ref2.apply(this, arguments);
56
+ };
57
+ }();
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.runTool = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ /**
11
+ * Generic runner that invokes a single `@atlaskit/ads-mcp/tools/*` handler and unwraps its
12
+ * MCP-shaped result into plain data.
13
+ *
14
+ * This is the one place the CLI actually talks to the shared ADS query logic. Keeping the
15
+ * dispatch here (rather than reimplementing search/ranking) is what guarantees zero drift
16
+ * between the MCP server, the ADS skill scripts, and this CLI.
17
+ */
18
+
19
+ /**
20
+ * Result of unwrapping an ADS MCP tool response.
21
+ */
22
+
23
+ /**
24
+ * The ADS search tools signal "no results" by returning a single text block that starts
25
+ * with `Error:`. Detect that so the CLI can map it to a NOT_FOUND exit code.
26
+ */
27
+ var isErrorText = function isErrorText(text) {
28
+ return text.trimStart().startsWith('Error:');
29
+ };
30
+
31
+ /**
32
+ * Attempt to JSON-parse a string, returning the original string on failure. Mirrors the
33
+ * `try { JSON.parse } catch { raw }` pattern used by the existing skill scripts.
34
+ */
35
+ var tryParseJson = function tryParseJson(text) {
36
+ try {
37
+ return JSON.parse(text);
38
+ } catch (_unused) {
39
+ return text;
40
+ }
41
+ };
42
+
43
+ /**
44
+ * Extract the text blocks from an MCP tool result.
45
+ */
46
+ var getTextBlocks = function getTextBlocks(result) {
47
+ return result.content.filter(function (item) {
48
+ return item.type === 'text' && typeof item.text === 'string';
49
+ }).map(function (item) {
50
+ return item.text;
51
+ });
52
+ };
53
+
54
+ /**
55
+ * Invoke an ADS MCP tool handler and unwrap its result into plain data.
56
+ *
57
+ * @param handler - The tool function (e.g. `searchComponentsTool`).
58
+ * @param args - The arguments object matching the tool's zod input schema, or `undefined`
59
+ * for zero-argument tools such as `getAllComponentsTool`.
60
+ */
61
+ var runTool = exports.runTool = /*#__PURE__*/function () {
62
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
63
+ var handler, args, result, textBlocks, text;
64
+ return _regenerator.default.wrap(function (_context) {
65
+ while (1) switch (_context.prev = _context.next) {
66
+ case 0:
67
+ handler = _ref.handler, args = _ref.args;
68
+ _context.next = 1;
69
+ return handler(args);
70
+ case 1:
71
+ result = _context.sent;
72
+ textBlocks = getTextBlocks(result); // A single text block is the common case (search tools, guidelines). Multiple blocks are
73
+ // returned by the `get-all-*` tools, which emit one JSON object per entry.
74
+ if (!(textBlocks.length === 0)) {
75
+ _context.next = 2;
76
+ break;
77
+ }
78
+ return _context.abrupt("return", {
79
+ data: null,
80
+ isError: Boolean(result.isError)
81
+ });
82
+ case 2:
83
+ if (!(textBlocks.length === 1)) {
84
+ _context.next = 3;
85
+ break;
86
+ }
87
+ text = textBlocks[0];
88
+ return _context.abrupt("return", {
89
+ data: tryParseJson(text),
90
+ isError: Boolean(result.isError) || isErrorText(text)
91
+ });
92
+ case 3:
93
+ return _context.abrupt("return", {
94
+ data: textBlocks.map(tryParseJson),
95
+ isError: Boolean(result.isError)
96
+ });
97
+ case 4:
98
+ case "end":
99
+ return _context.stop();
100
+ }
101
+ }, _callee);
102
+ }));
103
+ return function runTool(_x) {
104
+ return _ref2.apply(this, arguments);
105
+ };
106
+ }();
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createErrorEnvelope = void 0;
7
+ /**
8
+ * Builder for the error variant of the CLI's JSON output envelope.
9
+ */
10
+
11
+ /**
12
+ * Build an error envelope for a command.
13
+ */
14
+ var createErrorEnvelope = exports.createErrorEnvelope = function createErrorEnvelope(_ref) {
15
+ var command = _ref.command,
16
+ code = _ref.code,
17
+ message = _ref.message;
18
+ return {
19
+ type: 'ads-cli/error',
20
+ command: command,
21
+ ok: false,
22
+ error: {
23
+ code: code,
24
+ message: message
25
+ }
26
+ };
27
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createSuccessEnvelope = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ 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; }
10
+ 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; }
11
+ /**
12
+ * Builder for the success variant of the CLI's JSON output envelope.
13
+ */
14
+
15
+ /**
16
+ * Build a success envelope for a command.
17
+ *
18
+ * The `type` discriminator is derived from the envelope type name supplied by the command's
19
+ * registry entry. When `data` is an array, `count` is auto-derived into `meta`.
20
+ */
21
+ var createSuccessEnvelope = exports.createSuccessEnvelope = function createSuccessEnvelope(_ref) {
22
+ var envelopeType = _ref.envelopeType,
23
+ command = _ref.command,
24
+ data = _ref.data,
25
+ _ref$meta = _ref.meta,
26
+ meta = _ref$meta === void 0 ? {} : _ref$meta;
27
+ // Automatically compute `count` for array payloads so consumers get it for free.
28
+ var count = Array.isArray(data) ? data.length : meta.count;
29
+ return {
30
+ type: "ads-cli/".concat(envelopeType),
31
+ command: command,
32
+ ok: true,
33
+ data: data,
34
+ meta: _objectSpread(_objectSpread({}, meta), count === undefined ? {} : {
35
+ count: count
36
+ })
37
+ };
38
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isDisambiguation = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ /**
10
+ * Shared shape and type guard for an "ambiguous lookup" result.
11
+ *
12
+ * When an item command (`component`/`token`/`icon`) is given a name that fuzzy-matches multiple
13
+ * entries and none is an exact name match, the command's `transform` produces one of these
14
+ * instead of a single detail object. Both the human renderer and the `--json` envelope then
15
+ * present a "did you mean?" candidate list rather than silently picking the top fuzzy hit.
16
+ */
17
+
18
+ /**
19
+ * A candidate surfaced in a disambiguation result.
20
+ */
21
+
22
+ /**
23
+ * The marker object a `transform` returns when a lookup is ambiguous.
24
+ */
25
+
26
+ /**
27
+ * Narrow an unknown value to a {@link DisambiguationResult}.
28
+ */
29
+ var isDisambiguation = exports.isDisambiguation = function isDisambiguation(value) {
30
+ return (0, _typeof2.default)(value) === 'object' && value !== null && value.ambiguous === true;
31
+ };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatComponent = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ /**
11
+ * Human-readable renderer for a single ADS component's detailed docs.
12
+ *
13
+ * Renders the `component <Name>` view: a readable header, a props table, and the usage examples —
14
+ * instead of dumping the raw JSON payload. Full structured data (including the `designSource` link
15
+ * and untruncated types) remains available via `--json`.
16
+ */
17
+
18
+ /**
19
+ * One prop entry as returned by `searchComponentsTool`. Only the fields the detailed view needs
20
+ * are modelled; anything else is ignored.
21
+ */
22
+
23
+ /**
24
+ * A component payload as returned by `searchComponentsTool` / `getAllComponentsTool`.
25
+ */
26
+
27
+ /**
28
+ * Collapse whitespace/newlines in a prop description so each prop stays on one readable line.
29
+ */
30
+ var oneLine = function oneLine(text) {
31
+ return text.replace(/\s+/g, ' ').trim();
32
+ };
33
+
34
+ /**
35
+ * Render the props section as an aligned two-column list: `name type`, with the description on
36
+ * a wrapped continuation line. Returns an empty array when there are no props.
37
+ */
38
+ var formatProps = function formatProps(props) {
39
+ if (props.length === 0) {
40
+ return ['Props: none'];
41
+ }
42
+
43
+ // Align the type column to the longest prop name for readability.
44
+ var longestName = props.reduce(function (max, prop) {
45
+ var _prop$name;
46
+ return Math.max(max, ((_prop$name = prop.name) !== null && _prop$name !== void 0 ? _prop$name : '').length);
47
+ }, 0);
48
+ var rows = props.flatMap(function (prop) {
49
+ var _prop$name2;
50
+ var name = ((_prop$name2 = prop.name) !== null && _prop$name2 !== void 0 ? _prop$name2 : '(unknown)').padEnd(longestName);
51
+ var type = prop.type ? oneLine(prop.type) : '';
52
+ var header = " ".concat(name, " ").concat(type).trimEnd();
53
+ var description = prop.description ? " ".concat(oneLine(prop.description)) : null;
54
+ return description ? [header, description] : [header];
55
+ });
56
+ return ["Props (".concat(props.length, "):")].concat((0, _toConsumableArray2.default)(rows));
57
+ };
58
+
59
+ /**
60
+ * Render the examples section. Each example is a code snippet string; they are printed verbatim
61
+ * inside a fenced block so they can be copy-pasted.
62
+ */
63
+ var formatExamples = function formatExamples(examples) {
64
+ if (examples.length === 0) {
65
+ return [];
66
+ }
67
+ var blocks = examples.map(function (example, index) {
68
+ var code = typeof example === 'string' ? example : JSON.stringify(example, null, 2);
69
+ return ["Example ".concat(index + 1, ":"), '```tsx', code, '```'].join('\n');
70
+ });
71
+ return ["Examples (".concat(examples.length, "):"), ''].concat((0, _toConsumableArray2.default)(blocks));
72
+ };
73
+
74
+ /**
75
+ * Render a single component payload as detailed, human-readable docs. Returns `null` when the
76
+ * data is not a recognisable component object, so the caller can fall back to generic rendering.
77
+ */
78
+ var formatComponent = exports.formatComponent = function formatComponent(data) {
79
+ var _component$props, _component$examples, _component$designSour;
80
+ // `component <name>` reuses component search with limit 1, so `data` is a one-element array.
81
+ var component = Array.isArray(data) ? data[0] : data;
82
+ if (!component || (0, _typeof2.default)(component) !== 'object' || typeof component.name !== 'string') {
83
+ return null;
84
+ }
85
+ var header = component.package ? "".concat(component.name, " (").concat(component.package, ")") : component.name;
86
+ var sections = [header, '='.repeat(header.length), ''].concat((0, _toConsumableArray2.default)(formatProps((_component$props = component.props) !== null && _component$props !== void 0 ? _component$props : [])));
87
+ var examples = formatExamples((_component$examples = component.examples) !== null && _component$examples !== void 0 ? _component$examples : []);
88
+ if (examples.length > 0) {
89
+ sections.push.apply(sections, [''].concat((0, _toConsumableArray2.default)(examples)));
90
+ }
91
+
92
+ // Render the design link from the `figmaUrl` inside `designSource`. Only emit the line when a
93
+ // URL is actually present, so a `designSource` object without a `figmaUrl` doesn't print
94
+ // `Design: undefined`.
95
+ if ((_component$designSour = component.designSource) !== null && _component$designSour !== void 0 && _component$designSour.figmaUrl) {
96
+ sections.push('', "Design: ".concat(component.designSource.figmaUrl));
97
+ }
98
+ return sections.join('\n');
99
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatDisambiguation = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ /**
10
+ * Human-readable renderer for an ambiguous item lookup ("did you mean?").
11
+ */
12
+
13
+ /**
14
+ * Render a "did you mean?" list for an ambiguous lookup.
15
+ *
16
+ * Mirrors the compact search rows (name, optional hint, and a `→ <follow-up>` command) so the
17
+ * output is consistent with `search`, and tells the user how to disambiguate.
18
+ */
19
+ var formatDisambiguation = exports.formatDisambiguation = function formatDisambiguation(_ref) {
20
+ var query = _ref.query,
21
+ noun = _ref.noun,
22
+ candidates = _ref.candidates;
23
+ var header = "Multiple ".concat(noun, "s match \"").concat(query, "\". Did you mean one of these?");
24
+ var rows = candidates.map(function (candidate) {
25
+ var hint = candidate.hint ? " ".concat(candidate.hint) : '';
26
+ return " ".concat(candidate.name).concat(hint, "\n \u2192 ads-cli ").concat(candidate.followUp);
27
+ });
28
+ return [header, ''].concat((0, _toConsumableArray2.default)(rows)).join('\n');
29
+ };
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatDocObject = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+ /**
12
+ * Human-readable renderer for a single "doc object" payload — the shape returned by the
13
+ * accessibility (`docs a11y`) and migration (`docs migration`) tools.
14
+ *
15
+ * These tools return a structured object (title, description, and several labelled lists such
16
+ * as `guidelines`, `bestPractices`, `nextSteps`). The default output prints this as readable text
17
+ * rather than raw JSON; `--json` still exposes the full structured payload.
18
+ */
19
+
20
+ /**
21
+ * Convert a camelCase / snake_case field key into a human "Title Case" heading,
22
+ * e.g. `bestPractices` → `Best Practices`, `additionalResources` → `Additional Resources`.
23
+ */
24
+ var humanizeKey = function humanizeKey(key) {
25
+ return key.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').replace(/\b\w/g, function (char) {
26
+ return char.toUpperCase();
27
+ }).trim();
28
+ };
29
+
30
+ /**
31
+ * Collapse whitespace so list items and inline values stay readable on their own lines.
32
+ */
33
+ var oneLine = function oneLine(text) {
34
+ return text.replace(/\s+/g, ' ').trim();
35
+ };
36
+
37
+ /**
38
+ * Render a single list item. Strings are collapsed to one line. Objects that look like a code
39
+ * example (`title` + `code`/`before`/`after`) are rendered as a titled fenced block so the
40
+ * snippet stays copy-pasteable; any other object falls back to compact JSON so no data is lost.
41
+ */
42
+ var formatListItem = function formatListItem(item) {
43
+ if (typeof item === 'string') {
44
+ return " - ".concat(oneLine(item));
45
+ }
46
+ if (item !== null && (0, _typeof2.default)(item) === 'object') {
47
+ var record = item;
48
+ var title = typeof record.title === 'string' ? record.title : null;
49
+ var code = ['code', 'before', 'after'].find(function (key) {
50
+ return typeof record[key] === 'string';
51
+ });
52
+ if (title && code) {
53
+ var description = typeof record.description === 'string' ? "\n ".concat(oneLine(record.description)) : '';
54
+ return " - ".concat(title).concat(description, "\n ```tsx\n").concat(record[code], "\n ```");
55
+ }
56
+ if (title) {
57
+ return " - ".concat(title);
58
+ }
59
+ }
60
+
61
+ // Unknown object shape: keep the data rather than drop it.
62
+ return " - ".concat(JSON.stringify(item));
63
+ };
64
+
65
+ /**
66
+ * Keys that identify the record or provide its header/description — rendered as the header or
67
+ * skipped, never as their own labelled section. `message` is the header used by the "index"
68
+ * response the a11y tool returns when no topic is supplied (it has no `title`).
69
+ */
70
+ var IDENTITY_KEYS = new Set(['topic', 'migration', 'title', 'message', 'description']);
71
+
72
+ /**
73
+ * Render a doc-object payload as readable text. Handles both the full guide shape (a11y guidance,
74
+ * migration guide — keyed by `title`) and the topic-index shape the a11y tool returns when no
75
+ * topic is given (keyed by `message` + `availableTopics`). Returns `null` when the data is not a
76
+ * recognisable doc object so the caller can fall back to generic rendering.
77
+ */
78
+ var formatDocObject = exports.formatDocObject = function formatDocObject(data) {
79
+ if (data === null || (0, _typeof2.default)(data) !== 'object' || Array.isArray(data)) {
80
+ return null;
81
+ }
82
+ var record = data;
83
+
84
+ // Derive a header from `title` (full guide) or `message` (topic index). Without either, this
85
+ // is not a doc object we can render sensibly, so defer to the generic fallback.
86
+ var header = typeof record.title === 'string' ? record.title : record.message;
87
+ if (typeof header !== 'string' || !header) {
88
+ return null;
89
+ }
90
+ var sections = [header, '='.repeat(header.length)];
91
+ if (typeof record.description === 'string' && record.description) {
92
+ sections.push('', oneLine(record.description));
93
+ }
94
+
95
+ // Render every remaining field in declaration order: strings as `Label: value`, arrays as a
96
+ // labelled bulleted list. Identity/header fields are skipped (handled above).
97
+ for (var _i = 0, _Object$entries = Object.entries(record); _i < _Object$entries.length; _i++) {
98
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
99
+ key = _Object$entries$_i[0],
100
+ value = _Object$entries$_i[1];
101
+ if (IDENTITY_KEYS.has(key)) {
102
+ continue;
103
+ }
104
+ var label = humanizeKey(key);
105
+ if (Array.isArray(value)) {
106
+ if (value.length === 0) {
107
+ continue;
108
+ }
109
+ sections.push.apply(sections, ['', "".concat(label, ":")].concat((0, _toConsumableArray2.default)(value.map(formatListItem))));
110
+ } else if (typeof value === 'string' && value) {
111
+ sections.push('', "".concat(label, ": ").concat(oneLine(value)));
112
+ }
113
+ }
114
+ return sections.join('\n');
115
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.formatGroupedResults = void 0;
7
+ var _formatResults = require("./format-results");
8
+ /**
9
+ * Sectioned compact renderer for grouped (multi-kind) results, e.g. unified `search`.
10
+ *
11
+ * Prints a Components section, then Tokens, then Icons — reusing the per-kind compact renderer
12
+ * for each. Empty groups are skipped, so one command surfaces whatever kinds match, grouped by
13
+ * kind.
14
+ */
15
+
16
+ /**
17
+ * Render grouped results as sectioned compact output.
18
+ */
19
+ var formatGroupedResults = exports.formatGroupedResults = function formatGroupedResults(_ref) {
20
+ var groups = _ref.groups,
21
+ totalCount = _ref.totalCount;
22
+ // Fixed display order, with human-friendly section titles.
23
+ var sections = [{
24
+ kind: 'components',
25
+ title: 'Components'
26
+ }, {
27
+ kind: 'tokens',
28
+ title: 'Tokens'
29
+ }, {
30
+ kind: 'icons',
31
+ title: 'Icons'
32
+ }];
33
+ var blocks = ["Results (".concat(totalCount, "):")];
34
+ for (var _i = 0, _sections = sections; _i < _sections.length; _i++) {
35
+ var _groups$kind;
36
+ var _sections$_i = _sections[_i],
37
+ kind = _sections$_i.kind,
38
+ title = _sections$_i.title;
39
+ var entries = (_groups$kind = groups[kind]) !== null && _groups$kind !== void 0 ? _groups$kind : [];
40
+ if (entries.length === 0) {
41
+ continue;
42
+ }
43
+ // Reuse the single-kind compact renderer with drill-in follow-ups enabled (this is the
44
+ // unified `search` view), then strip its own "Results (n):" header and following blank
45
+ // line so the grouped output uses the section title instead.
46
+ var rendered = (0, _formatResults.formatCompactResults)({
47
+ kind: kind,
48
+ data: entries,
49
+ showFollowUp: true
50
+ });
51
+ var body = rendered ? rendered.split('\n').slice(2).join('\n') : '';
52
+ blocks.push('', "".concat(title, " (").concat(entries.length, "):"), '', body);
53
+ }
54
+ return blocks.join('\n');
55
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.formatIcon = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ /**
10
+ * Human-readable renderer for a single ADS icon's detail view.
11
+ *
12
+ * The icon dataset provides `componentName`, `package` (the exact subpath entry-point), and a
13
+ * `usage` note. The detail view surfaces the copy-paste `import` line — the actionable thing a
14
+ * consumer needs — alongside the usage guidance. Full structured data remains available via
15
+ * `--json`.
16
+ */
17
+
18
+ /**
19
+ * An icon payload as returned by `searchIconsTool` / `getAllIconsTool`.
20
+ */
21
+
22
+ /**
23
+ * Collapse whitespace/newlines so the usage note stays readable on its own line.
24
+ */
25
+ var oneLine = function oneLine(text) {
26
+ return text.replace(/\s+/g, ' ').trim();
27
+ };
28
+
29
+ /**
30
+ * Render a single icon payload as a detail view. Returns `null` when the data is not a
31
+ * recognisable icon object, so the caller can fall back to generic rendering.
32
+ */
33
+ var formatIcon = exports.formatIcon = function formatIcon(data) {
34
+ // `icon <name>` reuses icon search with limit 1, so `data` is a one-element array.
35
+ var icon = Array.isArray(data) ? data[0] : data;
36
+ if (!icon || (0, _typeof2.default)(icon) !== 'object' || typeof icon.componentName !== 'string') {
37
+ return null;
38
+ }
39
+ var sections = [icon.componentName, '='.repeat(icon.componentName.length)];
40
+ if (icon.package) {
41
+ sections.push('', "Package: ".concat(icon.package));
42
+ // The actionable bit: the barrel-correct import for this icon.
43
+ sections.push('', 'Import:', " import ".concat(icon.componentName, " from '").concat(icon.package, "';"));
44
+ }
45
+ if (icon.usage) {
46
+ sections.push('', "Usage: ".concat(oneLine(icon.usage)));
47
+ }
48
+ return sections.join('\n');
49
+ };