@dainprotocol/cli 1.2.36 → 1.3.1
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/build.d.ts +9 -0
- package/dist/commands/build.js +108 -260
- package/dist/commands/config.d.ts +1 -0
- package/dist/commands/config.js +37 -96
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.js +123 -267
- package/dist/commands/dev.d.ts +6 -0
- package/dist/commands/dev.js +202 -314
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +28 -31
- package/dist/commands/logs.d.ts +4 -0
- package/dist/commands/logs.js +53 -143
- package/dist/commands/start.d.ts +3 -0
- package/dist/commands/start.js +16 -22
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.js +26 -83
- package/dist/commands/testchat.d.ts +5 -0
- package/dist/commands/testchat.js +82 -197
- package/dist/commands/undeploy.d.ts +3 -0
- package/dist/commands/undeploy.js +18 -74
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -38
- package/dist/templates/default/package.json +1 -1
- package/dist/templates/default/tsconfig.json +3 -3
- package/dist/utils.d.ts +62 -0
- package/dist/utils.js +149 -247
- package/package.json +5 -4
- package/dist/__tests__/build.test.js +0 -289
- package/dist/__tests__/deploy.test.js +0 -126
- package/dist/__tests__/dev.test.js +0 -321
- package/dist/__tests__/init.test.js +0 -290
- package/dist/__tests__/integration.test.js +0 -134
- package/dist/__tests__/logs.test.js +0 -135
- package/dist/__tests__/testchat.test.js +0 -214
- package/dist/__tests__/utils.test.js +0 -335
package/dist/commands/logs.js
CHANGED
|
@@ -1,60 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
39
|
-
var t = {};
|
|
40
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
41
|
-
t[p] = s[p];
|
|
42
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
43
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
44
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
45
|
-
t[p[i]] = s[p[i]];
|
|
46
|
-
}
|
|
47
|
-
return t;
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.default = logs;
|
|
54
|
-
var ora_1 = __importDefault(require("ora"));
|
|
55
|
-
var utils_1 = require("../utils");
|
|
56
|
-
var watchInterval = null;
|
|
57
|
-
var isShuttingDown = false;
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { getDainConfig, logError, logInfo, platformRequest, validatePlatformConfig, } from "../utils.js";
|
|
3
|
+
let watchInterval = null;
|
|
4
|
+
let isShuttingDown = false;
|
|
58
5
|
function cleanup() {
|
|
59
6
|
if (isShuttingDown)
|
|
60
7
|
return;
|
|
@@ -64,101 +11,64 @@ function cleanup() {
|
|
|
64
11
|
watchInterval = null;
|
|
65
12
|
}
|
|
66
13
|
}
|
|
67
|
-
function logs(options) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
newResult = _a.sent();
|
|
102
|
-
process.stdout.write("\x1Bc");
|
|
103
|
-
(0, utils_1.logInfo)("Project logs: ".concat(formatProjectLogs(newResult, ctx.deploymentId)));
|
|
104
|
-
return [3 /*break*/, 4];
|
|
105
|
-
case 3:
|
|
106
|
-
error_2 = _a.sent();
|
|
107
|
-
(0, utils_1.logError)("Error fetching logs", error_2);
|
|
108
|
-
return [3 /*break*/, 4];
|
|
109
|
-
case 4: return [2 /*return*/];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}); }, 10000);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
process.exit(0);
|
|
116
|
-
}
|
|
117
|
-
return [3 /*break*/, 4];
|
|
118
|
-
case 3:
|
|
119
|
-
error_1 = _a.sent();
|
|
120
|
-
spinner.fail("Failed to retrieve project logs.");
|
|
121
|
-
(0, utils_1.logError)("Error during log fetch", error_1);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
return [3 /*break*/, 4];
|
|
124
|
-
case 4: return [2 /*return*/];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
14
|
+
export default async function logs(options) {
|
|
15
|
+
const config = getDainConfig(options.config);
|
|
16
|
+
const ctx = validatePlatformConfig(config);
|
|
17
|
+
process.once("SIGINT", () => { cleanup(); process.exit(0); });
|
|
18
|
+
process.once("SIGTERM", () => { cleanup(); process.exit(0); });
|
|
19
|
+
const spinner = ora(`Fetching logs for project ${config["project-id"]}...`).start();
|
|
20
|
+
try {
|
|
21
|
+
const result = await fetchLogs(ctx);
|
|
22
|
+
spinner.stop();
|
|
23
|
+
logInfo(`Project logs: ${formatProjectLogs(result, ctx.deploymentId)}`);
|
|
24
|
+
if (options.watch) {
|
|
25
|
+
logInfo("Watching for log updates (Ctrl+C to stop)...");
|
|
26
|
+
watchInterval = setInterval(async () => {
|
|
27
|
+
if (isShuttingDown)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
const newResult = await fetchLogs(ctx);
|
|
31
|
+
process.stdout.write("\x1Bc");
|
|
32
|
+
logInfo(`Project logs: ${formatProjectLogs(newResult, ctx.deploymentId)}`);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
logError("Error fetching logs", error);
|
|
36
|
+
}
|
|
37
|
+
}, 10000);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
spinner.fail("Failed to retrieve project logs.");
|
|
45
|
+
logError("Error during log fetch", error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
128
48
|
}
|
|
129
|
-
function fetchLogs(ctx) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
case 1:
|
|
136
|
-
response = _a.sent();
|
|
137
|
-
if (!response.ok) {
|
|
138
|
-
throw new Error("Log fetch failed: ".concat(response.status, " ").concat(response.statusText));
|
|
139
|
-
}
|
|
140
|
-
return [2 /*return*/, response.json()];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
49
|
+
async function fetchLogs(ctx) {
|
|
50
|
+
const response = await platformRequest(ctx, "logs");
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`Log fetch failed: ${response.status} ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
return response.json();
|
|
144
55
|
}
|
|
145
56
|
function formatProjectLogs(projectLogs, deploymentId) {
|
|
146
57
|
try {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.map(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var formattedValue = stringValue.includes("T")
|
|
58
|
+
const { logs = "", ...metadata } = projectLogs;
|
|
59
|
+
const formattedMetadata = Object.entries(metadata)
|
|
60
|
+
.map(([key, value]) => {
|
|
61
|
+
const stringValue = String(value);
|
|
62
|
+
const formattedValue = stringValue.includes("T")
|
|
153
63
|
? new Date(stringValue).toLocaleString()
|
|
154
64
|
: value;
|
|
155
|
-
return
|
|
65
|
+
return `\x1b[36m${key.replace(/([A-Z])/g, " $1").toLowerCase()}:\x1b[0m ${formattedValue}`;
|
|
156
66
|
})
|
|
157
67
|
.join("\n");
|
|
158
|
-
|
|
159
|
-
return ["\n", "\x1b[1m=== Project ===\x1b[0m", formattedMetadata, projectUrl, "\n\x1b[1m=== Logs ===\x1b[0m",
|
|
68
|
+
const projectUrl = `\nurl: https://${deploymentId.replace("codegen-", "")}-agent.dainapp.com`;
|
|
69
|
+
return ["\n", "\x1b[1m=== Project ===\x1b[0m", formattedMetadata, projectUrl, "\n\x1b[1m=== Logs ===\x1b[0m", logs].join("\n");
|
|
160
70
|
}
|
|
161
71
|
catch (error) {
|
|
162
|
-
return
|
|
72
|
+
return `Error formatting logs: ${error.message}`;
|
|
163
73
|
}
|
|
164
74
|
}
|
package/dist/commands/start.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var child_process_1 = require("child_process");
|
|
8
|
-
var fs_1 = __importDefault(require("fs"));
|
|
9
|
-
var path_1 = __importDefault(require("path"));
|
|
10
|
-
var utils_1 = require("../utils");
|
|
11
|
-
function start(options) {
|
|
12
|
-
var config = (0, utils_1.getDainConfig)();
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getDainConfig, logError } from '../utils.js';
|
|
5
|
+
export default function start(options) {
|
|
6
|
+
const config = getDainConfig();
|
|
13
7
|
process.env.PORT = options.port;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const mainFile = config['main-file'];
|
|
9
|
+
const outDir = config['out-dir'] || 'dist';
|
|
10
|
+
const outputFile = path.join(process.cwd(), outDir, `${path.basename(mainFile, path.extname(mainFile))}.js`);
|
|
11
|
+
const entryFile = fs.existsSync(outputFile) ? outputFile : mainFile;
|
|
18
12
|
if (entryFile === mainFile && mainFile.endsWith('.ts')) {
|
|
19
|
-
|
|
13
|
+
logError(`Build output not found: ${outputFile}. Run "dain build" first.`);
|
|
20
14
|
process.exit(1);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
child.on('error',
|
|
24
|
-
console.error(
|
|
16
|
+
const child = spawn('node', [entryFile], { stdio: 'inherit' });
|
|
17
|
+
child.on('error', (error) => {
|
|
18
|
+
console.error(`Error: ${error.message}`);
|
|
25
19
|
process.exit(1);
|
|
26
20
|
});
|
|
27
|
-
child.on('exit',
|
|
21
|
+
child.on('exit', (code) => {
|
|
28
22
|
if (code !== 0) {
|
|
29
|
-
console.error(
|
|
23
|
+
console.error(`Process exited with code ${code}`);
|
|
30
24
|
process.exit(code || 1);
|
|
31
25
|
}
|
|
32
26
|
process.exit(0);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface StatusResult {
|
|
2
|
+
status: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export default function status(options: {
|
|
6
|
+
config?: string;
|
|
7
|
+
}, preDefinedDeploymentId?: string, preDefinedEnvironmentName?: string, preDefinedServiceId?: string): Promise<StatusResult | undefined>;
|
|
8
|
+
export {};
|
package/dist/commands/status.js
CHANGED
|
@@ -1,86 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
import { getDainConfig, logError, platformRequest, validatePlatformConfig, } from "../utils.js";
|
|
3
|
+
export default async function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
4
|
+
const config = getDainConfig(options.config);
|
|
5
|
+
const ctx = validatePlatformConfig(config, {
|
|
6
|
+
deploymentId: preDefinedDeploymentId,
|
|
7
|
+
serviceId: preDefinedServiceId,
|
|
9
8
|
});
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.default = status;
|
|
43
|
-
var ora_1 = __importDefault(require("ora"));
|
|
44
|
-
var utils_1 = require("../utils");
|
|
45
|
-
function status(options, preDefinedDeploymentId, preDefinedEnvironmentName, preDefinedServiceId) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
-
var config, ctx, spinner, response, result, error_1;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
config = (0, utils_1.getDainConfig)(options.config);
|
|
52
|
-
ctx = (0, utils_1.validatePlatformConfig)(config, {
|
|
53
|
-
deploymentId: preDefinedDeploymentId,
|
|
54
|
-
serviceId: preDefinedServiceId,
|
|
55
|
-
});
|
|
56
|
-
spinner = (0, ora_1.default)("Checking status for project ".concat(config["project-id"], "...")).start();
|
|
57
|
-
_a.label = 1;
|
|
58
|
-
case 1:
|
|
59
|
-
_a.trys.push([1, 4, , 5]);
|
|
60
|
-
return [4 /*yield*/, (0, utils_1.platformRequest)(ctx, "status", "GET", {
|
|
61
|
-
environment: preDefinedEnvironmentName,
|
|
62
|
-
})];
|
|
63
|
-
case 2:
|
|
64
|
-
response = _a.sent();
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
throw new Error("Status check failed: ".concat(response.status, " ").concat(response.statusText));
|
|
67
|
-
}
|
|
68
|
-
return [4 /*yield*/, response.json()];
|
|
69
|
-
case 3:
|
|
70
|
-
result = _a.sent();
|
|
71
|
-
spinner.info("Status: " + result.message);
|
|
72
|
-
if (!preDefinedDeploymentId) {
|
|
73
|
-
process.exit(0);
|
|
74
|
-
}
|
|
75
|
-
return [2 /*return*/, result];
|
|
76
|
-
case 4:
|
|
77
|
-
error_1 = _a.sent();
|
|
78
|
-
spinner.fail("Failed to retrieve project status.");
|
|
79
|
-
(0, utils_1.logError)("Error during status check", error_1);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
return [3 /*break*/, 5];
|
|
82
|
-
case 5: return [2 /*return*/];
|
|
83
|
-
}
|
|
9
|
+
const spinner = ora(`Checking status for project ${config["project-id"]}...`).start();
|
|
10
|
+
try {
|
|
11
|
+
const response = await platformRequest(ctx, "status", "GET", {
|
|
12
|
+
environment: preDefinedEnvironmentName,
|
|
84
13
|
});
|
|
85
|
-
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
throw new Error(`Status check failed: ${response.status} ${response.statusText}`);
|
|
16
|
+
}
|
|
17
|
+
const result = await response.json();
|
|
18
|
+
spinner.info("Status: " + result.message);
|
|
19
|
+
if (!preDefinedDeploymentId) {
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
spinner.fail("Failed to retrieve project status.");
|
|
26
|
+
logError("Error during status check", error);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
86
29
|
}
|