bdy 1.25.1-master → 1.25.2-beta

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 (53) hide show
  1. package/distTs/package.json +2 -6
  2. package/distTs/src/command/api/info.js +224 -255
  3. package/distTs/src/command/api/list.js +14 -17
  4. package/distTs/src/command/yaml/actions/detect.js +11 -2
  5. package/distTs/src/command/yaml/actions/info.js +22 -12
  6. package/distTs/src/command/yaml/actions/list.js +11 -20
  7. package/distTs/src/command/yaml/actions/schema.js +43 -87
  8. package/distTs/src/command/yaml/pipeline.js +9 -25
  9. package/distTs/src/command/yaml/render.js +83 -71
  10. package/distTs/src/command/yaml/schemaUtils.js +12 -50
  11. package/distTs/src/command/yaml/validate.js +32 -27
  12. package/distTs/src/diskCache.js +0 -1
  13. package/distTs/src/openapi.js +16 -68
  14. package/distTs/src/texts.js +7 -9
  15. package/package.json +2 -6
  16. package/distTs/README.md +0 -181
  17. package/distTs/src/autocomplete.js +0 -90
  18. package/distTs/src/command/autocomplete/install.js +0 -16
  19. package/distTs/src/command/autocomplete/uninstall.js +0 -16
  20. package/distTs/src/command/autocomplete.js +0 -14
  21. package/distTs/src/command/environment/resolve.js +0 -47
  22. package/distTs/src/command/package/create.js +0 -64
  23. package/distTs/src/command/package/delete.js +0 -38
  24. package/distTs/src/command/package/docker/login.js +0 -26
  25. package/distTs/src/command/package/docker.js +0 -11
  26. package/distTs/src/command/package/download.js +0 -138
  27. package/distTs/src/command/package/get.js +0 -36
  28. package/distTs/src/command/package/list.js +0 -31
  29. package/distTs/src/command/package/publish.js +0 -241
  30. package/distTs/src/command/package/version/delete.js +0 -39
  31. package/distTs/src/command/package/version/get.js +0 -45
  32. package/distTs/src/command/package/version/list.js +0 -47
  33. package/distTs/src/command/package/version.js +0 -16
  34. package/distTs/src/command/package.js +0 -26
  35. package/distTs/src/command/project/get.js +0 -18
  36. package/distTs/src/command/project/set.js +0 -31
  37. package/distTs/src/command/sandbox/get/yaml.js +0 -30
  38. package/distTs/src/command/scrape/validation.js +0 -154
  39. package/distTs/src/command/scrape.js +0 -144
  40. package/distTs/src/command/ut/upload.js +0 -86
  41. package/distTs/src/command/ut.js +0 -12
  42. package/distTs/src/command/vt/close.js +0 -27
  43. package/distTs/src/command/vt/compare/validation.js +0 -46
  44. package/distTs/src/command/vt/compare.js +0 -100
  45. package/distTs/src/command/vt/exec.js +0 -82
  46. package/distTs/src/command/vt/installBrowser.js +0 -20
  47. package/distTs/src/command/vt/scrape.js +0 -193
  48. package/distTs/src/command/vt/shared/validation.js +0 -145
  49. package/distTs/src/command/vt/storybook.js +0 -138
  50. package/distTs/src/command/vt.js +0 -20
  51. package/distTs/src/main.js +0 -190
  52. package/distTs/src/types/options.js +0 -2
  53. package/distTs/src/types/scrape.js +0 -2
