bdy 1.25.38-dev-pr → 1.25.38-master

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/distTs/package.json +1 -2
  2. package/distTs/src/api/client.js +1 -191
  3. package/distTs/src/cliError.js +0 -5
  4. package/distTs/src/cliIndex.js +0 -3
  5. package/distTs/src/command/login.js +1 -1
  6. package/distTs/src/output/pipeline.js +56 -54
  7. package/distTs/src/output.js +22 -72
  8. package/distTs/src/texts.js +1 -450
  9. package/distTs/src/tunnel/output/interactive/tunnel.js +10 -14
  10. package/distTs/src/tunnel/output/noninteractive/tunnel.js +1 -3
  11. package/distTs/src/utils.js +3 -133
  12. package/package.json +1 -2
  13. package/distTs/src/autocomplete.js +0 -90
  14. package/distTs/src/command/artifact/downloadDir.js +0 -110
  15. package/distTs/src/command/autocomplete/install.js +0 -16
  16. package/distTs/src/command/autocomplete/uninstall.js +0 -16
  17. package/distTs/src/command/autocomplete.js +0 -14
  18. package/distTs/src/command/environment/resolve.js +0 -39
  19. package/distTs/src/command/package/create.js +0 -64
  20. package/distTs/src/command/package/delete.js +0 -38
  21. package/distTs/src/command/package/docker/login.js +0 -26
  22. package/distTs/src/command/package/docker.js +0 -11
  23. package/distTs/src/command/package/download.js +0 -138
  24. package/distTs/src/command/package/get.js +0 -36
  25. package/distTs/src/command/package/list.js +0 -31
  26. package/distTs/src/command/package/publish.js +0 -241
  27. package/distTs/src/command/package/version/delete.js +0 -39
  28. package/distTs/src/command/package/version/get.js +0 -45
  29. package/distTs/src/command/package/version/list.js +0 -47
  30. package/distTs/src/command/package/version.js +0 -16
  31. package/distTs/src/command/package.js +0 -26
  32. package/distTs/src/command/pipeline/run/apply.js +0 -62
  33. package/distTs/src/command/pr/comment/add.js +0 -66
  34. package/distTs/src/command/pr/comment/list.js +0 -169
  35. package/distTs/src/command/pr/comment/status.js +0 -48
  36. package/distTs/src/command/pr/comment.js +0 -19
  37. package/distTs/src/command/pr/create.js +0 -43
  38. package/distTs/src/command/pr/diff.js +0 -227
  39. package/distTs/src/command/pr/file/list.js +0 -124
  40. package/distTs/src/command/pr/file/mark.js +0 -45
  41. package/distTs/src/command/pr/file.js +0 -16
  42. package/distTs/src/command/pr/get.js +0 -29
  43. package/distTs/src/command/pr/list.js +0 -79
  44. package/distTs/src/command/pr/merge.js +0 -66
  45. package/distTs/src/command/pr/review/request.js +0 -29
  46. package/distTs/src/command/pr/review/start.js +0 -29
  47. package/distTs/src/command/pr/review/verdict.js +0 -81
  48. package/distTs/src/command/pr/review.js +0 -18
  49. package/distTs/src/command/pr/shared.js +0 -595
  50. package/distTs/src/command/pr/state.js +0 -38
  51. package/distTs/src/command/pr/summary.js +0 -316
  52. package/distTs/src/command/pr/update.js +0 -54
  53. package/distTs/src/command/pr/updateBranch.js +0 -22
  54. package/distTs/src/command/pr/versions.js +0 -42
  55. package/distTs/src/command/pr.js +0 -39
  56. package/distTs/src/command/scrape/validation.js +0 -154
  57. package/distTs/src/command/scrape.js +0 -144
  58. package/distTs/src/command/suiteLink.js +0 -14
  59. package/distTs/src/command/tests/visual/result/download.js +0 -31
  60. package/distTs/src/command/tests/visual/result/get.js +0 -68
  61. package/distTs/src/command/tests/visual/result/list.js +0 -49
  62. package/distTs/src/command/tests/visual/result.js +0 -23
  63. package/distTs/src/command/tests/visual/session/get.js +0 -70
  64. package/distTs/src/command/tests/visual/session/list.js +0 -69
  65. package/distTs/src/command/tests/visual/session/open.js +0 -22
  66. package/distTs/src/command/tests/visual/session/reviewUrl.js +0 -37
  67. package/distTs/src/command/tests/visual/session/update.js +0 -26
  68. package/distTs/src/command/tests/visual/shared/context.js +0 -144
  69. package/distTs/src/command/tests/visual/shared/diffRegions.js +0 -172
  70. package/distTs/src/command/tests/visual/shared/format.js +0 -21
  71. package/distTs/src/command/tests/visual/shared/lookup.js +0 -107
  72. package/distTs/src/command/tests/visual/shared/options.js +0 -90
  73. package/distTs/src/command/tests/visual/shared/review.js +0 -146
  74. package/distTs/src/command/tests/visual/shared/reviewUrl.js +0 -62
  75. package/distTs/src/command/tests/visual/shared/session.js +0 -217
  76. package/distTs/src/command/tests/visual/snapshot/get.js +0 -46
  77. package/distTs/src/command/tests/visual/snapshot/list.js +0 -68
  78. package/distTs/src/command/tests/visual/snapshot/open.js +0 -26
  79. package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +0 -48
  80. package/distTs/src/command/tests/visual/snapshot.js +0 -28
  81. package/distTs/src/command/tests/visual/suite/create.js +0 -38
  82. package/distTs/src/command/tests/visual/suite/delete.js +0 -29
  83. package/distTs/src/command/tests/visual/suite/get.js +0 -43
  84. package/distTs/src/command/tests/visual/suite/list.js +0 -35
  85. package/distTs/src/command/tests/visual/suite/open.js +0 -20
  86. package/distTs/src/command/tests/visual/suite/update.js +0 -47
  87. package/distTs/src/command/tests/visual/suite.js +0 -30
  88. package/distTs/src/command/ut/upload.js +0 -86
  89. package/distTs/src/command/ut.js +0 -12
  90. package/distTs/src/command/vt/close.js +0 -27
  91. package/distTs/src/command/vt/compare/validation.js +0 -46
  92. package/distTs/src/command/vt/compare.js +0 -100
  93. package/distTs/src/command/vt/exec.js +0 -82
  94. package/distTs/src/command/vt/installBrowser.js +0 -20
  95. package/distTs/src/command/vt/shared/validation.js +0 -145
  96. package/distTs/src/command/vt/storybook.js +0 -138
  97. package/distTs/src/command/vt.js +0 -20
  98. package/distTs/src/command/yaml/agents.js +0 -88
  99. package/distTs/src/command/yaml/init.js +0 -110
  100. package/distTs/src/main.js +0 -190
  101. package/distTs/src/types/options.js +0 -2
  102. package/distTs/src/types/scrape.js +0 -2
  103. package/distTs/src/types/visualTests.js +0 -2
