bdy 1.16.11-master → 1.16.11-sbs-2
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 +4 -3
- package/distTs/src/api/client.js +78 -2
- package/distTs/src/command/agent/install.js +11 -17
- package/distTs/src/command/login.js +298 -0
- package/distTs/src/command/logout.js +15 -0
- package/distTs/src/command/package/download.js +259 -0
- package/distTs/src/command/package/publish.js +231 -0
- package/distTs/src/command/package.js +14 -0
- package/distTs/src/command/project/list.js +61 -0
- package/distTs/src/command/project/set.js +85 -0
- package/distTs/src/command/project.js +14 -0
- package/distTs/src/command/sandbox/command/kill.js +35 -0
- package/distTs/src/command/sandbox/command/list.js +54 -0
- package/distTs/src/command/sandbox/command/logs.js +133 -0
- package/distTs/src/command/sandbox/command/status.js +44 -0
- package/distTs/src/command/sandbox/command.js +18 -0
- package/distTs/src/command/sandbox/cp.js +123 -0
- package/distTs/src/command/sandbox/create.js +99 -0
- package/distTs/src/command/sandbox/destroy.js +35 -0
- package/distTs/src/command/sandbox/endpoint/add.js +91 -0
- package/distTs/src/command/sandbox/endpoint/delete.js +46 -0
- package/distTs/src/command/sandbox/endpoint/get.js +58 -0
- package/distTs/src/command/sandbox/endpoint/list.js +51 -0
- package/distTs/src/command/sandbox/endpoint/update.js +85 -0
- package/distTs/src/command/sandbox/endpoint.js +20 -0
- package/distTs/src/command/sandbox/exec.js +127 -0
- package/distTs/src/command/sandbox/get.js +51 -0
- package/distTs/src/command/sandbox/list.js +41 -0
- package/distTs/src/command/sandbox/restart.js +49 -0
- package/distTs/src/command/sandbox/snapshot/create.js +68 -0
- package/distTs/src/command/sandbox/snapshot/delete.js +42 -0
- package/distTs/src/command/sandbox/snapshot/get.js +54 -0
- package/distTs/src/command/sandbox/snapshot/list.js +48 -0
- package/distTs/src/command/sandbox/snapshot.js +18 -0
- package/distTs/src/command/sandbox/start.js +49 -0
- package/distTs/src/command/sandbox/status.js +35 -0
- package/distTs/src/command/sandbox/stop.js +49 -0
- package/distTs/src/command/sandbox.js +36 -0
- package/distTs/src/command/tunnel/http.js +4 -3
- package/distTs/src/command/tunnel/tcp.js +4 -3
- package/distTs/src/command/tunnel/tls.js +4 -3
- package/distTs/src/command/workspace/list.js +57 -0
- package/distTs/src/command/workspace/set.js +81 -0
- package/distTs/src/command/workspace.js +14 -0
- package/distTs/src/index.js +10 -0
- package/distTs/src/input.js +24 -4
- package/distTs/src/texts.js +164 -8
- package/distTs/src/tunnel/cfg.js +53 -4
- package/package.json +4 -3
- package/distTs/src/command/agent/standalone/kill.js +0 -22
- package/distTs/src/command/agent/standalone.js +0 -136
- package/distTs/src/command/vt/scrap.js +0 -193
|
@@ -0,0 +1,259 @@
|
|
|
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 client_1 = __importDefault(require("../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const promises_1 = __importDefault(require("stream/promises"));
|
|
16
|
+
const fflate_1 = require("fflate");
|
|
17
|
+
const commandPackageDownload = (0, utils_1.newCommand)('download', texts_1.DESC_COMMAND_PACKAGE_DOWNLOAD);
|
|
18
|
+
commandPackageDownload.alias('dd');
|
|
19
|
+
commandPackageDownload.option('-t, --token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
20
|
+
commandPackageDownload.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
21
|
+
commandPackageDownload.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
22
|
+
commandPackageDownload.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
23
|
+
commandPackageDownload.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
24
|
+
commandPackageDownload.option('-m, --merge', texts_1.OPTION_PACKAGE_DOWNLOAD_MERGE);
|
|
25
|
+
commandPackageDownload.option('-r, --replace', texts_1.OPTION_PACKAGE_DOWNLOAD_REPLACE);
|
|
26
|
+
commandPackageDownload.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
27
|
+
commandPackageDownload.argument('<directory>', texts_1.OPTION_PACKAGE_DOWNLOAD_PATH);
|
|
28
|
+
commandPackageDownload.action(async (id, path, options) => {
|
|
29
|
+
const token = input_1.default.restApiToken(options.token);
|
|
30
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
31
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
32
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
33
|
+
const client = new client_1.default(baseUrl, token);
|
|
34
|
+
// eslint-disable-next-line prefer-const
|
|
35
|
+
let { identifier, version } = input_1.default.packageSplitIdentifier(id);
|
|
36
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
|
|
37
|
+
if (!data || !data.domain) {
|
|
38
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
39
|
+
}
|
|
40
|
+
if (project && !data.project_identifier) {
|
|
41
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
|
|
42
|
+
}
|
|
43
|
+
const packageId = data.pkg_id;
|
|
44
|
+
if (!packageId) {
|
|
45
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_DOWNLOAD_NOT_FOUND);
|
|
46
|
+
}
|
|
47
|
+
let versionId = data.pkg_version_id;
|
|
48
|
+
if (version && !versionId) {
|
|
49
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
|
|
50
|
+
}
|
|
51
|
+
if (!version || !versionId) {
|
|
52
|
+
const v = await client.getPackageLatest(workspace, packageId);
|
|
53
|
+
if (!v) {
|
|
54
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_NOT_FOUND);
|
|
55
|
+
}
|
|
56
|
+
version = v.version;
|
|
57
|
+
versionId = v.id;
|
|
58
|
+
}
|
|
59
|
+
const dirPath = (0, path_1.resolve)(path);
|
|
60
|
+
const exists = fs_1.default.existsSync(dirPath);
|
|
61
|
+
if (!exists) {
|
|
62
|
+
try {
|
|
63
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
64
|
+
recursive: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
logger_1.default.error(err);
|
|
69
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_MKDIR)(dirPath));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (options.replace) {
|
|
73
|
+
try {
|
|
74
|
+
fs_1.default.rmSync(dirPath, {
|
|
75
|
+
recursive: true,
|
|
76
|
+
force: true,
|
|
77
|
+
});
|
|
78
|
+
fs_1.default.mkdirSync(dirPath, {
|
|
79
|
+
recursive: true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
logger_1.default.error(err);
|
|
84
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_REPLACE)(dirPath));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
89
|
+
if (!stat.isDirectory()) {
|
|
90
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_IS_FILE)(dirPath));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
logger_1.default.error(err);
|
|
95
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
96
|
+
}
|
|
97
|
+
let empty = true;
|
|
98
|
+
try {
|
|
99
|
+
const entries = fs_1.default.readdirSync(dirPath);
|
|
100
|
+
empty = !entries.length;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
logger_1.default.error(err);
|
|
104
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_READDIR)(dirPath));
|
|
105
|
+
}
|
|
106
|
+
if (!empty && !options.merge) {
|
|
107
|
+
output_1.default.exitError((0, texts_1.ERR_PACKAGE_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
|
|
108
|
+
}
|
|
109
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
110
|
+
const clearZip = () => {
|
|
111
|
+
try {
|
|
112
|
+
fs_1.default.rmSync(zipPath);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// do nothing
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADING_ZIP);
|
|
119
|
+
const body = await client.downloadPackageVersion(workspace, packageId, versionId);
|
|
120
|
+
try {
|
|
121
|
+
await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
|
|
122
|
+
output_1.default.clearPreviousLine();
|
|
123
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_DOWNLOADED_ZIP);
|
|
124
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPING);
|
|
125
|
+
let count = 0;
|
|
126
|
+
await unzip(dirPath, zipPath, () => {
|
|
127
|
+
count += 1;
|
|
128
|
+
output_1.default.clearPreviousLine();
|
|
129
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_UNZIPPING_COUNT)(count));
|
|
130
|
+
});
|
|
131
|
+
clearZip();
|
|
132
|
+
output_1.default.clearPreviousLine();
|
|
133
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UNZIPPED);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
logger_1.default.error(err);
|
|
137
|
+
clearZip();
|
|
138
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
139
|
+
}
|
|
140
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_DOWNLOADED)(version, dirPath));
|
|
141
|
+
});
|
|
142
|
+
const unzip = (dirPath, zipPath, onFile) => {
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
let _startedFiles = 0;
|
|
145
|
+
let _finishedFiles = 0;
|
|
146
|
+
let _finishedStream = false;
|
|
147
|
+
let _finishedError = null;
|
|
148
|
+
let _calledResolve = false;
|
|
149
|
+
const rs = fs_1.default.createReadStream(zipPath);
|
|
150
|
+
const _finish = () => {
|
|
151
|
+
if (_finishedError || _finishedStream) {
|
|
152
|
+
try {
|
|
153
|
+
rs.removeAllListeners();
|
|
154
|
+
rs.close();
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// do nothing
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (_calledResolve)
|
|
161
|
+
return;
|
|
162
|
+
if (_finishedError) {
|
|
163
|
+
_calledResolve = true;
|
|
164
|
+
reject(_finishedError);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (_finishedStream && _startedFiles === _finishedFiles) {
|
|
168
|
+
_calledResolve = true;
|
|
169
|
+
resolve();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const finishFile = (err, fws) => {
|
|
173
|
+
if (!_finishedError && err)
|
|
174
|
+
_finishedError = err;
|
|
175
|
+
_finishedFiles += 1;
|
|
176
|
+
if (fws) {
|
|
177
|
+
try {
|
|
178
|
+
fws.removeAllListeners();
|
|
179
|
+
fws.close();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// do nothing
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
onFile();
|
|
186
|
+
_finish();
|
|
187
|
+
};
|
|
188
|
+
const finishStream = (err) => {
|
|
189
|
+
if (!_finishedError && err)
|
|
190
|
+
_finishedError = err;
|
|
191
|
+
_finishedStream = true;
|
|
192
|
+
_finish();
|
|
193
|
+
};
|
|
194
|
+
const unzip = new fflate_1.Unzip(async (file) => {
|
|
195
|
+
if (_finishedError)
|
|
196
|
+
return;
|
|
197
|
+
_startedFiles += 1;
|
|
198
|
+
const fullPath = (0, path_1.join)(dirPath, file.name);
|
|
199
|
+
const parentPath = (0, path_1.dirname)(fullPath);
|
|
200
|
+
let fws;
|
|
201
|
+
try {
|
|
202
|
+
await fs_1.default.promises.rm(fullPath, {
|
|
203
|
+
recursive: true,
|
|
204
|
+
force: true,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// do nothing
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
if (fullPath.endsWith('/')) {
|
|
212
|
+
await fs_1.default.promises.mkdir(fullPath, {
|
|
213
|
+
recursive: true,
|
|
214
|
+
});
|
|
215
|
+
finishFile();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
await fs_1.default.promises.mkdir(parentPath, {
|
|
219
|
+
recursive: true,
|
|
220
|
+
});
|
|
221
|
+
fws = fs_1.default.createWriteStream(fullPath, {
|
|
222
|
+
flags: 'w',
|
|
223
|
+
});
|
|
224
|
+
fws.on('error', (err) => {
|
|
225
|
+
finishFile(err, fws);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
finishFile(err, fws);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
file.ondata = (err, data, final) => {
|
|
233
|
+
if (_finishedError)
|
|
234
|
+
return;
|
|
235
|
+
if (err)
|
|
236
|
+
finishFile(err, fws);
|
|
237
|
+
else {
|
|
238
|
+
if (fws)
|
|
239
|
+
fws.write(data);
|
|
240
|
+
if (final)
|
|
241
|
+
finishFile(null, fws);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
file.start();
|
|
245
|
+
});
|
|
246
|
+
unzip.register(fflate_1.AsyncUnzipInflate);
|
|
247
|
+
rs.on('data', (chunk) => {
|
|
248
|
+
unzip.push(chunk, false);
|
|
249
|
+
});
|
|
250
|
+
rs.on('error', (err) => {
|
|
251
|
+
finishStream(err);
|
|
252
|
+
});
|
|
253
|
+
rs.on('end', () => {
|
|
254
|
+
unzip.push(new Uint8Array(0), true);
|
|
255
|
+
finishStream();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
exports.default = commandPackageDownload;
|
|
@@ -0,0 +1,231 @@
|
|
|
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 client_1 = __importDefault(require("../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../logger"));
|
|
12
|
+
const fflate_1 = __importDefault(require("fflate"));
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const uuid_1 = require("uuid");
|
|
16
|
+
const commandPackagePublish = (0, utils_1.newCommand)('publish', texts_1.DESC_COMMAND_PACKAGE_PUBLISH);
|
|
17
|
+
commandPackagePublish.alias('pub');
|
|
18
|
+
commandPackagePublish.option('-t, --token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
19
|
+
commandPackagePublish.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
20
|
+
commandPackagePublish.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
21
|
+
commandPackagePublish.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
22
|
+
commandPackagePublish.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
23
|
+
commandPackagePublish.option('-c, --create', texts_1.OPTION_PACKAGE_PUBLISH_CREATE);
|
|
24
|
+
commandPackagePublish.option('-f, --force', texts_1.OPTION_PACKAGE_PUBLISH_OVERWRITE_VERSION);
|
|
25
|
+
commandPackagePublish.argument('<identifier>', texts_1.OPTION_PACKAGE_ID);
|
|
26
|
+
commandPackagePublish.argument('<directory>', texts_1.OPTION_PACKAGE_PUBLISH_PATH);
|
|
27
|
+
commandPackagePublish.action(async (id, path, options) => {
|
|
28
|
+
let dirPath = input_1.default.resolvePath(path);
|
|
29
|
+
const token = input_1.default.restApiToken(options.token);
|
|
30
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
31
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
32
|
+
const project = input_1.default.restApiProject(options.project, true);
|
|
33
|
+
// eslint-disable-next-line prefer-const
|
|
34
|
+
let { identifier, version } = input_1.default.packageSplitIdentifier(id);
|
|
35
|
+
if (!version)
|
|
36
|
+
version = (0, uuid_1.v4)();
|
|
37
|
+
const client = new client_1.default(baseUrl, token);
|
|
38
|
+
const data = await client.getPackageVersionByIdentifier(workspace, project, identifier, version);
|
|
39
|
+
if (!data || !data.domain) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_FOUND);
|
|
41
|
+
}
|
|
42
|
+
if (project && !data.project_identifier) {
|
|
43
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NOT_FOUND);
|
|
44
|
+
}
|
|
45
|
+
let packageId = data.pkg_id;
|
|
46
|
+
if (!packageId) {
|
|
47
|
+
if (options.create) {
|
|
48
|
+
const d = await client.postPackage(workspace, project, identifier);
|
|
49
|
+
packageId = d.id;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_PUBLISH_NOT_FOUND);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
let packageVersionId = data.pkg_version_id;
|
|
56
|
+
let url;
|
|
57
|
+
if (packageVersionId && !options.force) {
|
|
58
|
+
output_1.default.exitError(texts_1.ERR_PACKAGE_VERSION_EXISTS);
|
|
59
|
+
}
|
|
60
|
+
if (!packageVersionId) {
|
|
61
|
+
const d = await client.postPackageVersion(workspace, packageId, version);
|
|
62
|
+
url = d.version_url;
|
|
63
|
+
packageVersionId = d.id;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const d = await client.getPackageVersion(workspace, packageId, packageVersionId);
|
|
67
|
+
url = d.version_url;
|
|
68
|
+
}
|
|
69
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_SCANNING_DIR, false);
|
|
70
|
+
const stat = fs_1.default.statSync(dirPath);
|
|
71
|
+
let entries;
|
|
72
|
+
if (stat.isDirectory()) {
|
|
73
|
+
entries = fs_1.default.readdirSync(dirPath, {
|
|
74
|
+
withFileTypes: true,
|
|
75
|
+
recursive: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const parentPath = (0, path_1.dirname)(dirPath);
|
|
80
|
+
entries = [
|
|
81
|
+
{
|
|
82
|
+
isDirectory: () => stat.isDirectory(),
|
|
83
|
+
isFile: () => stat.isFile(),
|
|
84
|
+
isBlockDevice: () => stat.isBlockDevice(),
|
|
85
|
+
isCharacterDevice: () => stat.isCharacterDevice(),
|
|
86
|
+
isFIFO: () => stat.isFIFO(),
|
|
87
|
+
isSocket: () => stat.isSocket(),
|
|
88
|
+
isSymbolicLink: () => stat.isSymbolicLink(),
|
|
89
|
+
name: (0, path_1.basename)(dirPath),
|
|
90
|
+
parentPath,
|
|
91
|
+
path: parentPath,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
dirPath = parentPath;
|
|
95
|
+
}
|
|
96
|
+
if (!entries.length) {
|
|
97
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_NO_ENTRIES_FOUND);
|
|
98
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
99
|
+
}
|
|
100
|
+
else if (entries.length === 1) {
|
|
101
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ONE_ENTRY_FOUND);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ENTRIES_FOUND)(entries.length));
|
|
105
|
+
}
|
|
106
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(0));
|
|
107
|
+
const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${(0, uuid_1.v4)()}.zip`);
|
|
108
|
+
const clearZip = () => {
|
|
109
|
+
try {
|
|
110
|
+
fs_1.default.rmSync(zipPath);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// do nothing
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let blob;
|
|
117
|
+
try {
|
|
118
|
+
let proc = 0;
|
|
119
|
+
await createZip(dirPath, zipPath, entries, () => {
|
|
120
|
+
proc += 1;
|
|
121
|
+
output_1.default.clearPreviousLine();
|
|
122
|
+
output_1.default.normal((0, texts_1.TXT_PACKAGE_ZIP_ENTRIES)(proc));
|
|
123
|
+
});
|
|
124
|
+
output_1.default.clearPreviousLine();
|
|
125
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_ZIPPED);
|
|
126
|
+
blob = await fs_1.default.openAsBlob(zipPath);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
logger_1.default.error(err);
|
|
130
|
+
clearZip();
|
|
131
|
+
output_1.default.exitError(texts_1.ERR_SWW);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADING);
|
|
135
|
+
await client.postPackageVersionZip(workspace, packageId, packageVersionId, blob);
|
|
136
|
+
output_1.default.clearPreviousLine();
|
|
137
|
+
output_1.default.normal(texts_1.TXT_PACKAGE_UPLOADED);
|
|
138
|
+
clearZip();
|
|
139
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PACKAGE_PUBLISHED)(url));
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
clearZip();
|
|
143
|
+
logger_1.default.error(err);
|
|
144
|
+
output_1.default.exitError(err);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const addEntryToZip = (dirPath, zip, entry) => {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const isDir = entry.isDirectory();
|
|
150
|
+
let name = (0, path_1.join)(entry.parentPath.replace(dirPath, ''), entry.name);
|
|
151
|
+
if (isDir)
|
|
152
|
+
name += '/';
|
|
153
|
+
const file = new fflate_1.default.AsyncZipDeflate(name, {
|
|
154
|
+
level: 9,
|
|
155
|
+
});
|
|
156
|
+
zip.add(file);
|
|
157
|
+
if (isDir) {
|
|
158
|
+
file.push(new Uint8Array(0), true);
|
|
159
|
+
resolve();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const fullPath = (0, path_1.join)(entry.parentPath, entry.name);
|
|
163
|
+
const rs = fs_1.default.createReadStream(fullPath);
|
|
164
|
+
const finish = (err) => {
|
|
165
|
+
try {
|
|
166
|
+
rs.removeAllListeners();
|
|
167
|
+
rs.close();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// do nothing
|
|
171
|
+
}
|
|
172
|
+
if (err)
|
|
173
|
+
reject(err);
|
|
174
|
+
else
|
|
175
|
+
resolve();
|
|
176
|
+
};
|
|
177
|
+
rs.on('data', (chunk) => {
|
|
178
|
+
file.push(chunk, false);
|
|
179
|
+
});
|
|
180
|
+
rs.on('error', (err) => {
|
|
181
|
+
finish(err);
|
|
182
|
+
});
|
|
183
|
+
rs.on('end', () => {
|
|
184
|
+
file.push(new Uint8Array(0), true);
|
|
185
|
+
finish();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const addEntriesToZip = async (dirPath, zip, entries, onEntry) => {
|
|
190
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
191
|
+
await addEntryToZip(dirPath, zip, entries[i]);
|
|
192
|
+
onEntry();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const createZip = (dirPath, zipPath, entries, onEntry) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
const ws = fs_1.default.createWriteStream(zipPath);
|
|
198
|
+
let wasError = false;
|
|
199
|
+
const zip = new fflate_1.default.Zip((err, data, final) => {
|
|
200
|
+
if (wasError) {
|
|
201
|
+
// do nothing
|
|
202
|
+
}
|
|
203
|
+
else if (err) {
|
|
204
|
+
wasError = true;
|
|
205
|
+
ws.close();
|
|
206
|
+
reject(err);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
ws.write(data);
|
|
210
|
+
if (final) {
|
|
211
|
+
ws.close((err) => {
|
|
212
|
+
if (err)
|
|
213
|
+
reject(err);
|
|
214
|
+
else
|
|
215
|
+
resolve();
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
addEntriesToZip(dirPath, zip, entries, onEntry)
|
|
221
|
+
.then(() => {
|
|
222
|
+
zip.end();
|
|
223
|
+
})
|
|
224
|
+
.catch((err) => {
|
|
225
|
+
ws.close(() => {
|
|
226
|
+
reject(err);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
exports.default = commandPackagePublish;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 publish_1 = __importDefault(require("./package/publish"));
|
|
9
|
+
const download_1 = __importDefault(require("./package/download"));
|
|
10
|
+
const commandPackage = (0, utils_1.newCommand)('package', texts_1.DESC_COMMAND_PACKAGE);
|
|
11
|
+
commandPackage.alias('pkg');
|
|
12
|
+
commandPackage.addCommand(publish_1.default);
|
|
13
|
+
commandPackage.addCommand(download_1.default);
|
|
14
|
+
exports.default = commandPackage;
|
|
@@ -0,0 +1,61 @@
|
|
|
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 cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
7
|
+
const output_1 = __importDefault(require("../../output"));
|
|
8
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
9
|
+
const texts_1 = require("../../texts");
|
|
10
|
+
const utils_1 = require("../../utils");
|
|
11
|
+
const commandProjectList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_PROJECT_LIST);
|
|
12
|
+
commandProjectList.alias('ls');
|
|
13
|
+
commandProjectList.action(async () => {
|
|
14
|
+
const token = cfg_1.default.getToken();
|
|
15
|
+
if (!token) {
|
|
16
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_LOGGED_IN);
|
|
17
|
+
}
|
|
18
|
+
const workspace = cfg_1.default.getWorkspace();
|
|
19
|
+
if (!workspace) {
|
|
20
|
+
output_1.default.exitError(texts_1.TXT_WORKSPACE_NONE);
|
|
21
|
+
}
|
|
22
|
+
const baseUrl = cfg_1.default.getBaseUrl();
|
|
23
|
+
const region = cfg_1.default.getRegion();
|
|
24
|
+
const currentProject = cfg_1.default.getProject();
|
|
25
|
+
let apiUrl;
|
|
26
|
+
if (baseUrl) {
|
|
27
|
+
apiUrl = baseUrl;
|
|
28
|
+
}
|
|
29
|
+
else if (region?.toLowerCase() === 'eu') {
|
|
30
|
+
apiUrl = 'api.eu.buddy.works';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
apiUrl = 'api.buddy.works';
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const client = new client_1.default(new URL(`https://${apiUrl}`), token);
|
|
37
|
+
const response = await client.getProjects(workspace);
|
|
38
|
+
if (!response.projects || response.projects.length === 0) {
|
|
39
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NO_PROJECTS);
|
|
40
|
+
}
|
|
41
|
+
const data = [['NAME', 'DISPLAY NAME', 'STATUS', '']];
|
|
42
|
+
for (const proj of response.projects) {
|
|
43
|
+
const isCurrent = proj.name === currentProject;
|
|
44
|
+
data.push([
|
|
45
|
+
proj.name,
|
|
46
|
+
proj.display_name,
|
|
47
|
+
proj.status,
|
|
48
|
+
isCurrent ? '(current)' : '',
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
output_1.default.table(data);
|
|
52
|
+
if (currentProject) {
|
|
53
|
+
output_1.default.normal(`\n${(0, texts_1.TXT_PROJECT_CURRENT)(currentProject)}`);
|
|
54
|
+
}
|
|
55
|
+
process.exit(0);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
output_1.default.exitError(err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
exports.default = commandProjectList;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
// @ts-ignore
|
|
7
|
+
const termkit_no_lazy_require_1 = __importDefault(require("terminal-kit/lib/termkit-no-lazy-require"));
|
|
8
|
+
const cfg_1 = __importDefault(require("../../tunnel/cfg"));
|
|
9
|
+
const output_1 = __importDefault(require("../../output"));
|
|
10
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
11
|
+
const texts_1 = require("../../texts");
|
|
12
|
+
const utils_1 = require("../../utils");
|
|
13
|
+
const terminal = termkit_no_lazy_require_1.default.terminal;
|
|
14
|
+
// Handle Ctrl+C and ESC
|
|
15
|
+
terminal.on('key', (key) => {
|
|
16
|
+
if (key === 'CTRL_C' || key === 'ESCAPE') {
|
|
17
|
+
terminal.grabInput(false);
|
|
18
|
+
terminal('\nCanceled\n');
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
async function selectProject(projects, currentName) {
|
|
23
|
+
terminal(`${texts_1.TXT_PROJECT_SELECT}\n`);
|
|
24
|
+
const items = projects.map((p) => {
|
|
25
|
+
const isCurrent = p.name === currentName;
|
|
26
|
+
return `${p.display_name} (${p.name})${isCurrent ? ' (current)' : ''}`;
|
|
27
|
+
});
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
terminal.singleColumnMenu(items, (error, response) => {
|
|
30
|
+
terminal('\n');
|
|
31
|
+
resolve(projects[response.selectedIndex]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const commandProjectSet = (0, utils_1.newCommand)('set', texts_1.DESC_COMMAND_PROJECT_SET);
|
|
36
|
+
commandProjectSet.argument('[project]', 'Project name to set');
|
|
37
|
+
commandProjectSet.action(async (projectName) => {
|
|
38
|
+
const token = cfg_1.default.getToken();
|
|
39
|
+
if (!token) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_WORKSPACE_NOT_LOGGED_IN);
|
|
41
|
+
}
|
|
42
|
+
const workspace = cfg_1.default.getWorkspace();
|
|
43
|
+
if (!workspace) {
|
|
44
|
+
output_1.default.exitError(texts_1.TXT_WORKSPACE_NONE);
|
|
45
|
+
}
|
|
46
|
+
const baseUrl = cfg_1.default.getBaseUrl();
|
|
47
|
+
const region = cfg_1.default.getRegion();
|
|
48
|
+
const currentProject = cfg_1.default.getProject();
|
|
49
|
+
let apiUrl;
|
|
50
|
+
if (baseUrl) {
|
|
51
|
+
apiUrl = baseUrl;
|
|
52
|
+
}
|
|
53
|
+
else if (region?.toLowerCase() === 'eu') {
|
|
54
|
+
apiUrl = 'api.eu.buddy.works';
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
apiUrl = 'api.buddy.works';
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const client = new client_1.default(new URL(`https://${apiUrl}`), token);
|
|
61
|
+
const response = await client.getProjects(workspace);
|
|
62
|
+
if (!response.projects || response.projects.length === 0) {
|
|
63
|
+
output_1.default.exitError(texts_1.ERR_PROJECT_NO_PROJECTS);
|
|
64
|
+
}
|
|
65
|
+
let selectedProject;
|
|
66
|
+
if (projectName) {
|
|
67
|
+
// Project provided as argument
|
|
68
|
+
const found = response.projects.find((p) => p.name === projectName);
|
|
69
|
+
if (!found) {
|
|
70
|
+
output_1.default.exitError((0, texts_1.ERR_PROJECT_NOT_FOUND)(projectName));
|
|
71
|
+
}
|
|
72
|
+
selectedProject = found;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// Interactive selection
|
|
76
|
+
selectedProject = await selectProject(response.projects, currentProject);
|
|
77
|
+
}
|
|
78
|
+
cfg_1.default.setProject(selectedProject.name);
|
|
79
|
+
output_1.default.exitSuccess((0, texts_1.TXT_PROJECT_SET_SUCCESS)(selectedProject.name));
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
output_1.default.exitError(err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
exports.default = commandProjectSet;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 list_1 = __importDefault(require("./project/list"));
|
|
9
|
+
const set_1 = __importDefault(require("./project/set"));
|
|
10
|
+
const commandProject = (0, utils_1.newCommand)('project', texts_1.DESC_COMMAND_PROJECT);
|
|
11
|
+
commandProject.alias('proj');
|
|
12
|
+
commandProject.addCommand(list_1.default);
|
|
13
|
+
commandProject.addCommand(set_1.default);
|
|
14
|
+
exports.default = commandProject;
|