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