@@ -1,138 +0,0 @@
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 node_fs_1 = require("node:fs");
10
- const node_path_1 = __importDefault(require("node:path"));
11
- const node_zlib_1 = require("node:zlib");
12
- const commandVtStorybook = (0, utils_1.newCommand)('storybook', texts_1.DESC_COMMAND_VT_STORYBOOK);
13
- commandVtStorybook.action(async () => {
14
- const { getCiAndGitInfo, formattedCiInfo } = require('@buddy-works/ci-info');
15
- const { checkToken } = require('../../visualTest/validation');
16
- const { getDefaultSettings, sendStorybook } = require('../../visualTest/requests');
17
- const { setDefaultSettings } = require('../../visualTest/snapshots');
18
- const { setCiAndCommitInfo } = require('../../visualTest/context');
19
- if (!checkToken('vt')) {
20
- output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
21
- }
22
- const currentDirectoryFiles = getCurrentDirectoryFiles();
23
- if (!isStorybookDirectory(currentDirectoryFiles)) {
24
- output_1.default.exitError(texts_1.ERR_WRONG_STORYBOOK_DIRECTORY);
25
- }
26
- const storybookStoriesIndex = getStorybookStoriesIndex(currentDirectoryFiles);
27
- const storiesList = getStoriesList(storybookStoriesIndex);
28
- const storybookSnapshots = getStorybookSnapshots(storiesList);
29
- const defaultSettings = await getDefaultSettings();
30
- setDefaultSettings(defaultSettings);
31
- const ciAndGitInfo = await getCiAndGitInfo({
32
- baseBranch: defaultSettings.baseBranch,
33
- logger: output_1.default.warning,
34
- });
35
- setCiAndCommitInfo(ciAndGitInfo);
36
- output_1.default.normal(formattedCiInfo(ciAndGitInfo));
37
- try {
38
- const compressedStorybookDirectory = await createCompressedStorybookDirectory(currentDirectoryFiles);
39
- const { message } = await sendStorybook(storybookSnapshots, compressedStorybookDirectory);
40
- output_1.default.exitSuccess(message);
41
- }
42
- catch (error) {
43
- output_1.default.exitError(`${error}`);
44
- }
45
- });
46
- function getCurrentDirectoryFiles() {
47
- const cwd = process.cwd();
48
- const filesAndDirectories = (0, node_fs_1.readdirSync)(cwd, {
49
- encoding: 'utf8',
50
- recursive: true,
51
- });
52
- return filesAndDirectories.filter((file) => {
53
- const elementPath = node_path_1.default.join(cwd, file);
54
- const stats = (0, node_fs_1.statSync)(elementPath);
55
- return stats.isFile();
56
- });
57
- }
58
- async function createCompressedStorybookDirectory(files) {
59
- const tar = require('tar-stream');
60
- const cwd = process.cwd();
61
- const chunks = [];
62
- return new Promise((resolve, reject) => {
63
- const compressStream = (0, node_zlib_1.createBrotliCompress)({
64
- params: {
65
- [node_zlib_1.constants.BROTLI_PARAM_QUALITY]: 6,
66
- },
67
- });
68
- compressStream.on('data', (chunk) => {
69
- chunks.push(chunk);
70
- });
71
- compressStream.on('end', () => {
72
- resolve(Buffer.concat(chunks));
73
- });
74
- compressStream.on('error', reject);
75
- const packStream = tar.pack();
76
- packStream.pipe(compressStream);
77
- let filesProcessed = 0;
78
- for (const file of files) {
79
- const filePath = node_path_1.default.join(cwd, file);
80
- const stats = (0, node_fs_1.statSync)(filePath);
81
- const entry = packStream.entry({
82
- name: file,
83
- size: stats.size,
84
- }, (error) => {
85
- if (error) {
86
- reject(error);
87
- }
88
- else {
89
- filesProcessed += 1;
90
- if (filesProcessed === files.length) {
91
- packStream.finalize();
92
- }
93
- }
94
- });
95
- const fileStream = (0, node_fs_1.createReadStream)(filePath);
96
- fileStream.pipe(entry);
97
- fileStream.on('error', reject);
98
- }
99
- });
100
- }
101
- function isStorybookDirectory(files) {
102
- return (files.length > 0 &&
103
- files.includes('index.html') &&
104
- files.includes('iframe.html'));
105
- }
106
- function getStorybookStoriesIndex(files) {
107
- const indexFiles = files.find((file) => file === 'index.json');
108
- if (indexFiles) {
109
- return indexFiles;
110
- }
111
- else {
112
- return output_1.default.exitError(texts_1.ERR_MISSING_STORYBOOK_INDEX_FILE);
113
- }
114
- }
115
- function getStoriesList(storybookStoriesIndex) {
116
- const storiesListFile = (0, node_fs_1.readFileSync)(storybookStoriesIndex);
117
- try {
118
- const json = JSON.parse(storiesListFile.toString());
119
- if (![4, 5].includes(json.v)) {
120
- output_1.default.exitError(texts_1.ERR_UNSUPPORTED_STORYBOOK);
121
- }
122
- return json;
123
- }
124
- catch {
125
- output_1.default.exitError(texts_1.ERR_PARSING_STORIES);
126
- }
127
- }
128
- function getStorybookSnapshots(storiesList) {
129
- const stories = Object.entries(storiesList.entries)
130
- .filter(([, value]) => value.type === 'story')
131
- .map(([key, value]) => ({
132
- id: key,
133
- name: `${value.title}/${value.name}`,
134
- }));
135
- output_1.default.normal((0, texts_1.TXT_STORIES_AMOUNT)(stories.length));
136
- return stories;
137
- }
138
- exports.default = commandVtStorybook;
@@ -1,20 +0,0 @@
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 texts_1 = require("../texts");
7
- const utils_1 = require("../utils");
8
- const close_1 = __importDefault(require("./vt/close"));
9
- const storybook_1 = __importDefault(require("./vt/storybook"));
10
- const exec_1 = __importDefault(require("./vt/exec"));
11
- const installBrowser_1 = __importDefault(require("./vt/installBrowser"));
12
- const compare_1 = __importDefault(require("./vt/compare"));
13
- const commandVt = (0, utils_1.newCommand)('visual', texts_1.DESC_COMMAND_VT);
14
- commandVt.alias('vt');
15
- commandVt.addCommand(close_1.default);
16
- commandVt.addCommand(storybook_1.default);
17
- commandVt.addCommand(exec_1.default);
18
- commandVt.addCommand(installBrowser_1.default);
19
- commandVt.addCommand(compare_1.default);
20
- exports.default = commandVt;
@@ -1,88 +0,0 @@
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.AGENTS = void 0;
7
- exports.getAgentById = getAgentById;
8
- exports.detectExistingAgents = detectExistingAgents;
9
- exports.writeAgentInstructions = writeAgentInstructions;
10
- exports.updateExistingAgentInstructions = updateExistingAgentInstructions;
11
- exports.getUniqueAgentFiles = getUniqueAgentFiles;
12
- const fs_1 = require("fs");
13
- const path_1 = __importDefault(require("path"));
14
- const output_1 = __importDefault(require("../../output"));
15
- const texts_1 = require("../../texts");
16
- exports.AGENTS = [
17
- { id: 'claude', name: 'Claude Code', file: 'CLAUDE.md' },
18
- { id: 'chatgpt-codex', name: 'ChatGPT / Codex', file: 'AGENTS.md' },
19
- { id: 'gemini', name: 'Gemini CLI', file: 'GEMINI.md' },
20
- { id: 'copilot', name: 'GitHub Copilot', file: '.github/copilot-instructions.md' },
21
- { id: 'cursor', name: 'Cursor', file: '.cursor/rules/bdy.mdc' },
22
- { id: 'windsurf', name: 'Windsurf', file: '.windsurf/rules/bdy.md' },
23
- { id: 'jetbrains', name: 'JetBrains AI', file: '.aiassistant/rules/bdy.md' },
24
- { id: 'amp', name: 'Amp', file: 'AGENTS.md' },
25
- ];
26
- const MARKER_START = '<!--BDY START-->';
27
- const MARKER_END = '<!--BDY END-->';
28
- const MARKER_REGEX = /<!--BDY START-->[\s\S]*?<!--BDY END-->/;
29
- function wrapWithMarkers(content) {
30
- return `${MARKER_START}\n${content.trimEnd()}\n${MARKER_END}`;
31
- }
32
- function getAgentById(id) {
33
- return exports.AGENTS.find(a => a.id === id);
34
- }
35
- function detectExistingAgents(dir) {
36
- return exports.AGENTS.filter(agent => (0, fs_1.existsSync)(path_1.default.resolve(dir, agent.file)));
37
- }
38
- async function writeAgentInstructions(filePath, section) {
39
- const wrapped = wrapWithMarkers(section);
40
- const dir = path_1.default.dirname(filePath);
41
- if (!(0, fs_1.existsSync)(dir)) {
42
- (0, fs_1.mkdirSync)(dir, { recursive: true });
43
- }
44
- if (!(0, fs_1.existsSync)(filePath)) {
45
- (0, fs_1.writeFileSync)(filePath, wrapped + '\n', 'utf8');
46
- return 'created';
47
- }
48
- const content = (0, fs_1.readFileSync)(filePath, 'utf8');
49
- if (MARKER_REGEX.test(content)) {
50
- const updated = content.replace(MARKER_REGEX, wrapped);
51
- (0, fs_1.writeFileSync)(filePath, updated, 'utf8');
52
- return 'updated';
53
- }
54
- const shouldAppend = await output_1.default.confirm((0, texts_1.TXT_YAML_INIT_APPEND_CONFIRM)(path_1.default.basename(filePath)));
55
- if (!shouldAppend) {
56
- return 'skipped';
57
- }
58
- (0, fs_1.writeFileSync)(filePath, content.trimEnd() + '\n\n' + wrapped + '\n', 'utf8');
59
- return 'appended';
60
- }
61
- function updateExistingAgentInstructions(dir, section) {
62
- const wrapped = wrapWithMarkers(section);
63
- const updated = [];
64
- for (const agent of exports.AGENTS) {
65
- const filePath = path_1.default.resolve(dir, agent.file);
66
- if (!(0, fs_1.existsSync)(filePath))
67
- continue;
68
- const content = (0, fs_1.readFileSync)(filePath, 'utf8');
69
- if (!MARKER_REGEX.test(content))
70
- continue;
71
- const newContent = content.replace(MARKER_REGEX, wrapped);
72
- (0, fs_1.writeFileSync)(filePath, newContent, 'utf8');
73
- updated.push(agent.file);
74
- }
75
- return updated;
76
- }
77
- function getUniqueAgentFiles(agentIds) {
78
- const fileMap = new Map();
79
- for (const id of agentIds) {
80
- const agent = getAgentById(id);
81
- if (!agent)
82
- continue;
83
- const existing = fileMap.get(agent.file) || [];
84
- existing.push(agent);
85
- fileMap.set(agent.file, existing);
86
- }
87
- return Array.from(fileMap.entries()).map(([file, agents]) => ({ file, agents }));
88
- }
@@ -1,110 +0,0 @@
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 fs_1 = require("fs");
7
- const path_1 = __importDefault(require("path"));
8
- const { resolve } = path_1.default;
9
- const utils_1 = require("../../utils");
10
- const output_1 = __importDefault(require("../../output"));
11
- const texts_1 = require("../../texts");
12
- const agents_1 = require("./agents");
13
- const OLD_SECTION_HEADER = '## Buddy YAML Actions';
14
- const OLD_SECTION_REGEX = /## Buddy YAML Actions[\s\S]*?(?=\n## |\n# |$)/;
15
- const OLD_MARKER_LESS_HEADER = '## Buddy CI/CD YAML Reference';
16
- const OLD_MARKER_LESS_REGEX = /## Buddy CI\/CD YAML Reference[\s\S]*?(?=\n## |\n# |$)/;
17
- function generateSection() {
18
- return `## Buddy CI/CD YAML Reference
19
-
20
- Use \`bdy yaml\` commands to browse, validate, and create Buddy CI/CD pipeline YAML.
21
- These commands are useful when you need exact field names, types, or available options — they return the live schema so you don't have to guess.
22
-
23
- ### Pipeline Configuration
24
-
25
- - \`bdy yaml pipeline\` — Show the full pipeline schema (all properties, types, descriptions) plus example YAML
26
-
27
- ### Action Definitions
28
-
29
- - \`bdy yaml actions list\` — List all action types (TYPE, name, description)
30
- - \`bdy yaml actions list --search <query>\` — Search action types by name, type, or description
31
- - \`bdy yaml actions info <type>\` — View full schema for an action type (common + type-specific fields) plus example YAML
32
-
33
- ### Validation
34
-
35
- - \`bdy yaml validate <file>\` — Validate entire pipeline YAML file (settings, events, variables, targets, permissions, actions)
36
-
37
- ### Workflow
38
-
39
- 1. Review the pipeline schema and examples: \`bdy yaml pipeline\`
40
- 2. Find the action type you need: \`bdy yaml actions list --search s3\`
41
- 3. Get the action schema and example: \`bdy yaml actions info AMAZON_S3\`
42
- 4. Generate YAML using the schema fields and examples
43
- 5. Validate: \`bdy yaml validate buddy.yml\`
44
- 6. Fix any errors and re-validate`;
45
- }
46
- function migrateOldSections(filePath) {
47
- if (!(0, fs_1.existsSync)(filePath))
48
- return;
49
- let content = (0, fs_1.readFileSync)(filePath, 'utf8');
50
- let changed = false;
51
- if (content.includes(OLD_SECTION_HEADER)) {
52
- content = content.replace(OLD_SECTION_REGEX, '').replace(/\n{3,}/g, '\n\n').trimEnd();
53
- changed = true;
54
- }
55
- if (content.includes(OLD_MARKER_LESS_HEADER) && !content.includes('<!--BDY START-->')) {
56
- content = content.replace(OLD_MARKER_LESS_REGEX, '').replace(/\n{3,}/g, '\n\n').trimEnd();
57
- changed = true;
58
- }
59
- if (changed) {
60
- (0, fs_1.writeFileSync)(filePath, content, 'utf8');
61
- }
62
- }
63
- const commandYamlInit = (0, utils_1.newCommand)('init', texts_1.DESC_COMMAND_YAML_INIT);
64
- commandYamlInit.option('-t, --target <file>', texts_1.OPTION_YAML_INIT_TARGET);
65
- commandYamlInit.action(async (options) => {
66
- const section = generateSection();
67
- const dir = resolve('.');
68
- if (options.target) {
69
- const filePath = resolve(options.target);
70
- migrateOldSections(filePath);
71
- const result = await (0, agents_1.writeAgentInstructions)(filePath, section);
72
- const verb = result === 'created' ? 'Created' : result === 'skipped' ? 'Skipped' : 'Updated';
73
- output_1.default.dim(`${verb}: ${filePath}`);
74
- if (result !== 'skipped') {
75
- output_1.default.exitSuccess((0, texts_1.TXT_YAML_INIT_SUCCESS)(path_1.default.basename(filePath)));
76
- }
77
- return;
78
- }
79
- const existing = (0, agents_1.detectExistingAgents)(dir);
80
- let selectedIds;
81
- if (existing.length > 0) {
82
- selectedIds = existing.map(a => a.id);
83
- }
84
- else {
85
- selectedIds = await output_1.default.inputCheckbox(texts_1.TXT_YAML_INIT_SELECT_AGENTS, agents_1.AGENTS.map(a => ({
86
- name: `${a.name} (${a.file})`,
87
- value: a.id,
88
- })));
89
- }
90
- if (selectedIds.length === 0) {
91
- output_1.default.exitNormal(texts_1.TXT_YAML_INIT_NO_AGENTS_SELECTED);
92
- return;
93
- }
94
- const uniqueFiles = (0, agents_1.getUniqueAgentFiles)(selectedIds);
95
- const writtenFiles = [];
96
- for (const { file } of uniqueFiles) {
97
- const filePath = resolve(path_1.default.join(dir, file));
98
- migrateOldSections(filePath);
99
- const result = await (0, agents_1.writeAgentInstructions)(filePath, section);
100
- const verb = result === 'created' ? 'Created' : result === 'skipped' ? 'Skipped' : 'Updated';
101
- output_1.default.dim(`${verb}: ${file}`);
102
- if (result !== 'skipped') {
103
- writtenFiles.push(file);
104
- }
105
- }
106
- if (writtenFiles.length > 0) {
107
- output_1.default.exitSuccess((0, texts_1.TXT_YAML_INIT_SUCCESS)(writtenFiles.join(', ')));
108
- }
109
- });
110
- exports.default = commandYamlInit;
@@ -1,190 +0,0 @@
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 output_1 = __importDefault(require("./output"));
7
- const selectCommand = async (parentCommand) => {
8
- let items = [];
9
- const map = {};
10
- parentCommand.commands.filter((c) => !c._hidden).forEach((c) => {
11
- const name = c.name();
12
- map[name] = c;
13
- items.push({
14
- name,
15
- description: c.description(),
16
- value: name,
17
- });
18
- });
19
- items = items.sort((a, b) => a.name.localeCompare(b.name));
20
- const goBack = 'go back';
21
- items.push({
22
- name: 'help',
23
- description: 'Display help for current command',
24
- value: 'help',
25
- });
26
- if (parentCommand.parent) {
27
- items.unshift({
28
- name: goBack,
29
- description: 'Go back to parent command',
30
- value: goBack
31
- });
32
- }
33
- output_1.default.clearPreviousLine();
34
- const name = await output_1.default.inputMenuAdv(getFinalCommand(parentCommand, {}, []), items);
35
- if (name === 'help') {
36
- parentCommand.help();
37
- output_1.default.exitNormal();
38
- }
39
- else if (name === goBack && parentCommand.parent) {
40
- return await selectCommand(parentCommand.parent);
41
- }
42
- const cmd = map[name];
43
- if (cmd.commands.length > 0) {
44
- return await selectCommand(cmd);
45
- }
46
- return cmd;
47
- };
48
- const setOptionValue = async (opt) => {
49
- output_1.default.clearPreviousLine();
50
- let name = opt.name();
51
- const desc = opt.description;
52
- if (desc)
53
- name += ` (${desc})`;
54
- if (opt.isBoolean()) {
55
- const val = await output_1.default.inputMenu(`--${name}`, ['true', 'false']);
56
- return val === 0;
57
- }
58
- else {
59
- return await output_1.default.inputString(`--${name}:`, opt.defaultValue);
60
- }
61
- };
62
- const nameToCamelCase = (name) => {
63
- const s = name.split('-');
64
- if (s.length <= 1)
65
- return name;
66
- return s
67
- .map((txt, i) => {
68
- if (!txt || !txt.length || !i)
69
- return txt;
70
- return `${txt[0].toUpperCase()}${txt.substring(1)}`;
71
- })
72
- .join('');
73
- };
74
- const camelCaseToName = (cc) => {
75
- return cc.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
76
- };
77
- const selectOptions = async (cmd) => {
78
- const options = {};
79
- if (cmd.options.length > 0) {
80
- const map = {};
81
- let items = [];
82
- cmd.options.forEach((opt) => {
83
- const name = opt.name();
84
- map[name] = opt;
85
- items.push({
86
- name: `--${name}`,
87
- description: opt.description,
88
- value: name,
89
- });
90
- });
91
- items = items.sort((a, b) => a.name.localeCompare(b.name));
92
- items.unshift({
93
- name: 'Skip options',
94
- value: '',
95
- });
96
- while (true) {
97
- output_1.default.clearPreviousLine();
98
- const name = await output_1.default.inputMenuAdv(getFinalCommand(cmd, options, []), items);
99
- if (map[name]) {
100
- const opt = map[name];
101
- const value = await setOptionValue(opt);
102
- const cc = nameToCamelCase(name);
103
- if (opt.variadic) {
104
- if (!options[cc])
105
- options[cc] = [];
106
- const o = options[cc];
107
- o.push(value);
108
- }
109
- else {
110
- options[cc] = value;
111
- }
112
- }
113
- else {
114
- break;
115
- }
116
- }
117
- }
118
- return options;
119
- };
120
- const selectArguments = async (cmd) => {
121
- const args = [];
122
- if (cmd.registeredArguments.length > 0) {
123
- for (let i = 0; i < cmd.registeredArguments.length; i += 1) {
124
- const arg = cmd.registeredArguments[i];
125
- let desc = arg.name();
126
- if (arg.description)
127
- desc += ` - ${arg.description}`;
128
- desc += ':';
129
- output_1.default.clearPreviousLine();
130
- const value = await output_1.default.inputString(`${desc[0].toUpperCase()}${desc.substring(1)}`, arg.defaultValue, arg.required);
131
- if (arg.variadic) {
132
- args.push(value.split(' '));
133
- }
134
- else {
135
- args.push(value);
136
- }
137
- }
138
- }
139
- return args;
140
- };
141
- const getFinalCommand = (cmd, options, args) => {
142
- let txt = '';
143
- let c = cmd;
144
- while (c !== null) {
145
- txt = c.name() + ' ' + txt;
146
- c = c.parent;
147
- }
148
- txt = txt.trim();
149
- Object.entries(options).forEach(([name, val]) => {
150
- const n = camelCaseToName(name);
151
- if (val === true) {
152
- txt += ` --${n}`;
153
- }
154
- else if (val === false) {
155
- txt += ` --${n}=false`;
156
- }
157
- else if (Array.isArray(val)) {
158
- val.forEach((v) => {
159
- txt += ` --${n}="${v}"`;
160
- });
161
- }
162
- else {
163
- txt += ` --${n}="${val}"`;
164
- }
165
- });
166
- args.forEach((arg) => {
167
- if (Array.isArray(arg)) {
168
- txt += ` ${arg.map(a => `"${a}"`).join(' ')}`;
169
- }
170
- else {
171
- txt += ` "${arg}"`;
172
- }
173
- });
174
- return txt;
175
- };
176
- const main = async (program) => {
177
- if (!output_1.default.isTTY()) {
178
- program.help();
179
- output_1.default.exitNormal();
180
- }
181
- const cmd = await selectCommand(program);
182
- const options = await selectOptions(cmd);
183
- const args = await selectArguments(cmd);
184
- Object.entries(options).forEach(([k, v]) => cmd.setOptionValue(camelCaseToName(k), v));
185
- output_1.default.clearPreviousLine();
186
- output_1.default.cyan('❯ ', false);
187
- output_1.default.normal(getFinalCommand(cmd, options, args));
188
- await cmd._actionHandler([...args, options, cmd]);
189
- };
190
- exports.default = main;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });