@atlaskit/ads-cli 0.8.2 → 0.10.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 +18 -0
- package/README.md +38 -0
- package/dist/cjs/cli.js +49 -20
- package/dist/cjs/commands/definitions.js +12 -0
- package/dist/cjs/commands/init.js +500 -0
- package/dist/cjs/commands/update-agents-file.js +150 -0
- package/dist/es2019/cli.js +20 -0
- package/dist/es2019/commands/definitions.js +10 -0
- package/dist/es2019/commands/init.js +371 -0
- package/dist/es2019/commands/update-agents-file.js +139 -0
- package/dist/esm/cli.js +46 -17
- package/dist/esm/commands/definitions.js +12 -0
- package/dist/esm/commands/init.js +493 -0
- package/dist/esm/commands/update-agents-file.js +143 -0
- package/dist/types/commands/init.d.ts +10 -0
- package/dist/types/commands/types.d.ts +10 -1
- package/dist/types/commands/update-agents-file.d.ts +22 -0
- package/package.json +2 -2
package/dist/esm/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ import { commands } from './commands/definitions';
|
|
|
24
24
|
import { getCommand } from './commands/get-command';
|
|
25
25
|
import { getVersion } from './commands/get-version';
|
|
26
26
|
import { importToolHandler } from './commands/import-tool-handler';
|
|
27
|
+
import { runInitCommand } from './commands/init';
|
|
27
28
|
import { runTool } from './commands/run-tool';
|
|
28
29
|
import { createErrorEnvelope } from './envelope/create-error-envelope';
|
|
29
30
|
import { createSuccessEnvelope } from './envelope/create-success-envelope';
|
|
@@ -65,6 +66,9 @@ var buildHelpText = function buildHelpText(invocation) {
|
|
|
65
66
|
return " --".concat(flag.name).concat(aliases).padEnd(18) + flag.description;
|
|
66
67
|
}).join('\n');
|
|
67
68
|
var examples = [{
|
|
69
|
+
command: 'init',
|
|
70
|
+
comment: 'set up repository-local frontend skills and the Atlas plugin'
|
|
71
|
+
}, {
|
|
68
72
|
command: 'search contrast',
|
|
69
73
|
comment: 'unified: components, tokens, icons & docs'
|
|
70
74
|
}, {
|
|
@@ -125,9 +129,21 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
125
129
|
while (1) switch (_context2.prev = _context2.next) {
|
|
126
130
|
case 0:
|
|
127
131
|
command = _ref3.command, input = _ref3.input, json = _ref3.json, writer = _ref3.writer, invocation = _ref3.invocation;
|
|
132
|
+
if (!(command.action === 'init')) {
|
|
133
|
+
_context2.next = 1;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
return _context2.abrupt("return", runInitCommand({
|
|
137
|
+
input: input,
|
|
138
|
+
json: json,
|
|
139
|
+
writer: writer,
|
|
140
|
+
invocation: invocation,
|
|
141
|
+
cwd: process.cwd()
|
|
142
|
+
}));
|
|
143
|
+
case 1:
|
|
128
144
|
resolved = command.resolve(input); // A resolver returning `{ error }` indicates invalid input (a usage error).
|
|
129
145
|
if (!('error' in resolved)) {
|
|
130
|
-
_context2.next =
|
|
146
|
+
_context2.next = 2;
|
|
131
147
|
break;
|
|
132
148
|
}
|
|
133
149
|
if (json) {
|
|
@@ -147,9 +163,9 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
147
163
|
writer.err("Usage: ".concat(command.usage));
|
|
148
164
|
}
|
|
149
165
|
return _context2.abrupt("return", ExitCode.UsageError);
|
|
150
|
-
case
|
|
166
|
+
case 2:
|
|
151
167
|
if (!('data' in resolved)) {
|
|
152
|
-
_context2.next =
|
|
168
|
+
_context2.next = 3;
|
|
153
169
|
break;
|
|
154
170
|
}
|
|
155
171
|
return _context2.abrupt("return", renderSingleResult({
|
|
@@ -164,9 +180,9 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
164
180
|
writer: writer,
|
|
165
181
|
invocation: invocation
|
|
166
182
|
}));
|
|
167
|
-
case
|
|
183
|
+
case 3:
|
|
168
184
|
if (!resolved.batch) {
|
|
169
|
-
_context2.next =
|
|
185
|
+
_context2.next = 4;
|
|
170
186
|
break;
|
|
171
187
|
}
|
|
172
188
|
return _context2.abrupt("return", runBatchRequests({
|
|
@@ -176,8 +192,8 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
176
192
|
writer: writer,
|
|
177
193
|
invocation: invocation
|
|
178
194
|
}));
|
|
179
|
-
case
|
|
180
|
-
_context2.next =
|
|
195
|
+
case 4:
|
|
196
|
+
_context2.next = 5;
|
|
181
197
|
return Promise.all(resolved.tools.map( /*#__PURE__*/function () {
|
|
182
198
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tool) {
|
|
183
199
|
var handler, _t, _t2;
|
|
@@ -212,10 +228,10 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
212
228
|
return _ref5.apply(this, arguments);
|
|
213
229
|
};
|
|
214
230
|
}()));
|
|
215
|
-
case
|
|
231
|
+
case 5:
|
|
216
232
|
results = _context2.sent;
|
|
217
233
|
if (!resolved.grouped) {
|
|
218
|
-
_context2.next =
|
|
234
|
+
_context2.next = 6;
|
|
219
235
|
break;
|
|
220
236
|
}
|
|
221
237
|
return _context2.abrupt("return", renderGroupedResult({
|
|
@@ -227,7 +243,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
227
243
|
writer: writer,
|
|
228
244
|
invocation: invocation
|
|
229
245
|
}));
|
|
230
|
-
case
|
|
246
|
+
case 6:
|
|
231
247
|
return _context2.abrupt("return", renderSingleResult({
|
|
232
248
|
command: command,
|
|
233
249
|
input: input,
|
|
@@ -237,7 +253,7 @@ var runRegistryCommand = /*#__PURE__*/function () {
|
|
|
237
253
|
writer: writer,
|
|
238
254
|
invocation: invocation
|
|
239
255
|
}));
|
|
240
|
-
case
|
|
256
|
+
case 7:
|
|
241
257
|
case "end":
|
|
242
258
|
return _context2.stop();
|
|
243
259
|
}
|
|
@@ -409,6 +425,7 @@ var createCapturedWriter = function createCapturedWriter() {
|
|
|
409
425
|
*/
|
|
410
426
|
var runBatchChild = /*#__PURE__*/function () {
|
|
411
427
|
var _ref0 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref9) {
|
|
428
|
+
var _getCommand;
|
|
412
429
|
var request, invocation, parsed, response, captured;
|
|
413
430
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
414
431
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -424,7 +441,7 @@ var runBatchChild = /*#__PURE__*/function () {
|
|
|
424
441
|
code: 'USAGE_ERROR',
|
|
425
442
|
message: 'A batch request must start with a command name.'
|
|
426
443
|
});
|
|
427
|
-
_context3.next =
|
|
444
|
+
_context3.next = 5;
|
|
428
445
|
break;
|
|
429
446
|
case 1:
|
|
430
447
|
if (!(parsed.command === 'batch')) {
|
|
@@ -436,15 +453,27 @@ var runBatchChild = /*#__PURE__*/function () {
|
|
|
436
453
|
code: 'USAGE_ERROR',
|
|
437
454
|
message: 'Nested batch requests are not supported.'
|
|
438
455
|
});
|
|
439
|
-
_context3.next =
|
|
456
|
+
_context3.next = 5;
|
|
440
457
|
break;
|
|
441
458
|
case 2:
|
|
459
|
+
if (!((_getCommand = getCommand(parsed.command)) !== null && _getCommand !== void 0 && _getCommand.action)) {
|
|
460
|
+
_context3.next = 3;
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
response = createErrorEnvelope({
|
|
464
|
+
command: parsed.command,
|
|
465
|
+
code: 'USAGE_ERROR',
|
|
466
|
+
message: "Action command \"".concat(parsed.command, "\" cannot run inside batch.")
|
|
467
|
+
});
|
|
468
|
+
_context3.next = 5;
|
|
469
|
+
break;
|
|
470
|
+
case 3:
|
|
442
471
|
captured = createCapturedWriter();
|
|
443
|
-
_context3.next =
|
|
472
|
+
_context3.next = 4;
|
|
444
473
|
return run([].concat(_toConsumableArray(request.argv), ['--json']), captured, {
|
|
445
474
|
invocation: invocation
|
|
446
475
|
});
|
|
447
|
-
case
|
|
476
|
+
case 4:
|
|
448
477
|
try {
|
|
449
478
|
response = JSON.parse(captured.stdout.join('\n'));
|
|
450
479
|
} catch (_unused) {
|
|
@@ -454,13 +483,13 @@ var runBatchChild = /*#__PURE__*/function () {
|
|
|
454
483
|
message: 'The child command did not produce a valid JSON envelope.'
|
|
455
484
|
});
|
|
456
485
|
}
|
|
457
|
-
case
|
|
486
|
+
case 5:
|
|
458
487
|
return _context3.abrupt("return", {
|
|
459
488
|
request: request.argv,
|
|
460
489
|
status: classifyBatchResponse(response),
|
|
461
490
|
response: response
|
|
462
491
|
});
|
|
463
|
-
case
|
|
492
|
+
case 6:
|
|
464
493
|
case "end":
|
|
465
494
|
return _context3.stop();
|
|
466
495
|
}
|
|
@@ -570,6 +570,18 @@ var resolveBatch = function resolveBatch(input) {
|
|
|
570
570
|
* The full set of CLI commands. Order here is the order shown by `manifest` and `--help`.
|
|
571
571
|
*/
|
|
572
572
|
export var commands = [{
|
|
573
|
+
name: 'init',
|
|
574
|
+
action: 'init',
|
|
575
|
+
description: 'Set up the ADS, UI Styling Standard, and Accessibility Foundation skills at the Git repository root and install the Atlas CLI ADS plugin.',
|
|
576
|
+
usage: 'init',
|
|
577
|
+
arguments: [],
|
|
578
|
+
flags: [],
|
|
579
|
+
examples: ['init'],
|
|
580
|
+
responseTypes: ['ads-cli/init'],
|
|
581
|
+
envelopeType: function envelopeType() {
|
|
582
|
+
return 'init';
|
|
583
|
+
}
|
|
584
|
+
}, {
|
|
573
585
|
name: 'search',
|
|
574
586
|
description: 'Fuzzy-search ADS components, tokens, icons, and docs together (or narrow results with --type). Returns up to 2 matches per term, per result type by default; override with --limit.',
|
|
575
587
|
usage: "search <query...> [--type ".concat(Object.keys(SEARCH_TYPE_VALUES).join('|'), "] [--limit N]"),
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
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; } } }; }
|
|
4
|
+
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; } }
|
|
5
|
+
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; }
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
import { lstatSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { createErrorEnvelope } from '../envelope/create-error-envelope';
|
|
11
|
+
import { createSuccessEnvelope } from '../envelope/create-success-envelope';
|
|
12
|
+
import { writeHumanError } from '../output/write-human-error';
|
|
13
|
+
import { writeJsonEnvelope } from '../output/write-json-envelope';
|
|
14
|
+
import { ExitCode } from '../types';
|
|
15
|
+
import { CLI_ATLAS_INVOCATION } from './cli-metadata';
|
|
16
|
+
import { AGENTS_FILE_RELATIVE_PATH, updateAgentsFile } from './update-agents-file';
|
|
17
|
+
var SKILL_ENTRYPOINT = 'SKILL.md';
|
|
18
|
+
var SKILLS = [{
|
|
19
|
+
name: 'atlassian-design-system',
|
|
20
|
+
displayName: 'ADS',
|
|
21
|
+
relativePath: '.agents/skills/atlassian-design-system',
|
|
22
|
+
requiredFiles: [SKILL_ENTRYPOINT]
|
|
23
|
+
}, {
|
|
24
|
+
name: 'ui-styling-standard',
|
|
25
|
+
displayName: 'UI Styling Standard',
|
|
26
|
+
relativePath: '.agents/skills/ui-styling-standard',
|
|
27
|
+
requiredFiles: [SKILL_ENTRYPOINT]
|
|
28
|
+
}, {
|
|
29
|
+
name: 'a11y-foundation',
|
|
30
|
+
displayName: 'Accessibility Foundation',
|
|
31
|
+
relativePath: '.agents/skills/a11y-foundation',
|
|
32
|
+
requiredFiles: [SKILL_ENTRYPOINT]
|
|
33
|
+
}];
|
|
34
|
+
var ADS_SKILL = SKILLS[0];
|
|
35
|
+
var SKILL_GET_STARTED_RELATIVE_PATH = "".concat(ADS_SKILL.relativePath, "/references/get-started.md");
|
|
36
|
+
var GIT_MARKER = '.git';
|
|
37
|
+
var SKILLS_INSTALLER_PACKAGE = '@atlassian/skills';
|
|
38
|
+
var SKILLS_INSTALLER_UNAVAILABLE_REASON = 'skills-installer-unavailable';
|
|
39
|
+
var SKILLS_INSTALLER_UNAVAILABLE_ERROR_CODES = new Set(['EACCES', 'EAI_AGAIN', 'ECONNREFUSED', 'ECONNRESET', 'ENOENT', 'ENOTFOUND', 'ETIMEDOUT']);
|
|
40
|
+
var defaultPathExists = function defaultPathExists(target) {
|
|
41
|
+
try {
|
|
42
|
+
lstatSync(target);
|
|
43
|
+
return true;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error.code === 'ENOENT') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var defaultRunProcess = function defaultRunProcess(_ref) {
|
|
52
|
+
var command = _ref.command,
|
|
53
|
+
args = _ref.args,
|
|
54
|
+
cwd = _ref.cwd,
|
|
55
|
+
capture = _ref.capture;
|
|
56
|
+
var result = spawnSync(command, args, {
|
|
57
|
+
cwd: cwd,
|
|
58
|
+
encoding: 'utf8',
|
|
59
|
+
stdio: capture ? 'pipe' : 'inherit'
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
status: result.status,
|
|
63
|
+
stdout: typeof result.stdout === 'string' ? result.stdout : '',
|
|
64
|
+
stderr: typeof result.stderr === 'string' ? result.stderr : '',
|
|
65
|
+
error: result.error
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var processFailureMessage = function processFailureMessage(result, fallback) {
|
|
69
|
+
var _result$error;
|
|
70
|
+
var details = result.stderr.trim() || ((_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.message);
|
|
71
|
+
return details ? "".concat(fallback, ": ").concat(details) : fallback;
|
|
72
|
+
};
|
|
73
|
+
var isSkillsInstallerUnavailableFailure = function isSkillsInstallerUnavailableFailure(result) {
|
|
74
|
+
var _result$error2, _result$error$message, _result$error3;
|
|
75
|
+
if (result.status === null || (_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.code && SKILLS_INSTALLER_UNAVAILABLE_ERROR_CODES.has(result.error.code)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
var details = "".concat(result.stdout, "\n").concat(result.stderr, "\n").concat((_result$error$message = (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.message) !== null && _result$error$message !== void 0 ? _result$error$message : '').toLowerCase();
|
|
79
|
+
if (!details.trim()) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return ['401 unauthorized', '403 forbidden', '404 not found', 'authentication required', 'could not resolve', 'e401', 'e403', 'e404', 'eneedauth', 'failed to fetch', 'network error', 'not in this registry', 'registry unavailable', 'unable to authenticate', 'unable to resolve'].some(function (message) {
|
|
83
|
+
return details.includes(message);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
var createNotInstalledSkillResults = function createNotInstalledSkillResults(reason) {
|
|
87
|
+
return SKILLS.map(function (skillDefinition) {
|
|
88
|
+
return {
|
|
89
|
+
name: skillDefinition.name,
|
|
90
|
+
status: 'not-installed',
|
|
91
|
+
path: skillDefinition.relativePath,
|
|
92
|
+
reason: reason
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
var findRepositoryRoot = function findRepositoryRoot(cwd) {
|
|
97
|
+
var current = path.resolve(cwd);
|
|
98
|
+
while (true) {
|
|
99
|
+
if (defaultPathExists(path.join(current, GIT_MARKER))) {
|
|
100
|
+
return current;
|
|
101
|
+
}
|
|
102
|
+
var parent = path.dirname(current);
|
|
103
|
+
if (parent === current) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
current = parent;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var writeUsageError = function writeUsageError(_ref2) {
|
|
110
|
+
var message = _ref2.message,
|
|
111
|
+
json = _ref2.json,
|
|
112
|
+
writer = _ref2.writer;
|
|
113
|
+
if (json) {
|
|
114
|
+
writeJsonEnvelope({
|
|
115
|
+
envelope: createErrorEnvelope({
|
|
116
|
+
command: 'init',
|
|
117
|
+
code: 'USAGE_ERROR',
|
|
118
|
+
message: message
|
|
119
|
+
}),
|
|
120
|
+
writer: writer
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
writeHumanError({
|
|
124
|
+
message: message,
|
|
125
|
+
writer: writer
|
|
126
|
+
});
|
|
127
|
+
writer.err('Usage: init');
|
|
128
|
+
}
|
|
129
|
+
return ExitCode.UsageError;
|
|
130
|
+
};
|
|
131
|
+
var validateInput = function validateInput(input) {
|
|
132
|
+
if (input.positionals.length > 0) {
|
|
133
|
+
return '`init` does not accept positional arguments.';
|
|
134
|
+
}
|
|
135
|
+
var allowedFlags = new Set(['json']);
|
|
136
|
+
var unknownFlag = Object.keys(input.flags).find(function (flag) {
|
|
137
|
+
return !allowedFlags.has(flag);
|
|
138
|
+
});
|
|
139
|
+
if (unknownFlag) {
|
|
140
|
+
return "Unknown flag \"--".concat(unknownFlag, "\".");
|
|
141
|
+
}
|
|
142
|
+
return undefined;
|
|
143
|
+
};
|
|
144
|
+
var writeAgentsFileResult = function writeAgentsFileResult(_ref3) {
|
|
145
|
+
var result = _ref3.result,
|
|
146
|
+
writer = _ref3.writer;
|
|
147
|
+
switch (result.status) {
|
|
148
|
+
case 'created':
|
|
149
|
+
writer.out("\u2713 Created ".concat(AGENTS_FILE_RELATIVE_PATH, " with ADS setup guidance"));
|
|
150
|
+
return;
|
|
151
|
+
case 'appended':
|
|
152
|
+
writer.out("\u2713 Appended ADS setup guidance to ".concat(AGENTS_FILE_RELATIVE_PATH));
|
|
153
|
+
return;
|
|
154
|
+
case 'updated':
|
|
155
|
+
writer.out("\u2713 Updated ADS setup guidance in ".concat(AGENTS_FILE_RELATIVE_PATH));
|
|
156
|
+
return;
|
|
157
|
+
case 'already-current':
|
|
158
|
+
writer.out("\u2713 ADS setup guidance already current in ".concat(AGENTS_FILE_RELATIVE_PATH));
|
|
159
|
+
return;
|
|
160
|
+
case 'not-written':
|
|
161
|
+
writer.out("\u2013 ".concat(AGENTS_FILE_RELATIVE_PATH, " not updated because the current directory is not in a Git repository"));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
export var runInitCommand = /*#__PURE__*/function () {
|
|
165
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref4) {
|
|
166
|
+
var input, json, writer, invocation, cwd, usageError, projectRoot, skills, agentsMd, repositorySetupErrors, npxCommand, skillsInstallerUnavailable, skillHumanOutput, _loop, _i, _SKILLS, skillResultsByName, _iterator, _step, line, installedSkills, _adsSkillInstalled, atlasCwd, atlasPluginStatus, _atlasCheck$error, atlasCheck, installResult, verification, adsSkillInstalled, nextStep, data;
|
|
167
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
168
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
input = _ref4.input, json = _ref4.json, writer = _ref4.writer, invocation = _ref4.invocation, cwd = _ref4.cwd;
|
|
171
|
+
usageError = validateInput(input);
|
|
172
|
+
if (!usageError) {
|
|
173
|
+
_context2.next = 1;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
return _context2.abrupt("return", writeUsageError({
|
|
177
|
+
message: usageError,
|
|
178
|
+
json: json,
|
|
179
|
+
writer: writer
|
|
180
|
+
}));
|
|
181
|
+
case 1:
|
|
182
|
+
projectRoot = findRepositoryRoot(cwd);
|
|
183
|
+
skills = [];
|
|
184
|
+
repositorySetupErrors = [];
|
|
185
|
+
if (projectRoot) {
|
|
186
|
+
_context2.next = 2;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
skills.push.apply(skills, _toConsumableArray(createNotInstalledSkillResults('not-in-git-repository')));
|
|
190
|
+
if (!json) {
|
|
191
|
+
writer.out('– Repository-local skills not installed because the current directory is not in a Git repository');
|
|
192
|
+
}
|
|
193
|
+
agentsMd = {
|
|
194
|
+
status: 'not-written',
|
|
195
|
+
path: AGENTS_FILE_RELATIVE_PATH,
|
|
196
|
+
reason: 'not-in-git-repository'
|
|
197
|
+
};
|
|
198
|
+
if (!json) {
|
|
199
|
+
writeAgentsFileResult({
|
|
200
|
+
result: agentsMd,
|
|
201
|
+
writer: writer
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
_context2.next = 7;
|
|
205
|
+
break;
|
|
206
|
+
case 2:
|
|
207
|
+
npxCommand = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
208
|
+
skillsInstallerUnavailable = false;
|
|
209
|
+
skillHumanOutput = [];
|
|
210
|
+
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
211
|
+
var skillDefinition, skillPath, skillEntrypoint, skillPathExists, skillEntrypointExists, isCurrent, skillResult, result, missingRequiredFile, missingRelativePath, statusMessage, _t;
|
|
212
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
213
|
+
while (1) switch (_context.prev = _context.next) {
|
|
214
|
+
case 0:
|
|
215
|
+
skillDefinition = _SKILLS[_i];
|
|
216
|
+
_context.prev = 1;
|
|
217
|
+
skillPath = path.join(projectRoot, skillDefinition.relativePath);
|
|
218
|
+
skillEntrypoint = path.join(skillPath, SKILL_ENTRYPOINT);
|
|
219
|
+
skillPathExists = defaultPathExists(skillPath);
|
|
220
|
+
skillEntrypointExists = defaultPathExists(skillEntrypoint);
|
|
221
|
+
isCurrent = skillDefinition.requiredFiles.every(function (requiredFile) {
|
|
222
|
+
return defaultPathExists(path.join(skillPath, requiredFile));
|
|
223
|
+
});
|
|
224
|
+
if (!(skillPathExists && !skillEntrypointExists)) {
|
|
225
|
+
_context.next = 2;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
throw new Error("Cannot install the ".concat(skillDefinition.displayName, " skill because ").concat(skillDefinition.relativePath, " already exists without a ").concat(SKILL_ENTRYPOINT, ". Move or remove it, then run init again."));
|
|
229
|
+
case 2:
|
|
230
|
+
if (!isCurrent) {
|
|
231
|
+
_context.next = 3;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
skillResult = {
|
|
235
|
+
name: skillDefinition.name,
|
|
236
|
+
status: 'already-installed',
|
|
237
|
+
path: skillDefinition.relativePath
|
|
238
|
+
};
|
|
239
|
+
_context.next = 7;
|
|
240
|
+
break;
|
|
241
|
+
case 3:
|
|
242
|
+
result = defaultRunProcess({
|
|
243
|
+
command: npxCommand,
|
|
244
|
+
args: ['--yes', SKILLS_INSTALLER_PACKAGE, 'add', skillDefinition.name, '--universal', '--yes'],
|
|
245
|
+
cwd: projectRoot,
|
|
246
|
+
capture: true
|
|
247
|
+
});
|
|
248
|
+
if (!(result.status !== 0)) {
|
|
249
|
+
_context.next = 5;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
if (!isSkillsInstallerUnavailableFailure(result)) {
|
|
253
|
+
_context.next = 4;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
skillsInstallerUnavailable = true;
|
|
257
|
+
return _context.abrupt("return", 1);
|
|
258
|
+
case 4:
|
|
259
|
+
throw new Error(processFailureMessage(result, "Failed to install the ".concat(skillDefinition.displayName, " skill")));
|
|
260
|
+
case 5:
|
|
261
|
+
missingRequiredFile = skillDefinition.requiredFiles.find(function (requiredFile) {
|
|
262
|
+
return !defaultPathExists(path.join(skillPath, requiredFile));
|
|
263
|
+
});
|
|
264
|
+
if (!missingRequiredFile) {
|
|
265
|
+
_context.next = 6;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
missingRelativePath = "".concat(skillDefinition.relativePath, "/").concat(missingRequiredFile);
|
|
269
|
+
throw new Error("The skill installer completed without creating ".concat(missingRelativePath, "."));
|
|
270
|
+
case 6:
|
|
271
|
+
skillResult = {
|
|
272
|
+
name: skillDefinition.name,
|
|
273
|
+
status: skillEntrypointExists ? 'updated' : 'installed',
|
|
274
|
+
path: skillDefinition.relativePath
|
|
275
|
+
};
|
|
276
|
+
case 7:
|
|
277
|
+
skills.push(skillResult);
|
|
278
|
+
if (!json) {
|
|
279
|
+
statusMessage = skillResult.status === 'already-installed' ? 'already set up' : skillResult.status;
|
|
280
|
+
skillHumanOutput.push("\u2713 ".concat(skillDefinition.displayName, " skill ").concat(statusMessage, " at ").concat(skillDefinition.relativePath));
|
|
281
|
+
}
|
|
282
|
+
_context.next = 9;
|
|
283
|
+
break;
|
|
284
|
+
case 8:
|
|
285
|
+
_context.prev = 8;
|
|
286
|
+
_t = _context["catch"](1);
|
|
287
|
+
repositorySetupErrors.push(_t instanceof Error ? _t : new Error("Failed to set up the ".concat(skillDefinition.displayName, " skill.")));
|
|
288
|
+
case 9:
|
|
289
|
+
case "end":
|
|
290
|
+
return _context.stop();
|
|
291
|
+
}
|
|
292
|
+
}, _loop, null, [[1, 8]]);
|
|
293
|
+
});
|
|
294
|
+
_i = 0, _SKILLS = SKILLS;
|
|
295
|
+
case 3:
|
|
296
|
+
if (!(_i < _SKILLS.length)) {
|
|
297
|
+
_context2.next = 6;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
return _context2.delegateYield(_loop(), "t0", 4);
|
|
301
|
+
case 4:
|
|
302
|
+
if (!_context2.t0) {
|
|
303
|
+
_context2.next = 5;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
return _context2.abrupt("continue", 6);
|
|
307
|
+
case 5:
|
|
308
|
+
_i++;
|
|
309
|
+
_context2.next = 3;
|
|
310
|
+
break;
|
|
311
|
+
case 6:
|
|
312
|
+
if (skillsInstallerUnavailable) {
|
|
313
|
+
skillResultsByName = new Map(skills.map(function (skill) {
|
|
314
|
+
return [skill.name, skill];
|
|
315
|
+
}));
|
|
316
|
+
skills.splice.apply(skills, [0, skills.length].concat(_toConsumableArray(SKILLS.map(function (skillDefinition) {
|
|
317
|
+
var _skillResultsByName$g;
|
|
318
|
+
return (_skillResultsByName$g = skillResultsByName.get(skillDefinition.name)) !== null && _skillResultsByName$g !== void 0 ? _skillResultsByName$g : {
|
|
319
|
+
name: skillDefinition.name,
|
|
320
|
+
status: 'not-installed',
|
|
321
|
+
path: skillDefinition.relativePath,
|
|
322
|
+
reason: SKILLS_INSTALLER_UNAVAILABLE_REASON
|
|
323
|
+
};
|
|
324
|
+
}))));
|
|
325
|
+
}
|
|
326
|
+
if (!json) {
|
|
327
|
+
_iterator = _createForOfIteratorHelper(skillHumanOutput);
|
|
328
|
+
try {
|
|
329
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
330
|
+
line = _step.value;
|
|
331
|
+
writer.out(line);
|
|
332
|
+
}
|
|
333
|
+
} catch (err) {
|
|
334
|
+
_iterator.e(err);
|
|
335
|
+
} finally {
|
|
336
|
+
_iterator.f();
|
|
337
|
+
}
|
|
338
|
+
if (skillsInstallerUnavailable) {
|
|
339
|
+
writer.out(skillHumanOutput.length > 0 ? '– Remaining repository-local skills skipped because @atlassian/skills is unavailable; npx @atlaskit/ads-cli remains available' : '– Repository-local skills skipped because @atlassian/skills is unavailable; npx @atlaskit/ads-cli remains available');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
installedSkills = skills.filter(function (skill) {
|
|
343
|
+
return skill.status !== 'not-installed';
|
|
344
|
+
});
|
|
345
|
+
_adsSkillInstalled = installedSkills.some(function (skill) {
|
|
346
|
+
return skill.name === ADS_SKILL.name;
|
|
347
|
+
});
|
|
348
|
+
if (skillsInstallerUnavailable || _adsSkillInstalled) {
|
|
349
|
+
try {
|
|
350
|
+
agentsMd = updateAgentsFile({
|
|
351
|
+
projectRoot: projectRoot,
|
|
352
|
+
guidance: _adsSkillInstalled ? {
|
|
353
|
+
mode: 'skills-installed',
|
|
354
|
+
skillEntrypoints: installedSkills.map(function (skill) {
|
|
355
|
+
return "".concat(skill.path, "/").concat(SKILL_ENTRYPOINT);
|
|
356
|
+
}),
|
|
357
|
+
getStartedPath: SKILL_GET_STARTED_RELATIVE_PATH
|
|
358
|
+
} : {
|
|
359
|
+
mode: 'public'
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (!json) {
|
|
363
|
+
writeAgentsFileResult({
|
|
364
|
+
result: agentsMd,
|
|
365
|
+
writer: writer
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
} catch (error) {
|
|
369
|
+
repositorySetupErrors.push(error instanceof Error ? error : new Error('Failed to set up the ADS repository guidance.'));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
case 7:
|
|
373
|
+
atlasCwd = projectRoot !== null && projectRoot !== void 0 ? projectRoot : path.resolve(cwd);
|
|
374
|
+
if (!(invocation === CLI_ATLAS_INVOCATION)) {
|
|
375
|
+
_context2.next = 8;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
atlasPluginStatus = 'already-installed';
|
|
379
|
+
if (!json) {
|
|
380
|
+
writer.out('✓ Atlas CLI ADS plugin already available');
|
|
381
|
+
}
|
|
382
|
+
_context2.next = 13;
|
|
383
|
+
break;
|
|
384
|
+
case 8:
|
|
385
|
+
atlasCheck = defaultRunProcess({
|
|
386
|
+
command: 'atlas',
|
|
387
|
+
args: ['ads', '--help'],
|
|
388
|
+
cwd: atlasCwd,
|
|
389
|
+
capture: true
|
|
390
|
+
});
|
|
391
|
+
if (!(atlasCheck.status === 0)) {
|
|
392
|
+
_context2.next = 9;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
atlasPluginStatus = 'already-installed';
|
|
396
|
+
if (!json) {
|
|
397
|
+
writer.out('✓ Atlas CLI ADS plugin already available');
|
|
398
|
+
}
|
|
399
|
+
_context2.next = 13;
|
|
400
|
+
break;
|
|
401
|
+
case 9:
|
|
402
|
+
if (!(((_atlasCheck$error = atlasCheck.error) === null || _atlasCheck$error === void 0 ? void 0 : _atlasCheck$error.code) === 'ENOENT')) {
|
|
403
|
+
_context2.next = 10;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
atlasPluginStatus = 'atlas-cli-unavailable';
|
|
407
|
+
if (!json) {
|
|
408
|
+
writer.out('– Atlas CLI is unavailable; use npx @atlaskit/ads-cli for ADS commands');
|
|
409
|
+
}
|
|
410
|
+
_context2.next = 13;
|
|
411
|
+
break;
|
|
412
|
+
case 10:
|
|
413
|
+
installResult = defaultRunProcess({
|
|
414
|
+
command: 'atlas',
|
|
415
|
+
args: ['plugin', 'install', '--name', 'ads'],
|
|
416
|
+
cwd: atlasCwd,
|
|
417
|
+
capture: json
|
|
418
|
+
});
|
|
419
|
+
if (!(installResult.status !== 0)) {
|
|
420
|
+
_context2.next = 11;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
throw new Error(processFailureMessage(installResult, 'Failed to install the Atlas CLI ADS plugin. npx @atlaskit/ads-cli remains available'));
|
|
424
|
+
case 11:
|
|
425
|
+
verification = defaultRunProcess({
|
|
426
|
+
command: 'atlas',
|
|
427
|
+
args: ['ads', '--help'],
|
|
428
|
+
cwd: atlasCwd,
|
|
429
|
+
capture: true
|
|
430
|
+
});
|
|
431
|
+
if (!(verification.status !== 0)) {
|
|
432
|
+
_context2.next = 12;
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
throw new Error('The Atlas CLI ADS plugin was installed but `atlas ads --help` did not succeed. npx @atlaskit/ads-cli remains available.');
|
|
436
|
+
case 12:
|
|
437
|
+
atlasPluginStatus = 'installed';
|
|
438
|
+
if (!json) {
|
|
439
|
+
writer.out('✓ Atlas CLI ADS plugin installed');
|
|
440
|
+
}
|
|
441
|
+
case 13:
|
|
442
|
+
if (!(repositorySetupErrors.length > 0)) {
|
|
443
|
+
_context2.next = 14;
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
throw new Error(repositorySetupErrors.map(function (error) {
|
|
447
|
+
return error.message;
|
|
448
|
+
}).join('\n'));
|
|
449
|
+
case 14:
|
|
450
|
+
if (!(skills.length !== SKILLS.length || !agentsMd)) {
|
|
451
|
+
_context2.next = 15;
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
throw new Error('Failed to determine the ADS repository setup result.');
|
|
455
|
+
case 15:
|
|
456
|
+
adsSkillInstalled = skills.some(function (skill) {
|
|
457
|
+
return skill.name === ADS_SKILL.name && skill.status !== 'not-installed';
|
|
458
|
+
});
|
|
459
|
+
nextStep = projectRoot && adsSkillInstalled ? SKILL_GET_STARTED_RELATIVE_PATH : null;
|
|
460
|
+
if (!json && nextStep) {
|
|
461
|
+
writer.out("\u2192 Next: follow ".concat(nextStep, " to complete repository setup"));
|
|
462
|
+
}
|
|
463
|
+
data = {
|
|
464
|
+
projectRoot: projectRoot !== null && projectRoot !== void 0 ? projectRoot : null,
|
|
465
|
+
skills: skills,
|
|
466
|
+
agentsMd: agentsMd,
|
|
467
|
+
atlas: {
|
|
468
|
+
status: atlasPluginStatus
|
|
469
|
+
},
|
|
470
|
+
nextStep: nextStep
|
|
471
|
+
};
|
|
472
|
+
if (json) {
|
|
473
|
+
writeJsonEnvelope({
|
|
474
|
+
envelope: createSuccessEnvelope({
|
|
475
|
+
envelopeType: 'init',
|
|
476
|
+
command: 'init',
|
|
477
|
+
data: data,
|
|
478
|
+
meta: {}
|
|
479
|
+
}),
|
|
480
|
+
writer: writer
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return _context2.abrupt("return", ExitCode.Ok);
|
|
484
|
+
case 16:
|
|
485
|
+
case "end":
|
|
486
|
+
return _context2.stop();
|
|
487
|
+
}
|
|
488
|
+
}, _callee);
|
|
489
|
+
}));
|
|
490
|
+
return function runInitCommand(_x) {
|
|
491
|
+
return _ref5.apply(this, arguments);
|
|
492
|
+
};
|
|
493
|
+
}();
|