@dainprotocol/cli 1.2.28 → 1.2.31
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/dist/__tests__/build.test.js +289 -0
- package/dist/__tests__/deploy.test.js +10 -27
- package/dist/__tests__/dev.test.js +189 -0
- package/dist/__tests__/init.test.js +290 -0
- package/dist/__tests__/integration.test.js +5 -22
- package/dist/__tests__/testchat.test.js +214 -0
- package/dist/__tests__/utils.test.js +324 -0
- package/dist/commands/build.js +29 -62
- package/dist/commands/deploy.js +96 -167
- package/dist/commands/dev.js +34 -84
- package/dist/commands/init.js +2 -9
- package/dist/commands/logs.js +35 -117
- package/dist/commands/start.js +15 -4
- package/dist/commands/status.js +14 -65
- package/dist/commands/undeploy.js +10 -66
- package/dist/index.js +0 -7
- package/dist/templates/default/dain.json +1 -1
- package/dist/utils.js +169 -35
- package/package.json +3 -3
package/dist/commands/logs.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -64,10 +53,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
64
53
|
exports.default = logs;
|
|
65
54
|
var ora_1 = __importDefault(require("ora"));
|
|
66
55
|
var utils_1 = require("../utils");
|
|
67
|
-
// Module state for cleanup
|
|
68
56
|
var watchInterval = null;
|
|
69
57
|
var isShuttingDown = false;
|
|
70
58
|
function cleanup() {
|
|
59
|
+
if (isShuttingDown)
|
|
60
|
+
return;
|
|
71
61
|
isShuttingDown = true;
|
|
72
62
|
if (watchInterval) {
|
|
73
63
|
clearInterval(watchInterval);
|
|
@@ -76,41 +66,28 @@ function cleanup() {
|
|
|
76
66
|
}
|
|
77
67
|
function logs(options) {
|
|
78
68
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var config,
|
|
69
|
+
var config, ctx, spinner, result, error_1;
|
|
80
70
|
var _this = this;
|
|
81
|
-
return __generator(this, function (
|
|
82
|
-
switch (
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
83
73
|
case 0:
|
|
84
74
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(0, utils_1.logError)("Org ID or deployment ID not found");
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
// Setup cleanup handlers
|
|
92
|
-
process.once("SIGINT", function () {
|
|
93
|
-
cleanup();
|
|
94
|
-
process.exit(0);
|
|
95
|
-
});
|
|
96
|
-
process.once("SIGTERM", function () {
|
|
97
|
-
cleanup();
|
|
98
|
-
process.exit(0);
|
|
99
|
-
});
|
|
75
|
+
ctx = (0, utils_1.validatePlatformConfig)(config);
|
|
76
|
+
process.once("SIGINT", function () { cleanup(); process.exit(0); });
|
|
77
|
+
process.once("SIGTERM", function () { cleanup(); process.exit(0); });
|
|
100
78
|
spinner = (0, ora_1.default)("Fetching logs for project ".concat(config["project-id"], "...")).start();
|
|
101
|
-
|
|
79
|
+
_a.label = 1;
|
|
102
80
|
case 1:
|
|
103
|
-
|
|
104
|
-
return [4 /*yield*/, fetchLogs(
|
|
81
|
+
_a.trys.push([1, 3, , 4]);
|
|
82
|
+
return [4 /*yield*/, fetchLogs(ctx)];
|
|
105
83
|
case 2:
|
|
106
|
-
result =
|
|
84
|
+
result = _a.sent();
|
|
107
85
|
spinner.stop();
|
|
108
|
-
|
|
109
|
-
(0, utils_1.logInfo)("Project logs: ".concat(formattedLogs));
|
|
86
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(result, ctx.deploymentId)));
|
|
110
87
|
if (options.watch) {
|
|
111
88
|
(0, utils_1.logInfo)("Watching for log updates (Ctrl+C to stop)...");
|
|
112
89
|
watchInterval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
113
|
-
var newResult,
|
|
90
|
+
var newResult, error_2;
|
|
114
91
|
return __generator(this, function (_a) {
|
|
115
92
|
switch (_a.label) {
|
|
116
93
|
case 0:
|
|
@@ -119,12 +96,11 @@ function logs(options) {
|
|
|
119
96
|
_a.label = 1;
|
|
120
97
|
case 1:
|
|
121
98
|
_a.trys.push([1, 3, , 4]);
|
|
122
|
-
return [4 /*yield*/, fetchLogs(
|
|
99
|
+
return [4 /*yield*/, fetchLogs(ctx)];
|
|
123
100
|
case 2:
|
|
124
101
|
newResult = _a.sent();
|
|
125
|
-
process.stdout.write("\x1Bc");
|
|
126
|
-
|
|
127
|
-
(0, utils_1.logInfo)("Project logs: ".concat(newFormattedLogs));
|
|
102
|
+
process.stdout.write("\x1Bc");
|
|
103
|
+
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(newResult, ctx.deploymentId)));
|
|
128
104
|
return [3 /*break*/, 4];
|
|
129
105
|
case 3:
|
|
130
106
|
error_2 = _a.sent();
|
|
@@ -140,8 +116,9 @@ function logs(options) {
|
|
|
140
116
|
}
|
|
141
117
|
return [3 /*break*/, 4];
|
|
142
118
|
case 3:
|
|
143
|
-
error_1 =
|
|
144
|
-
|
|
119
|
+
error_1 = _a.sent();
|
|
120
|
+
spinner.fail("Failed to retrieve project logs.");
|
|
121
|
+
(0, utils_1.logError)("Error during log fetch", error_1);
|
|
145
122
|
process.exit(1);
|
|
146
123
|
return [3 /*break*/, 4];
|
|
147
124
|
case 4: return [2 /*return*/];
|
|
@@ -149,98 +126,39 @@ function logs(options) {
|
|
|
149
126
|
});
|
|
150
127
|
});
|
|
151
128
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
var deploymentId = config["deployment-id"];
|
|
156
|
-
var environment = config["environment"];
|
|
157
|
-
var serviceId = config["service-id"];
|
|
158
|
-
var logsUrl = "".concat(baseUrl, "/codegen-deploy/logs/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
159
|
-
return { apiKey: apiKey, deploymentId: deploymentId, logsUrl: logsUrl };
|
|
160
|
-
};
|
|
161
|
-
var FETCH_TIMEOUT_MS = 30000;
|
|
162
|
-
function fetchWithTimeout(url_1, options_1) {
|
|
163
|
-
return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
|
|
164
|
-
var controller, timeoutId, response;
|
|
165
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
129
|
+
function fetchLogs(ctx) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var response;
|
|
166
132
|
return __generator(this, function (_a) {
|
|
167
133
|
switch (_a.label) {
|
|
168
|
-
case 0:
|
|
169
|
-
controller = new AbortController();
|
|
170
|
-
timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
|
|
171
|
-
_a.label = 1;
|
|
134
|
+
case 0: return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "logs")];
|
|
172
135
|
case 1:
|
|
173
|
-
_a.trys.push([1, , 3, 4]);
|
|
174
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
175
|
-
case 2:
|
|
176
136
|
response = _a.sent();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [
|
|
181
|
-
case 4: return [2 /*return*/];
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
throw new Error("Log fetch failed: ".concat(response.status, " ").concat(response.statusText));
|
|
139
|
+
}
|
|
140
|
+
return [2 /*return*/, response.json()];
|
|
182
141
|
}
|
|
183
142
|
});
|
|
184
143
|
});
|
|
185
144
|
}
|
|
186
|
-
|
|
187
|
-
var response;
|
|
188
|
-
return __generator(this, function (_a) {
|
|
189
|
-
switch (_a.label) {
|
|
190
|
-
case 0: return [4 /*yield*/, fetchWithTimeout(logsUrl, {
|
|
191
|
-
method: "GET",
|
|
192
|
-
headers: {
|
|
193
|
-
"Content-Type": "application/json",
|
|
194
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
195
|
-
},
|
|
196
|
-
})];
|
|
197
|
-
case 1:
|
|
198
|
-
response = _a.sent();
|
|
199
|
-
if (!response.ok) {
|
|
200
|
-
throw new Error("Log fetch failed: ".concat(response.status, " ").concat(response.statusText));
|
|
201
|
-
}
|
|
202
|
-
return [2 /*return*/, response.json()];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
}); };
|
|
206
|
-
var handleError = function (spinner, error) {
|
|
207
|
-
spinner.fail("Failed to retrieve project logs.");
|
|
208
|
-
(0, utils_1.logError)("Error during log fetch", error);
|
|
209
|
-
};
|
|
210
|
-
var formatProjectLogs = function (projectLogs, deploymentId) {
|
|
145
|
+
function formatProjectLogs(projectLogs, deploymentId) {
|
|
211
146
|
try {
|
|
212
147
|
var _a = projectLogs.logs, logs_1 = _a === void 0 ? "" : _a, metadata = __rest(projectLogs, ["logs"]);
|
|
213
|
-
var formatDate_1 = function (dateString) {
|
|
214
|
-
try {
|
|
215
|
-
return new Date(dateString).toLocaleString();
|
|
216
|
-
}
|
|
217
|
-
catch (_a) {
|
|
218
|
-
return dateString;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
148
|
var formattedMetadata = Object.entries(metadata)
|
|
222
149
|
.map(function (_a) {
|
|
223
|
-
var _b;
|
|
224
150
|
var key = _a[0], value = _a[1];
|
|
225
|
-
var
|
|
226
|
-
|
|
151
|
+
var stringValue = String(value);
|
|
152
|
+
var formattedValue = stringValue.includes("T")
|
|
153
|
+
? new Date(stringValue).toLocaleString()
|
|
227
154
|
: value;
|
|
228
|
-
|
|
229
|
-
return "\u001B[36m".concat(formattedKey, ":\u001B[0m ").concat(formattedValue);
|
|
155
|
+
return "\u001B[36m".concat(key.replace(/([A-Z])/g, " $1").toLowerCase(), ":\u001B[0m ").concat(formattedValue);
|
|
230
156
|
})
|
|
231
157
|
.join("\n");
|
|
232
158
|
var projectUrl = "\nurl: https://".concat(deploymentId.replace("codegen-", ""), "-agent.dainapp.com");
|
|
233
|
-
|
|
234
|
-
"\n",
|
|
235
|
-
"\x1b[1m=== Project ===\x1b[0m",
|
|
236
|
-
formattedMetadata,
|
|
237
|
-
projectUrl,
|
|
238
|
-
"\n\x1b[1m=== Logs ===\x1b[0m",
|
|
239
|
-
logs_1,
|
|
240
|
-
];
|
|
241
|
-
return output.join("\n");
|
|
159
|
+
return ["\n", "\x1b[1m=== Project ===\x1b[0m", formattedMetadata, projectUrl, "\n\x1b[1m=== Logs ===\x1b[0m", logs_1].join("\n");
|
|
242
160
|
}
|
|
243
161
|
catch (error) {
|
|
244
162
|
return "Error formatting logs: ".concat(error.message);
|
|
245
163
|
}
|
|
246
|
-
}
|
|
164
|
+
}
|
package/dist/commands/start.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.default = start;
|
|
4
7
|
var child_process_1 = require("child_process");
|
|
8
|
+
var fs_1 = __importDefault(require("fs"));
|
|
9
|
+
var path_1 = __importDefault(require("path"));
|
|
5
10
|
var utils_1 = require("../utils");
|
|
6
11
|
function start(options) {
|
|
12
|
+
var config = (0, utils_1.getDainConfig)();
|
|
7
13
|
process.env.PORT = options.port;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
var mainFile = config['main-file'];
|
|
15
|
+
var outDir = config['out-dir'] || 'dist';
|
|
16
|
+
var outputFile = path_1.default.join(process.cwd(), outDir, "".concat(path_1.default.basename(mainFile, path_1.default.extname(mainFile)), ".js"));
|
|
17
|
+
var entryFile = fs_1.default.existsSync(outputFile) ? outputFile : mainFile;
|
|
18
|
+
if (entryFile === mainFile && mainFile.endsWith('.ts')) {
|
|
19
|
+
(0, utils_1.logError)("Build output not found: ".concat(outputFile, ". Run \"dain build\" first."));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
var child = (0, child_process_1.spawn)('node', [entryFile], { stdio: 'inherit' });
|
|
12
23
|
child.on('error', function (error) {
|
|
13
24
|
console.error("Error: ".concat(error.message));
|
|
14
25
|
process.exit(1);
|
package/dist/commands/status.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -53,70 +42,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
42
|
exports.default = status;
|
|
54
43
|
var ora_1 = __importDefault(require("ora"));
|
|
55
44
|
var utils_1 = require("../utils");
|
|
56
|
-
var FETCH_TIMEOUT_MS = 30000;
|
|
57
|
-
function fetchWithTimeout(url_1, options_1) {
|
|
58
|
-
return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
|
|
59
|
-
var controller, timeoutId, response;
|
|
60
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
controller = new AbortController();
|
|
65
|
-
timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
|
|
66
|
-
_a.label = 1;
|
|
67
|
-
case 1:
|
|
68
|
-
_a.trys.push([1, , 3, 4]);
|
|
69
|
-
return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
|
|
70
|
-
case 2:
|
|
71
|
-
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3:
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
return [7 /*endfinally*/];
|
|
76
|
-
case 4: return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
45
|
function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
82
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var config,
|
|
84
|
-
return __generator(this, function (
|
|
85
|
-
switch (
|
|
47
|
+
var config, ctx, spinner, response, result, error_1;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
86
50
|
case 0:
|
|
87
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
52
|
+
ctx = (0, utils_1.validatePlatformConfig)(config, {
|
|
53
|
+
deploymentId: preDefinedDeploymentId,
|
|
54
|
+
serviceId: preDefinedServiceId,
|
|
55
|
+
});
|
|
94
56
|
spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
|
|
95
|
-
|
|
57
|
+
_a.label = 1;
|
|
96
58
|
case 1:
|
|
97
|
-
|
|
98
|
-
return [4 /*yield*/,
|
|
99
|
-
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
103
|
-
},
|
|
59
|
+
_a.trys.push([1, 4, , 5]);
|
|
60
|
+
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "status", "GET", {
|
|
61
|
+
environment: preDefinedEnvironmentName,
|
|
104
62
|
})];
|
|
105
63
|
case 2:
|
|
106
|
-
response =
|
|
64
|
+
response = _a.sent();
|
|
107
65
|
if (!response.ok) {
|
|
108
66
|
throw new Error("Status check failed: ".concat(response.status, " ").concat(response.statusText));
|
|
109
67
|
}
|
|
110
68
|
return [4 /*yield*/, response.json()];
|
|
111
69
|
case 3:
|
|
112
|
-
result =
|
|
70
|
+
result = _a.sent();
|
|
113
71
|
spinner.info("Status: " + result.message);
|
|
114
72
|
if (!preDefinedDeploymentId) {
|
|
115
73
|
process.exit(0);
|
|
116
74
|
}
|
|
117
75
|
return [2 /*return*/, result];
|
|
118
76
|
case 4:
|
|
119
|
-
error_1 =
|
|
77
|
+
error_1 = _a.sent();
|
|
120
78
|
spinner.fail("Failed to retrieve project status.");
|
|
121
79
|
(0, utils_1.logError)("Error during status check", error_1);
|
|
122
80
|
process.exit(1);
|
|
@@ -126,12 +84,3 @@ function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preD
|
|
|
126
84
|
});
|
|
127
85
|
});
|
|
128
86
|
}
|
|
129
|
-
var initializeConfig = function (config, orgId, preDefinedDeploymentId, preDefinedEnvironment, preDefinedServiceId) {
|
|
130
|
-
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
131
|
-
var apiKey = config["api-key"];
|
|
132
|
-
var deploymentId = preDefinedDeploymentId || config["deployment-id"];
|
|
133
|
-
var environment = preDefinedEnvironment || config["environment"];
|
|
134
|
-
var serviceId = preDefinedServiceId || config["service-id"];
|
|
135
|
-
var statusUrl = "".concat(baseUrl, "/codegen-deploy/status/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
136
|
-
return { apiKey: apiKey, deploymentId: deploymentId, statusUrl: statusUrl };
|
|
137
|
-
};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -51,59 +40,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
40
|
};
|
|
52
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
42
|
exports.default = undeploy;
|
|
54
|
-
var utils_1 = require("../utils");
|
|
55
43
|
var ora_1 = __importDefault(require("ora"));
|
|
56
|
-
var
|
|
57
|
-
function
|
|
58
|
-
return __awaiter(this,
|
|
59
|
-
var
|
|
60
|
-
if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
|
|
44
|
+
var utils_1 = require("../utils");
|
|
45
|
+
function undeploy(options) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var config, ctx, spinner, response, error_1;
|
|
61
48
|
return __generator(this, function (_a) {
|
|
62
49
|
switch (_a.label) {
|
|
63
50
|
case 0:
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
+
ctx = (0, utils_1.validatePlatformConfig)(config);
|
|
53
|
+
spinner = (0, ora_1.default)("Undeploying deployment ".concat(ctx.deploymentId, "...")).start();
|
|
66
54
|
_a.label = 1;
|
|
67
55
|
case 1:
|
|
68
|
-
_a.trys.push([1, ,
|
|
69
|
-
return [4 /*yield*/,
|
|
56
|
+
_a.trys.push([1, 3, , 4]);
|
|
57
|
+
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "undeploy", "DELETE")];
|
|
70
58
|
case 2:
|
|
71
59
|
response = _a.sent();
|
|
72
|
-
return [2 /*return*/, response];
|
|
73
|
-
case 3:
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
return [7 /*endfinally*/];
|
|
76
|
-
case 4: return [2 /*return*/];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function undeploy(options) {
|
|
82
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var config, spinner, orgId, _a, apiKey, deploymentId, undeployUrl, response, error_1;
|
|
84
|
-
return __generator(this, function (_b) {
|
|
85
|
-
switch (_b.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
config = (0, utils_1.getDainConfig)(options.config);
|
|
88
|
-
spinner = (0, ora_1.default)("Undeploying deployment ".concat(config["deployment-id"], "...")).start();
|
|
89
|
-
_b.label = 1;
|
|
90
|
-
case 1:
|
|
91
|
-
_b.trys.push([1, 3, , 4]);
|
|
92
|
-
orgId = "hackathon";
|
|
93
|
-
_a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, undeployUrl = _a.undeployUrl;
|
|
94
|
-
if (!deploymentId) {
|
|
95
|
-
(0, utils_1.logError)("Deployment ID not found");
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
return [4 /*yield*/, fetchWithTimeout(undeployUrl, {
|
|
99
|
-
method: "DELETE",
|
|
100
|
-
headers: {
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
Authorization: "Bearer ".concat(apiKey),
|
|
103
|
-
},
|
|
104
|
-
})];
|
|
105
|
-
case 2:
|
|
106
|
-
response = _b.sent();
|
|
107
60
|
if (!response.ok) {
|
|
108
61
|
throw new Error("Undeployment failed: ".concat(response.status, " ").concat(response.statusText));
|
|
109
62
|
}
|
|
@@ -111,7 +64,7 @@ function undeploy(options) {
|
|
|
111
64
|
process.exit(0);
|
|
112
65
|
return [3 /*break*/, 4];
|
|
113
66
|
case 3:
|
|
114
|
-
error_1 =
|
|
67
|
+
error_1 = _a.sent();
|
|
115
68
|
spinner.fail("Failed to undeploy project.");
|
|
116
69
|
(0, utils_1.logError)("Error during undeployment", error_1);
|
|
117
70
|
process.exit(1);
|
|
@@ -121,12 +74,3 @@ function undeploy(options) {
|
|
|
121
74
|
});
|
|
122
75
|
});
|
|
123
76
|
}
|
|
124
|
-
var initializeConfig = function (config, orgId) {
|
|
125
|
-
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
126
|
-
var apiKey = config["api-key"];
|
|
127
|
-
var deploymentId = config["deployment-id"];
|
|
128
|
-
var environment = config["environment"];
|
|
129
|
-
var serviceId = config["service-id"];
|
|
130
|
-
var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
131
|
-
return { apiKey: apiKey, deploymentId: deploymentId, undeployUrl: undeployUrl };
|
|
132
|
-
};
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var testchat_1 = __importDefault(require("./commands/testchat"));
|
|
|
14
14
|
var status_1 = __importDefault(require("./commands/status"));
|
|
15
15
|
var undeploy_1 = __importDefault(require("./commands/undeploy"));
|
|
16
16
|
var logs_1 = __importDefault(require("./commands/logs"));
|
|
17
|
-
var help_1 = __importDefault(require("./commands/help"));
|
|
18
17
|
var program = new commander_1.Command();
|
|
19
18
|
program
|
|
20
19
|
.name('dain')
|
|
@@ -91,12 +90,6 @@ program
|
|
|
91
90
|
.action(function (options) {
|
|
92
91
|
(0, logs_1.default)(options);
|
|
93
92
|
});
|
|
94
|
-
program
|
|
95
|
-
.command('help')
|
|
96
|
-
.description('Show the help')
|
|
97
|
-
.action(function () {
|
|
98
|
-
(0, help_1.default)();
|
|
99
|
-
});
|
|
100
93
|
program.parse(process.argv);
|
|
101
94
|
// Add a catch-all command for unknown commands
|
|
102
95
|
program.on('command:*', function () {
|