@dainprotocol/cli 1.1.21 → 1.1.28
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/commands/deploy.js +55 -52
- package/dist/commands/dev.js +70 -21
- package/dist/commands/logs.js +25 -23
- package/dist/commands/status.js +19 -17
- package/dist/commands/undeploy.js +16 -14
- package/dist/index.js +1 -1
- package/dist/templates/default/dain.json +2 -1
- package/dist/templates/default/package.json +3 -3
- package/dist/templates/default/src/index.ts +90 -68
- package/dist/utils.js +38 -32
- package/package.json +1 -1
- package/templates/default/dain.json +2 -1
- package/templates/default/package.json +3 -3
- package/templates/default/src/index.ts +90 -68
package/dist/commands/deploy.js
CHANGED
|
@@ -47,62 +47,63 @@ var path_1 = __importDefault(require("path"));
|
|
|
47
47
|
var archiver_1 = __importDefault(require("archiver"));
|
|
48
48
|
var build_1 = __importDefault(require("./build"));
|
|
49
49
|
var status_1 = __importDefault(require("./status"));
|
|
50
|
-
var START_DEPLOY_URI =
|
|
50
|
+
var START_DEPLOY_URI = "/api/app/data/deployments/start-deploy";
|
|
51
51
|
function deploy(options) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
var config, spinner, basePath, deployPath, envArray, result, deploymentId, dainJson, dainJsonObject, error_1;
|
|
53
|
+
var config, spinner, basePath, deployPath, isProduction, environmentName, envArray, result, deploymentId, serviceId, dainJson, dainJsonObject, error_1;
|
|
54
54
|
return __generator(this, function (_a) {
|
|
55
55
|
switch (_a.label) {
|
|
56
56
|
case 0:
|
|
57
57
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
58
|
-
spinner = (0, ora_1.default)(
|
|
59
|
-
basePath = config[
|
|
58
|
+
spinner = (0, ora_1.default)("Deploying project...").start();
|
|
59
|
+
basePath = config["api-base-url"] || "https://dain-platform-ochre.vercel.app";
|
|
60
60
|
deployPath = "".concat(basePath).concat(START_DEPLOY_URI);
|
|
61
|
+
isProduction = config["environment"] === "production";
|
|
62
|
+
environmentName = config["environment"] || "production";
|
|
61
63
|
_a.label = 1;
|
|
62
64
|
case 1:
|
|
63
|
-
_a.trys.push([1,
|
|
65
|
+
_a.trys.push([1, 8, , 9]);
|
|
64
66
|
return [4 /*yield*/, loadAndValidateEnvVariables()];
|
|
65
67
|
case 2:
|
|
66
68
|
envArray = _a.sent();
|
|
67
69
|
return [4 /*yield*/, (0, build_1.default)({ config: options.config, deploy: true })];
|
|
68
70
|
case 3:
|
|
69
71
|
_a.sent();
|
|
70
|
-
return [4 /*yield*/, deployAndPushFiles(deployPath, envArray)];
|
|
72
|
+
return [4 /*yield*/, deployAndPushFiles(deployPath, envArray, isProduction, environmentName)];
|
|
71
73
|
case 4:
|
|
72
74
|
result = _a.sent();
|
|
73
|
-
deploymentId = result.deploymentId
|
|
74
|
-
|
|
75
|
+
deploymentId = result.deploymentId;
|
|
76
|
+
serviceId = result.serviceId;
|
|
77
|
+
return [4 /*yield*/, fs_extra_1.default.readFile("./dain.json", "utf-8")];
|
|
75
78
|
case 5:
|
|
76
|
-
_a.sent();
|
|
77
|
-
return [4 /*yield*/, fs_extra_1.default.readFile('./dain.json', 'utf-8')];
|
|
78
|
-
case 6:
|
|
79
79
|
dainJson = _a.sent();
|
|
80
80
|
dainJsonObject = JSON.parse(dainJson);
|
|
81
|
-
dainJsonObject[
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
dainJsonObject["deployment-id"] = deploymentId;
|
|
82
|
+
dainJsonObject["service-id"] = serviceId;
|
|
83
|
+
return [4 /*yield*/, fs_extra_1.default.writeFile("./dain.json", JSON.stringify(dainJsonObject, null, 2))];
|
|
84
|
+
case 6:
|
|
84
85
|
_a.sent();
|
|
85
|
-
console.log(
|
|
86
|
+
console.log("\n-----------------------");
|
|
86
87
|
spinner.succeed("Deployment URL: ".concat(result.service.url));
|
|
87
88
|
spinner.succeed("Deployment ID: ".concat(result.deploymentId));
|
|
88
|
-
spinner.succeed(
|
|
89
|
-
spinner.succeed(
|
|
90
|
-
spinner.info(
|
|
91
|
-
console.log(
|
|
89
|
+
spinner.succeed("Deployment completed at: " + new Date().toISOString());
|
|
90
|
+
spinner.succeed("Deployment completed successfully.");
|
|
91
|
+
spinner.info("You can access logs using `dain logs -w` command.");
|
|
92
|
+
console.log("-----------------------");
|
|
92
93
|
return [4 /*yield*/, fetch(result.service.url, {
|
|
93
|
-
method:
|
|
94
|
+
method: "GET",
|
|
94
95
|
})];
|
|
95
|
-
case
|
|
96
|
+
case 7:
|
|
96
97
|
_a.sent();
|
|
97
98
|
process.exit(0);
|
|
98
|
-
return [3 /*break*/,
|
|
99
|
-
case
|
|
99
|
+
return [3 /*break*/, 9];
|
|
100
|
+
case 8:
|
|
100
101
|
error_1 = _a.sent();
|
|
101
|
-
spinner.fail(
|
|
102
|
-
(0, utils_1.logError)(
|
|
102
|
+
spinner.fail("Deployment failed.");
|
|
103
|
+
(0, utils_1.logError)("Error during deployment: ", error_1);
|
|
103
104
|
process.exit(1);
|
|
104
|
-
return [3 /*break*/,
|
|
105
|
-
case
|
|
105
|
+
return [3 /*break*/, 9];
|
|
106
|
+
case 9: return [2 /*return*/];
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
109
|
});
|
|
@@ -117,11 +118,11 @@ function loadAndValidateEnvVariables() {
|
|
|
117
118
|
case 1:
|
|
118
119
|
envArray = _a.sent();
|
|
119
120
|
if (envArray.length === 0) {
|
|
120
|
-
(0, utils_1.logError)(
|
|
121
|
+
(0, utils_1.logError)("No environment variables found. Please ensure your .env file is correctly set up.");
|
|
121
122
|
process.exit(1);
|
|
122
123
|
}
|
|
123
|
-
if (!envArray.some(function (env) { return env.name ===
|
|
124
|
-
(0, utils_1.logError)(
|
|
124
|
+
if (!envArray.some(function (env) { return env.name === "DAIN_API_KEY"; })) {
|
|
125
|
+
(0, utils_1.logError)("DAIN_API_KEY not found in environment variables. Please check your .env file.");
|
|
125
126
|
process.exit(1);
|
|
126
127
|
}
|
|
127
128
|
return [2 /*return*/, envArray];
|
|
@@ -130,25 +131,27 @@ function loadAndValidateEnvVariables() {
|
|
|
130
131
|
});
|
|
131
132
|
}
|
|
132
133
|
// Deploys and pushes files to the platform
|
|
133
|
-
function deployAndPushFiles(startDeployUrl, envArray) {
|
|
134
|
+
function deployAndPushFiles(startDeployUrl, envArray, isProduction, environmentName) {
|
|
134
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
135
136
|
var projectZip, projectZipBuffer, formData, response, errorText, result, error_2;
|
|
136
137
|
return __generator(this, function (_a) {
|
|
137
138
|
switch (_a.label) {
|
|
138
|
-
case 0: return [4 /*yield*/, zipDirectory(
|
|
139
|
+
case 0: return [4 /*yield*/, zipDirectory("./", "project.zip")];
|
|
139
140
|
case 1:
|
|
140
141
|
projectZip = _a.sent();
|
|
141
142
|
return [4 /*yield*/, fs_extra_1.default.readFile(projectZip)];
|
|
142
143
|
case 2:
|
|
143
144
|
projectZipBuffer = _a.sent();
|
|
144
145
|
formData = new FormData();
|
|
145
|
-
formData.append(
|
|
146
|
-
formData.append(
|
|
146
|
+
formData.append("array", JSON.stringify(envArray));
|
|
147
|
+
formData.append("file", new Blob([projectZipBuffer]), "project.zip");
|
|
148
|
+
formData.append("isProduction", isProduction.toString());
|
|
149
|
+
formData.append("environment", environmentName);
|
|
147
150
|
_a.label = 3;
|
|
148
151
|
case 3:
|
|
149
152
|
_a.trys.push([3, 8, , 9]);
|
|
150
153
|
return [4 /*yield*/, fetch(startDeployUrl, {
|
|
151
|
-
method:
|
|
154
|
+
method: "POST",
|
|
152
155
|
body: formData,
|
|
153
156
|
})];
|
|
154
157
|
case 4:
|
|
@@ -164,8 +167,8 @@ function deployAndPushFiles(startDeployUrl, envArray) {
|
|
|
164
167
|
return [2 /*return*/, result];
|
|
165
168
|
case 8:
|
|
166
169
|
error_2 = _a.sent();
|
|
167
|
-
(0, utils_1.logError)(
|
|
168
|
-
console.error(
|
|
170
|
+
(0, utils_1.logError)("Error during deployment and push files: ", error_2.stack);
|
|
171
|
+
console.error("Detailed error:", error_2);
|
|
169
172
|
process.exit(1);
|
|
170
173
|
return [3 /*break*/, 9];
|
|
171
174
|
case 9: return [2 /*return*/];
|
|
@@ -179,21 +182,21 @@ function loadEnvVariables() {
|
|
|
179
182
|
var files, envFile, envContent;
|
|
180
183
|
return __generator(this, function (_a) {
|
|
181
184
|
switch (_a.label) {
|
|
182
|
-
case 0: return [4 /*yield*/, fs_extra_1.default.readdir(
|
|
185
|
+
case 0: return [4 /*yield*/, fs_extra_1.default.readdir("./")];
|
|
183
186
|
case 1:
|
|
184
187
|
files = _a.sent();
|
|
185
|
-
envFile = files.find(function (file) { return file ===
|
|
188
|
+
envFile = files.find(function (file) { return file === ".env"; });
|
|
186
189
|
if (!envFile) {
|
|
187
|
-
(0, utils_1.logError)(
|
|
190
|
+
(0, utils_1.logError)("Environment file not found. Please create a .env file in the build directory.");
|
|
188
191
|
process.exit(1);
|
|
189
192
|
}
|
|
190
|
-
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join(
|
|
193
|
+
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join("./", envFile), "utf-8")];
|
|
191
194
|
case 2:
|
|
192
195
|
envContent = _a.sent();
|
|
193
196
|
return [2 /*return*/, envContent
|
|
194
|
-
.split(
|
|
197
|
+
.split("\n")
|
|
195
198
|
.map(function (line) {
|
|
196
|
-
var _a = line.split(
|
|
199
|
+
var _a = line.split("="), name = _a[0], value = _a[1];
|
|
197
200
|
return { name: name, value: value };
|
|
198
201
|
})
|
|
199
202
|
.filter(function (env) { return env.name && env.value; })];
|
|
@@ -207,33 +210,33 @@ function zipDirectory(sourceDir, outputZip) {
|
|
|
207
210
|
return __generator(this, function (_a) {
|
|
208
211
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
209
212
|
var output = fs_extra_1.default.createWriteStream(outputZip);
|
|
210
|
-
var archive = (0, archiver_1.default)(
|
|
211
|
-
output.on(
|
|
212
|
-
archive.on(
|
|
213
|
-
(0, utils_1.logError)(
|
|
213
|
+
var archive = (0, archiver_1.default)("zip", { zlib: { level: 9 } });
|
|
214
|
+
output.on("close", function () { return resolve(outputZip); });
|
|
215
|
+
archive.on("error", function (err) {
|
|
216
|
+
(0, utils_1.logError)("Error during zipping the directory: ", err);
|
|
214
217
|
reject(err);
|
|
215
218
|
});
|
|
216
219
|
archive.pipe(output);
|
|
217
|
-
archive.glob(
|
|
220
|
+
archive.glob("**/*", { ignore: ["node_modules/**", "project.zip"] });
|
|
218
221
|
archive.finalize();
|
|
219
222
|
})];
|
|
220
223
|
});
|
|
221
224
|
});
|
|
222
225
|
}
|
|
223
|
-
var recursiveStatusUntilRunning = function (config, deploymentId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
226
|
+
var recursiveStatusUntilRunning = function (config, deploymentId, environmentName, serviceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
224
227
|
var statusResult;
|
|
225
228
|
return __generator(this, function (_a) {
|
|
226
229
|
switch (_a.label) {
|
|
227
|
-
case 0: return [4 /*yield*/, (0, status_1.default)({}, deploymentId)];
|
|
230
|
+
case 0: return [4 /*yield*/, (0, status_1.default)({}, deploymentId, environmentName, serviceId)];
|
|
228
231
|
case 1:
|
|
229
232
|
statusResult = _a.sent();
|
|
230
|
-
if (statusResult.status ===
|
|
233
|
+
if (statusResult.status === "RUNNING") {
|
|
231
234
|
return [2 /*return*/];
|
|
232
235
|
}
|
|
233
236
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 15000); })];
|
|
234
237
|
case 2:
|
|
235
238
|
_a.sent();
|
|
236
|
-
return [4 /*yield*/, recursiveStatusUntilRunning(config, deploymentId)];
|
|
239
|
+
return [4 /*yield*/, recursiveStatusUntilRunning(config, deploymentId, environmentName, serviceId)];
|
|
237
240
|
case 3:
|
|
238
241
|
_a.sent();
|
|
239
242
|
return [2 /*return*/];
|
package/dist/commands/dev.js
CHANGED
|
@@ -59,18 +59,35 @@ var path_1 = __importDefault(require("path"));
|
|
|
59
59
|
var miniflare_1 = require("miniflare");
|
|
60
60
|
var build_1 = __importDefault(require("./build"));
|
|
61
61
|
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
62
|
+
var net_1 = require("net");
|
|
62
63
|
var childProcess = null;
|
|
63
64
|
var watcher = null;
|
|
64
65
|
var mf = null;
|
|
65
|
-
|
|
66
|
+
var tunnelUrl = null;
|
|
67
|
+
function isPortAvailable(port) {
|
|
68
|
+
return new Promise(function (resolve) {
|
|
69
|
+
var server = (0, net_1.createServer)()
|
|
70
|
+
.listen(port, function () {
|
|
71
|
+
server.close();
|
|
72
|
+
resolve(true);
|
|
73
|
+
})
|
|
74
|
+
.on('error', function () {
|
|
75
|
+
resolve(false);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function startProcess(command, options) {
|
|
66
80
|
var _a, _b;
|
|
67
81
|
if (childProcess) {
|
|
68
82
|
childProcess.kill();
|
|
69
83
|
}
|
|
70
84
|
var spinner = (0, ora_1.default)('Starting development server...').start();
|
|
71
|
-
childProcess = (0, child_process_1.exec)(command,
|
|
85
|
+
childProcess = (0, child_process_1.exec)(command, options);
|
|
72
86
|
(_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', function (data) {
|
|
73
87
|
spinner.succeed('Development server started.');
|
|
88
|
+
if (tunnelUrl) {
|
|
89
|
+
(0, utils_1.displayTunnelUrl)(tunnelUrl);
|
|
90
|
+
}
|
|
74
91
|
console.log(data);
|
|
75
92
|
});
|
|
76
93
|
(_b = childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
|
|
@@ -101,11 +118,33 @@ function cleanup() {
|
|
|
101
118
|
}
|
|
102
119
|
function dev(options) {
|
|
103
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var config, runtime, tsNodePath, command, envVars, proxyServer, watchPaths, dainDir, outFile, MFconfig_1, debounceTimer_1, watchDirs, error_1;
|
|
121
|
+
var config, portSource, port, portNumber, runtime, tsNodePath, command, envVars, proxyServer, portNumber_1, proxySetup, watchPaths, dainDir, outFile, MFconfig_1, debounceTimer_1, watchDirs, error_1;
|
|
105
122
|
return __generator(this, function (_a) {
|
|
106
123
|
switch (_a.label) {
|
|
107
124
|
case 0:
|
|
108
125
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
126
|
+
if (process.env.PORT) {
|
|
127
|
+
port = process.env.PORT;
|
|
128
|
+
portSource = '.env file';
|
|
129
|
+
}
|
|
130
|
+
else if (options.port) {
|
|
131
|
+
port = options.port;
|
|
132
|
+
portSource = 'command line argument';
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
port = '2022';
|
|
136
|
+
portSource = 'default value';
|
|
137
|
+
}
|
|
138
|
+
portNumber = parseInt(port);
|
|
139
|
+
if (isNaN(portNumber) || portNumber < 0 || portNumber > 65535) {
|
|
140
|
+
(0, utils_1.logError)('Invalid port number. Using default port 2022');
|
|
141
|
+
options.port = '2022';
|
|
142
|
+
portSource = 'default value (after invalid port)';
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
options.port = port;
|
|
146
|
+
}
|
|
147
|
+
(0, utils_1.logInfo)("Using port ".concat(options.port, " (from ").concat(portSource, ")"));
|
|
109
148
|
console.log('Config: ' + JSON.stringify(config));
|
|
110
149
|
runtime = options.runtime || config.runtime || 'node';
|
|
111
150
|
console.log('Runtime: ' + runtime);
|
|
@@ -121,19 +160,29 @@ function dev(options) {
|
|
|
121
160
|
proxyServer = null;
|
|
122
161
|
_a.label = 1;
|
|
123
162
|
case 1:
|
|
124
|
-
_a.trys.push([1,
|
|
125
|
-
|
|
163
|
+
_a.trys.push([1, 9, , 10]);
|
|
164
|
+
portNumber_1 = parseInt(options.port);
|
|
165
|
+
return [4 /*yield*/, isPortAvailable(portNumber_1)];
|
|
166
|
+
case 2:
|
|
167
|
+
if (!(_a.sent())) {
|
|
168
|
+
(0, utils_1.logError)("Port ".concat(portNumber_1, " is already in use. Please use a different port with --port option."));
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
process.env.PORT = portNumber_1.toString();
|
|
172
|
+
if (!!options.noproxy) return [3 /*break*/, 4];
|
|
126
173
|
if (!config['api-key']) {
|
|
127
174
|
throw new Error("'api-key' is required when using development proxy");
|
|
128
175
|
}
|
|
129
176
|
return [4 /*yield*/, (0, utils_1.setupProxy)(options.port, config['api-key'], config)];
|
|
130
|
-
case 2:
|
|
131
|
-
proxyServer = _a.sent();
|
|
132
|
-
_a.label = 3;
|
|
133
177
|
case 3:
|
|
134
|
-
|
|
178
|
+
proxySetup = _a.sent();
|
|
179
|
+
proxyServer = proxySetup.client;
|
|
180
|
+
tunnelUrl = proxySetup.tunnelUrl;
|
|
181
|
+
_a.label = 4;
|
|
182
|
+
case 4:
|
|
183
|
+
if (!(runtime === 'node')) return [3 /*break*/, 5];
|
|
135
184
|
// Existing Node.js development process
|
|
136
|
-
startProcess(command, envVars);
|
|
185
|
+
startProcess(command, { env: __assign(__assign({}, process.env), envVars) });
|
|
137
186
|
watchPaths = [
|
|
138
187
|
path_1.default.dirname(config['main-file']),
|
|
139
188
|
config['static-dir']
|
|
@@ -146,7 +195,7 @@ function dev(options) {
|
|
|
146
195
|
});
|
|
147
196
|
watcher.on('change', function (path) {
|
|
148
197
|
(0, utils_1.logInfo)("File ".concat(path, " has been changed. Restarting..."));
|
|
149
|
-
startProcess(command, envVars);
|
|
198
|
+
startProcess(command, { env: __assign(__assign({}, process.env), envVars) });
|
|
150
199
|
});
|
|
151
200
|
(0, utils_1.logInfo)('Watching for file changes...');
|
|
152
201
|
// Add signal handlers for graceful shutdown
|
|
@@ -201,14 +250,14 @@ function dev(options) {
|
|
|
201
250
|
process.exit(1);
|
|
202
251
|
}, 500);
|
|
203
252
|
});
|
|
204
|
-
return [3 /*break*/,
|
|
205
|
-
case
|
|
206
|
-
if (!(runtime === 'workers')) return [3 /*break*/,
|
|
253
|
+
return [3 /*break*/, 8];
|
|
254
|
+
case 5:
|
|
255
|
+
if (!(runtime === 'workers')) return [3 /*break*/, 7];
|
|
207
256
|
dainDir = path_1.default.join(process.cwd(), '.dain');
|
|
208
257
|
outFile = path_1.default.join(dainDir, path_1.default.basename(config['main-file'], '.ts') + '.mjs');
|
|
209
258
|
// Start the build process in watch mode
|
|
210
259
|
return [4 /*yield*/, (0, build_1.default)({ config: options.config, runtime: 'workers', watch: true })];
|
|
211
|
-
case
|
|
260
|
+
case 6:
|
|
212
261
|
// Start the build process in watch mode
|
|
213
262
|
_a.sent();
|
|
214
263
|
MFconfig_1 = {
|
|
@@ -234,10 +283,10 @@ function dev(options) {
|
|
|
234
283
|
});
|
|
235
284
|
});
|
|
236
285
|
(0, utils_1.logInfo)('Watching for file changes in source and build directories...');
|
|
237
|
-
return [3 /*break*/,
|
|
238
|
-
case
|
|
239
|
-
case
|
|
240
|
-
case
|
|
286
|
+
return [3 /*break*/, 8];
|
|
287
|
+
case 7: throw new Error("Unsupported runtime: ".concat(runtime));
|
|
288
|
+
case 8: return [3 /*break*/, 10];
|
|
289
|
+
case 9:
|
|
241
290
|
error_1 = _a.sent();
|
|
242
291
|
(0, utils_1.logError)("Error in dev process for ".concat(runtime, " runtime:"), error_1);
|
|
243
292
|
cleanup();
|
|
@@ -246,8 +295,8 @@ function dev(options) {
|
|
|
246
295
|
setTimeout(function () {
|
|
247
296
|
process.exit(1);
|
|
248
297
|
}, 500);
|
|
249
|
-
return [3 /*break*/,
|
|
250
|
-
case
|
|
298
|
+
return [3 /*break*/, 10];
|
|
299
|
+
case 10: return [2 /*return*/];
|
|
251
300
|
}
|
|
252
301
|
});
|
|
253
302
|
});
|
package/dist/commands/logs.js
CHANGED
|
@@ -61,13 +61,13 @@ function logs(options_1) {
|
|
|
61
61
|
switch (_b.label) {
|
|
62
62
|
case 0:
|
|
63
63
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
64
|
-
orgId =
|
|
64
|
+
orgId = "hackathon";
|
|
65
65
|
_a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, logsUrl = _a.logsUrl;
|
|
66
66
|
if (!orgId || !deploymentId) {
|
|
67
|
-
(0, utils_1.logError)(
|
|
67
|
+
(0, utils_1.logError)("Org ID or deployment ID not found");
|
|
68
68
|
return [2 /*return*/];
|
|
69
69
|
}
|
|
70
|
-
spinner = (0, ora_1.default)("Fetching logs for project ".concat(config[
|
|
70
|
+
spinner = (0, ora_1.default)("Fetching logs for project ".concat(config["project-id"], "...")).start();
|
|
71
71
|
_b.label = 1;
|
|
72
72
|
case 1:
|
|
73
73
|
_b.trys.push([1, 3, 4, 5]);
|
|
@@ -78,7 +78,7 @@ function logs(options_1) {
|
|
|
78
78
|
formatLogs = formatProjectLogs(result, deploymentId);
|
|
79
79
|
if (isWatching) {
|
|
80
80
|
// clear terminal before printing logs when watching
|
|
81
|
-
process.stdout.write(
|
|
81
|
+
process.stdout.write("\x1Bc");
|
|
82
82
|
}
|
|
83
83
|
(0, utils_1.logInfo)("Project logs: ".concat(formatLogs));
|
|
84
84
|
if (options.watch) {
|
|
@@ -101,10 +101,12 @@ function logs(options_1) {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
var initializeConfig = function (config, orgId) {
|
|
104
|
-
var baseUrl = config[
|
|
105
|
-
var apiKey = config[
|
|
106
|
-
var deploymentId = config[
|
|
107
|
-
var
|
|
104
|
+
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
105
|
+
var apiKey = config["api-key"];
|
|
106
|
+
var deploymentId = config["deployment-id"];
|
|
107
|
+
var environment = config["environment"];
|
|
108
|
+
var serviceId = config["service-id"];
|
|
109
|
+
var logsUrl = "".concat(baseUrl, "/codegen-deploy/logs/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
108
110
|
return { baseUrl: baseUrl, apiKey: apiKey, orgId: orgId, deploymentId: deploymentId, logsUrl: logsUrl };
|
|
109
111
|
};
|
|
110
112
|
var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -112,11 +114,11 @@ var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, vo
|
|
|
112
114
|
return __generator(this, function (_a) {
|
|
113
115
|
switch (_a.label) {
|
|
114
116
|
case 0: return [4 /*yield*/, fetch(logsUrl, {
|
|
115
|
-
method:
|
|
117
|
+
method: "GET",
|
|
116
118
|
headers: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
"X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
|
|
121
|
+
"X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
|
|
120
122
|
Authorization: "Bearer ".concat(apiKey),
|
|
121
123
|
},
|
|
122
124
|
})];
|
|
@@ -131,12 +133,12 @@ var fetchLogs = function (logsUrl, apiKey) { return __awaiter(void 0, void 0, vo
|
|
|
131
133
|
});
|
|
132
134
|
}); };
|
|
133
135
|
var handleError = function (spinner, error) {
|
|
134
|
-
spinner.fail(
|
|
135
|
-
(0, utils_1.logError)(
|
|
136
|
+
spinner.fail("Failed to retrieve project logs.");
|
|
137
|
+
(0, utils_1.logError)("Error during log fetch", error);
|
|
136
138
|
};
|
|
137
139
|
var formatProjectLogs = function (projectLogs, deploymentId) {
|
|
138
140
|
try {
|
|
139
|
-
var _a = projectLogs.logs, logs_1 = _a === void 0 ?
|
|
141
|
+
var _a = projectLogs.logs, logs_1 = _a === void 0 ? "" : _a, metadata = __rest(projectLogs, ["logs"]);
|
|
140
142
|
var formatDate_1 = function (dateString) {
|
|
141
143
|
try {
|
|
142
144
|
return new Date(dateString).toLocaleString();
|
|
@@ -149,23 +151,23 @@ var formatProjectLogs = function (projectLogs, deploymentId) {
|
|
|
149
151
|
.map(function (_a) {
|
|
150
152
|
var _b;
|
|
151
153
|
var key = _a[0], value = _a[1];
|
|
152
|
-
var formattedValue = ((_b = value === null || value === void 0 ? void 0 : value.includes) === null || _b === void 0 ? void 0 : _b.call(value,
|
|
154
|
+
var formattedValue = ((_b = value === null || value === void 0 ? void 0 : value.includes) === null || _b === void 0 ? void 0 : _b.call(value, "T"))
|
|
153
155
|
? formatDate_1(value)
|
|
154
156
|
: value;
|
|
155
|
-
var formattedKey = key.replace(/([A-Z])/g,
|
|
157
|
+
var formattedKey = key.replace(/([A-Z])/g, " $1").toLowerCase();
|
|
156
158
|
return "\u001B[36m".concat(formattedKey, ":\u001B[0m ").concat(formattedValue);
|
|
157
159
|
})
|
|
158
|
-
.join(
|
|
159
|
-
var projectUrl = "\nurl: https://".concat(deploymentId.replace(
|
|
160
|
+
.join("\n");
|
|
161
|
+
var projectUrl = "\nurl: https://".concat(deploymentId.replace("codegen-", ""), "-agent.dainapp.com");
|
|
160
162
|
var output = [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
"\n",
|
|
164
|
+
"\x1b[1m=== Project ===\x1b[0m",
|
|
163
165
|
formattedMetadata,
|
|
164
166
|
projectUrl,
|
|
165
|
-
|
|
167
|
+
"\n\x1b[1m=== Logs ===\x1b[0m",
|
|
166
168
|
logs_1,
|
|
167
169
|
];
|
|
168
|
-
return output.join(
|
|
170
|
+
return output.join("\n");
|
|
169
171
|
}
|
|
170
172
|
catch (error) {
|
|
171
173
|
return "Error formatting logs: ".concat(error.message);
|
package/dist/commands/status.js
CHANGED
|
@@ -42,29 +42,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.default = status;
|
|
43
43
|
var ora_1 = __importDefault(require("ora"));
|
|
44
44
|
var utils_1 = require("../utils");
|
|
45
|
-
function status(options, preDefinedDeploymentId) {
|
|
45
|
+
function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
47
47
|
var config, orgId, _a, apiKey, deploymentId, statusUrl, spinner, response, result, error_1;
|
|
48
48
|
return __generator(this, function (_b) {
|
|
49
49
|
switch (_b.label) {
|
|
50
50
|
case 0:
|
|
51
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
orgId =
|
|
53
|
-
_a = initializeConfig(config, orgId, preDefinedDeploymentId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, statusUrl = _a.statusUrl;
|
|
52
|
+
orgId = "hackathon";
|
|
53
|
+
_a = initializeConfig(config, orgId, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, statusUrl = _a.statusUrl;
|
|
54
54
|
if (!orgId || !deploymentId) {
|
|
55
|
-
(0, utils_1.logError)(
|
|
55
|
+
(0, utils_1.logError)("Org ID or deployment ID not found");
|
|
56
56
|
return [2 /*return*/];
|
|
57
57
|
}
|
|
58
|
-
spinner = (0, ora_1.default)("Checking status for project ".concat(config[
|
|
58
|
+
spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
|
|
59
59
|
_b.label = 1;
|
|
60
60
|
case 1:
|
|
61
61
|
_b.trys.push([1, 4, , 5]);
|
|
62
62
|
return [4 /*yield*/, fetch(statusUrl, {
|
|
63
|
-
method:
|
|
63
|
+
method: "GET",
|
|
64
64
|
headers: {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
|
|
67
|
+
"X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
|
|
68
68
|
Authorization: "Bearer ".concat(apiKey),
|
|
69
69
|
},
|
|
70
70
|
})];
|
|
@@ -76,15 +76,15 @@ function status(options, preDefinedDeploymentId) {
|
|
|
76
76
|
return [4 /*yield*/, response.json()];
|
|
77
77
|
case 3:
|
|
78
78
|
result = _b.sent();
|
|
79
|
-
spinner.info(
|
|
79
|
+
spinner.info("Status: " + result.message);
|
|
80
80
|
if (!preDefinedDeploymentId) {
|
|
81
81
|
process.exit(0);
|
|
82
82
|
}
|
|
83
83
|
return [2 /*return*/, result];
|
|
84
84
|
case 4:
|
|
85
85
|
error_1 = _b.sent();
|
|
86
|
-
spinner.fail(
|
|
87
|
-
(0, utils_1.logError)(
|
|
86
|
+
spinner.fail("Failed to retrieve project status.");
|
|
87
|
+
(0, utils_1.logError)("Error during status check", error_1);
|
|
88
88
|
process.exit(1);
|
|
89
89
|
return [3 /*break*/, 5];
|
|
90
90
|
case 5: return [2 /*return*/];
|
|
@@ -92,11 +92,13 @@ function status(options, preDefinedDeploymentId) {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
var initializeConfig = function (config, orgId, preDefinedDeploymentId) {
|
|
96
|
-
var baseUrl = config[
|
|
97
|
-
var apiKey = config[
|
|
95
|
+
var initializeConfig = function (config, orgId, preDefinedDeploymentId, preDefinedEnvironment, preDefinedServiceId) {
|
|
96
|
+
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
97
|
+
var apiKey = config["api-key"];
|
|
98
98
|
var orgIdToBeUsed = orgId || (0, utils_1.extractOrgId)(apiKey);
|
|
99
|
-
var deploymentId = preDefinedDeploymentId || config[
|
|
100
|
-
var
|
|
99
|
+
var deploymentId = preDefinedDeploymentId || config["deployment-id"];
|
|
100
|
+
var environment = preDefinedEnvironment || config["environment"];
|
|
101
|
+
var serviceId = preDefinedServiceId || config["service-id"];
|
|
102
|
+
var statusUrl = "".concat(baseUrl, "/codegen-deploy/status/").concat(orgIdToBeUsed, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
101
103
|
return { baseUrl: baseUrl, apiKey: apiKey, orgIdToBeUsed: orgIdToBeUsed, deploymentId: deploymentId, statusUrl: statusUrl };
|
|
102
104
|
};
|
|
@@ -49,22 +49,22 @@ function undeploy(options) {
|
|
|
49
49
|
switch (_b.label) {
|
|
50
50
|
case 0:
|
|
51
51
|
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
spinner = (0, ora_1.default)("Undeploying deployment ".concat(config[
|
|
52
|
+
spinner = (0, ora_1.default)("Undeploying deployment ".concat(config["deployment-id"], "...")).start();
|
|
53
53
|
_b.label = 1;
|
|
54
54
|
case 1:
|
|
55
55
|
_b.trys.push([1, 3, 4, 5]);
|
|
56
|
-
orgId =
|
|
56
|
+
orgId = "hackathon";
|
|
57
57
|
_a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, undeployUrl = _a.undeployUrl;
|
|
58
58
|
if (!orgId || !deploymentId) {
|
|
59
|
-
(0, utils_1.logError)(
|
|
59
|
+
(0, utils_1.logError)("Org ID or deployment ID not found");
|
|
60
60
|
return [2 /*return*/];
|
|
61
61
|
}
|
|
62
62
|
return [4 /*yield*/, fetch(undeployUrl, {
|
|
63
|
-
method:
|
|
63
|
+
method: "DELETE",
|
|
64
64
|
headers: {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
|
|
67
|
+
"X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
|
|
68
68
|
Authorization: "Bearer ".concat(apiKey),
|
|
69
69
|
},
|
|
70
70
|
})];
|
|
@@ -73,13 +73,13 @@ function undeploy(options) {
|
|
|
73
73
|
if (!response.ok) {
|
|
74
74
|
throw new Error("Undeployment failed: ".concat(response.statusText));
|
|
75
75
|
}
|
|
76
|
-
spinner.succeed(
|
|
76
|
+
spinner.succeed("Undeployment completed successfully.");
|
|
77
77
|
spinner.info("Undeployment completed with status code: ".concat(response.status));
|
|
78
78
|
return [3 /*break*/, 5];
|
|
79
79
|
case 3:
|
|
80
80
|
error_1 = _b.sent();
|
|
81
|
-
spinner.fail(
|
|
82
|
-
(0, utils_1.logError)(
|
|
81
|
+
spinner.fail("Failed to undeploy project.");
|
|
82
|
+
(0, utils_1.logError)("Error during undeployment", error_1);
|
|
83
83
|
process.exit(1);
|
|
84
84
|
return [3 /*break*/, 5];
|
|
85
85
|
case 4:
|
|
@@ -92,10 +92,12 @@ function undeploy(options) {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
var initializeConfig = function (config, orgId) {
|
|
95
|
-
var baseUrl = config[
|
|
96
|
-
var apiKey = config[
|
|
95
|
+
var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
|
|
96
|
+
var apiKey = config["api-key"];
|
|
97
97
|
var orgIdToBeUsed = orgId || (0, utils_1.extractOrgId)(apiKey);
|
|
98
|
-
var deploymentId = config[
|
|
99
|
-
var
|
|
98
|
+
var deploymentId = config["deployment-id"];
|
|
99
|
+
var environment = config["environment"];
|
|
100
|
+
var serviceId = config["service-id"];
|
|
101
|
+
var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgIdToBeUsed, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
|
|
100
102
|
return { baseUrl: baseUrl, apiKey: apiKey, orgIdToBeUsed: orgIdToBeUsed, deploymentId: deploymentId, undeployUrl: undeployUrl };
|
|
101
103
|
};
|