@@ -1,16 +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 autocomplete_1 = __importDefault(require("../../autocomplete"));
8
- const texts_1 = require("../../texts");
9
- const output_1 = __importDefault(require("../../output"));
10
- const commandAutocompleteUninstall = (0, utils_1.newCommand)('uninstall', texts_1.DESC_COMMAND_AUTOCOMPLETE_UNINSTALL);
11
- commandAutocompleteUninstall.alias('u');
12
- commandAutocompleteUninstall.action(async () => {
13
- await autocomplete_1.default.uninstall();
14
- output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_UNINSTALLED);
15
- });
16
- exports.default = commandAutocompleteUninstall;
@@ -1,14 +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 install_1 = __importDefault(require("./autocomplete/install"));
8
- const uninstall_1 = __importDefault(require("./autocomplete/uninstall"));
9
- const texts_1 = require("../texts");
10
- const commandAutocomplete = (0, utils_1.newCommand)('autocomplete', texts_1.DESC_COMMAND_AUTOCOMPLETE);
11
- commandAutocomplete.alias('ac');
12
- commandAutocomplete.addCommand(install_1.default);
13
- commandAutocomplete.addCommand(uninstall_1.default);
14
- exports.default = commandAutocomplete;
@@ -1,47 +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.resolveEnvironmentId = void 0;
7
- const texts_1 = require("../../texts");
8
- const output_1 = __importDefault(require("../../output"));
9
- const input_1 = __importDefault(require("../../input"));
10
- // Shared resolve preamble for commands taking an environment identifier:
11
- // project context from flags/env -> /identifiers -> hash id, exiting on a
12
- // miss. Without a project the identifier resolves as a workspace
13
- // environment; with one, along the project line.
14
- //
15
- // Since the backend made /identifiers resolve strictly along the requested
16
- // line, a project param no longer falls back to the workspace environment of
17
- // the same identifier. Reads keep that fallback by asking a second time
18
- // without the project - that is how workspace environments stay addressable
19
- // from inside a project context, which the CLI enters on its own from
20
- // BUDDY_PROJECT or a linked project.
21
- //
22
- // strictProject is for mutating commands (update/delete): an explicit -p is
23
- // a statement "the environment of this project", so the resolved environment
24
- // must actually live there - no fallback, and the scope is verified once
25
- // more in case the API resolves loosely again.
26
- const resolveEnvironmentId = async (client, workspace, identifier, options, strictProject = false) => {
27
- const project = input_1.default.restApiProject(options.project, true);
28
- let resolved = await client.getEnvironmentByIdentifier(workspace, identifier, project);
29
- if (!resolved.environment_id && project && !strictProject) {
30
- resolved = await client.getEnvironmentByIdentifier(workspace, identifier);
31
- }
32
- // A nonexistent project is rejected by the API client
33
- // (getResourceByIdentifier); here only the environment itself can miss.
34
- if (!resolved.environment_id) {
35
- output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
36
- }
37
- if (strictProject && options.project) {
38
- const environment = await client.getEnvironment(workspace, resolved.environment_id);
39
- // a workspace environment carries no project, so this also fails the
40
- // workspace-fallback case
41
- if (environment.project?.name !== resolved.project_identifier) {
42
- output_1.default.exitError(texts_1.ERR_ENVIRONMENT_NOT_FOUND);
43
- }
44
- }
45
- return resolved.environment_id;
46
- };
47
- exports.resolveEnvironmentId = resolveEnvironmentId;
@@ -1,64 +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 input_1 = __importDefault(require("../../input"));
9
- const output_1 = __importDefault(require("../../output"));
10
- const commandPackageCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_PACKAGE_CREATE);
11
- commandPackageCreate.alias('add');
12
- commandPackageCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_PACKAGE_CREATE_IDENTIFIER);
13
- commandPackageCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
14
- commandPackageCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
15
- commandPackageCreate.option('-t, --type <type>', texts_1.OPT_COMMAND_PACKAGE_TYPE, utils_1.PACKAGE_TYPE.FILE);
16
- commandPackageCreate.option('-b, --buddy', texts_1.OPTION_HTTP_AUTH_BUDDY);
17
- commandPackageCreate.option('-a, --auth <user:pass>', texts_1.OPTION_HTTP_AUTH);
18
- commandPackageCreate.argument('[name]', texts_1.OPT_COMMAND_PACKAGE_NAME);
19
- commandPackageCreate.addHelpText('after', texts_1.EXAMPLE_PACKAGE_CREATE);
20
- commandPackageCreate.action(async (name, options) => {
21
- const humanId = require('human-id').default;
22
- const workspace = input_1.default.restApiWorkspace(options.workspace);
23
- const project = input_1.default.restApiProject(options.project, true);
24
- const client = input_1.default.restApiTokenClient();
25
- const type = input_1.default.packageType(options.type);
26
- const scope = input_1.default.packageScope(project);
27
- if (!name) {
28
- if (options.identifier)
29
- name = options.identifier;
30
- else
31
- name = humanId({ separator: '-', capitalize: false });
32
- }
33
- const data = {
34
- name,
35
- type,
36
- scope,
37
- authorization: {
38
- type: utils_1.PACKAGE_AUTH_TYPE.NONE,
39
- },
40
- };
41
- if (project) {
42
- data.project = {
43
- name: project,
44
- };
45
- }
46
- if (options.identifier)
47
- data.identifier = options.identifier;
48
- if (options.auth) {
49
- const { password, login } = input_1.default.auth(options.auth);
50
- data.authorization = {
51
- type: utils_1.PACKAGE_AUTH_TYPE.BASIC,
52
- user: login,
53
- password,
54
- };
55
- }
56
- else if (options.buddy) {
57
- data.authorization = {
58
- type: utils_1.PACKAGE_AUTH_TYPE.BUDDY,
59
- };
60
- }
61
- const result = await client.createPackage(workspace, data);
62
- output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_CREATED)(client.baseUrl, workspace, result));
63
- });
64
- exports.default = commandPackageCreate;
@@ -1,38 +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 input_1 = __importDefault(require("../../input"));
9
- const output_1 = __importDefault(require("../../output"));
10
- const commandPackageDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_PACKAGE_DELETE);
11
- commandPackageDelete.alias('rm');
12
- commandPackageDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
13
- commandPackageDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
14
- commandPackageDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
15
- commandPackageDelete.argument('<identifier>', texts_1.OPT_COMMAND_PACKAGE_IDENTIFIER);
16
- commandPackageDelete.addHelpText('after', texts_1.EXAMPLE_PACKAGE_DELETE);
17
- commandPackageDelete.action(async (identifier, options) => {
18
- const workspace = input_1.default.restApiWorkspace(options.workspace);
19
- const project = input_1.default.restApiProject(options.project);
20
- const client = input_1.default.restApiTokenClient();
21
- const data = await client.getPackageVersionByIdentifier(workspace, project, identifier);
22
- if (!data || !data.domain) {
23
- output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
24
- }
25
- if (!data.pkg_id) {
26
- output_1.default.exitError(texts_1.ERR_PACKAGE_NOT_FOUND);
27
- }
28
- const confirmed = options.force ||
29
- (await output_1.default.confirm((0, texts_1.TXT_PACKAGE_DELETE_CONFIRM)(identifier)));
30
- if (confirmed) {
31
- await client.deletePackage(workspace, data.pkg_id);
32
- output_1.default.exitSuccess(texts_1.TXT_PACKAGE_DELETED);
33
- }
34
- else {
35
- output_1.default.exitNormal();
36
- }
37
- });
38
- exports.default = commandPackageDelete;
@@ -1,26 +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 input_1 = __importDefault(require("../../../input"));
10
- const commandPackageDockerLogin = (0, utils_1.newCommand)('login', texts_1.DESC_COMMAND_PACKAGE_DOCKER_LOGIN);
11
- commandPackageDockerLogin.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
12
- commandPackageDockerLogin.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
13
- commandPackageDockerLogin.option('--region <region>', texts_1.OPTION_REST_API_REGION);
14
- commandPackageDockerLogin.action(async (options) => {
15
- const client = input_1.default.restApiTokenClient(false, options.api, options.region, options.token);
16
- await client.getInvoker();
17
- const host = (0, utils_1.getDockerRegistryHostByApiBaseUrl)(client.baseUrl);
18
- const output = await (0, utils_1.execLocally)(`docker login ${host} -u buddy -p "${client.token}"`);
19
- if (/Login\sSucceeded/gi.test(output)) {
20
- output_1.default.exitSuccess(texts_1.TXT_PACKAGE_DOCKER_LOGIN_SUCCESS);
21
- }
22
- else {
23
- output_1.default.exitError(texts_1.TXT_PACKAGE_DOCKER_LOGIN_FAILED);
24
- }
25
- });
26
- exports.default = commandPackageDockerLogin;
@@ -1,11 +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 login_1 = __importDefault(require("./docker/login"));
9
- const commandPackageDocker = (0, utils_1.newCommand)('docker', texts_1.DESC_COMMAND_PACKAGE_DOCKER_LOGIN);
10
- commandPackageDocker.addCommand(login_1.default);
11
- exports.default = commandPackageDocker;
@@ -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 input_1 = __importDefault(require("../../input"));
9
- const output_1 = __importDefault(require("../../output"));
10
- const logger_1 = __importDefault(require("../../logger"));
11
- const path_1 = require("path");
12
- const fs_1 = __importDefault(require("fs"));
13
- const promises_1 = __importDefault(require("node:stream/promises"));
14
- const commandPackageDownload = (0, utils_1.newCommand)('download', texts_1.DESC_COMMAND_PACKAGE_DOWNLOAD);
15
- commandPackageDownload.alias('dd');
16
- commandPackageDownload.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
- commandPackageDownload.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
- commandPackageDownload.option('-m, --merge', texts_1.OPTION_PACKAGE_DOWNLOAD_MERGE);
19
- commandPackageDownload.option('-r, --replace', texts_1.OPTION_PACKAGE_DOWNLOAD_REPLACE);
20
- commandPackageDownload.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
21
- commandPackageDownload.argument('<directory>', texts_1.OPTION_PACKAGE_DOWNLOAD_PATH);
22
- commandPackageDownload.addHelpText('after', texts_1.EXAMPLE_PACKAGE_DOWNLOAD);
23
- commandPackageDownload.action(async (id, path, options) => {
24
- const { v4 } = require('uuid');
25
- const ArchiverExtract = require('../../unzipper').default;
26
- const { UNZIPPER_FORMAT } = require('../../unzipper');
27
- const client = input_1.default.restApiTokenClient();
28
- const workspace = input_1.default.restApiWorkspace(options.workspace);
29
- const project = input_1.default.restApiProject(options.project, true);
30
- // eslint-disable-next-line prefer-const
31
- let { identifier, version } = input_1.default.packageSplitIdentifier(id);
32
- const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
33
- if (!data || !data.domain) {
34
- output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
35
- }
36
- if (project && !data.project_identifier) {
37
- output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
38
- }
39
- const packageId = data.pkg_id;
40
- if (!packageId) {
41
- output_1.default.exitError(texts_1.ERR_PACKAGE_DOWNLOAD_NOT_FOUND);
42
- }
43
- let versionId = data.pkg_version_id;
44
- if (version && !versionId) {
45
- output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
46
- }
47
- if (!version || !versionId) {
48
- const v = await client.getPackageLatest(workspace, packageId);
49
- if (!v) {
50
- output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
51
- }
52
- version = v.version;
53
- versionId = v.id;
54
- }
55
- const dirPath = (0, path_1.resolve)(path);
56
- const exists = fs_1.default.existsSync(dirPath);
57
- if (!exists) {
58
- try {
59
- fs_1.default.mkdirSync(dirPath, {
60
- recursive: true,
61
- });
62
- }
63
- catch (err) {
64
- logger_1.default.error(err);
65
- output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_MKDIR)(dirPath));
66
- }
67
- }
68
- else if (options.replace) {
69
- try {
70
- fs_1.default.rmSync(dirPath, {
71
- recursive: true,
72
- force: true,
73
- });
74
- fs_1.default.mkdirSync(dirPath, {
75
- recursive: true,
76
- });
77
- }
78
- catch (err) {
79
- logger_1.default.error(err);
80
- output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_REPLACE)(dirPath));
81
- }
82
- }
83
- try {
84
- const stat = fs_1.default.statSync(dirPath);
85
- if (!stat.isDirectory()) {
86
- output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_IS_FILE)(dirPath));
87
- }
88
- }
89
- catch (err) {
90
- logger_1.default.error(err);
91
- output_1.default.exitError(texts_1.ERR_SWW);
92
- }
93
- let empty = true;
94
- try {
95
- const entries = fs_1.default.readdirSync(dirPath);
96
- empty = !entries.length;
97
- }
98
- catch (err) {
99
- logger_1.default.error(err);
100
- output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_READDIR)(dirPath));
101
- }
102
- if (!empty && !options.merge) {
103
- output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
104
- }
105
- const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
106
- const clearZip = () => {
107
- try {
108
- fs_1.default.rmSync(zipPath);
109
- }
110
- catch {
111
- // do nothing
112
- }
113
- };
114
- output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADING_ZIP);
115
- const body = await client.downloadPackageVersion(workspace, packageId, versionId);
116
- try {
117
- await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
118
- output_1.default.clearPreviousLine();
119
- output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADED_ZIP);
120
- output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPING);
121
- let count = 0;
122
- await ArchiverExtract.extract(UNZIPPER_FORMAT.ZIP, zipPath, dirPath, async () => {
123
- count += 1;
124
- output_1.default.clearPreviousLine();
125
- output_1.default.normal((0, texts_1.TXT_PACKAGE_UNZIPPING_COUNT)(count));
126
- });
127
- clearZip();
128
- output_1.default.clearPreviousLine();
129
- output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPED);
130
- }
131
- catch (err) {
132
- logger_1.default.error(err);
133
- clearZip();
134
- output_1.default.exitError(texts_1.ERR_SWW);
135
- }
136
- output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_DOWNLOADED)(version, dirPath));
137
- });
138
- exports.default = commandPackageDownload;
@@ -1,36 +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 input_1 = __importDefault(require("../../input"));
9
- const output_1 = __importDefault(require("../../output"));
10
- const commandSandboxGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_PACKAGE_GET);
11
- commandSandboxGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
12
- commandSandboxGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
13
- commandSandboxGet.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
14
- commandSandboxGet.action(async (identifier, options) => {
15
- const workspace = input_1.default.restApiWorkspace(options.workspace);
16
- const project = input_1.default.restApiProject(options.project, true);
17
- const client = input_1.default.restApiTokenClient();
18
- const data = await client.getPackageVersionByIdentifier(workspace, project, identifier);
19
- if (!data || !data.domain) {
20
- output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
21
- }
22
- if (!data || !data.pkg_id) {
23
- output_1.default.exitError(texts_1.ERR_PACKAGE_NOT_FOUND);
24
- }
25
- const pkg = await client.getPackage(workspace, data.pkg_id);
26
- output_1.default.object({
27
- Name: pkg.name,
28
- Identifier: pkg.identifier,
29
- Type: pkg.type,
30
- Scope: pkg.scope,
31
- Size: (0, utils_1.formatBytes)(pkg.size || 0),
32
- Created: pkg.created_date,
33
- });
34
- output_1.default.exitNormal(`\n${(0, texts_1.TXT_PACKAGE_PUBLISH)(client.baseUrl, workspace, pkg)}`);
35
- });
36
- exports.default = commandSandboxGet;
@@ -1,31 +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 texts_1 = require("../../texts");
8
- const utils_1 = require("../../utils");
9
- const input_1 = __importDefault(require("../../input"));
10
- const commandPackageList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_PACKAGE_LIST);
11
- commandPackageList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
12
- commandPackageList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
13
- commandPackageList.alias('ls');
14
- commandPackageList.action(async (options) => {
15
- const workspace = input_1.default.restApiWorkspace(options.workspace);
16
- const project = input_1.default.restApiProject(options.project, true);
17
- const client = input_1.default.restApiTokenClient();
18
- const response = await client.getPackages(workspace, project);
19
- if (!response.packages || response.packages.length === 0) {
20
- output_1.default.exitError(texts_1.ERR_COMMAND_PACKAGE_NO_PROJECTS);
21
- }
22
- const data = [['NAME', 'IDENTIFIER', 'TYPE', 'URL']];
23
- for (const pkg of response.packages) {
24
- if (project && pkg.scope === utils_1.PACKAGE_SCOPE.WORKSPACE)
25
- continue;
26
- data.push([pkg.name, pkg.identifier, pkg.type, pkg.html_url]);
27
- }
28
- output_1.default.table(data);
29
- output_1.default.exitNormal();
30
- });
31
- exports.default = commandPackageList;
@@ -1,241 +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 input_1 = __importDefault(require("../../input"));
9
- const output_1 = __importDefault(require("../../output"));
10
- const logger_1 = __importDefault(require("../../logger"));
11
- const fs_1 = __importDefault(require("fs"));
12
- const path_1 = require("path");
13
- const commandPackagePublish = (0, utils_1.newCommand)('publish', texts_1.DESC_COMMAND_PACKAGE_PUBLISH);
14
- commandPackagePublish.alias('pub');
15
- commandPackagePublish.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
16
- commandPackagePublish.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
17
- commandPackagePublish.option('-c, --create', texts_1.OPTION_PACKAGE_PUBLISH_CREATE);
18
- commandPackagePublish.option('-f, --force', texts_1.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION);
19
- commandPackagePublish.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
20
- commandPackagePublish.argument('<directory>', texts_1.OPTION_PACKAGE_PUBLISH_PATH);
21
- commandPackagePublish.addHelpText('after', texts_1.EXAMPLE_PACKAGE_PUBLISH);
22
- commandPackagePublish.action(async (id, path, options) => {
23
- const { v4 } = require('uuid');
24
- let dirPath = input_1.default.resolvePath(path);
25
- const workspace = input_1.default.restApiWorkspace(options.workspace);
26
- const project = input_1.default.restApiProject(options.project, true);
27
- // eslint-disable-next-line prefer-const
28
- let { identifier, version } = input_1.default.packageSplitIdentifier(id);
29
- if (!version)
30
- version = v4();
31
- const client = input_1.default.restApiTokenClient();
32
- const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
33
- if (!data || !data.domain) {
34
- output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
35
- }
36
- if (project && !data.project_identifier) {
37
- output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
38
- }
39
- let packageId = data.pkg_id;
40
- if (!packageId) {
41
- if (options.create) {
42
- const data = {
43
- name: identifier,
44
- identifier,
45
- type: utils_1.PACKAGE_TYPE.FILE,
46
- scope: utils_1.PACKAGE_SCOPE.WORKSPACE,
47
- authorization: {
48
- type: utils_1.PACKAGE_AUTH_TYPE.BUDDY,
49
- },
50
- };
51
- if (project) {
52
- data.scope = utils_1.PACKAGE_SCOPE.PROJECT;
53
- data.project = {
54
- name: project,
55
- };
56
- }
57
- const d = await client.createPackage(workspace, data);
58
- packageId = d.id;
59
- }
60
- else {
61
- output_1.default.exitError(texts_1.ERR_PACKAGE_PUBLISH_NOT_FOUND);
62
- }
63
- }
64
- let packageVersionId = data.pkg_version_id;
65
- let url;
66
- if (packageVersionId && !options.force) {
67
- output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_EXISTS);
68
- }
69
- if (!packageVersionId) {
70
- const d = await client.createPackageVersion(workspace, packageId, version);
71
- url = d.version_url;
72
- packageVersionId = d.id;
73
- }
74
- else {
75
- const d = await client.getPackageVersion(workspace, packageId, packageVersionId);
76
- url = d.version_url;
77
- }
78
- output_1.default.normal(texts_1.TXT_PACKAGE_SCANNING_DIR, false);
79
- const stat = fs_1.default.statSync(dirPath);
80
- let entries;
81
- if (stat.isDirectory()) {
82
- entries = fs_1.default.readdirSync(dirPath, {
83
- withFileTypes: true,
84
- recursive: true,
85
- });
86
- }
87
- else {
88
- const parentPath = (0, path_1.dirname)(dirPath);
89
- entries = [
90
- {
91
- isDirectory: () => stat.isDirectory(),
92
- isFile: () => stat.isFile(),
93
- isBlockDevice: () => stat.isBlockDevice(),
94
- isCharacterDevice: () => stat.isCharacterDevice(),
95
- isFIFO: () => stat.isFIFO(),
96
- isSocket: () => stat.isSocket(),
97
- isSymbolicLink: () => stat.isSymbolicLink(),
98
- name: (0, path_1.basename)(dirPath),
99
- parentPath,
100
- },
101
- ];
102
- dirPath = parentPath;
103
- }
104
- if (!entries.length) {
105
- output_1.default.normal(texts_1.TXT_PACKAGE_NO_ENTRIES_FOUND);
106
- output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
107
- }
108
- else if (entries.length === 1) {
109
- output_1.default.normal(texts_1.TXT_PACKAGE_ONE_ENTRY_FOUND);
110
- }
111
- else {
112
- output_1.default.normal((0, texts_1.TXT_PACKAGE_ENTRIES_FOUND)(entries.length));
113
- }
114
- output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(0));
115
- const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
116
- const clearZip = () => {
117
- try {
118
- fs_1.default.rmSync(zipPath);
119
- }
120
- catch {
121
- // do nothing
122
- }
123
- };
124
- let blob;
125
- try {
126
- let proc = 0;
127
- await createZip(dirPath, zipPath, entries, () => {
128
- proc += 1;
129
- output_1.default.clearPreviousLine();
130
- output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(proc));
131
- });
132
- output_1.default.clearPreviousLine();
133
- output_1.default.normal(texts_1.TXT_PACKAGE_ZIPPED);
134
- blob = await fs_1.default.openAsBlob(zipPath);
135
- }
136
- catch (err) {
137
- logger_1.default.error(err);
138
- clearZip();
139
- output_1.default.exitError(texts_1.ERR_SWW);
140
- }
141
- try {
142
- output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADING);
143
- await client.createPackageVersionZip(workspace, packageId, packageVersionId, blob);
144
- output_1.default.clearPreviousLine();
145
- output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADED);
146
- clearZip();
147
- output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
148
- }
149
- catch (err) {
150
- clearZip();
151
- logger_1.default.error(err);
152
- output_1.default.exitError(err);
153
- }
154
- });
155
- const addEntryToZip = (dirPath, zip, entry) => {
156
- const fflate = require('fflate');
157
- return new Promise((resolve, reject) => {
158
- const isDir = entry.isDirectory();
159
- let name = (0, path_1.join)(entry.parentPath.replace(dirPath, ''), entry.name);
160
- if (isDir)
161
- name += '/';
162
- else
163
- name = name.replace(/^\//, '');
164
- const file = new fflate.ZipDeflate(name, {
165
- level: 3,
166
- });
167
- zip.add(file);
168
- if (isDir) {
169
- file.push(new Uint8Array(0), true);
170
- resolve();
171
- return;
172
- }
173
- const fullPath = (0, path_1.join)(entry.parentPath, entry.name);
174
- const rs = fs_1.default.createReadStream(fullPath);
175
- const finish = (err) => {
176
- try {
177
- rs.removeAllListeners();
178
- rs.close();
179
- }
180
- catch {
181
- // do nothing
182
- }
183
- if (err)
184
- reject(err);
185
- else
186
- resolve();
187
- };
188
- rs.on('data', (chunk) => {
189
- file.push(chunk, false);
190
- });
191
- rs.on('error', (err) => {
192
- finish(err);
193
- });
194
- rs.on('end', () => {
195
- file.push(new Uint8Array(0), true);
196
- finish();
197
- });
198
- });
199
- };
200
- const addEntriesToZip = async (dirPath, zip, entries, onEntry) => {
201
- for (let i = 0; i < entries.length; i += 1) {
202
- await addEntryToZip(dirPath, zip, entries[i]);
203
- onEntry();
204
- }
205
- };
206
- const createZip = (dirPath, zipPath, entries, onEntry) => {
207
- const fflate = require('fflate');
208
- return new Promise((resolve, reject) => {
209
- const ws = fs_1.default.createWriteStream(zipPath);
210
- let wasError = false;
211
- const zip = new fflate.Zip((err, data, final) => {
212
- if (wasError) {
213
- // do nothing
214
- }
215
- else if (err) {
216
- wasError = true;
217
- ws.close();
218
- reject(err);
219
- }
220
- else if (final) {
221
- ws.end(data, () => {
222
- resolve();
223
- });
224
- }
225
- else {
226
- ws.write(data);
227
- }
228
- });
229
- addEntriesToZip(dirPath, zip, entries, onEntry)
230
- .then(() => {
231
- zip.end();
232
- })
233
- .catch((err) => {
234
- wasError = true;
235
- ws.close(() => {
236
- reject(err);
237
- });
238
- });
239
- });
240
- };
241
- exports.default = commandPackagePublish;