bdy 1.18.34-dev → 1.19.0-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.
- package/distTs/package.json +2 -2
- package/distTs/src/api/client.js +25 -25
- package/distTs/src/command/artifact/create.js +64 -0
- package/distTs/src/command/artifact/delete.js +38 -0
- package/distTs/src/command/artifact/docker/login.js +26 -0
- package/distTs/src/command/artifact/docker.js +11 -0
- package/distTs/src/command/artifact/download.js +138 -0
- package/distTs/src/command/artifact/get.js +36 -0
- package/distTs/src/command/artifact/list.js +31 -0
- package/distTs/src/command/artifact/publish.js +241 -0
- package/distTs/src/command/artifact/version/delete.js +39 -0
- package/distTs/src/command/artifact/version/get.js +45 -0
- package/distTs/src/command/artifact/version/list.js +47 -0
- package/distTs/src/command/artifact/version.js +16 -0
- package/distTs/src/command/artifact.js +26 -0
- package/distTs/src/command/login.js +1 -1
- package/distTs/src/command/project/link.js +2 -2
- package/distTs/src/index.js +2 -2
- package/distTs/src/input.js +8 -8
- package/distTs/src/texts.js +140 -146
- package/distTs/src/utils.js +37 -37
- package/package.json +2 -2
package/distTs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bdy",
|
|
3
3
|
"preferGlobal": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.19.0-beta",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"e2e:auth": "vitest run --config e2e/vitest.config.ts e2e/modules/auth/",
|
|
16
16
|
"e2e:workspace": "vitest run --config e2e/vitest.config.ts e2e/modules/workspace/",
|
|
17
17
|
"e2e:project": "vitest run --config e2e/vitest.config.ts e2e/modules/project/",
|
|
18
|
-
"e2e:
|
|
18
|
+
"e2e:artifact": "vitest run --config e2e/vitest.config.ts e2e/modules/artifact/",
|
|
19
19
|
"e2e:sandbox": "vitest run --config e2e/vitest.config.ts e2e/modules/sandbox/",
|
|
20
20
|
"e2e:api": "vitest run --config e2e/vitest.config.ts e2e/modules/api/",
|
|
21
21
|
"e2e:pipeline": "vitest run --config e2e/vitest.config.ts e2e/modules/pipeline/",
|
package/distTs/src/api/client.js
CHANGED
|
@@ -642,13 +642,13 @@ class ApiClient {
|
|
|
642
642
|
parseResponseBody: true,
|
|
643
643
|
});
|
|
644
644
|
}
|
|
645
|
-
async
|
|
645
|
+
async getArtifacts(workspace, project) {
|
|
646
646
|
let query = '';
|
|
647
647
|
if (project)
|
|
648
648
|
query += `?project_name=${encodeURIComponent(project)}`;
|
|
649
649
|
return await this.request({
|
|
650
650
|
method: 'GET',
|
|
651
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
651
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts${query}`,
|
|
652
652
|
parseResponseBody: true,
|
|
653
653
|
});
|
|
654
654
|
}
|
|
@@ -694,20 +694,20 @@ class ApiClient {
|
|
|
694
694
|
pipeline: identifier,
|
|
695
695
|
});
|
|
696
696
|
}
|
|
697
|
-
async
|
|
697
|
+
async deleteArtifactVersion(workspace, artifactId, versionId) {
|
|
698
698
|
return await this.request({
|
|
699
699
|
method: 'DELETE',
|
|
700
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
700
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}`,
|
|
701
701
|
});
|
|
702
702
|
}
|
|
703
|
-
async
|
|
703
|
+
async getArtifactVersionByIdentifier(workspace, project, artifact, version) {
|
|
704
704
|
const opts = {
|
|
705
|
-
|
|
705
|
+
artifact,
|
|
706
706
|
};
|
|
707
707
|
if (project)
|
|
708
708
|
opts.project = project;
|
|
709
709
|
if (version)
|
|
710
|
-
opts.
|
|
710
|
+
opts.artifact_version = version;
|
|
711
711
|
return await this.getResourceByIdentifier(workspace, opts);
|
|
712
712
|
}
|
|
713
713
|
async getSandboxByIdentifier(workspace, project, sandbox) {
|
|
@@ -742,10 +742,10 @@ class ApiClient {
|
|
|
742
742
|
parseResponseBody: true,
|
|
743
743
|
});
|
|
744
744
|
}
|
|
745
|
-
async
|
|
745
|
+
async getArtifactVersions(workspace, artifactId, page = 1, perPage = 10) {
|
|
746
746
|
return await this.request({
|
|
747
747
|
method: 'GET',
|
|
748
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
748
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${artifactId}/versions`,
|
|
749
749
|
query: {
|
|
750
750
|
page: page.toString(),
|
|
751
751
|
per_page: perPage.toString(),
|
|
@@ -753,24 +753,24 @@ class ApiClient {
|
|
|
753
753
|
parseResponseBody: true,
|
|
754
754
|
});
|
|
755
755
|
}
|
|
756
|
-
async
|
|
756
|
+
async getArtifactVersion(workspace, artifactId, versionId) {
|
|
757
757
|
return await this.request({
|
|
758
758
|
method: 'GET',
|
|
759
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
759
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}`,
|
|
760
760
|
parseResponseBody: true,
|
|
761
761
|
});
|
|
762
762
|
}
|
|
763
|
-
async
|
|
763
|
+
async getArtifact(workspace, artifactId) {
|
|
764
764
|
return await this.request({
|
|
765
765
|
method: 'GET',
|
|
766
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
766
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${artifactId}`,
|
|
767
767
|
parseResponseBody: true,
|
|
768
768
|
});
|
|
769
769
|
}
|
|
770
|
-
async
|
|
770
|
+
async getArtifactLatest(workspace, artifactId) {
|
|
771
771
|
const res = await this.request({
|
|
772
772
|
method: 'GET',
|
|
773
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
773
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions?page=1&per_page=1`,
|
|
774
774
|
parseResponseBody: true,
|
|
775
775
|
});
|
|
776
776
|
if (res && res.versions && res.versions.length > 0) {
|
|
@@ -778,45 +778,45 @@ class ApiClient {
|
|
|
778
778
|
}
|
|
779
779
|
return null;
|
|
780
780
|
}
|
|
781
|
-
async
|
|
781
|
+
async downloadArtifactVersion(workspace, artifactId, versionId) {
|
|
782
782
|
return await this.request({
|
|
783
783
|
method: 'GET',
|
|
784
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
784
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}/download`,
|
|
785
785
|
rawResponseBody: true,
|
|
786
786
|
});
|
|
787
787
|
}
|
|
788
|
-
async
|
|
788
|
+
async createArtifactVersion(workspace, artifactId, version) {
|
|
789
789
|
return await this.request({
|
|
790
790
|
method: 'POST',
|
|
791
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
791
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions`,
|
|
792
792
|
body: {
|
|
793
793
|
version,
|
|
794
794
|
},
|
|
795
795
|
parseResponseBody: true,
|
|
796
796
|
});
|
|
797
797
|
}
|
|
798
|
-
async
|
|
798
|
+
async createArtifactVersionZip(workspace, artifactId, versionId, file) {
|
|
799
799
|
const form = new undici_1.FormData();
|
|
800
800
|
form.append('file', file, 'file.zip');
|
|
801
801
|
return await this.request({
|
|
802
802
|
method: 'POST',
|
|
803
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
803
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}/versions/${encodeURIComponent(versionId)}/upload`,
|
|
804
804
|
body: form,
|
|
805
805
|
parseResponseBody: true,
|
|
806
806
|
});
|
|
807
807
|
}
|
|
808
|
-
async
|
|
808
|
+
async createArtifact(workspace, data) {
|
|
809
809
|
return await this.request({
|
|
810
810
|
method: 'POST',
|
|
811
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
811
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts`,
|
|
812
812
|
body: data,
|
|
813
813
|
parseResponseBody: true,
|
|
814
814
|
});
|
|
815
815
|
}
|
|
816
|
-
async
|
|
816
|
+
async deleteArtifact(workspace, artifactId) {
|
|
817
817
|
return await this.request({
|
|
818
818
|
method: 'DELETE',
|
|
819
|
-
path: `/workspaces/${encodeURIComponent(workspace)}/
|
|
819
|
+
path: `/workspaces/${encodeURIComponent(workspace)}/artifacts/${encodeURIComponent(artifactId)}`,
|
|
820
820
|
});
|
|
821
821
|
}
|
|
822
822
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 commandArtifactCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_ARTIFACT_CREATE);
|
|
11
|
+
commandArtifactCreate.alias('add');
|
|
12
|
+
commandArtifactCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_ARTIFACT_CREATE_IDENTIFIER);
|
|
13
|
+
commandArtifactCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
14
|
+
commandArtifactCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
15
|
+
commandArtifactCreate.option('-t, --type <type>', texts_1.OPT_COMMAND_ARTIFACT_TYPE, utils_1.ARTIFACT_TYPE.BUCKET);
|
|
16
|
+
commandArtifactCreate.option('-b, --buddy', texts_1.OPTION_HTTP_AUTH_BUDDY);
|
|
17
|
+
commandArtifactCreate.option('-a, --auth <user:pass>', texts_1.OPTION_HTTP_AUTH);
|
|
18
|
+
commandArtifactCreate.argument('[name]', texts_1.OPT_COMMAND_ARTIFACT_NAME);
|
|
19
|
+
commandArtifactCreate.addHelpText('after', texts_1.EXAMPLE_ARTIFACT_CREATE);
|
|
20
|
+
commandArtifactCreate.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.artifactType(options.type);
|
|
26
|
+
const scope = input_1.default.artifactScope(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.ARTIFACT_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.ARTIFACT_AUTH_TYPE.BASIC,
|
|
52
|
+
user: login,
|
|
53
|
+
password,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (options.buddy) {
|
|
57
|
+
data.authorization = {
|
|
58
|
+
type: utils_1.ARTIFACT_AUTH_TYPE.BUDDY,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const result = await client.createArtifact(workspace, data);
|
|
62
|
+
output_1.default.exitSuccess((0, texts_1.TXT_ARTIFACT_CREATED)(client.baseUrl, workspace, result));
|
|
63
|
+
});
|
|
64
|
+
exports.default = commandArtifactCreate;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 commandArtifactDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_ARTIFACT_DELETE);
|
|
11
|
+
commandArtifactDelete.alias('rm');
|
|
12
|
+
commandArtifactDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
13
|
+
commandArtifactDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
14
|
+
commandArtifactDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
|
|
15
|
+
commandArtifactDelete.argument('<identifier>', texts_1.OPT_COMMAND_ARTIFACT_IDENTIFIER);
|
|
16
|
+
commandArtifactDelete.addHelpText('after', texts_1.EXAMPLE_ARTIFACT_DELETE);
|
|
17
|
+
commandArtifactDelete.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.getArtifactVersionByIdentifier(workspace, project, identifier);
|
|
22
|
+
if (!data || !data.domain) {
|
|
23
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
24
|
+
}
|
|
25
|
+
if (!data.artifact_id) {
|
|
26
|
+
output_1.default.exitError(texts_1.ERR_ARTIFACT_NOT_FOUND);
|
|
27
|
+
}
|
|
28
|
+
const confirmed = options.force ||
|
|
29
|
+
(await output_1.default.confirm((0, texts_1.TXT_ARTIFACT_DELETE_CONFIRM)(identifier)));
|
|
30
|
+
if (confirmed) {
|
|
31
|
+
await client.deleteArtifact(workspace, data.artifact_id);
|
|
32
|
+
output_1.default.exitSuccess(texts_1.TXT_ARTIFACT_DELETED);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
output_1.default.exitNormal();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
exports.default = commandArtifactDelete;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 commandArtifactDockerLogin = (0, utils_1.newCommand)('login', texts_1.DESC_COMMAND_ARTIFACT_DOCKER_LOGIN);
|
|
11
|
+
commandArtifactDockerLogin.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
12
|
+
commandArtifactDockerLogin.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
13
|
+
commandArtifactDockerLogin.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
14
|
+
commandArtifactDockerLogin.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_ARTIFACT_DOCKER_LOGIN_SUCCESS);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
output_1.default.exitError(texts_1.TXT_ARTIFACT_DOCKER_LOGIN_FAILED);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
exports.default = commandArtifactDockerLogin;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 commandArtifactDocker = (0, utils_1.newCommand)('docker', texts_1.DESC_COMMAND_ARTIFACT_DOCKER_LOGIN);
|
|
10
|
+
commandArtifactDocker.addCommand(login_1.default);
|
|
11
|
+
exports.default = commandArtifactDocker;
|
|
@@ -0,0 +1,138 @@
|
|
|
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 commandArtifactDownload = (0, utils_1.newCommand)('download', texts_1.DESC_COMMAND_ARTIFACT_DOWNLOAD);
|
|
15
|
+
commandArtifactDownload.alias('dd');
|
|
16
|
+
commandArtifactDownload.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandArtifactDownload.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandArtifactDownload.option('-m, --merge', texts_1.OPTION_ARTIFACT_DOWNLOAD_MERGE);
|
|
19
|
+
commandArtifactDownload.option('-r, --replace', texts_1.OPTION_ARTIFACT_DOWNLOAD_REPLACE);
|
|
20
|
+
commandArtifactDownload.argument('<identifier>', texts_1.OPTION_ARTIFACT_ID);
|
|
21
|
+
commandArtifactDownload.argument('<directory>', texts_1.OPTION_ARTIFACT_DOWNLOAD_PATH);
|
|
22
|
+
commandArtifactDownload.addHelpText('after', texts_1.EXAMPLE_ARTIFACT_DOWNLOAD);
|
|
23
|
+
commandArtifactDownload.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.artifactSplitIdentifier(id);
|
|
32
|
+
const data = await client.getArtifactVersionByIdentifier(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 artifactId = data.artifact_id;
|
|
40
|
+
if (!artifactId) {
|
|
41
|
+
output_1.default.exitError(texts_1.ERR_ARTIFACT_DOWNLOAD_NOT_FOUND);
|
|
42
|
+
}
|
|
43
|
+
let versionId = data.artifact_version_id;
|
|
44
|
+
if (version && !versionId) {
|
|
45
|
+
output_1.default.exitError(texts_1.ERR_ARTIFACT_VERSION_NOT_FOUND);
|
|
46
|
+
}
|
|
47
|
+
if (!version || !versionId) {
|
|
48
|
+
const v = await client.getArtifactLatest(workspace, artifactId);
|
|
49
|
+
if (!v) {
|
|
50
|
+
output_1.default.exitError(texts_1.ERR_ARTIFACT_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_ARTIFACT_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_ARTIFACT_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_ARTIFACT_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_ARTIFACT_DOWNLOAD_READDIR)(dirPath));
|
|
101
|
+
}
|
|
102
|
+
if (!empty && !options.merge) {
|
|
103
|
+
output_1.default.exitError((0, texts_1.ERR_ARTIFACT_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_ARTIFACT_DOWNLOADING_ZIP);
|
|
115
|
+
const body = await client.downloadArtifactVersion(workspace, artifactId, 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_ARTIFACT_DOWNLOADED_ZIP);
|
|
120
|
+
output_1.default.normal(texts_1.TXT_ARTIFACT_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_ARTIFACT_UNZIPPING_COUNT)(count));
|
|
126
|
+
});
|
|
127
|
+
clearZip();
|
|
128
|
+
output_1.default.clearPreviousLine();
|
|
129
|
+
output_1.default.normal(texts_1.TXT_ARTIFACT_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_ARTIFACT_DOWNLOADED)(version, dirPath));
|
|
137
|
+
});
|
|
138
|
+
exports.default = commandArtifactDownload;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 commandArtifactGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_ARTIFACT_GET);
|
|
11
|
+
commandArtifactGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
12
|
+
commandArtifactGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
13
|
+
commandArtifactGet.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
14
|
+
commandArtifactGet.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.getArtifactVersionByIdentifier(workspace, project, identifier);
|
|
19
|
+
if (!data || !data.domain) {
|
|
20
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
21
|
+
}
|
|
22
|
+
if (!data || !data.artifact_id) {
|
|
23
|
+
output_1.default.exitError(texts_1.ERR_ARTIFACT_NOT_FOUND);
|
|
24
|
+
}
|
|
25
|
+
const art = await client.getArtifact(workspace, data.artifact_id);
|
|
26
|
+
output_1.default.object({
|
|
27
|
+
Name: art.name,
|
|
28
|
+
Identifier: art.identifier,
|
|
29
|
+
Type: art.type,
|
|
30
|
+
Scope: art.scope,
|
|
31
|
+
Size: (0, utils_1.formatBytes)(art.size || 0),
|
|
32
|
+
Created: art.created_date,
|
|
33
|
+
});
|
|
34
|
+
output_1.default.exitNormal(`\n${(0, texts_1.TXT_ARTIFACT_PUBLISH)(client.baseUrl, workspace, art)}`);
|
|
35
|
+
});
|
|
36
|
+
exports.default = commandArtifactGet;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 commandArtifactList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_ARTIFACT_LIST);
|
|
11
|
+
commandArtifactList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
12
|
+
commandArtifactList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
13
|
+
commandArtifactList.alias('ls');
|
|
14
|
+
commandArtifactList.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.getArtifacts(workspace, project);
|
|
19
|
+
if (!response.artifacts || response.artifacts.length === 0) {
|
|
20
|
+
output_1.default.exitError(texts_1.ERR_COMMAND_ARTIFACT_NO_PROJECTS);
|
|
21
|
+
}
|
|
22
|
+
const data = [['NAME', 'IDENTIFIER', 'TYPE', 'URL']];
|
|
23
|
+
for (const artifact of response.artifacts) {
|
|
24
|
+
if (project && artifact.scope === utils_1.ARTIFACT_SCOPE.WORKSPACE)
|
|
25
|
+
continue;
|
|
26
|
+
data.push([artifact.name, artifact.identifier, artifact.type, artifact.html_url]);
|
|
27
|
+
}
|
|
28
|
+
output_1.default.table(data);
|
|
29
|
+
output_1.default.exitNormal();
|
|
30
|
+
});
|
|
31
|
+
exports.default = commandArtifactList;
|