bdy 1.26.3-stage → 1.26.3

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.26.3-stage",
4
+ "version": "1.26.3",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const ruleset_1 = require("./ruleset");
11
+ const commandRulesetCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_RULESET_CREATE, {
12
+ requiredScopes: [utils_1.REST_API_SCOPE.RULESET_MANAGE],
13
+ examples: texts_1.EXAMPLE_RULESET_CREATE,
14
+ });
15
+ commandRulesetCreate.alias('add');
16
+ commandRulesetCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
+ commandRulesetCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
+ commandRulesetCreate.option('--yaml <content|@path>', texts_1.OPTION_RULESET_YAML);
19
+ commandRulesetCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
20
+ commandRulesetCreate.action(async (options) => {
21
+ const body = (0, ruleset_1.rulesetBody)(options.yaml);
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const project = input_1.default.restApiProject(options.project);
24
+ const client = input_1.default.restApiTokenClient();
25
+ const result = await client.createRuleset(workspace, project, body);
26
+ if (options.format === 'json') {
27
+ output_1.default.json(result);
28
+ output_1.default.exitNormal();
29
+ }
30
+ output_1.default.exitSuccess((0, texts_1.TXT_RULESET_CREATED)(result.identifier, result.html_url));
31
+ });
32
+ exports.default = commandRulesetCreate;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const ruleset_1 = require("./ruleset");
11
+ const commandRulesetDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_RULESET_DELETE, {
12
+ requiredScopes: [utils_1.REST_API_SCOPE.RULESET_MANAGE],
13
+ examples: texts_1.EXAMPLE_RULESET_DELETE,
14
+ });
15
+ commandRulesetDelete.alias('rm');
16
+ commandRulesetDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
+ commandRulesetDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
+ commandRulesetDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
19
+ commandRulesetDelete.option('--format <text|json>', texts_1.OPTION_FORMAT);
20
+ commandRulesetDelete.argument('<identifier>', texts_1.OPTION_RULESET_IDENTIFIER);
21
+ commandRulesetDelete.action(async (identifier, options) => {
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const project = input_1.default.restApiProject(options.project);
24
+ const client = input_1.default.restApiTokenClient();
25
+ const rulesetId = await (0, ruleset_1.resolveRulesetId)(client, workspace, project, identifier);
26
+ const json = options.format === 'json';
27
+ const confirmed = await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_RULESET_DELETE_CONFIRM)(identifier), json);
28
+ if (!confirmed)
29
+ output_1.default.exitResult(json, { deleted: null });
30
+ await client.deleteRuleset(workspace, project, rulesetId);
31
+ output_1.default.exitResult(json, { deleted: identifier }, (0, texts_1.TXT_RULESET_DELETED)(identifier));
32
+ });
33
+ exports.default = commandRulesetDelete;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const ruleset_1 = require("./ruleset");
11
+ const commandRulesetGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_RULESET_GET, {
12
+ requiredScopes: [utils_1.REST_API_SCOPE.RULESET_READ],
13
+ examples: texts_1.EXAMPLE_RULESET_GET,
14
+ });
15
+ commandRulesetGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
16
+ commandRulesetGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
17
+ commandRulesetGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
18
+ commandRulesetGet.argument('<identifier>', texts_1.OPTION_RULESET_IDENTIFIER);
19
+ const list = (values) => (values || []).join(', ') || '-';
20
+ const bypassEntries = (entries) => (entries || []).map((e) => `${e.id} (${e.access})`).join(', ') || '-';
21
+ commandRulesetGet.action(async (identifier, options) => {
22
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
23
+ const project = input_1.default.restApiProject(options.project);
24
+ const client = input_1.default.restApiTokenClient();
25
+ const rulesetId = await (0, ruleset_1.resolveRulesetId)(client, workspace, project, identifier);
26
+ const ruleset = await client.getRuleset(workspace, project, rulesetId);
27
+ if (options.format === 'json') {
28
+ output_1.default.json(ruleset);
29
+ }
30
+ else {
31
+ const bypass = ruleset.bypass || {};
32
+ const checks = ruleset.rules?.required_checks || {};
33
+ const data = [
34
+ ['Field', 'Value'],
35
+ ['ID', ruleset.id || '-'],
36
+ ['Identifier', ruleset.identifier || '-'],
37
+ ['Name', ruleset.name || '-'],
38
+ ['State', ruleset.disabled ? 'DISABLED' : 'ACTIVE'],
39
+ ['Refs', list(ruleset.refs)],
40
+ ['Rules', (0, ruleset_1.rulesFlags)(ruleset.rules)],
41
+ ['Required pipelines', list(checks.pipelines)],
42
+ ['Required unit test suites', list(checks.unit_tests_suites)],
43
+ ['Required visual test suites', list(checks.visual_tests_suites)],
44
+ ['Require up to date', checks.require_up_to_date ? 'true' : 'false'],
45
+ ['Bypass admins', bypass.admins ? 'true' : 'false'],
46
+ ['Bypass others', bypass.others || '-'],
47
+ ['Bypass users', bypassEntries(bypass.users)],
48
+ ['Bypass groups', bypassEntries(bypass.groups)],
49
+ ['Note', ruleset.note || '-'],
50
+ ['Agent note', ruleset.agent_note || '-'],
51
+ ];
52
+ if ((ruleset.missing_sources || []).length) {
53
+ data.push([
54
+ 'Missing sources',
55
+ ruleset.missing_sources
56
+ .map((s) => `${s.identifier} (${s.type})`)
57
+ .join(', '),
58
+ ]);
59
+ }
60
+ if (ruleset.html_url) {
61
+ data.push(['URL', ruleset.html_url]);
62
+ }
63
+ output_1.default.table(data);
64
+ }
65
+ output_1.default.exitNormal();
66
+ });
67
+ exports.default = commandRulesetGet;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const ruleset_1 = require("./ruleset");
11
+ const commandRulesetList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_RULESET_LIST, {
12
+ requiredScopes: [utils_1.REST_API_SCOPE.RULESET_READ],
13
+ examples: texts_1.EXAMPLE_RULESET_LIST,
14
+ });
15
+ commandRulesetList.alias('ls');
16
+ commandRulesetList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
+ commandRulesetList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
+ commandRulesetList.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ commandRulesetList.action(async (options) => {
20
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
21
+ const project = input_1.default.restApiProject(options.project);
22
+ const client = input_1.default.restApiTokenClient();
23
+ const result = await client.getRulesets(workspace, project);
24
+ const rulesets = result.rulesets || [];
25
+ if (options.format === 'json') {
26
+ output_1.default.json(rulesets);
27
+ }
28
+ else {
29
+ if (rulesets.length === 0) {
30
+ output_1.default.exitNormal(texts_1.TXT_RULESET_NOT_FOUND);
31
+ }
32
+ const data = [['IDENTIFIER', 'NAME', 'STATE', 'REFS', 'RULES']];
33
+ for (const ruleset of rulesets) {
34
+ data.push([
35
+ ruleset.identifier || '-',
36
+ ruleset.name || '-',
37
+ ruleset.disabled ? 'DISABLED' : 'ACTIVE',
38
+ (ruleset.refs || []).join(', ') || '-',
39
+ (0, ruleset_1.rulesFlags)(ruleset.rules),
40
+ ]);
41
+ }
42
+ output_1.default.table(data);
43
+ }
44
+ output_1.default.exitNormal();
45
+ });
46
+ exports.default = commandRulesetList;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rulesFlags = exports.rulesetBody = exports.resolveRulesetId = void 0;
7
+ const yaml_1 = __importDefault(require("yaml"));
8
+ const texts_1 = require("../../texts");
9
+ const cliError_1 = __importDefault(require("../../cliError"));
10
+ const input_1 = __importDefault(require("../../input"));
11
+ // /identifiers does not resolve rulesets, so the identifier is looked up in
12
+ // the project's list - one request, a project holds at most 75 rulesets.
13
+ const resolveRulesetId = async (client, workspace, project, identifier) => {
14
+ const result = await client.getRulesets(workspace, project);
15
+ const ruleset = (result.rulesets || []).find((r) => r.identifier === identifier);
16
+ if (!ruleset?.id) {
17
+ throw new cliError_1.default('not_found', texts_1.ERR_RULESET_NOT_FOUND, texts_1.HINT_RULESET_LIST);
18
+ }
19
+ return ruleset.id;
20
+ };
21
+ exports.resolveRulesetId = resolveRulesetId;
22
+ // The REST API takes the ruleset as JSON; YAML is accepted too (JSON is YAML),
23
+ // with the same snake_case fields.
24
+ const rulesetBody = (value) => {
25
+ const content = input_1.default.restApiYaml(value);
26
+ let parsed;
27
+ try {
28
+ parsed = yaml_1.default.parse(content);
29
+ }
30
+ catch (e) {
31
+ throw new cliError_1.default('usage_error', (0, texts_1.ERR_YAML_PARSE)(e.message));
32
+ }
33
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
34
+ throw new cliError_1.default('usage_error', texts_1.ERR_RULESET_YAML_NOT_OBJECT);
35
+ }
36
+ return parsed;
37
+ };
38
+ exports.rulesetBody = rulesetBody;
39
+ const rulesFlags = (rules) => {
40
+ if (!rules)
41
+ return '-';
42
+ const names = [
43
+ 'require_pull_request',
44
+ 'block_force_push',
45
+ 'restrict_deletion',
46
+ 'restrict_creation',
47
+ 'restrict_update',
48
+ ].filter((name) => rules[name]);
49
+ const checks = rules.required_checks;
50
+ if (checks &&
51
+ ((checks.pipelines || []).length ||
52
+ (checks.unit_tests_suites || []).length ||
53
+ (checks.visual_tests_suites || []).length)) {
54
+ names.unshift('required_checks');
55
+ }
56
+ return names.join(', ') || '-';
57
+ };
58
+ exports.rulesFlags = rulesFlags;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const input_1 = __importDefault(require("../../input"));
10
+ const ruleset_1 = require("./ruleset");
11
+ const commandRulesetUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_RULESET_UPDATE, {
12
+ requiredScopes: [utils_1.REST_API_SCOPE.RULESET_MANAGE],
13
+ examples: texts_1.EXAMPLE_RULESET_UPDATE,
14
+ helpText: texts_1.HELP_RULESET_UPDATE,
15
+ });
16
+ commandRulesetUpdate.alias('edit');
17
+ commandRulesetUpdate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
18
+ commandRulesetUpdate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
19
+ commandRulesetUpdate.option('--yaml <content|@path>', texts_1.OPTION_RULESET_YAML);
20
+ commandRulesetUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
21
+ commandRulesetUpdate.argument('<identifier>', texts_1.OPTION_RULESET_IDENTIFIER);
22
+ commandRulesetUpdate.action(async (identifier, options) => {
23
+ const body = (0, ruleset_1.rulesetBody)(options.yaml);
24
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
25
+ const project = input_1.default.restApiProject(options.project);
26
+ const client = input_1.default.restApiTokenClient();
27
+ const rulesetId = await (0, ruleset_1.resolveRulesetId)(client, workspace, project, identifier);
28
+ const result = await client.updateRuleset(workspace, project, rulesetId, body);
29
+ if (options.format === 'json') {
30
+ output_1.default.json(result);
31
+ output_1.default.exitNormal();
32
+ }
33
+ output_1.default.exitSuccess((0, texts_1.TXT_RULESET_UPDATED)(result.identifier, result.html_url));
34
+ });
35
+ exports.default = commandRulesetUpdate;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../utils");
7
+ const texts_1 = require("../texts");
8
+ const list_1 = __importDefault(require("./ruleset/list"));
9
+ const get_1 = __importDefault(require("./ruleset/get"));
10
+ const create_1 = __importDefault(require("./ruleset/create"));
11
+ const update_1 = __importDefault(require("./ruleset/update"));
12
+ const delete_1 = __importDefault(require("./ruleset/delete"));
13
+ const commandRuleset = (0, utils_1.newCommand)('ruleset', texts_1.DESC_COMMAND_RULESET);
14
+ commandRuleset.alias('rs');
15
+ commandRuleset.addCommand(list_1.default);
16
+ commandRuleset.addCommand(get_1.default);
17
+ commandRuleset.addCommand(create_1.default);
18
+ commandRuleset.addCommand(update_1.default);
19
+ commandRuleset.addCommand(delete_1.default);
20
+ exports.default = commandRuleset;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'agent',
8
+ description: texts_1.DESC_COMMAND_YAML_AGENT,
9
+ examples: texts_1.EXAMPLE_YAML_AGENT,
10
+ document: 'agents',
11
+ scope: schemaUtils_1.agentsScope,
12
+ title: texts_1.TXT_YAML_AGENT_PROPERTIES,
13
+ });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'custom-action',
8
+ description: texts_1.DESC_COMMAND_YAML_CUSTOM_ACTION,
9
+ examples: texts_1.EXAMPLE_YAML_CUSTOM_ACTION,
10
+ document: 'customActions',
11
+ scope: schemaUtils_1.customActionsScope,
12
+ title: texts_1.TXT_YAML_CUSTOM_ACTION_PROPERTIES,
13
+ });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'distro',
8
+ description: texts_1.DESC_COMMAND_YAML_DISTRO,
9
+ examples: texts_1.EXAMPLE_YAML_DISTRO,
10
+ document: 'distributions',
11
+ scope: schemaUtils_1.distributionsScope,
12
+ title: texts_1.TXT_YAML_DISTRO_PROPERTIES,
13
+ });
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YAML_TYPES = void 0;
4
+ exports.identifierOf = identifierOf;
5
+ exports.detectYamlType = detectYamlType;
6
+ exports.YAML_TYPES = {
7
+ pipeline: 'pipelines',
8
+ 'custom-action': 'customActions',
9
+ environment: 'environments',
10
+ target: 'targets',
11
+ sandbox: 'sandboxes',
12
+ agent: 'agents',
13
+ domain: 'domains',
14
+ distro: 'distributions',
15
+ };
16
+ // `agent` before `target`: an agent entry has a `target` switch of its own.
17
+ const BY_IDENTIFIER = [
18
+ ['pipeline', 'pipeline'],
19
+ ['environment', 'environment'],
20
+ ['sandbox', 'sandbox'],
21
+ ['distribution', 'distro'],
22
+ ['agent', 'agent'],
23
+ ['target', 'target'],
24
+ ];
25
+ function identifierOf(type) {
26
+ return BY_IDENTIFIER.find(([, owner]) => owner === type)?.[0];
27
+ }
28
+ function isObject(value) {
29
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
30
+ }
31
+ function typeOfEntry(entry) {
32
+ const found = BY_IDENTIFIER.find(([key]) => Object.hasOwn(entry, key));
33
+ if (!found)
34
+ return undefined;
35
+ const isSwitch = typeof entry.target === 'boolean' || entry.target === 'on' || entry.target === 'off';
36
+ return found[1] === 'target' && !Object.hasOwn(entry, 'type') && isSwitch ? 'agent' : found[1];
37
+ }
38
+ function typeOfContent(content) {
39
+ let parsed;
40
+ try {
41
+ parsed = require('yaml').parse(content);
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ if (Array.isArray(parsed)) {
47
+ for (const item of parsed) {
48
+ const type = isObject(item) ? typeOfEntry(item) : undefined;
49
+ if (type)
50
+ return type;
51
+ }
52
+ return undefined;
53
+ }
54
+ if (!isObject(parsed))
55
+ return undefined;
56
+ const zones = Object.values(parsed);
57
+ if (zones.length > 0 && zones.every((zone) => isObject(zone) && Object.hasOwn(zone, 'records'))) {
58
+ return 'domain';
59
+ }
60
+ return typeOfEntry(parsed);
61
+ }
62
+ function detectYamlType(content) {
63
+ return content === undefined ? undefined : typeOfContent(content);
64
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'domain',
8
+ description: texts_1.DESC_COMMAND_YAML_DOMAIN,
9
+ examples: texts_1.EXAMPLE_YAML_DOMAIN,
10
+ document: 'domains',
11
+ scope: schemaUtils_1.domainsScope,
12
+ title: texts_1.TXT_YAML_DOMAIN_PROPERTIES,
13
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'environment',
8
+ description: texts_1.DESC_COMMAND_YAML_ENVIRONMENT,
9
+ examples: texts_1.EXAMPLE_YAML_ENVIRONMENT,
10
+ document: 'environments',
11
+ scope: schemaUtils_1.environmentsScope,
12
+ title: texts_1.TXT_YAML_ENVIRONMENT_PROPERTIES,
13
+ typesHint: texts_1.TXT_YAML_ENVIRONMENT_TARGET_FIELDS,
14
+ });
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rootedYamlCommand = rootedYamlCommand;
7
+ const utils_1 = require("../../utils");
8
+ const output_1 = __importDefault(require("../../output"));
9
+ const texts_1 = require("../../texts");
10
+ const schemaUtils_1 = require("./schemaUtils");
11
+ const render_1 = require("./render");
12
+ function rootedYamlCommand({ name, description, examples, document, scope, title, typesHint, }) {
13
+ const command = (0, utils_1.newCommand)(name, description, { requiredScopes: [], examples });
14
+ command.option('--format <text|json>', texts_1.OPTION_FORMAT);
15
+ command.action(async (options) => {
16
+ await (0, schemaUtils_1.ensureYamlSchema)(document);
17
+ const root = await scope().root();
18
+ const properties = root ? await scope().properties(root.name) : [];
19
+ const types = root?.types ?? {};
20
+ const rootExamples = (root?.examples ?? []);
21
+ if (options.format === 'json') {
22
+ output_1.default.json({
23
+ properties: (0, render_1.propertiesJson)(properties),
24
+ required: properties.filter((p) => p.required).map((p) => p.name),
25
+ types: (0, render_1.typesJson)(types),
26
+ examples: rootExamples,
27
+ });
28
+ output_1.default.exitNormal();
29
+ return;
30
+ }
31
+ output_1.default.blue(title);
32
+ output_1.default.normal('');
33
+ (0, render_1.outputProperties)(properties);
34
+ if (Object.keys(types).length > 0) {
35
+ output_1.default.normal('');
36
+ output_1.default.blue(texts_1.TXT_YAML_TYPES);
37
+ if (typesHint)
38
+ output_1.default.muted(typesHint);
39
+ (0, render_1.outputTypes)(types);
40
+ }
41
+ if (rootExamples.length > 0) {
42
+ output_1.default.normal('');
43
+ (0, render_1.outputExamples)(rootExamples);
44
+ }
45
+ output_1.default.exitNormal();
46
+ });
47
+ return command;
48
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const texts_1 = require("../../texts");
4
+ const schemaUtils_1 = require("./schemaUtils");
5
+ const rooted_1 = require("./rooted");
6
+ exports.default = (0, rooted_1.rootedYamlCommand)({
7
+ name: 'sandbox',
8
+ description: texts_1.DESC_COMMAND_YAML_SANDBOX,
9
+ examples: texts_1.EXAMPLE_YAML_SANDBOX,
10
+ document: 'sandboxes',
11
+ scope: schemaUtils_1.sandboxesScope,
12
+ title: texts_1.TXT_YAML_SANDBOX_PROPERTIES,
13
+ });
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const output_1 = __importDefault(require("../../../output"));
8
+ const texts_1 = require("../../../texts");
9
+ const schemaUtils_1 = require("../schemaUtils");
10
+ const render_1 = require("../render");
11
+ const schema_1 = require("./schema");
12
+ const commandYamlTargetsInfo = (0, utils_1.newCommand)('info', texts_1.DESC_COMMAND_YAML_TARGETS_INFO, {
13
+ requiredScopes: [],
14
+ examples: texts_1.EXAMPLE_YAML_TARGETS_INFO,
15
+ });
16
+ commandYamlTargetsInfo.argument('<type>', texts_1.OPTION_YAML_TARGET_TYPE);
17
+ commandYamlTargetsInfo.option('--format <text|json>', texts_1.OPTION_FORMAT);
18
+ commandYamlTargetsInfo.action(async (type, options) => {
19
+ await (0, schemaUtils_1.ensureYamlSchema)('targets');
20
+ const target = await (0, schema_1.findTarget)(type);
21
+ if (!target) {
22
+ if (options.format === 'json') {
23
+ output_1.default.json(null);
24
+ output_1.default.exitNormal();
25
+ return;
26
+ }
27
+ output_1.default.error((0, texts_1.ERR_YAML_TARGET_NOT_FOUND)(type));
28
+ const similar = await (0, schema_1.searchTargets)(type, 5);
29
+ if (similar.length > 0) {
30
+ output_1.default.muted((0, texts_1.TXT_ACTION_DID_YOU_MEAN)(similar.map((one) => `${one.value} (${one.name})`).join(', ')));
31
+ }
32
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_USE_LIST);
33
+ output_1.default.exitNormal();
34
+ return;
35
+ }
36
+ const commonFields = new Set(await (0, schemaUtils_1.targetsScope)().commonFields());
37
+ const common = [];
38
+ const specific = [];
39
+ for (const property of target.properties) {
40
+ (commonFields.has(property.name) ? common : specific).push(property);
41
+ }
42
+ const types = target.document?.types ?? {};
43
+ if (options.format === 'json') {
44
+ output_1.default.json({
45
+ type: target.value,
46
+ slug: target.slug,
47
+ name: target.name,
48
+ description: target.description,
49
+ required: target.required,
50
+ fields: {
51
+ specific: (0, render_1.propertiesJson)(specific),
52
+ common: (0, render_1.propertiesJson)(common),
53
+ },
54
+ types: (0, render_1.typesJson)(types),
55
+ examples: target.examples,
56
+ });
57
+ output_1.default.exitNormal();
58
+ return;
59
+ }
60
+ output_1.default.blue(target.name, false);
61
+ output_1.default.gray(` · ${target.value}`);
62
+ output_1.default.gray(target.description);
63
+ output_1.default.normal('');
64
+ if (specific.length > 0) {
65
+ output_1.default.blue(texts_1.TXT_YAML_TYPE_SPECIFIC_FIELDS);
66
+ (0, render_1.outputProperties)(specific);
67
+ output_1.default.normal('');
68
+ }
69
+ if (common.length > 0) {
70
+ output_1.default.blue(texts_1.TXT_YAML_COMMON_FIELDS);
71
+ (0, render_1.outputProperties)(common);
72
+ }
73
+ if (Object.keys(types).length > 0) {
74
+ output_1.default.normal('');
75
+ output_1.default.blue(texts_1.TXT_YAML_TYPES);
76
+ (0, render_1.outputTypes)(types);
77
+ }
78
+ if (target.examples.length > 0) {
79
+ output_1.default.normal('');
80
+ (0, render_1.outputExamples)(target.examples);
81
+ }
82
+ output_1.default.exitNormal();
83
+ });
84
+ exports.default = commandYamlTargetsInfo;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../../utils");
7
+ const output_1 = __importDefault(require("../../../output"));
8
+ const texts_1 = require("../../../texts");
9
+ const schemaUtils_1 = require("../schemaUtils");
10
+ const schema_1 = require("./schema");
11
+ function targetTable(targets) {
12
+ output_1.default.wrappedTable([
13
+ ['TYPE', 'NAME', 'DESCRIPTION'],
14
+ ...targets.map((target) => [target.value, target.name, target.description]),
15
+ ]);
16
+ }
17
+ const targetJson = (targets) => targets.map((target) => ({
18
+ type: target.value,
19
+ slug: target.slug,
20
+ name: target.name,
21
+ description: target.description,
22
+ }));
23
+ const commandYamlTargetsList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_YAML_TARGETS_LIST, {
24
+ requiredScopes: [],
25
+ examples: texts_1.EXAMPLE_YAML_TARGETS_LIST,
26
+ });
27
+ commandYamlTargetsList.alias('ls');
28
+ commandYamlTargetsList.option('-s, --search <query>', texts_1.OPTION_ACTION_SEARCH);
29
+ commandYamlTargetsList.option('--format <text|json>', texts_1.OPTION_FORMAT);
30
+ commandYamlTargetsList.action(async (options) => {
31
+ await (0, schemaUtils_1.ensureYamlSchema)('targets');
32
+ const json = options.format === 'json';
33
+ if (options.search) {
34
+ const results = await (0, schema_1.searchTargets)(options.search);
35
+ if (json) {
36
+ output_1.default.json(targetJson(results));
37
+ }
38
+ else if (results.length === 0) {
39
+ output_1.default.error((0, texts_1.ERR_YAML_TARGET_SEARCH_NO_RESULTS)(options.search));
40
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_USE_LIST);
41
+ }
42
+ else {
43
+ targetTable(results);
44
+ }
45
+ output_1.default.exitNormal();
46
+ return;
47
+ }
48
+ const targets = await (0, schema_1.loadTargets)();
49
+ if (json) {
50
+ output_1.default.json(targetJson(targets));
51
+ output_1.default.exitNormal();
52
+ return;
53
+ }
54
+ output_1.default.blue((0, texts_1.TXT_YAML_TARGETS_ALL)(targets.length));
55
+ targetTable(targets);
56
+ output_1.default.normal('');
57
+ output_1.default.muted(texts_1.TXT_YAML_TARGET_HINT);
58
+ output_1.default.exitNormal();
59
+ });
60
+ exports.default = commandYamlTargetsList;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNSUPPORTED_TARGET_TYPES = void 0;
4
+ exports.loadTargets = loadTargets;
5
+ exports.findTarget = findTarget;
6
+ exports.searchTargets = searchTargets;
7
+ const schemaUtils_1 = require("../schemaUtils");
8
+ exports.UNSUPPORTED_TARGET_TYPES = new Set(['MATCH', 'PROJECT_REPOSITORY']);
9
+ async function loadTargets() {
10
+ const scope = (0, schemaUtils_1.targetsScope)();
11
+ const types = (await scope.list()).filter((type) => !exports.UNSUPPORTED_TARGET_TYPES.has(type));
12
+ const all = await Promise.all(types.map((type) => scope.get(type)));
13
+ return all
14
+ .filter((member) => member !== undefined)
15
+ .toSorted((a, b) => a.value.localeCompare(b.value));
16
+ }
17
+ async function findTarget(query) {
18
+ const all = await loadTargets();
19
+ return (all.find((member) => member.value === query.toUpperCase()) ??
20
+ all.find((member) => member.slug === query.toLowerCase()));
21
+ }
22
+ async function searchTargets(query, limit = Infinity) {
23
+ const bySearch = await (0, schemaUtils_1.targetsScope)().search(query, { fuzzy: 0.3, limit: Infinity });
24
+ const byType = new Map((await loadTargets()).map((member) => [member.value, member]));
25
+ return bySearch
26
+ .filter((hit) => hit.kind === 'member')
27
+ .flatMap((hit) => byType.get(hit.key) ?? [])
28
+ .slice(0, limit);
29
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const texts_1 = require("../../texts");
8
+ const list_1 = __importDefault(require("./targets/list"));
9
+ const info_1 = __importDefault(require("./targets/info"));
10
+ const commandYamlTargets = (0, utils_1.newCommand)('targets', texts_1.DESC_COMMAND_YAML_TARGETS, {
11
+ examples: [...texts_1.EXAMPLE_YAML_TARGETS_LIST, ...texts_1.EXAMPLE_YAML_TARGETS_INFO],
12
+ });
13
+ commandYamlTargets.addCommand(list_1.default);
14
+ commandYamlTargets.addCommand(info_1.default);
15
+ exports.default = commandYamlTargets;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.26.3-stage",
4
+ "version": "1.26.3",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",