@adep/cli 0.0.8 → 0.1.0
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/README.md +103 -31
- package/dist/index.js +2256 -1641
- package/dist/vite.js +2818 -0
- package/dist/worker-entry.js +10 -10
- package/package.json +35 -10
- package/src/index.ts +8 -0
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __export = (target, all) => {
|
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
//
|
|
12
|
+
// src/config.ts
|
|
13
13
|
function resolvePaths(env = process.env) {
|
|
14
14
|
const home = env["ADEP_HOME"] ?? `${env["HOME"] ?? ""}/.adep`;
|
|
15
15
|
return { home, credentialsFile: `${home}/credentials` };
|
|
@@ -18,12 +18,12 @@ function resolveServer(env = process.env) {
|
|
|
18
18
|
return (env["ADEP_SERVER"] ?? "https://adep.jajabjbj.top").replace(/\/+$/, "");
|
|
19
19
|
}
|
|
20
20
|
var init_config = __esm({
|
|
21
|
-
"
|
|
21
|
+
"src/config.ts"() {
|
|
22
22
|
"use strict";
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
//
|
|
26
|
+
// src/credentials.ts
|
|
27
27
|
import { mkdir, open, readFile, rm, stat } from "node:fs/promises";
|
|
28
28
|
import { dirname } from "node:path";
|
|
29
29
|
async function saveCredentials(paths, credentials) {
|
|
@@ -70,15 +70,15 @@ function decodeToken(encoded) {
|
|
|
70
70
|
return Buffer.from(encoded, "base64").toString("utf8");
|
|
71
71
|
}
|
|
72
72
|
var init_credentials = __esm({
|
|
73
|
-
"
|
|
73
|
+
"src/credentials.ts"() {
|
|
74
74
|
"use strict";
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
//
|
|
78
|
+
// src/offline/errors.ts
|
|
79
79
|
var NetworkRequiredError;
|
|
80
80
|
var init_errors = __esm({
|
|
81
|
-
"
|
|
81
|
+
"src/offline/errors.ts"() {
|
|
82
82
|
"use strict";
|
|
83
83
|
NetworkRequiredError = class extends Error {
|
|
84
84
|
command;
|
|
@@ -93,7 +93,7 @@ var init_errors = __esm({
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
//
|
|
96
|
+
// src/offline/net.ts
|
|
97
97
|
var net_exports = {};
|
|
98
98
|
__export(net_exports, {
|
|
99
99
|
isOffline: () => isOffline,
|
|
@@ -136,7 +136,7 @@ async function requireNetwork(command) {
|
|
|
136
136
|
}
|
|
137
137
|
var PROBE_TTL_MS, PROBE_URL, PROBE_TIMEOUT_MS, cachedResult;
|
|
138
138
|
var init_net = __esm({
|
|
139
|
-
"
|
|
139
|
+
"src/offline/net.ts"() {
|
|
140
140
|
"use strict";
|
|
141
141
|
init_errors();
|
|
142
142
|
PROBE_TTL_MS = 3e4;
|
|
@@ -146,7 +146,7 @@ var init_net = __esm({
|
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
148
|
|
|
149
|
-
//
|
|
149
|
+
// src/auth.ts
|
|
150
150
|
function sessionCookieOf(setCookie) {
|
|
151
151
|
const line = setCookie.find(
|
|
152
152
|
(entry) => entry.startsWith("better-auth.session_token=") && !/max-age=0/i.test(entry)
|
|
@@ -217,7 +217,7 @@ async function logout(paths) {
|
|
|
217
217
|
}
|
|
218
218
|
var CliError;
|
|
219
219
|
var init_auth = __esm({
|
|
220
|
-
"
|
|
220
|
+
"src/auth.ts"() {
|
|
221
221
|
"use strict";
|
|
222
222
|
init_credentials();
|
|
223
223
|
init_net();
|
|
@@ -232,7 +232,140 @@ var init_auth = __esm({
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
-
//
|
|
235
|
+
// ../../shared/sdk/adep-config.ts
|
|
236
|
+
function typeNameOf(value) {
|
|
237
|
+
if (value === null) return "null";
|
|
238
|
+
if (Array.isArray(value)) return "array";
|
|
239
|
+
return typeof value;
|
|
240
|
+
}
|
|
241
|
+
function asRecord(value) {
|
|
242
|
+
if (value === null || Array.isArray(value) || typeof value !== "object") return null;
|
|
243
|
+
return value;
|
|
244
|
+
}
|
|
245
|
+
function asStringRecord(value) {
|
|
246
|
+
const rec = asRecord(value);
|
|
247
|
+
if (rec === null) return null;
|
|
248
|
+
for (const v of Object.values(rec)) {
|
|
249
|
+
if (typeof v !== "string") return null;
|
|
250
|
+
}
|
|
251
|
+
return rec;
|
|
252
|
+
}
|
|
253
|
+
function parseAdepConfig(raw) {
|
|
254
|
+
if (raw === null || raw === void 0) {
|
|
255
|
+
return { ok: true, data: { ...DEFAULT_ADEP_CONFIG } };
|
|
256
|
+
}
|
|
257
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
258
|
+
return {
|
|
259
|
+
ok: false,
|
|
260
|
+
errors: [`adep.config.ts \u7684 default export \u5FC5\u987B\u662F\u5BF9\u8C61\uFF0C\u6536\u5230 ${typeNameOf(raw)}`]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const errors = [];
|
|
264
|
+
const input = raw;
|
|
265
|
+
const data = { ...DEFAULT_ADEP_CONFIG };
|
|
266
|
+
if (input.name !== void 0) {
|
|
267
|
+
if (typeof input.name !== "string") {
|
|
268
|
+
errors.push(`name \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u6536\u5230 ${typeNameOf(input.name)}`);
|
|
269
|
+
} else {
|
|
270
|
+
data.name = input.name;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (input.functionsDir !== void 0) {
|
|
274
|
+
if (typeof input.functionsDir !== "string") {
|
|
275
|
+
errors.push(`functionsDir \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u6536\u5230 ${typeNameOf(input.functionsDir)}`);
|
|
276
|
+
} else {
|
|
277
|
+
data.functionsDir = input.functionsDir;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (input.functions_prefix !== void 0) {
|
|
281
|
+
if (typeof input.functions_prefix !== "string") {
|
|
282
|
+
errors.push(`functions_prefix \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\uFF0C\u6536\u5230 ${typeNameOf(input.functions_prefix)}`);
|
|
283
|
+
} else {
|
|
284
|
+
data.functions_prefix = input.functions_prefix;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (input.frontend !== void 0) {
|
|
288
|
+
const rec = asRecord(input.frontend);
|
|
289
|
+
if (rec === null) {
|
|
290
|
+
errors.push(`frontend \u5FC5\u987B\u662F\u5BF9\u8C61\uFF0C\u6536\u5230 ${typeNameOf(input.frontend)}`);
|
|
291
|
+
} else {
|
|
292
|
+
data.frontend = rec;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (input.environment !== void 0) {
|
|
296
|
+
const rec = asStringRecord(input.environment);
|
|
297
|
+
if (rec === null) {
|
|
298
|
+
errors.push(
|
|
299
|
+
`environment \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u5230\u5B57\u7B26\u4E32\u7684\u6620\u5C04\uFF08Record<string, string>\uFF09\uFF0C\u6536\u5230 ${typeNameOf(input.environment)}`
|
|
300
|
+
);
|
|
301
|
+
} else {
|
|
302
|
+
data.environment = rec;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (input.runtime !== void 0) {
|
|
306
|
+
const rec = asRecord(input.runtime);
|
|
307
|
+
if (rec === null) {
|
|
308
|
+
errors.push(`runtime \u5FC5\u987B\u662F\u5BF9\u8C61\uFF0C\u6536\u5230 ${typeNameOf(input.runtime)}`);
|
|
309
|
+
} else {
|
|
310
|
+
data.runtime = rec;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (errors.length > 0) return { ok: false, errors };
|
|
314
|
+
return { ok: true, data };
|
|
315
|
+
}
|
|
316
|
+
function renderTsValue(value) {
|
|
317
|
+
if (value === null) return "null";
|
|
318
|
+
if (typeof value === "string") return `'${value}'`;
|
|
319
|
+
if (typeof value === "boolean") return value ? "true" : "false";
|
|
320
|
+
if (typeof value === "number") return String(value);
|
|
321
|
+
if (Array.isArray(value)) return `[${value.map(renderTsValue).join(", ")}]`;
|
|
322
|
+
if (typeof value === "object") {
|
|
323
|
+
const entries = Object.entries(value).map(([k, v]) => `${k}: ${renderTsValue(v)}`).join(", ");
|
|
324
|
+
return `{ ${entries} }`;
|
|
325
|
+
}
|
|
326
|
+
return String(value);
|
|
327
|
+
}
|
|
328
|
+
function renderAdepConfig(config, options = {}) {
|
|
329
|
+
const functionsDir = config.functionsDir ?? DEFAULT_ADEP_CONFIG.functionsDir;
|
|
330
|
+
const functionsPrefix = config.functions_prefix ?? DEFAULT_ADEP_CONFIG.functions_prefix;
|
|
331
|
+
const lines = [];
|
|
332
|
+
if (options.header !== void 0 && options.header.length > 0) {
|
|
333
|
+
lines.push(options.header);
|
|
334
|
+
}
|
|
335
|
+
lines.push("export default {");
|
|
336
|
+
if (config.name !== void 0) lines.push(` name: '${config.name}',`);
|
|
337
|
+
lines.push(` functionsDir: '${functionsDir}',`);
|
|
338
|
+
lines.push(` functions_prefix: '${functionsPrefix}',`);
|
|
339
|
+
if (config.frontend !== void 0) {
|
|
340
|
+
lines.push(` frontend: ${renderTsValue(config.frontend)},`);
|
|
341
|
+
}
|
|
342
|
+
if (config.environment !== void 0) {
|
|
343
|
+
lines.push(` environment: ${renderTsValue(config.environment)},`);
|
|
344
|
+
}
|
|
345
|
+
if (config.runtime !== void 0) {
|
|
346
|
+
lines.push(` runtime: ${renderTsValue(config.runtime)},`);
|
|
347
|
+
}
|
|
348
|
+
if (options.extraFields !== void 0) {
|
|
349
|
+
for (const [key, value] of Object.entries(options.extraFields)) {
|
|
350
|
+
lines.push(` ${key}: ${renderTsValue(value)},`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
lines.push("}");
|
|
354
|
+
return `${lines.join("\n")}
|
|
355
|
+
`;
|
|
356
|
+
}
|
|
357
|
+
var DEFAULT_ADEP_CONFIG;
|
|
358
|
+
var init_adep_config = __esm({
|
|
359
|
+
"../../shared/sdk/adep-config.ts"() {
|
|
360
|
+
"use strict";
|
|
361
|
+
DEFAULT_ADEP_CONFIG = {
|
|
362
|
+
functionsDir: "functions",
|
|
363
|
+
functions_prefix: "/api"
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
// src/prompt.ts
|
|
236
369
|
var prompt_exports = {};
|
|
237
370
|
__export(prompt_exports, {
|
|
238
371
|
createPrompt: () => createPrompt
|
|
@@ -263,7 +396,7 @@ function createPrompt(input = process.stdin) {
|
|
|
263
396
|
}
|
|
264
397
|
var MutedStream;
|
|
265
398
|
var init_prompt = __esm({
|
|
266
|
-
"
|
|
399
|
+
"src/prompt.ts"() {
|
|
267
400
|
"use strict";
|
|
268
401
|
MutedStream = class extends Writable {
|
|
269
402
|
write(_chunk, ...rest) {
|
|
@@ -274,10 +407,10 @@ var init_prompt = __esm({
|
|
|
274
407
|
}
|
|
275
408
|
});
|
|
276
409
|
|
|
277
|
-
//
|
|
410
|
+
// ../runtime/src/shared/capability-keys.ts
|
|
278
411
|
var RPC_CAPABILITY_KEY, CHAIN_CAPABILITY_KEY, DB_RPC, REALTIME_CAPABILITY_CODES, REALTIME_CAPABILITY_METHODS;
|
|
279
412
|
var init_capability_keys = __esm({
|
|
280
|
-
"
|
|
413
|
+
"../runtime/src/shared/capability-keys.ts"() {
|
|
281
414
|
"use strict";
|
|
282
415
|
RPC_CAPABILITY_KEY = "__adepRpc";
|
|
283
416
|
CHAIN_CAPABILITY_KEY = "__adepChain";
|
|
@@ -312,7 +445,7 @@ var init_capability_keys = __esm({
|
|
|
312
445
|
}
|
|
313
446
|
});
|
|
314
447
|
|
|
315
|
-
//
|
|
448
|
+
// ../runtime/src/shared/executor-runtime.ts
|
|
316
449
|
function isHttpStatus(status) {
|
|
317
450
|
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599;
|
|
318
451
|
}
|
|
@@ -321,7 +454,7 @@ function normalizeHttpStatus(status) {
|
|
|
321
454
|
}
|
|
322
455
|
var ExecutorError, TIMEOUT_CODE, OOM_CODE, DEFAULT_TIMEOUT_MS, DEFAULT_MEMORY_LIMIT_MB;
|
|
323
456
|
var init_executor_runtime = __esm({
|
|
324
|
-
"
|
|
457
|
+
"../runtime/src/shared/executor-runtime.ts"() {
|
|
325
458
|
"use strict";
|
|
326
459
|
ExecutorError = class extends Error {
|
|
327
460
|
constructor(status, code, message) {
|
|
@@ -338,18 +471,18 @@ var init_executor_runtime = __esm({
|
|
|
338
471
|
}
|
|
339
472
|
});
|
|
340
473
|
|
|
341
|
-
//
|
|
474
|
+
// ../runtime/src/functions/runtime/executor.ts
|
|
342
475
|
var init_executor = __esm({
|
|
343
|
-
"
|
|
476
|
+
"../runtime/src/functions/runtime/executor.ts"() {
|
|
344
477
|
"use strict";
|
|
345
478
|
init_executor_runtime();
|
|
346
479
|
}
|
|
347
480
|
});
|
|
348
481
|
|
|
349
|
-
//
|
|
482
|
+
// ../runtime/src/functions/domain.ts
|
|
350
483
|
var MAX_TOTAL_SOURCE_BYTES, FnError;
|
|
351
484
|
var init_domain = __esm({
|
|
352
|
-
"
|
|
485
|
+
"../runtime/src/functions/domain.ts"() {
|
|
353
486
|
"use strict";
|
|
354
487
|
MAX_TOTAL_SOURCE_BYTES = 256 * 1024;
|
|
355
488
|
FnError = class extends Error {
|
|
@@ -365,7 +498,7 @@ var init_domain = __esm({
|
|
|
365
498
|
}
|
|
366
499
|
});
|
|
367
500
|
|
|
368
|
-
//
|
|
501
|
+
// ../runtime/src/functions/deps/manifest.ts
|
|
369
502
|
import { createHash } from "node:crypto";
|
|
370
503
|
function isVersionRangeSpec(spec) {
|
|
371
504
|
if (spec === "*" || spec === "latest") return true;
|
|
@@ -446,7 +579,7 @@ function depsKeyOf(dependencies) {
|
|
|
446
579
|
}
|
|
447
580
|
var PACKAGE_NAME_PATTERN, COMPARATOR_PATTERN, MANIFEST_MAX_DEPS;
|
|
448
581
|
var init_manifest = __esm({
|
|
449
|
-
"
|
|
582
|
+
"../runtime/src/functions/deps/manifest.ts"() {
|
|
450
583
|
"use strict";
|
|
451
584
|
init_domain();
|
|
452
585
|
PACKAGE_NAME_PATTERN = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-._~]+$/;
|
|
@@ -455,7 +588,7 @@ var init_manifest = __esm({
|
|
|
455
588
|
}
|
|
456
589
|
});
|
|
457
590
|
|
|
458
|
-
//
|
|
591
|
+
// ../runtime/src/functions/deps/resolve.ts
|
|
459
592
|
import { resolve as resolve2 } from "node:path";
|
|
460
593
|
function resolveExecutionDeps(config, projectId, manifestContent) {
|
|
461
594
|
const manifest = tryParseManifestDependencies(manifestContent);
|
|
@@ -469,13 +602,13 @@ function resolveExecutionDeps(config, projectId, manifestContent) {
|
|
|
469
602
|
};
|
|
470
603
|
}
|
|
471
604
|
var init_resolve = __esm({
|
|
472
|
-
"
|
|
605
|
+
"../runtime/src/functions/deps/resolve.ts"() {
|
|
473
606
|
"use strict";
|
|
474
607
|
init_manifest();
|
|
475
608
|
}
|
|
476
609
|
});
|
|
477
610
|
|
|
478
|
-
//
|
|
611
|
+
// ../runtime/src/functions/runtime/worker-executor.ts
|
|
479
612
|
import { readFileSync } from "node:fs";
|
|
480
613
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
481
614
|
import { dirname as dirname3, join as join2 } from "node:path";
|
|
@@ -518,7 +651,7 @@ function rpcReply(worker, id, ok, payload) {
|
|
|
518
651
|
}
|
|
519
652
|
var WorkerFunctionExecutor;
|
|
520
653
|
var init_worker_executor = __esm({
|
|
521
|
-
"
|
|
654
|
+
"../runtime/src/functions/runtime/worker-executor.ts"() {
|
|
522
655
|
"use strict";
|
|
523
656
|
init_executor();
|
|
524
657
|
init_resolve();
|
|
@@ -535,7 +668,7 @@ var init_worker_executor = __esm({
|
|
|
535
668
|
const entry = input.entry ?? "index.ts";
|
|
536
669
|
const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
|
|
537
670
|
const logs = [];
|
|
538
|
-
return new Promise((
|
|
671
|
+
return new Promise((resolve12, reject) => {
|
|
539
672
|
let worker;
|
|
540
673
|
try {
|
|
541
674
|
worker = new Worker(resolveWorkerEntry(), {
|
|
@@ -597,7 +730,7 @@ var init_worker_executor = __esm({
|
|
|
597
730
|
if (message.type === "result") {
|
|
598
731
|
clearTimeout(timer);
|
|
599
732
|
void worker.terminate();
|
|
600
|
-
|
|
733
|
+
resolve12({ body: message.body, logs });
|
|
601
734
|
return;
|
|
602
735
|
}
|
|
603
736
|
if (message.type === "error") {
|
|
@@ -632,13 +765,13 @@ var init_worker_executor = __esm({
|
|
|
632
765
|
}
|
|
633
766
|
});
|
|
634
767
|
|
|
635
|
-
//
|
|
768
|
+
// ../runtime/src/database/builder/dialect.ts
|
|
636
769
|
function dialectFor(driver) {
|
|
637
770
|
return driver.engine === "pg" ? postgresDialect : sqliteDialect;
|
|
638
771
|
}
|
|
639
772
|
var sqliteDialect, postgresDialect;
|
|
640
773
|
var init_dialect = __esm({
|
|
641
|
-
"
|
|
774
|
+
"../runtime/src/database/builder/dialect.ts"() {
|
|
642
775
|
"use strict";
|
|
643
776
|
sqliteDialect = {
|
|
644
777
|
name: "sqlite",
|
|
@@ -657,7 +790,7 @@ var init_dialect = __esm({
|
|
|
657
790
|
}
|
|
658
791
|
});
|
|
659
792
|
|
|
660
|
-
//
|
|
793
|
+
// ../runtime/src/database/provision/identifier.ts
|
|
661
794
|
function assertIdentifier(name) {
|
|
662
795
|
if (!IDENTIFIER_PATTERN.test(name)) {
|
|
663
796
|
throw new DbError(
|
|
@@ -673,7 +806,7 @@ function quoteIdentifier(name) {
|
|
|
673
806
|
}
|
|
674
807
|
var DbError, IDENTIFIER_PATTERN;
|
|
675
808
|
var init_identifier = __esm({
|
|
676
|
-
"
|
|
809
|
+
"../runtime/src/database/provision/identifier.ts"() {
|
|
677
810
|
"use strict";
|
|
678
811
|
DbError = class extends Error {
|
|
679
812
|
constructor(status, code, message) {
|
|
@@ -687,7 +820,7 @@ var init_identifier = __esm({
|
|
|
687
820
|
}
|
|
688
821
|
});
|
|
689
822
|
|
|
690
|
-
//
|
|
823
|
+
// ../runtime/src/database/builder/guards.ts
|
|
691
824
|
function unsafeOperation(message) {
|
|
692
825
|
return new DbError(400, "DB_UNSAFE_OP", message);
|
|
693
826
|
}
|
|
@@ -711,13 +844,13 @@ function assertReadOnlyQuery(sql) {
|
|
|
711
844
|
}
|
|
712
845
|
}
|
|
713
846
|
var init_guards = __esm({
|
|
714
|
-
"
|
|
847
|
+
"../runtime/src/database/builder/guards.ts"() {
|
|
715
848
|
"use strict";
|
|
716
849
|
init_identifier();
|
|
717
850
|
}
|
|
718
851
|
});
|
|
719
852
|
|
|
720
|
-
//
|
|
853
|
+
// ../runtime/src/database/builder/owned.ts
|
|
721
854
|
function changeLogTable(table) {
|
|
722
855
|
const name = `${CHANGE_LOG_PREFIX}${table}`;
|
|
723
856
|
assertIdentifier(name);
|
|
@@ -828,7 +961,7 @@ async function readChanges(driver, table, query = {}) {
|
|
|
828
961
|
}
|
|
829
962
|
var OWNED_PK, OWNED_OWNER_KEY, CHANGE_LOG_PREFIX;
|
|
830
963
|
var init_owned = __esm({
|
|
831
|
-
"
|
|
964
|
+
"../runtime/src/database/builder/owned.ts"() {
|
|
832
965
|
"use strict";
|
|
833
966
|
init_identifier();
|
|
834
967
|
init_dialect();
|
|
@@ -839,7 +972,7 @@ var init_owned = __esm({
|
|
|
839
972
|
}
|
|
840
973
|
});
|
|
841
974
|
|
|
842
|
-
//
|
|
975
|
+
// ../runtime/src/database/builder/ulid.ts
|
|
843
976
|
function encodeTime(now) {
|
|
844
977
|
let ts = Math.trunc(now);
|
|
845
978
|
let out = "";
|
|
@@ -901,7 +1034,7 @@ function ulid(now = Date.now()) {
|
|
|
901
1034
|
}
|
|
902
1035
|
var ENCODING, TIME_LEN, RANDOM_LEN, lastTime, lastRandom;
|
|
903
1036
|
var init_ulid = __esm({
|
|
904
|
-
"
|
|
1037
|
+
"../runtime/src/database/builder/ulid.ts"() {
|
|
905
1038
|
"use strict";
|
|
906
1039
|
ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
907
1040
|
TIME_LEN = 10;
|
|
@@ -911,7 +1044,7 @@ var init_ulid = __esm({
|
|
|
911
1044
|
}
|
|
912
1045
|
});
|
|
913
1046
|
|
|
914
|
-
//
|
|
1047
|
+
// ../runtime/src/database/builder/table.ts
|
|
915
1048
|
function pushParam(params, dialect, value) {
|
|
916
1049
|
params.push(value);
|
|
917
1050
|
return dialect.placeholder(params.length - 1);
|
|
@@ -1219,7 +1352,7 @@ function createTableBuilder(table, driver, dialect, options = {}) {
|
|
|
1219
1352
|
}
|
|
1220
1353
|
var OPERATORS, LIST_OPERATORS;
|
|
1221
1354
|
var init_table = __esm({
|
|
1222
|
-
"
|
|
1355
|
+
"../runtime/src/database/builder/table.ts"() {
|
|
1223
1356
|
"use strict";
|
|
1224
1357
|
init_identifier();
|
|
1225
1358
|
init_guards();
|
|
@@ -1240,7 +1373,7 @@ var init_table = __esm({
|
|
|
1240
1373
|
}
|
|
1241
1374
|
});
|
|
1242
1375
|
|
|
1243
|
-
//
|
|
1376
|
+
// ../runtime/src/database/builder/index.ts
|
|
1244
1377
|
function createCloudDb(driver, options = {}) {
|
|
1245
1378
|
const dialect = options.dialect ?? dialectFor(driver);
|
|
1246
1379
|
let txState = TX_STATES.get(driver);
|
|
@@ -1294,7 +1427,7 @@ function createCloudDb(driver, options = {}) {
|
|
|
1294
1427
|
}
|
|
1295
1428
|
var TX_STATES;
|
|
1296
1429
|
var init_builder = __esm({
|
|
1297
|
-
"
|
|
1430
|
+
"../runtime/src/database/builder/index.ts"() {
|
|
1298
1431
|
"use strict";
|
|
1299
1432
|
init_dialect();
|
|
1300
1433
|
init_guards();
|
|
@@ -1304,7 +1437,7 @@ var init_builder = __esm({
|
|
|
1304
1437
|
}
|
|
1305
1438
|
});
|
|
1306
1439
|
|
|
1307
|
-
//
|
|
1440
|
+
// ../runtime/src/database/sdk/cloud.ts
|
|
1308
1441
|
function errorWithCode(error) {
|
|
1309
1442
|
const code = typeof error === "object" && error !== null && typeof error.code === "string" ? error.code : void 0;
|
|
1310
1443
|
if (code !== void 0 && error instanceof Error) {
|
|
@@ -1400,7 +1533,7 @@ function createDbCapability(driver, options = {}) {
|
|
|
1400
1533
|
}
|
|
1401
1534
|
var CLOUD_DB_SPEC, WRITE_TERMINALS;
|
|
1402
1535
|
var init_cloud = __esm({
|
|
1403
|
-
"
|
|
1536
|
+
"../runtime/src/database/sdk/cloud.ts"() {
|
|
1404
1537
|
"use strict";
|
|
1405
1538
|
init_capability_keys();
|
|
1406
1539
|
init_builder();
|
|
@@ -1417,7 +1550,7 @@ var init_cloud = __esm({
|
|
|
1417
1550
|
}
|
|
1418
1551
|
});
|
|
1419
1552
|
|
|
1420
|
-
//
|
|
1553
|
+
// src/sim/sql-engine.ts
|
|
1421
1554
|
function ident(raw) {
|
|
1422
1555
|
return raw.trim().replace(/^"|"$/g, "").trim();
|
|
1423
1556
|
}
|
|
@@ -1582,7 +1715,7 @@ function project(rows, selectRaw) {
|
|
|
1582
1715
|
}
|
|
1583
1716
|
var SimDbError, ParamCursor, SimSqlEngine;
|
|
1584
1717
|
var init_sql_engine = __esm({
|
|
1585
|
-
"
|
|
1718
|
+
"src/sim/sql-engine.ts"() {
|
|
1586
1719
|
"use strict";
|
|
1587
1720
|
SimDbError = class extends Error {
|
|
1588
1721
|
constructor(code, message) {
|
|
@@ -1841,7 +1974,7 @@ var init_sql_engine = __esm({
|
|
|
1841
1974
|
}
|
|
1842
1975
|
});
|
|
1843
1976
|
|
|
1844
|
-
//
|
|
1977
|
+
// src/sim/db.ts
|
|
1845
1978
|
function toProjectDriver(engine) {
|
|
1846
1979
|
return {
|
|
1847
1980
|
engine: "sqlite",
|
|
@@ -1861,14 +1994,14 @@ function createSimDbCapability(options = {}) {
|
|
|
1861
1994
|
return { bundle, engine, driver };
|
|
1862
1995
|
}
|
|
1863
1996
|
var init_db = __esm({
|
|
1864
|
-
"
|
|
1997
|
+
"src/sim/db.ts"() {
|
|
1865
1998
|
"use strict";
|
|
1866
1999
|
init_cloud();
|
|
1867
2000
|
init_sql_engine();
|
|
1868
2001
|
}
|
|
1869
2002
|
});
|
|
1870
2003
|
|
|
1871
|
-
//
|
|
2004
|
+
// ../runtime/src/storage/driver.ts
|
|
1872
2005
|
function assertSafeStoragePath(path) {
|
|
1873
2006
|
if (typeof path !== "string" || path.length === 0) {
|
|
1874
2007
|
throw new StorageError(400, STORAGE_CODES.invalidPath, "\u5B58\u50A8\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
|
|
@@ -1896,7 +2029,7 @@ function assertSafeStoragePath(path) {
|
|
|
1896
2029
|
}
|
|
1897
2030
|
var PROJECT_QUOTA_BYTES, StorageError, STORAGE_CODES;
|
|
1898
2031
|
var init_driver = __esm({
|
|
1899
|
-
"
|
|
2032
|
+
"../runtime/src/storage/driver.ts"() {
|
|
1900
2033
|
"use strict";
|
|
1901
2034
|
PROJECT_QUOTA_BYTES = 1024 * 1024 * 1024;
|
|
1902
2035
|
StorageError = class extends Error {
|
|
@@ -1915,7 +2048,7 @@ var init_driver = __esm({
|
|
|
1915
2048
|
}
|
|
1916
2049
|
});
|
|
1917
2050
|
|
|
1918
|
-
//
|
|
2051
|
+
// ../runtime/src/storage/hmac-sha256.ts
|
|
1919
2052
|
function compress(h, block, w) {
|
|
1920
2053
|
for (let i = 0; i < 16; i += 1) {
|
|
1921
2054
|
const j = i * 4;
|
|
@@ -2010,7 +2143,7 @@ function hmacSha256Hex(key, message) {
|
|
|
2010
2143
|
}
|
|
2011
2144
|
var K, rotr;
|
|
2012
2145
|
var init_hmac_sha256 = __esm({
|
|
2013
|
-
"
|
|
2146
|
+
"../runtime/src/storage/hmac-sha256.ts"() {
|
|
2014
2147
|
"use strict";
|
|
2015
2148
|
K = new Uint32Array([
|
|
2016
2149
|
1116352408,
|
|
@@ -2082,7 +2215,7 @@ var init_hmac_sha256 = __esm({
|
|
|
2082
2215
|
}
|
|
2083
2216
|
});
|
|
2084
2217
|
|
|
2085
|
-
//
|
|
2218
|
+
// ../runtime/src/storage/signature.ts
|
|
2086
2219
|
function sign(secret, projectId, path, expires) {
|
|
2087
2220
|
const payload = `${projectId}|${path}|${expires}`;
|
|
2088
2221
|
return hmacSha256Hex(secret, payload);
|
|
@@ -2095,7 +2228,7 @@ function signDownloadUrl(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_
|
|
|
2095
2228
|
}
|
|
2096
2229
|
var DEFAULT_SIGN_TTL_SECONDS, SIGN_EXPIRES_KEY, SIGN_SIGNATURE_KEY;
|
|
2097
2230
|
var init_signature = __esm({
|
|
2098
|
-
"
|
|
2231
|
+
"../runtime/src/storage/signature.ts"() {
|
|
2099
2232
|
"use strict";
|
|
2100
2233
|
init_hmac_sha256();
|
|
2101
2234
|
DEFAULT_SIGN_TTL_SECONDS = 15 * 60;
|
|
@@ -2104,7 +2237,7 @@ var init_signature = __esm({
|
|
|
2104
2237
|
}
|
|
2105
2238
|
});
|
|
2106
2239
|
|
|
2107
|
-
//
|
|
2240
|
+
// ../runtime/src/storage/cloud.ts
|
|
2108
2241
|
function asBytes(data) {
|
|
2109
2242
|
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
2110
2243
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
@@ -2163,7 +2296,7 @@ function createStorageCapability(driver, signer, projectId) {
|
|
|
2163
2296
|
}
|
|
2164
2297
|
var DEFAULT_VISIBILITY;
|
|
2165
2298
|
var init_cloud2 = __esm({
|
|
2166
|
-
"
|
|
2299
|
+
"../runtime/src/storage/cloud.ts"() {
|
|
2167
2300
|
"use strict";
|
|
2168
2301
|
init_capability_keys();
|
|
2169
2302
|
init_driver();
|
|
@@ -2172,7 +2305,7 @@ var init_cloud2 = __esm({
|
|
|
2172
2305
|
}
|
|
2173
2306
|
});
|
|
2174
2307
|
|
|
2175
|
-
//
|
|
2308
|
+
// ../runtime/src/storage/driver/local.ts
|
|
2176
2309
|
import { mkdir as mkdir3, readFile as readFile2, readdir, rm as rm2, stat as stat3, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
2177
2310
|
import { dirname as dirname4, join as join3 } from "node:path";
|
|
2178
2311
|
function createLocalStorageDriver(options) {
|
|
@@ -2379,14 +2512,14 @@ function createLocalStorageDriver(options) {
|
|
|
2379
2512
|
}
|
|
2380
2513
|
var META_SUFFIX;
|
|
2381
2514
|
var init_local = __esm({
|
|
2382
|
-
"
|
|
2515
|
+
"../runtime/src/storage/driver/local.ts"() {
|
|
2383
2516
|
"use strict";
|
|
2384
2517
|
init_driver();
|
|
2385
2518
|
META_SUFFIX = ".adep-meta.json";
|
|
2386
2519
|
}
|
|
2387
2520
|
});
|
|
2388
2521
|
|
|
2389
|
-
//
|
|
2522
|
+
// src/sim/storage.ts
|
|
2390
2523
|
import { join as join4 } from "node:path";
|
|
2391
2524
|
function createSimStorageCapability(options) {
|
|
2392
2525
|
const dir = join4(options.cwd, ".adep", "sim", "storage");
|
|
@@ -2399,14 +2532,14 @@ function createSimStorageCapability(options) {
|
|
|
2399
2532
|
return { bundle, driver };
|
|
2400
2533
|
}
|
|
2401
2534
|
var init_storage = __esm({
|
|
2402
|
-
"
|
|
2535
|
+
"src/sim/storage.ts"() {
|
|
2403
2536
|
"use strict";
|
|
2404
2537
|
init_cloud2();
|
|
2405
2538
|
init_local();
|
|
2406
2539
|
}
|
|
2407
2540
|
});
|
|
2408
2541
|
|
|
2409
|
-
//
|
|
2542
|
+
// src/sim/realtime.ts
|
|
2410
2543
|
function realtimeError(code, message) {
|
|
2411
2544
|
return new Error(`[${code}] ${message}`);
|
|
2412
2545
|
}
|
|
@@ -2487,7 +2620,7 @@ function createSimRealtimeCapability() {
|
|
|
2487
2620
|
}
|
|
2488
2621
|
var SimRealtime, MAX_BUFFERED_MESSAGES, MAX_SUBSCRIPTIONS, REALTIME_CODES;
|
|
2489
2622
|
var init_realtime = __esm({
|
|
2490
|
-
"
|
|
2623
|
+
"src/sim/realtime.ts"() {
|
|
2491
2624
|
"use strict";
|
|
2492
2625
|
init_capability_keys();
|
|
2493
2626
|
SimRealtime = class {
|
|
@@ -2535,7 +2668,7 @@ var init_realtime = __esm({
|
|
|
2535
2668
|
}
|
|
2536
2669
|
});
|
|
2537
2670
|
|
|
2538
|
-
//
|
|
2671
|
+
// src/sim/runtime.ts
|
|
2539
2672
|
import { mkdir as mkdir4, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
|
|
2540
2673
|
import { dirname as dirname5, join as join5 } from "node:path";
|
|
2541
2674
|
function simDir(cwd) {
|
|
@@ -2600,7 +2733,7 @@ async function createSimRuntime(options) {
|
|
|
2600
2733
|
};
|
|
2601
2734
|
}
|
|
2602
2735
|
var init_runtime = __esm({
|
|
2603
|
-
"
|
|
2736
|
+
"src/sim/runtime.ts"() {
|
|
2604
2737
|
"use strict";
|
|
2605
2738
|
init_db();
|
|
2606
2739
|
init_storage();
|
|
@@ -2608,7 +2741,7 @@ var init_runtime = __esm({
|
|
|
2608
2741
|
}
|
|
2609
2742
|
});
|
|
2610
2743
|
|
|
2611
|
-
//
|
|
2744
|
+
// src/sim/env.ts
|
|
2612
2745
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
2613
2746
|
import { join as join6 } from "node:path";
|
|
2614
2747
|
function parseEnv(content) {
|
|
@@ -2641,12 +2774,12 @@ async function loadSimEnv(cwd, config = {}) {
|
|
|
2641
2774
|
return merged;
|
|
2642
2775
|
}
|
|
2643
2776
|
var init_env = __esm({
|
|
2644
|
-
"
|
|
2777
|
+
"src/sim/env.ts"() {
|
|
2645
2778
|
"use strict";
|
|
2646
2779
|
}
|
|
2647
2780
|
});
|
|
2648
2781
|
|
|
2649
|
-
//
|
|
2782
|
+
// src/sim/invoke.ts
|
|
2650
2783
|
function resolveFunctionEntry(files, fnName) {
|
|
2651
2784
|
const flat = `${fnName}.ts`;
|
|
2652
2785
|
if (files[flat] !== void 0) return flat;
|
|
@@ -2699,15 +2832,15 @@ function createSimInvokeHandler(options) {
|
|
|
2699
2832
|
};
|
|
2700
2833
|
}
|
|
2701
2834
|
var init_invoke = __esm({
|
|
2702
|
-
"
|
|
2835
|
+
"src/sim/invoke.ts"() {
|
|
2703
2836
|
"use strict";
|
|
2704
2837
|
}
|
|
2705
2838
|
});
|
|
2706
2839
|
|
|
2707
|
-
//
|
|
2840
|
+
// src/sim/boundary.ts
|
|
2708
2841
|
var SIM_BOUNDARIES;
|
|
2709
2842
|
var init_boundary = __esm({
|
|
2710
|
-
"
|
|
2843
|
+
"src/sim/boundary.ts"() {
|
|
2711
2844
|
"use strict";
|
|
2712
2845
|
SIM_BOUNDARIES = [
|
|
2713
2846
|
{
|
|
@@ -2739,36 +2872,78 @@ var init_boundary = __esm({
|
|
|
2739
2872
|
}
|
|
2740
2873
|
});
|
|
2741
2874
|
|
|
2742
|
-
//
|
|
2875
|
+
// src/ts-config.ts
|
|
2876
|
+
import { stat as stat4, readFile as readFile5 } from "node:fs/promises";
|
|
2877
|
+
import { join as join7 } from "node:path";
|
|
2878
|
+
async function loadAdepConfigModule(cwd) {
|
|
2879
|
+
const configPath = join7(cwd, "adep.config.ts");
|
|
2880
|
+
try {
|
|
2881
|
+
await stat4(configPath);
|
|
2882
|
+
} catch {
|
|
2883
|
+
return null;
|
|
2884
|
+
}
|
|
2885
|
+
let rawDefault;
|
|
2886
|
+
try {
|
|
2887
|
+
const bun = globalThis.Bun;
|
|
2888
|
+
if (bun !== void 0) {
|
|
2889
|
+
const mod = await import(configPath);
|
|
2890
|
+
rawDefault = mod.default;
|
|
2891
|
+
} else {
|
|
2892
|
+
const { transform } = await import("esbuild");
|
|
2893
|
+
const source = await readFile5(configPath, "utf8");
|
|
2894
|
+
const { code } = await transform(source, {
|
|
2895
|
+
loader: "ts",
|
|
2896
|
+
format: "esm",
|
|
2897
|
+
target: "node22"
|
|
2898
|
+
});
|
|
2899
|
+
const url = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
|
|
2900
|
+
const mod = await import(url);
|
|
2901
|
+
rawDefault = mod.default;
|
|
2902
|
+
}
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
2905
|
+
const message = `adep.config.ts \u52A0\u8F7D\u5931\u8D25\uFF1A${reason}`;
|
|
2906
|
+
process.stderr.write(`\u9519\u8BEF\uFF1A${message}
|
|
2907
|
+
`);
|
|
2908
|
+
throw new Error(message, { cause: error });
|
|
2909
|
+
}
|
|
2910
|
+
const result = parseAdepConfig(rawDefault);
|
|
2911
|
+
if (!result.ok) {
|
|
2912
|
+
const message = `adep.config.ts \u6821\u9A8C\u5931\u8D25\uFF1A
|
|
2913
|
+
${result.errors.map((e) => ` - ${e}`).join("\n")}`;
|
|
2914
|
+
process.stderr.write(`${message}
|
|
2915
|
+
`);
|
|
2916
|
+
throw new Error(message);
|
|
2917
|
+
}
|
|
2918
|
+
return result.data;
|
|
2919
|
+
}
|
|
2920
|
+
var init_ts_config = __esm({
|
|
2921
|
+
"src/ts-config.ts"() {
|
|
2922
|
+
"use strict";
|
|
2923
|
+
init_adep_config();
|
|
2924
|
+
}
|
|
2925
|
+
});
|
|
2926
|
+
|
|
2927
|
+
// src/dev.ts
|
|
2743
2928
|
var dev_exports = {};
|
|
2744
2929
|
__export(dev_exports, {
|
|
2745
2930
|
loadConfig: () => loadConfig,
|
|
2746
2931
|
parseEnvFile: () => parseEnvFile,
|
|
2932
|
+
resolveRouteFnName: () => resolveRouteFnName,
|
|
2747
2933
|
startDevServer: () => startDevServer
|
|
2748
2934
|
});
|
|
2749
2935
|
import { createServer } from "node:http";
|
|
2750
2936
|
import { watch } from "node:fs";
|
|
2751
|
-
import { mkdir as mkdir5, readdir as readdir2, readFile as
|
|
2752
|
-
import { basename, join as
|
|
2937
|
+
import { mkdir as mkdir5, readdir as readdir2, readFile as readFile6, writeFile as writeFile4 } from "node:fs/promises";
|
|
2938
|
+
import { basename, join as join8, resolve as resolve3 } from "node:path";
|
|
2753
2939
|
async function loadConfig(cwd) {
|
|
2754
2940
|
const name = basename(resolve3(cwd));
|
|
2755
|
-
const
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
}
|
|
2761
|
-
const bun = globalThis.Bun;
|
|
2762
|
-
if (bun === void 0) return { name, functionsDir: "functions" };
|
|
2763
|
-
try {
|
|
2764
|
-
const mod = await import(configPath);
|
|
2765
|
-
return {
|
|
2766
|
-
name: mod.default?.name ?? name,
|
|
2767
|
-
functionsDir: mod.default?.functionsDir ?? "functions"
|
|
2768
|
-
};
|
|
2769
|
-
} catch {
|
|
2770
|
-
return { name, functionsDir: "functions" };
|
|
2771
|
-
}
|
|
2941
|
+
const config = await loadAdepConfigModule(cwd);
|
|
2942
|
+
return {
|
|
2943
|
+
name: config?.name ?? name,
|
|
2944
|
+
functionsDir: config?.functionsDir ?? "functions",
|
|
2945
|
+
functionsPrefix: config?.functions_prefix ?? ""
|
|
2946
|
+
};
|
|
2772
2947
|
}
|
|
2773
2948
|
function parseEnvFile(content) {
|
|
2774
2949
|
const env = {};
|
|
@@ -2794,11 +2969,11 @@ async function collectFunctions(dir) {
|
|
|
2794
2969
|
}
|
|
2795
2970
|
for (const entry of entries) {
|
|
2796
2971
|
const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
2797
|
-
const full =
|
|
2972
|
+
const full = join8(sub, entry.name);
|
|
2798
2973
|
if (entry.isDirectory()) {
|
|
2799
2974
|
await walk(full, rel);
|
|
2800
2975
|
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
2801
|
-
files[rel] = await
|
|
2976
|
+
files[rel] = await readFile6(full, "utf8");
|
|
2802
2977
|
}
|
|
2803
2978
|
}
|
|
2804
2979
|
};
|
|
@@ -2824,6 +2999,32 @@ function bodyOf(req) {
|
|
|
2824
2999
|
req.on("error", rejectBody);
|
|
2825
3000
|
});
|
|
2826
3001
|
}
|
|
3002
|
+
function resolveRouteFnName(pathname, prefix) {
|
|
3003
|
+
const segments = pathname.split("/").filter((segment) => segment.length > 0);
|
|
3004
|
+
const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
|
|
3005
|
+
if (normalizedPrefix.length === 0) {
|
|
3006
|
+
const first = segments[0];
|
|
3007
|
+
return first === void 0 ? {} : { fnName: first };
|
|
3008
|
+
}
|
|
3009
|
+
if (segments[0] !== normalizedPrefix) {
|
|
3010
|
+
return {
|
|
3011
|
+
error: {
|
|
3012
|
+
code: "FN_PREFIX_REQUIRED",
|
|
3013
|
+
message: `\u5DF2\u914D\u7F6E functions_prefix "${normalizedPrefix}"\uFF1A\u4EE5 /${normalizedPrefix}/{fnName} \u8C03\u7528\u672C\u5730\u51FD\u6570`
|
|
3014
|
+
}
|
|
3015
|
+
};
|
|
3016
|
+
}
|
|
3017
|
+
const second = segments[1];
|
|
3018
|
+
if (second === void 0) {
|
|
3019
|
+
return {
|
|
3020
|
+
error: {
|
|
3021
|
+
code: "FN_NAME_REQUIRED",
|
|
3022
|
+
message: `\u4EE5 /${normalizedPrefix}/{fnName} \u8C03\u7528\u672C\u5730\u51FD\u6570`
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
return { fnName: second };
|
|
3027
|
+
}
|
|
2827
3028
|
function writeJson(res, status, payload) {
|
|
2828
3029
|
res.writeHead(status, { "content-type": "application/json" });
|
|
2829
3030
|
res.end(JSON.stringify(payload));
|
|
@@ -2835,8 +3036,8 @@ function printBoundaries(log) {
|
|
|
2835
3036
|
}
|
|
2836
3037
|
}
|
|
2837
3038
|
async function ensureGitignore(cwd) {
|
|
2838
|
-
const gitignorePath =
|
|
2839
|
-
const existing = await
|
|
3039
|
+
const gitignorePath = join8(cwd, ".gitignore");
|
|
3040
|
+
const existing = await readFile6(gitignorePath, "utf8").catch(() => "");
|
|
2840
3041
|
if (existing.split(/\r?\n/).includes(".adep/")) return;
|
|
2841
3042
|
await writeFile4(gitignorePath, `${existing.replace(/\n+$/, "")}
|
|
2842
3043
|
.adep/
|
|
@@ -2847,7 +3048,10 @@ async function startDevServer(options) {
|
|
|
2847
3048
|
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
2848
3049
|
`));
|
|
2849
3050
|
const config = await loadConfig(cwd);
|
|
2850
|
-
|
|
3051
|
+
if (options.prefix !== void 0) {
|
|
3052
|
+
config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
|
|
3053
|
+
}
|
|
3054
|
+
const functionsDir = join8(cwd, config.functionsDir);
|
|
2851
3055
|
const coldStartAt = Date.now();
|
|
2852
3056
|
const executor = new WorkerFunctionExecutor();
|
|
2853
3057
|
await mkdir5(functionsDir, { recursive: true });
|
|
@@ -2865,12 +3069,12 @@ async function startDevServer(options) {
|
|
|
2865
3069
|
const reload = async () => {
|
|
2866
3070
|
const [nextFiles, envText2] = await Promise.all([
|
|
2867
3071
|
collectFunctions(functionsDir),
|
|
2868
|
-
|
|
3072
|
+
readFile6(join8(cwd, ".env.local"), "utf8").catch(() => "")
|
|
2869
3073
|
]);
|
|
2870
3074
|
files = nextFiles;
|
|
2871
3075
|
env = parseEnvFile(envText2);
|
|
2872
3076
|
};
|
|
2873
|
-
const envText = await
|
|
3077
|
+
const envText = await readFile6(join8(cwd, ".env.local"), "utf8").catch(() => "");
|
|
2874
3078
|
env = parseEnvFile(envText);
|
|
2875
3079
|
let debounceTimer;
|
|
2876
3080
|
let watcher;
|
|
@@ -2920,7 +3124,11 @@ async function startDevServer(options) {
|
|
|
2920
3124
|
};
|
|
2921
3125
|
const handle = async (req, res) => {
|
|
2922
3126
|
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
2923
|
-
const fnName = url.pathname
|
|
3127
|
+
const { fnName, error: routeError } = resolveRouteFnName(url.pathname, config.functionsPrefix);
|
|
3128
|
+
if (routeError !== void 0) {
|
|
3129
|
+
writeJson(res, 400, { error: routeError });
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
2924
3132
|
if (fnName === void 0) {
|
|
2925
3133
|
writeJson(res, 400, {
|
|
2926
3134
|
error: { code: "FN_NAME_REQUIRED", message: "\u4EE5 /{fnName} \u8C03\u7528\u672C\u5730\u51FD\u6570" }
|
|
@@ -2963,10 +3171,28 @@ async function startDevServer(options) {
|
|
|
2963
3171
|
void handle(req, res);
|
|
2964
3172
|
});
|
|
2965
3173
|
const port = options.port ?? 8787;
|
|
3174
|
+
const disposeAfterListenError = async () => {
|
|
3175
|
+
if (debounceTimer !== void 0) clearTimeout(debounceTimer);
|
|
3176
|
+
try {
|
|
3177
|
+
watcher?.close();
|
|
3178
|
+
} catch {
|
|
3179
|
+
}
|
|
3180
|
+
try {
|
|
3181
|
+
await executor.dispose();
|
|
3182
|
+
} catch {
|
|
3183
|
+
}
|
|
3184
|
+
try {
|
|
3185
|
+
await runtime.dispose();
|
|
3186
|
+
} catch {
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
2966
3189
|
await new Promise((resolveListen, rejectListen) => {
|
|
2967
|
-
|
|
3190
|
+
const onListenError = (error) => {
|
|
3191
|
+
void disposeAfterListenError().finally(() => rejectListen(error));
|
|
3192
|
+
};
|
|
3193
|
+
server.once("error", onListenError);
|
|
2968
3194
|
server.listen(port, "127.0.0.1", () => {
|
|
2969
|
-
server.off("error",
|
|
3195
|
+
server.off("error", onListenError);
|
|
2970
3196
|
resolveListen();
|
|
2971
3197
|
});
|
|
2972
3198
|
});
|
|
@@ -2974,8 +3200,9 @@ async function startDevServer(options) {
|
|
|
2974
3200
|
const actualPort = typeof address === "object" && address !== null ? address.port : port;
|
|
2975
3201
|
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
2976
3202
|
const coldStartMs = Date.now() - coldStartAt;
|
|
3203
|
+
const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
|
|
2977
3204
|
log(`[adep] dev server listening on ${baseUrl}\uFF08\u6A21\u62DF\u8FD0\u884C\u65F6\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`);
|
|
2978
|
-
log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}
|
|
3205
|
+
log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
|
|
2979
3206
|
printBoundaries(log);
|
|
2980
3207
|
log(`[adep] \u6A21\u62DF\u6570\u636E\u76EE\u5F55\uFF1A${simDir(cwd)}`);
|
|
2981
3208
|
return {
|
|
@@ -2991,7 +3218,7 @@ async function startDevServer(options) {
|
|
|
2991
3218
|
};
|
|
2992
3219
|
}
|
|
2993
3220
|
var init_dev = __esm({
|
|
2994
|
-
"
|
|
3221
|
+
"src/dev.ts"() {
|
|
2995
3222
|
"use strict";
|
|
2996
3223
|
init_executor();
|
|
2997
3224
|
init_worker_executor();
|
|
@@ -2999,10 +3226,11 @@ var init_dev = __esm({
|
|
|
2999
3226
|
init_env();
|
|
3000
3227
|
init_invoke();
|
|
3001
3228
|
init_boundary();
|
|
3229
|
+
init_ts_config();
|
|
3002
3230
|
}
|
|
3003
3231
|
});
|
|
3004
3232
|
|
|
3005
|
-
//
|
|
3233
|
+
// src/serve/banner.ts
|
|
3006
3234
|
function isLoopback(host) {
|
|
3007
3235
|
return host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
|
|
3008
3236
|
}
|
|
@@ -3023,9 +3251,8 @@ function renderBanner(options) {
|
|
|
3023
3251
|
lines.push("");
|
|
3024
3252
|
lines.push(" \u80FD\u529B:");
|
|
3025
3253
|
if (functions.length > 0) {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
);
|
|
3254
|
+
const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/api/${options.functionsPrefix.replace(/^\/+|\/+$/g, "")}/{fn}`;
|
|
3255
|
+
lines.push(` - \u51FD\u6570\u8DEF\u7531: ${route}\uFF08${functions.length} \u4E2A\u51FD\u6570: ${functions.join(", ")}\uFF09`);
|
|
3029
3256
|
} else {
|
|
3030
3257
|
lines.push(" - \u51FD\u6570\u8DEF\u7531: \u65E0\uFF08functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF09");
|
|
3031
3258
|
}
|
|
@@ -3062,12 +3289,12 @@ function renderBanner(options) {
|
|
|
3062
3289
|
return lines.join("\n");
|
|
3063
3290
|
}
|
|
3064
3291
|
var init_banner = __esm({
|
|
3065
|
-
"
|
|
3292
|
+
"src/serve/banner.ts"() {
|
|
3066
3293
|
"use strict";
|
|
3067
3294
|
}
|
|
3068
3295
|
});
|
|
3069
3296
|
|
|
3070
|
-
//
|
|
3297
|
+
// src/serve/server.ts
|
|
3071
3298
|
var server_exports = {};
|
|
3072
3299
|
__export(server_exports, {
|
|
3073
3300
|
isLoopback: () => isLoopback,
|
|
@@ -3075,8 +3302,8 @@ __export(server_exports, {
|
|
|
3075
3302
|
});
|
|
3076
3303
|
import { createServer as createServer2 } from "node:http";
|
|
3077
3304
|
import { watch as watch2 } from "node:fs";
|
|
3078
|
-
import { mkdir as mkdir6, readdir as readdir3, readFile as
|
|
3079
|
-
import { join as
|
|
3305
|
+
import { mkdir as mkdir6, readdir as readdir3, readFile as readFile7, stat as stat5 } from "node:fs/promises";
|
|
3306
|
+
import { join as join9, relative, resolve as resolve4 } from "node:path";
|
|
3080
3307
|
function envNumber(name) {
|
|
3081
3308
|
const raw = process.env[name];
|
|
3082
3309
|
if (raw === void 0 || raw.trim() === "") return void 0;
|
|
@@ -3098,11 +3325,11 @@ async function collectFunctions2(dir) {
|
|
|
3098
3325
|
}
|
|
3099
3326
|
for (const entry of entries) {
|
|
3100
3327
|
const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
3101
|
-
const full =
|
|
3328
|
+
const full = join9(sub, entry.name);
|
|
3102
3329
|
if (entry.isDirectory()) {
|
|
3103
3330
|
await walk(full, rel);
|
|
3104
3331
|
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
3105
|
-
files[rel] = await
|
|
3332
|
+
files[rel] = await readFile7(full, "utf8");
|
|
3106
3333
|
}
|
|
3107
3334
|
}
|
|
3108
3335
|
};
|
|
@@ -3147,7 +3374,7 @@ async function startServeServer(options) {
|
|
|
3147
3374
|
options.staticDir ?? envString("ADEP_SERVE_STATIC_DIR") ?? "public"
|
|
3148
3375
|
);
|
|
3149
3376
|
const config = await loadConfig(cwd);
|
|
3150
|
-
const functionsDir =
|
|
3377
|
+
const functionsDir = join9(cwd, config.functionsDir);
|
|
3151
3378
|
let hasStatic = false;
|
|
3152
3379
|
try {
|
|
3153
3380
|
const publicStat = await stat5(staticDir);
|
|
@@ -3157,7 +3384,7 @@ async function startServeServer(options) {
|
|
|
3157
3384
|
}
|
|
3158
3385
|
let files = await collectFunctions2(functionsDir);
|
|
3159
3386
|
let functionNames = listFunctionNames(files);
|
|
3160
|
-
const envText = await
|
|
3387
|
+
const envText = await readFile7(join9(cwd, ".env.local"), "utf8").catch(() => "");
|
|
3161
3388
|
let env = parseEnvFile(envText);
|
|
3162
3389
|
let simEnv = await loadSimEnv(cwd).catch(() => ({}));
|
|
3163
3390
|
const runtime = await createSimRuntime({
|
|
@@ -3174,7 +3401,7 @@ async function startServeServer(options) {
|
|
|
3174
3401
|
const reload = async () => {
|
|
3175
3402
|
const [nextFiles, envLocalText] = await Promise.all([
|
|
3176
3403
|
collectFunctions2(functionsDir),
|
|
3177
|
-
|
|
3404
|
+
readFile7(join9(cwd, ".env.local"), "utf8").catch(() => "")
|
|
3178
3405
|
]);
|
|
3179
3406
|
files = nextFiles;
|
|
3180
3407
|
env = parseEnvFile(envLocalText);
|
|
@@ -3243,16 +3470,16 @@ async function startServeServer(options) {
|
|
|
3243
3470
|
const serveStatic = async (pathname, res) => {
|
|
3244
3471
|
if (!hasStatic) return false;
|
|
3245
3472
|
const safePath = pathname.replace(/\.\.\//g, "").replace(/^\//, "");
|
|
3246
|
-
const filePath =
|
|
3247
|
-
const resolvedPath = safePath === "" || safePath === "/" ?
|
|
3473
|
+
const filePath = join9(staticDir, safePath);
|
|
3474
|
+
const resolvedPath = safePath === "" || safePath === "/" ? join9(filePath, "index.html") : filePath;
|
|
3248
3475
|
try {
|
|
3249
3476
|
const fileStat = await stat5(resolvedPath);
|
|
3250
3477
|
if (fileStat.isDirectory()) {
|
|
3251
|
-
const indexPath =
|
|
3478
|
+
const indexPath = join9(resolvedPath, "index.html");
|
|
3252
3479
|
try {
|
|
3253
3480
|
const indexStat = await stat5(indexPath);
|
|
3254
3481
|
if (indexStat.isFile()) {
|
|
3255
|
-
const content2 = await
|
|
3482
|
+
const content2 = await readFile7(indexPath);
|
|
3256
3483
|
res.writeHead(200, { "content-type": contentTypeFor(indexPath) });
|
|
3257
3484
|
res.end(content2);
|
|
3258
3485
|
return true;
|
|
@@ -3261,7 +3488,7 @@ async function startServeServer(options) {
|
|
|
3261
3488
|
}
|
|
3262
3489
|
return false;
|
|
3263
3490
|
}
|
|
3264
|
-
const content = await
|
|
3491
|
+
const content = await readFile7(resolvedPath);
|
|
3265
3492
|
res.writeHead(200, { "content-type": contentTypeFor(resolvedPath) });
|
|
3266
3493
|
res.end(content);
|
|
3267
3494
|
return true;
|
|
@@ -3273,7 +3500,12 @@ async function startServeServer(options) {
|
|
|
3273
3500
|
const url = new URL(req.url ?? "/", `http://${host}:${port}`);
|
|
3274
3501
|
const pathname = url.pathname;
|
|
3275
3502
|
if (pathname === "/api" || pathname.startsWith("/api/")) {
|
|
3276
|
-
const
|
|
3503
|
+
const rest = pathname === "/api" ? "" : pathname.slice("/api/".length);
|
|
3504
|
+
const { fnName, error: routeError } = resolveRouteFnName(rest, config.functionsPrefix);
|
|
3505
|
+
if (routeError !== void 0) {
|
|
3506
|
+
writeJson2(res, 400, { error: routeError });
|
|
3507
|
+
return;
|
|
3508
|
+
}
|
|
3277
3509
|
if (fnName === void 0 || fnName.length === 0) {
|
|
3278
3510
|
writeJson2(res, 400, {
|
|
3279
3511
|
error: { code: "FN_NAME_REQUIRED", message: "\u4EE5 /api/{fnName} \u8C03\u7528\u51FD\u6570" }
|
|
@@ -3368,6 +3600,7 @@ async function startServeServer(options) {
|
|
|
3368
3600
|
port: actualPort,
|
|
3369
3601
|
projectName: config.name,
|
|
3370
3602
|
functions: functionNames,
|
|
3603
|
+
functionsPrefix: config.functionsPrefix,
|
|
3371
3604
|
hasStatic,
|
|
3372
3605
|
staticDir: relative(cwd, staticDir).length > 0 ? relative(cwd, staticDir) : staticDir
|
|
3373
3606
|
});
|
|
@@ -3389,7 +3622,7 @@ async function startServeServer(options) {
|
|
|
3389
3622
|
}
|
|
3390
3623
|
var MIME_TYPES;
|
|
3391
3624
|
var init_server = __esm({
|
|
3392
|
-
"
|
|
3625
|
+
"src/serve/server.ts"() {
|
|
3393
3626
|
"use strict";
|
|
3394
3627
|
init_executor();
|
|
3395
3628
|
init_worker_executor();
|
|
@@ -3422,7 +3655,7 @@ var init_server = __esm({
|
|
|
3422
3655
|
}
|
|
3423
3656
|
});
|
|
3424
3657
|
|
|
3425
|
-
//
|
|
3658
|
+
// src/client.ts
|
|
3426
3659
|
var client_exports = {};
|
|
3427
3660
|
__export(client_exports, {
|
|
3428
3661
|
createClient: () => createClient,
|
|
@@ -3515,7 +3748,7 @@ async function resolveSlug(cwd, slug) {
|
|
|
3515
3748
|
return config.name;
|
|
3516
3749
|
}
|
|
3517
3750
|
var init_client = __esm({
|
|
3518
|
-
"
|
|
3751
|
+
"src/client.ts"() {
|
|
3519
3752
|
"use strict";
|
|
3520
3753
|
init_auth();
|
|
3521
3754
|
init_credentials();
|
|
@@ -3523,15 +3756,15 @@ var init_client = __esm({
|
|
|
3523
3756
|
}
|
|
3524
3757
|
});
|
|
3525
3758
|
|
|
3526
|
-
//
|
|
3759
|
+
// src/deploy.ts
|
|
3527
3760
|
var deploy_exports = {};
|
|
3528
3761
|
__export(deploy_exports, {
|
|
3529
3762
|
collectEntries: () => collectEntries,
|
|
3530
3763
|
deploy: () => deploy
|
|
3531
3764
|
});
|
|
3532
3765
|
import { createHash as createHash2 } from "node:crypto";
|
|
3533
|
-
import { readdir as readdir4, readFile as
|
|
3534
|
-
import { join as
|
|
3766
|
+
import { readdir as readdir4, readFile as readFile8 } from "node:fs/promises";
|
|
3767
|
+
import { join as join10, resolve as resolve5, basename as basename2 } from "node:path";
|
|
3535
3768
|
function functionUrlBase(prefix) {
|
|
3536
3769
|
const raw = (prefix ?? "/api").trim();
|
|
3537
3770
|
const normalized = raw === "/" ? "/" : raw.replace(/\/+$/, "");
|
|
@@ -3547,7 +3780,7 @@ async function collectEntries(functionsDir) {
|
|
|
3547
3780
|
return entries;
|
|
3548
3781
|
}
|
|
3549
3782
|
for (const name of names) {
|
|
3550
|
-
entries[name] = await
|
|
3783
|
+
entries[name] = await readFile8(join10(functionsDir, `${name}.ts`), "utf8");
|
|
3551
3784
|
}
|
|
3552
3785
|
return entries;
|
|
3553
3786
|
}
|
|
@@ -3562,7 +3795,7 @@ async function deploy(paths, options) {
|
|
|
3562
3795
|
const cwd = resolve5(options.cwd);
|
|
3563
3796
|
const config = await loadConfig(cwd);
|
|
3564
3797
|
const slug = options.slug ?? config.name;
|
|
3565
|
-
const functionsDir = options.functionsDir === void 0 ?
|
|
3798
|
+
const functionsDir = options.functionsDir === void 0 ? join10(cwd, config.functionsDir) : resolve5(cwd, options.functionsDir);
|
|
3566
3799
|
const local = await collectEntries(functionsDir);
|
|
3567
3800
|
if (Object.keys(local).length === 0) {
|
|
3568
3801
|
throw new CliError("NO_FUNCTIONS", `${functionsDir} \u4E0B\u6CA1\u6709\u51FD\u6570\u6587\u4EF6`);
|
|
@@ -3631,7 +3864,7 @@ async function deploy(paths, options) {
|
|
|
3631
3864
|
};
|
|
3632
3865
|
}
|
|
3633
3866
|
var init_deploy = __esm({
|
|
3634
|
-
"
|
|
3867
|
+
"src/deploy.ts"() {
|
|
3635
3868
|
"use strict";
|
|
3636
3869
|
init_auth();
|
|
3637
3870
|
init_client();
|
|
@@ -3640,1387 +3873,1396 @@ var init_deploy = __esm({
|
|
|
3640
3873
|
}
|
|
3641
3874
|
});
|
|
3642
3875
|
|
|
3643
|
-
//
|
|
3644
|
-
var
|
|
3645
|
-
__export(
|
|
3646
|
-
|
|
3647
|
-
projectsInfo: () => projectsInfo,
|
|
3648
|
-
projectsList: () => projectsList
|
|
3876
|
+
// src/export/client.ts
|
|
3877
|
+
var client_exports2 = {};
|
|
3878
|
+
__export(client_exports2, {
|
|
3879
|
+
createExportApiClient: () => createExportApiClient
|
|
3649
3880
|
});
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
const created = await client.request(
|
|
3664
|
-
"/api/v1/projects",
|
|
3665
|
-
{ body },
|
|
3666
|
-
"PROJECT_CREATE_FAILED"
|
|
3667
|
-
);
|
|
3668
|
-
if (created.url === void 0 || created.url.length === 0) {
|
|
3669
|
-
throw new CliError("PROJECT_CREATE_FAILED", "\u5E73\u53F0\u672A\u8FD4\u56DE\u9879\u76EE\u5730\u5740\uFF0C\u65E0\u6CD5\u8F93\u51FA\u5B50\u57DF URL");
|
|
3670
|
-
}
|
|
3671
|
-
return created;
|
|
3881
|
+
import { writeFile as writeFile5 } from "node:fs/promises";
|
|
3882
|
+
function toExportJob(view) {
|
|
3883
|
+
return {
|
|
3884
|
+
id: view.id,
|
|
3885
|
+
status: view.status,
|
|
3886
|
+
progress: view.progress,
|
|
3887
|
+
createdAt: view.createdAt,
|
|
3888
|
+
...view.stage === void 0 ? {} : { stage: view.stage },
|
|
3889
|
+
...view.error === void 0 ? {} : { error: view.error },
|
|
3890
|
+
...view.downloadUrl === void 0 ? {} : { downloadUrl: view.downloadUrl },
|
|
3891
|
+
...view.bundleSize === void 0 ? {} : { bundleSize: view.bundleSize },
|
|
3892
|
+
...view.completedAt === void 0 ? {} : { completedAt: view.completedAt }
|
|
3893
|
+
};
|
|
3672
3894
|
}
|
|
3673
|
-
async function
|
|
3674
|
-
await requireNetworkGuard();
|
|
3895
|
+
async function createExportApiClient(paths) {
|
|
3675
3896
|
const client = await createClient(paths);
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3897
|
+
return {
|
|
3898
|
+
async triggerExport(projectId, options) {
|
|
3899
|
+
const view = await client.request(
|
|
3900
|
+
`/api/v1/projects/${encodeURIComponent(projectId)}/export`,
|
|
3901
|
+
{
|
|
3902
|
+
method: "POST",
|
|
3903
|
+
body: {
|
|
3904
|
+
withData: options.withData,
|
|
3905
|
+
withSource: options.withSource,
|
|
3906
|
+
...options.withoutSource === true ? { withoutSource: true } : {}
|
|
3907
|
+
}
|
|
3908
|
+
},
|
|
3909
|
+
"EXPORT_TRIGGER_FAILED"
|
|
3910
|
+
);
|
|
3911
|
+
return toExportJob(view);
|
|
3912
|
+
},
|
|
3913
|
+
async getJobStatus(jobId) {
|
|
3914
|
+
const view = await client.request(
|
|
3915
|
+
`/api/v1/exports/${encodeURIComponent(jobId)}`,
|
|
3916
|
+
{},
|
|
3917
|
+
"EXPORT_STATUS_FAILED"
|
|
3918
|
+
);
|
|
3919
|
+
return toExportJob(view);
|
|
3920
|
+
},
|
|
3921
|
+
async downloadBundle(jobId, outputPath) {
|
|
3922
|
+
const download = await client.request(
|
|
3923
|
+
`/api/v1/exports/${encodeURIComponent(jobId)}/download`,
|
|
3924
|
+
{},
|
|
3925
|
+
"EXPORT_DOWNLOAD_FAILED"
|
|
3926
|
+
);
|
|
3927
|
+
if (download.downloadUrl.length === 0) {
|
|
3928
|
+
throw new CliError("EXPORT_BUNDLE_UNAVAILABLE", "\u5BFC\u51FA\u4EA7\u7269\u4E0B\u8F7D URL \u4E3A\u7A7A\uFF0C\u4EA7\u7269\u53EF\u80FD\u5C1A\u4E0D\u53EF\u7528");
|
|
3929
|
+
}
|
|
3930
|
+
const response = await client.download(download.downloadUrl, "EXPORT_DOWNLOAD_FAILED");
|
|
3931
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
3932
|
+
await writeFile5(outputPath, bytes);
|
|
3933
|
+
return { path: outputPath, size: bytes.length };
|
|
3934
|
+
}
|
|
3935
|
+
};
|
|
3696
3936
|
}
|
|
3697
|
-
var
|
|
3698
|
-
"
|
|
3937
|
+
var init_client2 = __esm({
|
|
3938
|
+
"src/export/client.ts"() {
|
|
3699
3939
|
"use strict";
|
|
3700
3940
|
init_auth();
|
|
3701
3941
|
init_client();
|
|
3702
3942
|
}
|
|
3703
3943
|
});
|
|
3704
3944
|
|
|
3705
|
-
//
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
return {
|
|
3734
|
-
projectId: project2.id,
|
|
3735
|
-
slug: project2.slug,
|
|
3736
|
-
baseUrl: `${project2.url.replace(/\/+$/, "")}${prefixBase}`,
|
|
3737
|
-
functions: result.functions
|
|
3738
|
-
};
|
|
3739
|
-
}
|
|
3740
|
-
async function functionsLogs(paths, options) {
|
|
3741
|
-
if (options.name === void 0 || options.name.trim().length === 0) {
|
|
3742
|
-
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11\u51FD\u6570\u540D\uFF1Aadep functions logs <name>");
|
|
3743
|
-
}
|
|
3744
|
-
const client = await createClient(paths);
|
|
3745
|
-
const project2 = await resolveProject(client, options);
|
|
3746
|
-
const listed = await client.request(
|
|
3747
|
-
`/api/v1/projects/${project2.id}/functions`,
|
|
3748
|
-
{},
|
|
3749
|
-
"FUNCTION_LIST_FAILED"
|
|
3750
|
-
);
|
|
3751
|
-
const target = listed.functions.find((fn) => fn.name === options.name);
|
|
3752
|
-
if (target === void 0) {
|
|
3753
|
-
throw new CliError("FN_NOT_FOUND", `\u51FD\u6570 "${options.name}" \u4E0D\u5B58\u5728\u4E8E\u9879\u76EE "${project2.slug}"`);
|
|
3945
|
+
// ../../shared/deploy-bundle/zip.ts
|
|
3946
|
+
function zipRead(buf) {
|
|
3947
|
+
const r = new Reader(buf);
|
|
3948
|
+
const eocd = findEocd(buf);
|
|
3949
|
+
if (eocd < 0) throw new ZipFormatError("\u627E\u4E0D\u5230 EOCD \u7B7E\u540D");
|
|
3950
|
+
const total = r.u16(eocd + 10);
|
|
3951
|
+
const centralOffset = r.u32(eocd + 16);
|
|
3952
|
+
const decoder = new TextDecoder();
|
|
3953
|
+
const out = /* @__PURE__ */ new Map();
|
|
3954
|
+
let cursor = centralOffset;
|
|
3955
|
+
for (let i = 0; i < total; i++) {
|
|
3956
|
+
if (cursor + 46 > buf.length) throw new ZipFormatError("\u4E2D\u592E\u76EE\u5F55\u8BB0\u5F55\u8D8A\u754C");
|
|
3957
|
+
if (r.u32(cursor) !== SIG_CENTRAL) throw new ZipFormatError("\u4E2D\u592E\u76EE\u5F55\u7B7E\u540D\u4E0D\u5339\u914D");
|
|
3958
|
+
const method = r.u16(cursor + 10);
|
|
3959
|
+
if (method !== 0) throw new ZipFormatError("\u4EC5\u652F\u6301 store \u578B\u6761\u76EE\u8BFB\u53D6");
|
|
3960
|
+
const compSize = r.u32(cursor + 20);
|
|
3961
|
+
const nameLen = r.u16(cursor + 28);
|
|
3962
|
+
const extraLen = r.u16(cursor + 30);
|
|
3963
|
+
const commentLen = r.u16(cursor + 32);
|
|
3964
|
+
const localHeaderOffset = r.u32(cursor + 42);
|
|
3965
|
+
if (localHeaderOffset + 30 > buf.length) throw new ZipFormatError("\u672C\u5730\u5934\u504F\u79FB\u8D8A\u754C");
|
|
3966
|
+
const name = decoder.decode(r.slice(cursor + 46, nameLen));
|
|
3967
|
+
const localNameLen = r.u16(localHeaderOffset + 26);
|
|
3968
|
+
const localExtraLen = r.u16(localHeaderOffset + 28);
|
|
3969
|
+
const dataStart = localHeaderOffset + 30 + localNameLen + localExtraLen;
|
|
3970
|
+
if (dataStart + compSize > buf.length) throw new ZipFormatError("\u6761\u76EE\u6570\u636E\u8D8A\u754C");
|
|
3971
|
+
if (!out.has(name)) out.set(name, r.slice(dataStart, compSize));
|
|
3972
|
+
cursor += 46 + nameLen + extraLen + commentLen;
|
|
3754
3973
|
}
|
|
3755
|
-
|
|
3756
|
-
const result = await client.request(
|
|
3757
|
-
`/api/v1/functions/${target.id}/logs${tail}`,
|
|
3758
|
-
{},
|
|
3759
|
-
"FUNCTION_LOGS_FAILED"
|
|
3760
|
-
);
|
|
3761
|
-
return { functionId: target.id, name: target.name, logs: result.logs };
|
|
3974
|
+
return out;
|
|
3762
3975
|
}
|
|
3763
|
-
|
|
3764
|
-
const
|
|
3765
|
-
const
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
throw new CliError(
|
|
3769
|
-
"PROJECT_NOT_FOUND",
|
|
3770
|
-
`\u5E73\u53F0\u9879\u76EE "${slug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650\uFF1A\u5148\u6267\u884C adep projects create ${slug}`
|
|
3771
|
-
);
|
|
3976
|
+
function findEocd(buf) {
|
|
3977
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
3978
|
+
const min = Math.max(0, buf.length - 65557);
|
|
3979
|
+
for (let i = buf.length - 22; i >= min; i--) {
|
|
3980
|
+
if (view.getUint32(i, true) === SIG_EOCD) return i;
|
|
3772
3981
|
}
|
|
3773
|
-
return
|
|
3774
|
-
}
|
|
3775
|
-
async function projectsListFrom(client) {
|
|
3776
|
-
const result = await client.request("/api/v1/projects", {}, "PROJECT_LIST_FAILED");
|
|
3777
|
-
return result.projects;
|
|
3982
|
+
return -1;
|
|
3778
3983
|
}
|
|
3779
|
-
var
|
|
3780
|
-
|
|
3984
|
+
var SIG_CENTRAL, SIG_EOCD, CRC_TABLE, Reader, ZipFormatError;
|
|
3985
|
+
var init_zip = __esm({
|
|
3986
|
+
"../../shared/deploy-bundle/zip.ts"() {
|
|
3781
3987
|
"use strict";
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3988
|
+
SIG_CENTRAL = 33639248;
|
|
3989
|
+
SIG_EOCD = 101010256;
|
|
3990
|
+
CRC_TABLE = (() => {
|
|
3991
|
+
const table = new Uint32Array(256);
|
|
3992
|
+
for (let i = 0; i < 256; i++) {
|
|
3993
|
+
let c = i;
|
|
3994
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
3995
|
+
table[i] = c >>> 0;
|
|
3996
|
+
}
|
|
3997
|
+
return table;
|
|
3998
|
+
})();
|
|
3999
|
+
Reader = class {
|
|
4000
|
+
constructor(buf) {
|
|
4001
|
+
this.buf = buf;
|
|
4002
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4003
|
+
}
|
|
4004
|
+
view;
|
|
4005
|
+
u16(offset) {
|
|
4006
|
+
return this.view.getUint16(offset, true);
|
|
4007
|
+
}
|
|
4008
|
+
u32(offset) {
|
|
4009
|
+
return this.view.getUint32(offset, true);
|
|
4010
|
+
}
|
|
4011
|
+
slice(start, length) {
|
|
4012
|
+
return this.buf.subarray(start, start + length);
|
|
4013
|
+
}
|
|
4014
|
+
};
|
|
4015
|
+
ZipFormatError = class extends Error {
|
|
4016
|
+
constructor(message) {
|
|
4017
|
+
super(`[appexport] \u975E\u6CD5 zip\uFF1A${message}`);
|
|
4018
|
+
this.name = "ZipFormatError";
|
|
4019
|
+
}
|
|
4020
|
+
};
|
|
3785
4021
|
}
|
|
3786
4022
|
});
|
|
3787
4023
|
|
|
3788
|
-
//
|
|
3789
|
-
var
|
|
3790
|
-
__export(
|
|
3791
|
-
|
|
3792
|
-
mcpPublish: () => mcpPublish,
|
|
3793
|
-
mcpUnpublish: () => mcpUnpublish
|
|
4024
|
+
// src/export/fs.ts
|
|
4025
|
+
var fs_exports = {};
|
|
4026
|
+
__export(fs_exports, {
|
|
4027
|
+
createExportFileSystem: () => createExportFileSystem
|
|
3794
4028
|
});
|
|
3795
|
-
import {
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
const client = await createClient(paths);
|
|
3799
|
-
const project2 = await resolveProject2(client, options);
|
|
3800
|
-
const target = await resolveFunction(client, project2, fn);
|
|
3801
|
-
const body = {};
|
|
3802
|
-
if (options.toolName !== void 0 && options.toolName.trim().length > 0) {
|
|
3803
|
-
body.toolName = options.toolName.trim();
|
|
3804
|
-
}
|
|
3805
|
-
if (options.description !== void 0 && options.description.length > 0) {
|
|
3806
|
-
body.description = options.description;
|
|
3807
|
-
}
|
|
3808
|
-
const tool = await client.request(
|
|
3809
|
-
`/api/v1/functions/${target.id}/mcp-publish`,
|
|
3810
|
-
{ method: "POST", ...Object.keys(body).length === 0 ? {} : { body } },
|
|
3811
|
-
"MCP_PUBLISH_FAILED"
|
|
3812
|
-
);
|
|
3813
|
-
return { projectId: project2.id, tool };
|
|
3814
|
-
}
|
|
3815
|
-
async function mcpUnpublish(paths, options) {
|
|
3816
|
-
const fn = requireFunctionName(options.fn);
|
|
3817
|
-
const client = await createClient(paths);
|
|
3818
|
-
const project2 = await resolveProject2(client, options);
|
|
3819
|
-
const target = await resolveFunction(client, project2, fn);
|
|
3820
|
-
const toolName = options.toolName?.trim() || fn;
|
|
3821
|
-
const result = await client.request(
|
|
3822
|
-
`/api/v1/functions/${target.id}/mcp-publish?tool=${encodeURIComponent(toolName)}`,
|
|
3823
|
-
{ method: "DELETE" },
|
|
3824
|
-
"MCP_UNPUBLISH_FAILED"
|
|
3825
|
-
);
|
|
3826
|
-
return { projectId: project2.id, toolName, removed: result.unpublished === true };
|
|
3827
|
-
}
|
|
3828
|
-
async function mcpList(paths, options) {
|
|
3829
|
-
const client = await createClient(paths);
|
|
3830
|
-
const project2 = await resolveProject2(client, options);
|
|
3831
|
-
const prefix = project2.functionsPrefix ?? "/api";
|
|
3832
|
-
const prefixBase = prefix.trim() === "/" ? "" : prefix.trim().replace(/\/+$/, "");
|
|
3833
|
-
const endpoint = `${project2.url.replace(/\/+$/, "")}${prefixBase}/mcp`;
|
|
3834
|
-
let response;
|
|
3835
|
-
try {
|
|
3836
|
-
response = await fetch(endpoint, {
|
|
3837
|
-
method: "POST",
|
|
3838
|
-
headers: { "content-type": "application/json", cookie: client.cookie },
|
|
3839
|
-
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })
|
|
3840
|
-
});
|
|
3841
|
-
} catch (error) {
|
|
3842
|
-
throw new CliError(
|
|
3843
|
-
"SERVER_UNREACHABLE",
|
|
3844
|
-
`\u65E0\u6CD5\u8FDE\u63A5 MCP \u7AEF\u70B9 ${endpoint}\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
3845
|
-
);
|
|
3846
|
-
}
|
|
3847
|
-
const parsed = await response.json().catch(() => null);
|
|
3848
|
-
if (!response.ok) {
|
|
3849
|
-
const envelope = parsed ?? null;
|
|
3850
|
-
throw new CliError(
|
|
3851
|
-
envelope?.error?.code ?? "MCP_LIST_FAILED",
|
|
3852
|
-
envelope?.error?.message ?? `MCP \u7AEF\u70B9\u8FD4\u56DE HTTP ${response.status}`
|
|
3853
|
-
);
|
|
3854
|
-
}
|
|
3855
|
-
const rpcError = parsed?.error;
|
|
3856
|
-
if (rpcError !== void 0) {
|
|
3857
|
-
throw new CliError(
|
|
3858
|
-
rpcError.code ?? "MCP_LIST_FAILED",
|
|
3859
|
-
rpcError.message ?? "MCP tools/list \u5931\u8D25"
|
|
3860
|
-
);
|
|
3861
|
-
}
|
|
3862
|
-
return {
|
|
3863
|
-
projectId: project2.id,
|
|
3864
|
-
slug: project2.slug,
|
|
3865
|
-
endpoint,
|
|
3866
|
-
tools: parsed?.result?.tools ?? []
|
|
3867
|
-
};
|
|
3868
|
-
}
|
|
3869
|
-
function requireFunctionName(fn) {
|
|
3870
|
-
if (fn === void 0 || fn.trim().length === 0) {
|
|
3871
|
-
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11\u51FD\u6570\u540D\uFF1Aadep mcp publish --function <fn>");
|
|
3872
|
-
}
|
|
3873
|
-
return fn.trim();
|
|
3874
|
-
}
|
|
3875
|
-
async function resolveProject2(client, options) {
|
|
3876
|
-
const slug = await resolveSlug(resolve7(options.cwd), options.slug);
|
|
3877
|
-
const listed = await client.request("/api/v1/projects", {}, "PROJECT_LIST_FAILED");
|
|
3878
|
-
const match = listed.projects.find((project2) => project2.slug === slug);
|
|
3879
|
-
if (match === void 0) {
|
|
3880
|
-
throw new CliError(
|
|
3881
|
-
"PROJECT_NOT_FOUND",
|
|
3882
|
-
`\u5E73\u53F0\u9879\u76EE "${slug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650\uFF1A\u5148\u6267\u884C adep projects create ${slug}`
|
|
3883
|
-
);
|
|
3884
|
-
}
|
|
4029
|
+
import { mkdir as mkdir7, readFile as readFile9, rm as rm3, stat as stat6, writeFile as writeFile6 } from "node:fs/promises";
|
|
4030
|
+
import { dirname as dirname6, join as join11 } from "node:path";
|
|
4031
|
+
function createExportFileSystem() {
|
|
3885
4032
|
return {
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
4033
|
+
readFile: (path) => readFile9(path),
|
|
4034
|
+
writeFile: (path, content) => writeFile6(path, content),
|
|
4035
|
+
// 同时用于清理解压临时目录(${zip}.tmp 是个目录)——递归强制删除,缺失不报错。
|
|
4036
|
+
deleteFile: async (path) => {
|
|
4037
|
+
await rm3(path, { recursive: true, force: true });
|
|
4038
|
+
},
|
|
4039
|
+
fileExists: async (path) => {
|
|
4040
|
+
try {
|
|
4041
|
+
await stat6(path);
|
|
4042
|
+
return true;
|
|
4043
|
+
} catch {
|
|
4044
|
+
return false;
|
|
4045
|
+
}
|
|
4046
|
+
},
|
|
4047
|
+
mkdir: async (path) => {
|
|
4048
|
+
await mkdir7(path, { recursive: true });
|
|
4049
|
+
},
|
|
4050
|
+
unzip: async (zipPath, targetDir) => {
|
|
4051
|
+
const entries = zipRead(await readFile9(zipPath));
|
|
4052
|
+
for (const [name, data] of entries) {
|
|
4053
|
+
const dest = join11(targetDir, name);
|
|
4054
|
+
await mkdir7(dirname6(dest), { recursive: true });
|
|
4055
|
+
await writeFile6(dest, data);
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
3890
4058
|
};
|
|
3891
4059
|
}
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
const target = listed.functions.find((fn) => fn.name === name);
|
|
3895
|
-
if (target === void 0) {
|
|
3896
|
-
throw new CliError("FN_NOT_FOUND", `\u51FD\u6570 "${name}" \u4E0D\u5B58\u5728\u4E8E\u9879\u76EE "${project2.slug}"`);
|
|
3897
|
-
}
|
|
3898
|
-
return { id: target.id, name: target.name };
|
|
3899
|
-
}
|
|
3900
|
-
var init_mcp = __esm({
|
|
3901
|
-
"packages/cli/src/mcp.ts"() {
|
|
4060
|
+
var init_fs = __esm({
|
|
4061
|
+
"src/export/fs.ts"() {
|
|
3902
4062
|
"use strict";
|
|
3903
|
-
|
|
3904
|
-
init_client();
|
|
4063
|
+
init_zip();
|
|
3905
4064
|
}
|
|
3906
4065
|
});
|
|
3907
4066
|
|
|
3908
|
-
//
|
|
3909
|
-
var
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
4067
|
+
// ../../shared/deploy-bundle/manifest.ts
|
|
4068
|
+
var CURRENT_SCHEMA_VERSION, BundleContentKind, ALLOWED_CONTENT_KINDS;
|
|
4069
|
+
var init_manifest2 = __esm({
|
|
4070
|
+
"../../shared/deploy-bundle/manifest.ts"() {
|
|
4071
|
+
"use strict";
|
|
4072
|
+
CURRENT_SCHEMA_VERSION = 2;
|
|
4073
|
+
BundleContentKind = {
|
|
4074
|
+
/** 云函数代码与配置。 */
|
|
4075
|
+
Functions: "functions",
|
|
4076
|
+
/** 数据库 schema 与种子数据。 */
|
|
4077
|
+
Database: "database",
|
|
4078
|
+
/** 前端静态资源。 */
|
|
4079
|
+
Web: "web",
|
|
4080
|
+
/** 运行时配置(Dockerfile / docker-compose.yml)。 */
|
|
4081
|
+
Runtime: "runtime",
|
|
4082
|
+
/** 启动 / 备份 / 恢复脚本。 */
|
|
4083
|
+
Scripts: "scripts",
|
|
4084
|
+
/** 文档(README / 部署手册)。 */
|
|
4085
|
+
Docs: "docs"
|
|
4086
|
+
};
|
|
4087
|
+
ALLOWED_CONTENT_KINDS = Object.values(BundleContentKind);
|
|
4088
|
+
}
|
|
3913
4089
|
});
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
const
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
return { reachable: true, status: response.status };
|
|
3921
|
-
} catch (error) {
|
|
4090
|
+
|
|
4091
|
+
// ../../shared/deploy-bundle/validate.ts
|
|
4092
|
+
function validateBundleManifest(manifest) {
|
|
4093
|
+
const errors = [];
|
|
4094
|
+
const warnings = [];
|
|
4095
|
+
if (typeof manifest !== "object" || manifest === null) {
|
|
3922
4096
|
return {
|
|
3923
|
-
|
|
3924
|
-
|
|
4097
|
+
valid: false,
|
|
4098
|
+
errors: [{ code: "INVALID_TYPE", message: "Manifest \u5FC5\u987B\u662F\u5BF9\u8C61" }],
|
|
4099
|
+
warnings: []
|
|
3925
4100
|
};
|
|
3926
|
-
} finally {
|
|
3927
|
-
clearTimeout(timer);
|
|
3928
4101
|
}
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
4102
|
+
const m = manifest;
|
|
4103
|
+
const schemaVersion = m.schemaVersion;
|
|
4104
|
+
if (typeof schemaVersion !== "number" || !Number.isInteger(schemaVersion)) {
|
|
4105
|
+
errors.push({
|
|
4106
|
+
code: "INVALID_SCHEMA_VERSION",
|
|
4107
|
+
message: "schemaVersion \u5FC5\u987B\u662F\u6574\u6570",
|
|
4108
|
+
field: "schemaVersion"
|
|
4109
|
+
});
|
|
4110
|
+
} else if (schemaVersion > CURRENT_SCHEMA_VERSION) {
|
|
4111
|
+
errors.push({
|
|
4112
|
+
code: "SCHEMA_VERSION_TOO_HIGH",
|
|
4113
|
+
message: `schemaVersion ${schemaVersion} \u9AD8\u4E8E\u5F53\u524D\u652F\u6301\u7248\u672C ${CURRENT_SCHEMA_VERSION}\uFF0C\u9700\u5347\u7EA7\u5BFC\u51FA\u7AEF`,
|
|
4114
|
+
field: "schemaVersion"
|
|
4115
|
+
});
|
|
4116
|
+
} else if (schemaVersion < CURRENT_SCHEMA_VERSION) {
|
|
4117
|
+
warnings.push({
|
|
4118
|
+
code: "SCHEMA_VERSION_LOW",
|
|
4119
|
+
message: `schemaVersion ${schemaVersion} \u4F4E\u4E8E\u5F53\u524D\u7248\u672C ${CURRENT_SCHEMA_VERSION}\uFF0C\u5EFA\u8BAE\u91CD\u65B0\u5BFC\u51FA`,
|
|
4120
|
+
field: "schemaVersion"
|
|
4121
|
+
});
|
|
3936
4122
|
}
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
const health = await probeServer(server);
|
|
3944
|
-
const report = {
|
|
3945
|
-
server,
|
|
3946
|
-
credentials: {
|
|
3947
|
-
file: paths.credentialsFile,
|
|
3948
|
-
present: credentials !== null,
|
|
3949
|
-
...mode === void 0 ? {} : { mode }
|
|
3950
|
-
},
|
|
3951
|
-
network: { offline },
|
|
3952
|
-
serverHealth: health,
|
|
3953
|
-
offlineCommands: [...OFFLINE_COMMANDS],
|
|
3954
|
-
boundaries: SIM_BOUNDARIES.map((b) => ({ kind: b.kind, title: b.title, detail: b.detail }))
|
|
3955
|
-
};
|
|
3956
|
-
if (credentials !== null) report.credentials.email = credentials.email;
|
|
3957
|
-
if (mode !== void 0 && mode !== "600") {
|
|
3958
|
-
report.credentials.warning = `\u6743\u9650 ${mode} \u5BBD\u4E8E 0600\uFF0C\u5EFA\u8BAE chmod 600 ${paths.credentialsFile}`;
|
|
4123
|
+
if (typeof m.platformVersion !== "string" || m.platformVersion.trim() === "") {
|
|
4124
|
+
errors.push({
|
|
4125
|
+
code: "MISSING_PLATFORM_VERSION",
|
|
4126
|
+
message: "platformVersion \u5FC5\u987B\u975E\u7A7A",
|
|
4127
|
+
field: "platformVersion"
|
|
4128
|
+
});
|
|
3959
4129
|
}
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
lines.push(` \u2713 \u5DF2\u767B\u5F55 ${report.credentials.email ?? "(\u672A\u77E5\u90AE\u7BB1)"} @ ${report.server}`);
|
|
3967
|
-
lines.push(
|
|
3968
|
-
` \xB7 \u51ED\u636E\u6587\u4EF6 ${report.credentials.file}\uFF08${report.credentials.mode ?? "\u6743\u9650\u672A\u77E5"}\uFF09`
|
|
3969
|
-
);
|
|
3970
|
-
if (report.credentials.warning !== void 0) lines.push(` ! ${report.credentials.warning}`);
|
|
4130
|
+
if (typeof m.project !== "object" || m.project === null) {
|
|
4131
|
+
errors.push({
|
|
4132
|
+
code: "MISSING_PROJECT",
|
|
4133
|
+
message: "project \u5FC5\u987B\u662F\u5BF9\u8C61",
|
|
4134
|
+
field: "project"
|
|
4135
|
+
});
|
|
3971
4136
|
} else {
|
|
3972
|
-
|
|
3973
|
-
|
|
4137
|
+
const project2 = m.project;
|
|
4138
|
+
if (typeof project2.id !== "string" || project2.id.trim() === "") {
|
|
4139
|
+
errors.push({
|
|
4140
|
+
code: "MISSING_PROJECT_ID",
|
|
4141
|
+
message: "project.id \u5FC5\u987B\u975E\u7A7A",
|
|
4142
|
+
field: "project.id"
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
if (typeof project2.name !== "string" || project2.name.trim() === "") {
|
|
4146
|
+
errors.push({
|
|
4147
|
+
code: "MISSING_PROJECT_NAME",
|
|
4148
|
+
message: "project.name \u5FC5\u987B\u975E\u7A7A",
|
|
4149
|
+
field: "project.name"
|
|
4150
|
+
});
|
|
4151
|
+
}
|
|
4152
|
+
if (typeof project2.slug !== "string" || project2.slug.trim() === "") {
|
|
4153
|
+
errors.push({
|
|
4154
|
+
code: "MISSING_PROJECT_SLUG",
|
|
4155
|
+
message: "project.slug \u5FC5\u987B\u975E\u7A7A",
|
|
4156
|
+
field: "project.slug"
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
if (typeof project2.version !== "number" || !Number.isInteger(project2.version) || project2.version < 1) {
|
|
4160
|
+
errors.push({
|
|
4161
|
+
code: "INVALID_PROJECT_VERSION",
|
|
4162
|
+
message: "project.version \u5FC5\u987B\u662F\u6B63\u6574\u6570",
|
|
4163
|
+
field: "project.version"
|
|
4164
|
+
});
|
|
4165
|
+
}
|
|
3974
4166
|
}
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
4167
|
+
if (!Array.isArray(m.contents)) {
|
|
4168
|
+
errors.push({
|
|
4169
|
+
code: "MISSING_CONTENTS",
|
|
4170
|
+
message: "contents \u5FC5\u987B\u662F\u6570\u7EC4",
|
|
4171
|
+
field: "contents"
|
|
4172
|
+
});
|
|
4173
|
+
} else if (m.contents.length === 0) {
|
|
4174
|
+
errors.push({
|
|
4175
|
+
code: "EMPTY_CONTENTS",
|
|
4176
|
+
message: "contents \u4E0D\u80FD\u4E3A\u7A7A",
|
|
4177
|
+
field: "contents"
|
|
4178
|
+
});
|
|
3981
4179
|
} else {
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
);
|
|
4180
|
+
m.contents.forEach((content, index) => {
|
|
4181
|
+
validateContent(content, index, errors, warnings);
|
|
4182
|
+
});
|
|
3986
4183
|
}
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
4184
|
+
if (typeof m.runtime !== "object" || m.runtime === null) {
|
|
4185
|
+
errors.push({
|
|
4186
|
+
code: "MISSING_RUNTIME",
|
|
4187
|
+
message: "runtime \u5FC5\u987B\u662F\u5BF9\u8C61",
|
|
4188
|
+
field: "runtime"
|
|
4189
|
+
});
|
|
4190
|
+
} else {
|
|
4191
|
+
const runtime = m.runtime;
|
|
4192
|
+
if (typeof runtime.engine !== "string" || runtime.engine.trim() === "") {
|
|
4193
|
+
errors.push({
|
|
4194
|
+
code: "MISSING_ENGINE",
|
|
4195
|
+
message: "runtime.engine \u5FC5\u987B\u975E\u7A7A",
|
|
4196
|
+
field: "runtime.engine"
|
|
4197
|
+
});
|
|
4198
|
+
}
|
|
4199
|
+
if (typeof runtime.engineVersion !== "string" || runtime.engineVersion.trim() === "") {
|
|
4200
|
+
errors.push({
|
|
4201
|
+
code: "MISSING_ENGINE_VERSION",
|
|
4202
|
+
message: "runtime.engineVersion \u5FC5\u987B\u975E\u7A7A",
|
|
4203
|
+
field: "runtime.engineVersion"
|
|
4204
|
+
});
|
|
4205
|
+
}
|
|
4206
|
+
if (typeof runtime.port !== "number" || !Number.isInteger(runtime.port) || runtime.port < 1 || runtime.port > 65535) {
|
|
4207
|
+
errors.push({
|
|
4208
|
+
code: "INVALID_PORT",
|
|
4209
|
+
message: "runtime.port \u5FC5\u987B\u662F 1-65535 \u7684\u6574\u6570",
|
|
4210
|
+
field: "runtime.port"
|
|
4211
|
+
});
|
|
4212
|
+
}
|
|
4213
|
+
if (typeof runtime.startCommand !== "string" || runtime.startCommand.trim() === "") {
|
|
4214
|
+
errors.push({
|
|
4215
|
+
code: "MISSING_START_COMMAND",
|
|
4216
|
+
message: "runtime.startCommand \u5FC5\u987B\u975E\u7A7A",
|
|
4217
|
+
field: "runtime.startCommand"
|
|
4218
|
+
});
|
|
4219
|
+
}
|
|
3992
4220
|
}
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
"adep db\uFF08\u672C\u5730\u6A21\u62DF\uFF09",
|
|
4009
|
-
"adep doctor"
|
|
4010
|
-
];
|
|
4221
|
+
if (typeof m.exportedAt !== "string" || m.exportedAt.trim() === "") {
|
|
4222
|
+
errors.push({
|
|
4223
|
+
code: "MISSING_EXPORTED_AT",
|
|
4224
|
+
message: "exportedAt \u5FC5\u987B\u975E\u7A7A",
|
|
4225
|
+
field: "exportedAt"
|
|
4226
|
+
});
|
|
4227
|
+
} else {
|
|
4228
|
+
const date = new Date(m.exportedAt);
|
|
4229
|
+
if (Number.isNaN(date.getTime())) {
|
|
4230
|
+
errors.push({
|
|
4231
|
+
code: "INVALID_EXPORTED_AT",
|
|
4232
|
+
message: "exportedAt \u5FC5\u987B\u662F\u6709\u6548\u7684 ISO 8601 \u65F6\u95F4",
|
|
4233
|
+
field: "exportedAt"
|
|
4234
|
+
});
|
|
4235
|
+
}
|
|
4011
4236
|
}
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
dbExec: () => dbExec,
|
|
4018
|
-
dbRollback: () => dbRollback,
|
|
4019
|
-
dbSnapshotCreate: () => dbSnapshotCreate,
|
|
4020
|
-
dbSnapshotList: () => dbSnapshotList,
|
|
4021
|
-
dbSnapshotRestore: () => dbSnapshotRestore,
|
|
4022
|
-
dbStart: () => dbStart,
|
|
4023
|
-
dbStatus: () => dbStatus,
|
|
4024
|
-
dbStop: () => dbStop
|
|
4025
|
-
});
|
|
4026
|
-
import { resolve as resolve8 } from "node:path";
|
|
4027
|
-
async function open2(paths, options) {
|
|
4028
|
-
const client = await createClient(paths);
|
|
4029
|
-
const project2 = await resolveSlug(resolve8(options.cwd), options.slug);
|
|
4030
|
-
return { client, project: project2 };
|
|
4031
|
-
}
|
|
4032
|
-
async function dbStart(paths, options) {
|
|
4033
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4034
|
-
return client.request(`/api/v1/projects/${project2}/database`, { method: "POST" });
|
|
4035
|
-
}
|
|
4036
|
-
async function dbStatus(paths, options) {
|
|
4037
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4038
|
-
return client.request(`/api/v1/projects/${project2}/database`);
|
|
4039
|
-
}
|
|
4040
|
-
async function dbStop(paths, options) {
|
|
4041
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4042
|
-
return client.request(`/api/v1/projects/${project2}/database`, {
|
|
4043
|
-
method: "DELETE"
|
|
4044
|
-
});
|
|
4237
|
+
return {
|
|
4238
|
+
valid: errors.length === 0,
|
|
4239
|
+
errors,
|
|
4240
|
+
warnings
|
|
4241
|
+
};
|
|
4045
4242
|
}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
...options.params === void 0 ? {} : { params: options.params },
|
|
4055
|
-
...options.confirmTable === void 0 ? {} : { confirmTable: options.confirmTable }
|
|
4056
|
-
}
|
|
4057
|
-
},
|
|
4058
|
-
"SQL_EXEC_FAILED"
|
|
4059
|
-
);
|
|
4060
|
-
}
|
|
4061
|
-
async function dbSnapshotList(paths, options) {
|
|
4062
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4063
|
-
return client.request(
|
|
4064
|
-
`/api/v1/projects/${project2}/database/snapshots`
|
|
4065
|
-
);
|
|
4066
|
-
}
|
|
4067
|
-
async function dbSnapshotCreate(paths, options) {
|
|
4068
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4069
|
-
return client.request(`/api/v1/projects/${project2}/database/snapshots`, {
|
|
4070
|
-
method: "POST"
|
|
4071
|
-
});
|
|
4072
|
-
}
|
|
4073
|
-
async function dbSnapshotRestore(paths, options) {
|
|
4074
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4075
|
-
return client.request(
|
|
4076
|
-
`/api/v1/projects/${project2}/database/snapshots/${options.snapshotId}/restore`,
|
|
4077
|
-
{ method: "POST" }
|
|
4078
|
-
);
|
|
4079
|
-
}
|
|
4080
|
-
async function dbRollback(paths, options) {
|
|
4081
|
-
const { client, project: project2 } = await open2(paths, options);
|
|
4082
|
-
return client.request(
|
|
4083
|
-
`/api/v1/projects/${project2}/database/rollback`,
|
|
4084
|
-
{ method: "POST", body: { to: options.to } }
|
|
4085
|
-
);
|
|
4086
|
-
}
|
|
4087
|
-
var init_db2 = __esm({
|
|
4088
|
-
"packages/cli/src/db.ts"() {
|
|
4089
|
-
"use strict";
|
|
4090
|
-
init_client();
|
|
4243
|
+
function validateContent(content, index, errors, _warnings) {
|
|
4244
|
+
if (typeof content !== "object" || content === null) {
|
|
4245
|
+
errors.push({
|
|
4246
|
+
code: "INVALID_CONTENT",
|
|
4247
|
+
message: `contents[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61`,
|
|
4248
|
+
field: `contents[${index}]`
|
|
4249
|
+
});
|
|
4250
|
+
return;
|
|
4091
4251
|
}
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
storageList: () => storageList,
|
|
4100
|
-
storageRemove: () => storageRemove,
|
|
4101
|
-
storageUpload: () => storageUpload
|
|
4102
|
-
});
|
|
4103
|
-
import { mkdir as mkdir7, readFile as readFile8, stat as stat7, writeFile as writeFile5 } from "node:fs/promises";
|
|
4104
|
-
import { basename as basename3, dirname as dirname6, extname, join as join10, resolve as resolve9 } from "node:path";
|
|
4105
|
-
async function open3(paths, options) {
|
|
4106
|
-
const client = await createClient(paths);
|
|
4107
|
-
const project2 = await resolveSlug(resolve9(options.cwd), options.slug);
|
|
4108
|
-
return { client, project: project2 };
|
|
4109
|
-
}
|
|
4110
|
-
function contentTypeOf(path) {
|
|
4111
|
-
const map = {
|
|
4112
|
-
".html": "text/html; charset=utf-8",
|
|
4113
|
-
".htm": "text/html; charset=utf-8",
|
|
4114
|
-
".css": "text/css; charset=utf-8",
|
|
4115
|
-
".js": "text/javascript; charset=utf-8",
|
|
4116
|
-
".mjs": "text/javascript; charset=utf-8",
|
|
4117
|
-
".json": "application/json; charset=utf-8",
|
|
4118
|
-
".png": "image/png",
|
|
4119
|
-
".jpg": "image/jpeg",
|
|
4120
|
-
".jpeg": "image/jpeg",
|
|
4121
|
-
".gif": "image/gif",
|
|
4122
|
-
".svg": "image/svg+xml",
|
|
4123
|
-
".webp": "image/webp",
|
|
4124
|
-
".ico": "image/x-icon",
|
|
4125
|
-
".txt": "text/plain; charset=utf-8",
|
|
4126
|
-
".md": "text/markdown; charset=utf-8",
|
|
4127
|
-
".xml": "application/xml",
|
|
4128
|
-
".wasm": "application/wasm",
|
|
4129
|
-
".pdf": "application/pdf",
|
|
4130
|
-
".zip": "application/zip",
|
|
4131
|
-
".woff": "font/woff",
|
|
4132
|
-
".woff2": "font/woff2",
|
|
4133
|
-
".ttf": "font/ttf",
|
|
4134
|
-
".otf": "font/otf"
|
|
4135
|
-
};
|
|
4136
|
-
return map[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
4137
|
-
}
|
|
4138
|
-
async function storageUpload(paths, options) {
|
|
4139
|
-
const { client, project: project2 } = await open3(paths, options);
|
|
4140
|
-
const local = resolve9(options.file);
|
|
4141
|
-
const info = await stat7(local).catch(() => null);
|
|
4142
|
-
if (info === null || !info.isFile()) {
|
|
4143
|
-
throw new CliError("FILE_NOT_FOUND", `\u672C\u5730\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${local}`);
|
|
4252
|
+
const c = content;
|
|
4253
|
+
if (typeof c.path !== "string" || c.path.trim() === "") {
|
|
4254
|
+
errors.push({
|
|
4255
|
+
code: "MISSING_CONTENT_PATH",
|
|
4256
|
+
message: `contents[${index}].path \u5FC5\u987B\u975E\u7A7A`,
|
|
4257
|
+
field: `contents[${index}].path`
|
|
4258
|
+
});
|
|
4144
4259
|
}
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
}
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
}
|
|
4171
|
-
async function resolveDownloadUrl(client, project2, path) {
|
|
4172
|
-
const body = await client.request(
|
|
4173
|
-
`/api/v1/projects/${project2}/files?prefix=${encodeURIComponent(path)}`
|
|
4174
|
-
);
|
|
4175
|
-
const entry = body.files.find((file) => file.path === path);
|
|
4176
|
-
const url = entry?.url ?? entry?.signedUrl;
|
|
4177
|
-
if (entry === void 0 || url === void 0 || url.length === 0) {
|
|
4178
|
-
throw new CliError("STORAGE_NOT_FOUND", `\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${path}`);
|
|
4260
|
+
if (typeof c.sha256 !== "string" || c.sha256.trim() === "") {
|
|
4261
|
+
errors.push({
|
|
4262
|
+
code: "MISSING_CONTENT_SHA256",
|
|
4263
|
+
message: `contents[${index}].sha256 \u5FC5\u987B\u975E\u7A7A`,
|
|
4264
|
+
field: `contents[${index}].sha256`
|
|
4265
|
+
});
|
|
4266
|
+
} else if (!/^[a-fA-F0-9]{64}$/.test(c.sha256)) {
|
|
4267
|
+
errors.push({
|
|
4268
|
+
code: "INVALID_SHA256_FORMAT",
|
|
4269
|
+
message: `contents[${index}].sha256 \u5FC5\u987B\u662F 64 \u5B57\u7B26\u5341\u516D\u8FDB\u5236`,
|
|
4270
|
+
field: `contents[${index}].sha256`
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
if (typeof c.kind !== "string" || c.kind.trim() === "") {
|
|
4274
|
+
errors.push({
|
|
4275
|
+
code: "MISSING_CONTENT_KIND",
|
|
4276
|
+
message: `contents[${index}].kind \u5FC5\u987B\u975E\u7A7A`,
|
|
4277
|
+
field: `contents[${index}].kind`
|
|
4278
|
+
});
|
|
4279
|
+
} else if (!ALLOWED_CONTENT_KINDS.includes(c.kind)) {
|
|
4280
|
+
errors.push({
|
|
4281
|
+
code: "INVALID_CONTENT_KIND",
|
|
4282
|
+
message: `contents[${index}].kind "${c.kind}" \u4E0D\u5728\u5141\u8BB8\u5217\u8868\u5185\uFF0C\u5141\u8BB8\u503C\uFF1A${ALLOWED_CONTENT_KINDS.join(", ")}`,
|
|
4283
|
+
field: `contents[${index}].kind`
|
|
4284
|
+
});
|
|
4179
4285
|
}
|
|
4180
|
-
return url;
|
|
4181
|
-
}
|
|
4182
|
-
async function storageDownload(paths, options) {
|
|
4183
|
-
const { client, project: project2 } = await open3(paths, options);
|
|
4184
|
-
const url = await resolveDownloadUrl(client, project2, options.path);
|
|
4185
|
-
const response = await client.download(url, "STORAGE_DOWNLOAD_FAILED");
|
|
4186
|
-
const bytes = Buffer.from(await response.arrayBuffer());
|
|
4187
|
-
const output = resolve9(options.output ?? join10(resolve9(options.cwd), basename3(options.path)));
|
|
4188
|
-
await mkdir7(dirname6(output), { recursive: true });
|
|
4189
|
-
await writeFile5(output, bytes);
|
|
4190
|
-
return { path: options.path, output, size: bytes.length };
|
|
4191
4286
|
}
|
|
4192
|
-
|
|
4193
|
-
const
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4287
|
+
function verifyContents(contents, actualContents, hashFunction) {
|
|
4288
|
+
const errors = [];
|
|
4289
|
+
const warnings = [];
|
|
4290
|
+
for (const content of contents) {
|
|
4291
|
+
const actual = actualContents.get(content.path);
|
|
4292
|
+
if (actual === void 0) {
|
|
4293
|
+
errors.push({
|
|
4294
|
+
code: "CONTENT_NOT_FOUND",
|
|
4295
|
+
message: `\u5185\u5BB9\u7269 ${content.path} \u5728\u5B9E\u9645\u5305\u4E2D\u4E0D\u5B58\u5728`,
|
|
4296
|
+
field: `contents[${content.path}]`
|
|
4297
|
+
});
|
|
4298
|
+
continue;
|
|
4299
|
+
}
|
|
4300
|
+
const actualHash = hashFunction(actual);
|
|
4301
|
+
if (actualHash.toLowerCase() !== content.sha256.toLowerCase()) {
|
|
4302
|
+
errors.push({
|
|
4303
|
+
code: "CHECKSUM_MISMATCH",
|
|
4304
|
+
message: `\u5185\u5BB9\u7269 ${content.path} \u7684\u6821\u9A8C\u548C\u4E0D\u5339\u914D\uFF1A\u671F\u671B ${content.sha256}\uFF0C\u5B9E\u9645 ${actualHash}`,
|
|
4305
|
+
field: `contents[${content.path}].sha256`
|
|
4306
|
+
});
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
for (const path of actualContents.keys()) {
|
|
4310
|
+
if (!contents.some((c) => c.path === path)) {
|
|
4311
|
+
warnings.push({
|
|
4312
|
+
code: "UNDECLARED_CONTENT",
|
|
4313
|
+
message: `\u5B9E\u9645\u5305\u4E2D\u5B58\u5728 Manifest \u672A\u58F0\u660E\u7684\u5185\u5BB9\uFF1A${path}`,
|
|
4314
|
+
field: `contents[${path}]`
|
|
4315
|
+
});
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
return {
|
|
4319
|
+
valid: errors.length === 0,
|
|
4320
|
+
errors,
|
|
4321
|
+
warnings
|
|
4322
|
+
};
|
|
4198
4323
|
}
|
|
4199
|
-
var
|
|
4200
|
-
"
|
|
4324
|
+
var init_validate = __esm({
|
|
4325
|
+
"../../shared/deploy-bundle/validate.ts"() {
|
|
4201
4326
|
"use strict";
|
|
4202
|
-
|
|
4203
|
-
init_auth();
|
|
4327
|
+
init_manifest2();
|
|
4204
4328
|
}
|
|
4205
4329
|
});
|
|
4206
4330
|
|
|
4207
|
-
//
|
|
4208
|
-
var
|
|
4209
|
-
__export(
|
|
4210
|
-
|
|
4211
|
-
hostingDeploy: () => hostingDeploy,
|
|
4212
|
-
hostingInfo: () => hostingInfo,
|
|
4213
|
-
hostingPull: () => hostingPull
|
|
4331
|
+
// src/export/command.ts
|
|
4332
|
+
var command_exports = {};
|
|
4333
|
+
__export(command_exports, {
|
|
4334
|
+
ExportCommand: () => ExportCommand
|
|
4214
4335
|
});
|
|
4215
|
-
import {
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4336
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4337
|
+
var ExportCommand;
|
|
4338
|
+
var init_command = __esm({
|
|
4339
|
+
"src/export/command.ts"() {
|
|
4340
|
+
"use strict";
|
|
4341
|
+
init_validate();
|
|
4342
|
+
ExportCommand = class {
|
|
4343
|
+
constructor(apiClient, fs, pollInterval = 2e3, maxPollAttempts = 300) {
|
|
4344
|
+
this.apiClient = apiClient;
|
|
4345
|
+
this.fs = fs;
|
|
4346
|
+
this.pollInterval = pollInterval;
|
|
4347
|
+
this.maxPollAttempts = maxPollAttempts;
|
|
4348
|
+
}
|
|
4349
|
+
/**
|
|
4350
|
+
* 执行导出命令。
|
|
4351
|
+
*
|
|
4352
|
+
* @param options 命令选项
|
|
4353
|
+
* @returns 导出结果
|
|
4354
|
+
*/
|
|
4355
|
+
async execute(options) {
|
|
4356
|
+
const projectId = options.project ?? "default";
|
|
4357
|
+
const outputDir = options.out ?? "./exports";
|
|
4358
|
+
const jsonOutput = options.json ?? false;
|
|
4359
|
+
try {
|
|
4360
|
+
if (!jsonOutput) {
|
|
4361
|
+
console.log(`\u89E6\u53D1\u5BFC\u51FA\uFF1A\u9879\u76EE ${projectId}`);
|
|
4362
|
+
}
|
|
4363
|
+
const job = await this.apiClient.triggerExport(projectId, {
|
|
4364
|
+
withData: options.withData,
|
|
4365
|
+
withSource: options.withSource,
|
|
4366
|
+
withoutSource: options.withoutSource
|
|
4367
|
+
});
|
|
4368
|
+
if (!jsonOutput) {
|
|
4369
|
+
console.log(`\u5BFC\u51FA\u4EFB\u52A1\u5DF2\u521B\u5EFA\uFF1A${job.id}`);
|
|
4370
|
+
}
|
|
4371
|
+
const completedJob = await this.pollJobStatus(job.id, jsonOutput);
|
|
4372
|
+
if (completedJob.status === "failed") {
|
|
4373
|
+
return {
|
|
4374
|
+
success: false,
|
|
4375
|
+
jobId: job.id,
|
|
4376
|
+
status: "failed",
|
|
4377
|
+
error: completedJob.error ?? "\u5BFC\u51FA\u5931\u8D25"
|
|
4378
|
+
};
|
|
4379
|
+
}
|
|
4380
|
+
if (!jsonOutput) {
|
|
4381
|
+
console.log("\u4E0B\u8F7D\u5BFC\u51FA\u4EA7\u7269...");
|
|
4382
|
+
}
|
|
4383
|
+
const outputPath = `${outputDir}/${projectId}-export-${Date.now()}.zip`;
|
|
4384
|
+
await this.fs.mkdir(outputDir);
|
|
4385
|
+
const downloadResult = await this.apiClient.downloadBundle(job.id, outputPath);
|
|
4386
|
+
if (!jsonOutput) {
|
|
4387
|
+
console.log(`\u4EA7\u7269\u5DF2\u4E0B\u8F7D\uFF1A${downloadResult.path}\uFF08${this.formatSize(downloadResult.size)}\uFF09`);
|
|
4388
|
+
}
|
|
4389
|
+
if (!jsonOutput) {
|
|
4390
|
+
console.log("\u6267\u884C manifest \u81EA\u68C0...");
|
|
4391
|
+
}
|
|
4392
|
+
const manifest = await this.verifyManifest(downloadResult.path);
|
|
4393
|
+
if (!jsonOutput) {
|
|
4394
|
+
this.printContentList(manifest);
|
|
4395
|
+
}
|
|
4396
|
+
return {
|
|
4397
|
+
success: true,
|
|
4398
|
+
jobId: job.id,
|
|
4399
|
+
status: "completed",
|
|
4400
|
+
downloadPath: downloadResult.path,
|
|
4401
|
+
manifest: {
|
|
4402
|
+
projectName: manifest.project.name,
|
|
4403
|
+
platformVersion: manifest.platformVersion,
|
|
4404
|
+
exportedAt: manifest.exportedAt,
|
|
4405
|
+
contents: this.countContents(manifest.contents)
|
|
4406
|
+
}
|
|
4407
|
+
};
|
|
4408
|
+
} catch (error) {
|
|
4409
|
+
const message = error instanceof Error ? error.message : "unknown_error";
|
|
4410
|
+
if (message.includes("ECONNREFUSED") || message.includes("ENOTFOUND") || message.includes("network")) {
|
|
4411
|
+
return {
|
|
4412
|
+
success: false,
|
|
4413
|
+
error: `\u5E73\u53F0\u7AEF\u70B9\u4E0D\u53EF\u8FBE\uFF1A${message}\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u548C\u5E73\u53F0\u5730\u5740\u914D\u7F6E\uFF0C\u7136\u540E\u91CD\u8BD5\u3002`
|
|
4414
|
+
};
|
|
4415
|
+
}
|
|
4416
|
+
return {
|
|
4417
|
+
success: false,
|
|
4418
|
+
error: message
|
|
4419
|
+
};
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
/**
|
|
4423
|
+
* 轮询任务状态。
|
|
4424
|
+
*
|
|
4425
|
+
* @param jobId 任务 ID
|
|
4426
|
+
* @param jsonOutput 是否 JSON 输出
|
|
4427
|
+
* @returns 完成的任务
|
|
4428
|
+
*/
|
|
4429
|
+
async pollJobStatus(jobId, jsonOutput) {
|
|
4430
|
+
let attempts = 0;
|
|
4431
|
+
let lastProgress = -1;
|
|
4432
|
+
while (attempts < this.maxPollAttempts) {
|
|
4433
|
+
const job = await this.apiClient.getJobStatus(jobId);
|
|
4434
|
+
if (!jsonOutput && job.progress !== lastProgress) {
|
|
4435
|
+
const stage = job.stage ? `\uFF08${job.stage}\uFF09` : "";
|
|
4436
|
+
console.log(`\u8FDB\u5EA6\uFF1A${job.progress}%${stage}`);
|
|
4437
|
+
lastProgress = job.progress;
|
|
4438
|
+
}
|
|
4439
|
+
if (job.status === "completed" || job.status === "failed") {
|
|
4440
|
+
return job;
|
|
4441
|
+
}
|
|
4442
|
+
attempts++;
|
|
4443
|
+
await this.sleep(this.pollInterval);
|
|
4444
|
+
}
|
|
4445
|
+
throw new Error(`\u5BFC\u51FA\u4EFB\u52A1\u8D85\u65F6\uFF1A\u8F6E\u8BE2 ${this.maxPollAttempts} \u6B21\u540E\u4ECD\u672A\u5B8C\u6210`);
|
|
4446
|
+
}
|
|
4447
|
+
/**
|
|
4448
|
+
* 验证 Manifest:解压 → 契约校验 → 逐项 sha256 校验 → 清理临时目录。
|
|
4449
|
+
*
|
|
4450
|
+
* 逐项校验与导出端同法:内容物以 latin1 承载(逐字节双射,二进制条目不被解码改写),
|
|
4451
|
+
* 比对时对原字节做真实 sha256;任一不匹配即判定包损坏并抛错,不静默放行。
|
|
4452
|
+
* 无论成功失败,`${zip}.tmp` 临时目录都在 finally 里删除,不留残余。
|
|
4453
|
+
*
|
|
4454
|
+
* @param zipPath ZIP 文件路径
|
|
4455
|
+
* @returns Manifest
|
|
4456
|
+
*/
|
|
4457
|
+
async verifyManifest(zipPath) {
|
|
4458
|
+
const tempDir = `${zipPath}.tmp`;
|
|
4459
|
+
try {
|
|
4460
|
+
await this.fs.mkdir(tempDir);
|
|
4461
|
+
await this.fs.unzip(zipPath, tempDir);
|
|
4462
|
+
const manifestPath = `${tempDir}/manifest.json`;
|
|
4463
|
+
if (!await this.fs.fileExists(manifestPath)) {
|
|
4464
|
+
throw new Error("manifest.json \u4E0D\u5B58\u5728\uFF0C\u5305\u53EF\u80FD\u5DF2\u635F\u574F");
|
|
4465
|
+
}
|
|
4466
|
+
const manifestContent = await this.fs.readFile(manifestPath);
|
|
4467
|
+
const manifest = JSON.parse(manifestContent.toString("utf-8"));
|
|
4468
|
+
const validationResult = validateBundleManifest(manifest);
|
|
4469
|
+
if (!validationResult.valid) {
|
|
4470
|
+
const errors = validationResult.errors.map((e) => `${e.field ?? ""}: ${e.message}`).join("\n");
|
|
4471
|
+
throw new Error(`manifest \u6821\u9A8C\u5931\u8D25\uFF1A
|
|
4472
|
+
${errors}`);
|
|
4473
|
+
}
|
|
4474
|
+
const actual = /* @__PURE__ */ new Map();
|
|
4475
|
+
for (const content of manifest.contents) {
|
|
4476
|
+
const filePath = `${tempDir}/${content.path}`;
|
|
4477
|
+
if (await this.fs.fileExists(filePath)) {
|
|
4478
|
+
const bytes = await this.fs.readFile(filePath);
|
|
4479
|
+
actual.set(content.path, bytes.toString("latin1"));
|
|
4480
|
+
}
|
|
4481
|
+
}
|
|
4482
|
+
const contentResult = verifyContents(
|
|
4483
|
+
manifest.contents,
|
|
4484
|
+
actual,
|
|
4485
|
+
(text) => createHash3("sha256").update(Buffer.from(text, "latin1")).digest("hex")
|
|
4486
|
+
);
|
|
4487
|
+
if (!contentResult.valid) {
|
|
4488
|
+
const detail = contentResult.errors.map((e) => e.message).join("\n");
|
|
4489
|
+
throw new Error(`\u5185\u5BB9\u7269\u6821\u9A8C\u548C\u4E0D\u5339\u914D\uFF1A
|
|
4490
|
+
${detail}`);
|
|
4491
|
+
}
|
|
4492
|
+
return manifest;
|
|
4493
|
+
} finally {
|
|
4494
|
+
await this.fs.deleteFile(tempDir);
|
|
4495
|
+
}
|
|
4496
|
+
}
|
|
4497
|
+
/**
|
|
4498
|
+
* 统计内容物数量。
|
|
4499
|
+
*
|
|
4500
|
+
* @param contents 内容物列表
|
|
4501
|
+
* @returns 统计结果
|
|
4502
|
+
*/
|
|
4503
|
+
countContents(contents) {
|
|
4504
|
+
return {
|
|
4505
|
+
functions: contents.filter((c) => c.kind === "functions").length,
|
|
4506
|
+
database: contents.filter((c) => c.kind === "database").length,
|
|
4507
|
+
web: contents.filter((c) => c.kind === "web").length,
|
|
4508
|
+
runtime: contents.filter((c) => c.kind === "runtime").length,
|
|
4509
|
+
scripts: contents.filter((c) => c.kind === "scripts").length,
|
|
4510
|
+
docs: contents.filter((c) => c.kind === "docs").length,
|
|
4511
|
+
total: contents.length
|
|
4512
|
+
};
|
|
4513
|
+
}
|
|
4514
|
+
/**
|
|
4515
|
+
* 打印内容清单。
|
|
4516
|
+
*
|
|
4517
|
+
* @param manifest Manifest
|
|
4518
|
+
*/
|
|
4519
|
+
printContentList(manifest) {
|
|
4520
|
+
const counts = this.countContents(manifest.contents);
|
|
4521
|
+
console.log("");
|
|
4522
|
+
console.log("==========================================");
|
|
4523
|
+
console.log("\u5BFC\u51FA\u5185\u5BB9\u6E05\u5355");
|
|
4524
|
+
console.log("==========================================");
|
|
4525
|
+
console.log(`\u9879\u76EE\uFF1A${manifest.project.name}`);
|
|
4526
|
+
console.log(`\u5E73\u53F0\u7248\u672C\uFF1A${manifest.platformVersion}`);
|
|
4527
|
+
console.log(`\u5BFC\u51FA\u65F6\u95F4\uFF1A${manifest.exportedAt}`);
|
|
4528
|
+
console.log("");
|
|
4529
|
+
console.log(`\u51FD\u6570\u6587\u4EF6\uFF1A${counts.functions}`);
|
|
4530
|
+
console.log(`\u6570\u636E\u5E93\u6587\u4EF6\uFF1A${counts.database}`);
|
|
4531
|
+
console.log(`\u524D\u7AEF\u6587\u4EF6\uFF1A${counts.web}`);
|
|
4532
|
+
console.log(`\u8FD0\u884C\u65F6\u6587\u4EF6\uFF1A${counts.runtime}`);
|
|
4533
|
+
console.log(`\u811A\u672C\u6587\u4EF6\uFF1A${counts.scripts}`);
|
|
4534
|
+
console.log(`\u6587\u6863\u6587\u4EF6\uFF1A${counts.docs}`);
|
|
4535
|
+
console.log(`\u603B\u6587\u4EF6\u6570\uFF1A${counts.total}`);
|
|
4536
|
+
console.log("==========================================");
|
|
4537
|
+
}
|
|
4538
|
+
/**
|
|
4539
|
+
* 格式化文件大小。
|
|
4540
|
+
*
|
|
4541
|
+
* @param bytes 字节数
|
|
4542
|
+
* @returns 格式化后的大小
|
|
4543
|
+
*/
|
|
4544
|
+
formatSize(bytes) {
|
|
4545
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
4546
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
4547
|
+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4548
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
4549
|
+
}
|
|
4550
|
+
/**
|
|
4551
|
+
* 睡眠指定毫秒数。
|
|
4552
|
+
*
|
|
4553
|
+
* @param ms 毫秒数
|
|
4554
|
+
*/
|
|
4555
|
+
sleep(ms) {
|
|
4556
|
+
return new Promise((resolve12) => setTimeout(resolve12, ms));
|
|
4557
|
+
}
|
|
4558
|
+
};
|
|
4559
|
+
}
|
|
4560
|
+
});
|
|
4561
|
+
|
|
4562
|
+
// src/db.ts
|
|
4563
|
+
var db_exports = {};
|
|
4564
|
+
__export(db_exports, {
|
|
4565
|
+
dbExec: () => dbExec,
|
|
4566
|
+
dbRollback: () => dbRollback,
|
|
4567
|
+
dbSnapshotCreate: () => dbSnapshotCreate,
|
|
4568
|
+
dbSnapshotList: () => dbSnapshotList,
|
|
4569
|
+
dbSnapshotRestore: () => dbSnapshotRestore,
|
|
4570
|
+
dbStart: () => dbStart,
|
|
4571
|
+
dbStatus: () => dbStatus,
|
|
4572
|
+
dbStop: () => dbStop
|
|
4573
|
+
});
|
|
4574
|
+
import { resolve as resolve7 } from "node:path";
|
|
4575
|
+
async function open2(paths, options) {
|
|
4576
|
+
const client = await createClient(paths);
|
|
4577
|
+
const project2 = await resolveSlug(resolve7(options.cwd), options.slug);
|
|
4578
|
+
return { client, project: project2 };
|
|
4253
4579
|
}
|
|
4254
|
-
async function
|
|
4255
|
-
const { client, project: project2 } = await
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4580
|
+
async function dbStart(paths, options) {
|
|
4581
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4582
|
+
return client.request(`/api/v1/projects/${project2}/database`, { method: "POST" });
|
|
4583
|
+
}
|
|
4584
|
+
async function dbStatus(paths, options) {
|
|
4585
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4586
|
+
return client.request(`/api/v1/projects/${project2}/database`);
|
|
4587
|
+
}
|
|
4588
|
+
async function dbStop(paths, options) {
|
|
4589
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4590
|
+
return client.request(`/api/v1/projects/${project2}/database`, {
|
|
4591
|
+
method: "DELETE"
|
|
4592
|
+
});
|
|
4593
|
+
}
|
|
4594
|
+
async function dbExec(paths, options) {
|
|
4595
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4596
|
+
return client.request(
|
|
4597
|
+
`/api/v1/projects/${project2}/database/console/sql`,
|
|
4598
|
+
{
|
|
4599
|
+
method: "POST",
|
|
4600
|
+
body: {
|
|
4601
|
+
sql: options.sql,
|
|
4602
|
+
...options.params === void 0 ? {} : { params: options.params },
|
|
4603
|
+
...options.confirmTable === void 0 ? {} : { confirmTable: options.confirmTable }
|
|
4604
|
+
}
|
|
4605
|
+
},
|
|
4606
|
+
"SQL_EXEC_FAILED"
|
|
4607
|
+
);
|
|
4608
|
+
}
|
|
4609
|
+
async function dbSnapshotList(paths, options) {
|
|
4610
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4611
|
+
return client.request(
|
|
4612
|
+
`/api/v1/projects/${project2}/database/snapshots`
|
|
4613
|
+
);
|
|
4614
|
+
}
|
|
4615
|
+
async function dbSnapshotCreate(paths, options) {
|
|
4616
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4617
|
+
return client.request(`/api/v1/projects/${project2}/database/snapshots`, {
|
|
4618
|
+
method: "POST"
|
|
4619
|
+
});
|
|
4620
|
+
}
|
|
4621
|
+
async function dbSnapshotRestore(paths, options) {
|
|
4622
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4623
|
+
return client.request(
|
|
4624
|
+
`/api/v1/projects/${project2}/database/snapshots/${options.snapshotId}/restore`,
|
|
4625
|
+
{ method: "POST" }
|
|
4626
|
+
);
|
|
4627
|
+
}
|
|
4628
|
+
async function dbRollback(paths, options) {
|
|
4629
|
+
const { client, project: project2 } = await open2(paths, options);
|
|
4630
|
+
return client.request(
|
|
4631
|
+
`/api/v1/projects/${project2}/database/rollback`,
|
|
4632
|
+
{ method: "POST", body: { to: options.to } }
|
|
4633
|
+
);
|
|
4634
|
+
}
|
|
4635
|
+
var init_db2 = __esm({
|
|
4636
|
+
"src/db.ts"() {
|
|
4637
|
+
"use strict";
|
|
4638
|
+
init_client();
|
|
4261
4639
|
}
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4640
|
+
});
|
|
4641
|
+
|
|
4642
|
+
// src/storage.ts
|
|
4643
|
+
var storage_exports = {};
|
|
4644
|
+
__export(storage_exports, {
|
|
4645
|
+
contentTypeOf: () => contentTypeOf,
|
|
4646
|
+
storageDownload: () => storageDownload,
|
|
4647
|
+
storageList: () => storageList,
|
|
4648
|
+
storageRemove: () => storageRemove,
|
|
4649
|
+
storageUpload: () => storageUpload
|
|
4650
|
+
});
|
|
4651
|
+
import { mkdir as mkdir8, readFile as readFile10, stat as stat7, writeFile as writeFile7 } from "node:fs/promises";
|
|
4652
|
+
import { basename as basename3, dirname as dirname7, extname, join as join12, resolve as resolve8 } from "node:path";
|
|
4653
|
+
async function open3(paths, options) {
|
|
4654
|
+
const client = await createClient(paths);
|
|
4655
|
+
const project2 = await resolveSlug(resolve8(options.cwd), options.slug);
|
|
4656
|
+
return { client, project: project2 };
|
|
4657
|
+
}
|
|
4658
|
+
function contentTypeOf(path) {
|
|
4659
|
+
const map = {
|
|
4660
|
+
".html": "text/html; charset=utf-8",
|
|
4661
|
+
".htm": "text/html; charset=utf-8",
|
|
4662
|
+
".css": "text/css; charset=utf-8",
|
|
4663
|
+
".js": "text/javascript; charset=utf-8",
|
|
4664
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
4665
|
+
".json": "application/json; charset=utf-8",
|
|
4666
|
+
".png": "image/png",
|
|
4667
|
+
".jpg": "image/jpeg",
|
|
4668
|
+
".jpeg": "image/jpeg",
|
|
4669
|
+
".gif": "image/gif",
|
|
4670
|
+
".svg": "image/svg+xml",
|
|
4671
|
+
".webp": "image/webp",
|
|
4672
|
+
".ico": "image/x-icon",
|
|
4673
|
+
".txt": "text/plain; charset=utf-8",
|
|
4674
|
+
".md": "text/markdown; charset=utf-8",
|
|
4675
|
+
".xml": "application/xml",
|
|
4676
|
+
".wasm": "application/wasm",
|
|
4677
|
+
".pdf": "application/pdf",
|
|
4678
|
+
".zip": "application/zip",
|
|
4679
|
+
".woff": "font/woff",
|
|
4680
|
+
".woff2": "font/woff2",
|
|
4681
|
+
".ttf": "font/ttf",
|
|
4682
|
+
".otf": "font/otf"
|
|
4683
|
+
};
|
|
4684
|
+
return map[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
4685
|
+
}
|
|
4686
|
+
async function storageUpload(paths, options) {
|
|
4687
|
+
const { client, project: project2 } = await open3(paths, options);
|
|
4688
|
+
const local = resolve8(options.file);
|
|
4689
|
+
const info = await stat7(local).catch(() => null);
|
|
4690
|
+
if (info === null || !info.isFile()) {
|
|
4691
|
+
throw new CliError("FILE_NOT_FOUND", `\u672C\u5730\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${local}`);
|
|
4277
4692
|
}
|
|
4278
|
-
const
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4693
|
+
const visibility = options.visibility ?? "private";
|
|
4694
|
+
const bytes = await readFile10(local);
|
|
4695
|
+
const form = new FormData();
|
|
4696
|
+
form.set("path", options.path);
|
|
4697
|
+
form.set("visibility", visibility);
|
|
4698
|
+
form.set(
|
|
4699
|
+
"file",
|
|
4700
|
+
new Blob([bytes], { type: contentTypeOf(options.path) }),
|
|
4701
|
+
basename3(local)
|
|
4284
4702
|
);
|
|
4285
|
-
const
|
|
4286
|
-
|
|
4703
|
+
const response = await client.upload(
|
|
4704
|
+
`/api/v1/projects/${project2}/files`,
|
|
4705
|
+
form,
|
|
4706
|
+
"STORAGE_UPLOAD_FAILED"
|
|
4707
|
+
);
|
|
4708
|
+
const body = await response.json();
|
|
4709
|
+
return { ...body.file, ...body.signedUrl === void 0 ? {} : { signedUrl: body.signedUrl } };
|
|
4287
4710
|
}
|
|
4288
|
-
async function
|
|
4289
|
-
const { client } = await
|
|
4290
|
-
const
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
const target = join11(outputDir, ...rel.split("/"));
|
|
4305
|
-
await mkdir9(dirname7(target), { recursive: true });
|
|
4306
|
-
await writeFile8(target, bytes);
|
|
4307
|
-
files.push({ path: entry.path, size: bytes.length });
|
|
4711
|
+
async function storageList(paths, options) {
|
|
4712
|
+
const { client, project: project2 } = await open3(paths, options);
|
|
4713
|
+
const query = options.prefix === void 0 ? "" : `?prefix=${encodeURIComponent(options.prefix)}`;
|
|
4714
|
+
const body = await client.request(
|
|
4715
|
+
`/api/v1/projects/${project2}/files${query}`
|
|
4716
|
+
);
|
|
4717
|
+
return { project: project2, files: body.files };
|
|
4718
|
+
}
|
|
4719
|
+
async function resolveDownloadUrl(client, project2, path) {
|
|
4720
|
+
const body = await client.request(
|
|
4721
|
+
`/api/v1/projects/${project2}/files?prefix=${encodeURIComponent(path)}`
|
|
4722
|
+
);
|
|
4723
|
+
const entry = body.files.find((file) => file.path === path);
|
|
4724
|
+
const url = entry?.url ?? entry?.signedUrl;
|
|
4725
|
+
if (entry === void 0 || url === void 0 || url.length === 0) {
|
|
4726
|
+
throw new CliError("STORAGE_NOT_FOUND", `\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${path}`);
|
|
4308
4727
|
}
|
|
4309
|
-
return
|
|
4728
|
+
return url;
|
|
4729
|
+
}
|
|
4730
|
+
async function storageDownload(paths, options) {
|
|
4731
|
+
const { client, project: project2 } = await open3(paths, options);
|
|
4732
|
+
const url = await resolveDownloadUrl(client, project2, options.path);
|
|
4733
|
+
const response = await client.download(url, "STORAGE_DOWNLOAD_FAILED");
|
|
4734
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
4735
|
+
const output = resolve8(options.output ?? join12(resolve8(options.cwd), basename3(options.path)));
|
|
4736
|
+
await mkdir8(dirname7(output), { recursive: true });
|
|
4737
|
+
await writeFile7(output, bytes);
|
|
4738
|
+
return { path: options.path, output, size: bytes.length };
|
|
4310
4739
|
}
|
|
4311
|
-
async function
|
|
4312
|
-
const { client, project: project2 } = await
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
const result = await client.request(
|
|
4317
|
-
`/api/v1/projects/${project2}/hosting`,
|
|
4318
|
-
{ method: "PUT", body }
|
|
4740
|
+
async function storageRemove(paths, options) {
|
|
4741
|
+
const { client, project: project2 } = await open3(paths, options);
|
|
4742
|
+
return client.request(
|
|
4743
|
+
`/api/v1/projects/${project2}/files/${encodeURIComponent(options.path)}`,
|
|
4744
|
+
{ method: "DELETE" }
|
|
4319
4745
|
);
|
|
4320
|
-
return result.config;
|
|
4321
4746
|
}
|
|
4322
|
-
var
|
|
4323
|
-
|
|
4324
|
-
"packages/cli/src/hosting.ts"() {
|
|
4747
|
+
var init_storage2 = __esm({
|
|
4748
|
+
"src/storage.ts"() {
|
|
4325
4749
|
"use strict";
|
|
4326
4750
|
init_client();
|
|
4327
4751
|
init_auth();
|
|
4328
|
-
init_storage2();
|
|
4329
|
-
HOSTING_CONFIG_PATH = "site/.hosting.json";
|
|
4330
4752
|
}
|
|
4331
4753
|
});
|
|
4332
4754
|
|
|
4333
|
-
//
|
|
4334
|
-
var
|
|
4335
|
-
__export(
|
|
4336
|
-
|
|
4755
|
+
// src/doctor.ts
|
|
4756
|
+
var doctor_exports = {};
|
|
4757
|
+
__export(doctor_exports, {
|
|
4758
|
+
formatDoctorReport: () => formatDoctorReport,
|
|
4759
|
+
runDoctor: () => runDoctor
|
|
4337
4760
|
});
|
|
4338
|
-
import {
|
|
4339
|
-
function
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
}
|
|
4761
|
+
import { stat as stat8 } from "node:fs/promises";
|
|
4762
|
+
async function probeServer(server) {
|
|
4763
|
+
const controller = new AbortController();
|
|
4764
|
+
const timer = setTimeout(() => controller.abort(), SERVER_PROBE_TIMEOUT_MS);
|
|
4765
|
+
try {
|
|
4766
|
+
const response = await fetch(`${server}/api/v1/health`, { signal: controller.signal });
|
|
4767
|
+
return { reachable: true, status: response.status };
|
|
4768
|
+
} catch (error) {
|
|
4769
|
+
return {
|
|
4770
|
+
reachable: false,
|
|
4771
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4772
|
+
};
|
|
4773
|
+
} finally {
|
|
4774
|
+
clearTimeout(timer);
|
|
4775
|
+
}
|
|
4351
4776
|
}
|
|
4352
|
-
async function
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4777
|
+
async function credentialMode(file) {
|
|
4778
|
+
try {
|
|
4779
|
+
const info = await stat8(file);
|
|
4780
|
+
return (info.mode & 511).toString(8).padStart(3, "0");
|
|
4781
|
+
} catch {
|
|
4782
|
+
return void 0;
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
async function runDoctor(paths) {
|
|
4786
|
+
const credentials = await loadCredentials(paths);
|
|
4787
|
+
const server = credentials?.server ?? resolveServer();
|
|
4788
|
+
const mode = await credentialMode(paths.credentialsFile);
|
|
4789
|
+
const offline = await isOffline();
|
|
4790
|
+
const health = await probeServer(server);
|
|
4791
|
+
const report = {
|
|
4792
|
+
server,
|
|
4793
|
+
credentials: {
|
|
4794
|
+
file: paths.credentialsFile,
|
|
4795
|
+
present: credentials !== null,
|
|
4796
|
+
...mode === void 0 ? {} : { mode }
|
|
4370
4797
|
},
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
"EXPORT_DOWNLOAD_FAILED"
|
|
4376
|
-
);
|
|
4377
|
-
if (download.downloadUrl.length === 0) {
|
|
4378
|
-
throw new CliError("EXPORT_BUNDLE_UNAVAILABLE", "\u5BFC\u51FA\u4EA7\u7269\u4E0B\u8F7D URL \u4E3A\u7A7A\uFF0C\u4EA7\u7269\u53EF\u80FD\u5C1A\u4E0D\u53EF\u7528");
|
|
4379
|
-
}
|
|
4380
|
-
const response = await client.download(download.downloadUrl, "EXPORT_DOWNLOAD_FAILED");
|
|
4381
|
-
const bytes = Buffer.from(await response.arrayBuffer());
|
|
4382
|
-
await writeFile6(outputPath, bytes);
|
|
4383
|
-
return { path: outputPath, size: bytes.length };
|
|
4384
|
-
}
|
|
4798
|
+
network: { offline },
|
|
4799
|
+
serverHealth: health,
|
|
4800
|
+
offlineCommands: [...OFFLINE_COMMANDS],
|
|
4801
|
+
boundaries: SIM_BOUNDARIES.map((b) => ({ kind: b.kind, title: b.title, detail: b.detail }))
|
|
4385
4802
|
};
|
|
4803
|
+
if (credentials !== null) report.credentials.email = credentials.email;
|
|
4804
|
+
if (mode !== void 0 && mode !== "600") {
|
|
4805
|
+
report.credentials.warning = `\u6743\u9650 ${mode} \u5BBD\u4E8E 0600\uFF0C\u5EFA\u8BAE chmod 600 ${paths.credentialsFile}`;
|
|
4806
|
+
}
|
|
4807
|
+
return report;
|
|
4386
4808
|
}
|
|
4387
|
-
|
|
4388
|
-
"
|
|
4809
|
+
function formatDoctorReport(report) {
|
|
4810
|
+
const lines = ["adep doctor \xB7 \u73AF\u5883\u81EA\u68C0", ""];
|
|
4811
|
+
lines.push("\u51ED\u636E\u4E0E\u8EAB\u4EFD");
|
|
4812
|
+
if (report.credentials.present) {
|
|
4813
|
+
lines.push(` \u2713 \u5DF2\u767B\u5F55 ${report.credentials.email ?? "(\u672A\u77E5\u90AE\u7BB1)"} @ ${report.server}`);
|
|
4814
|
+
lines.push(
|
|
4815
|
+
` \xB7 \u51ED\u636E\u6587\u4EF6 ${report.credentials.file}\uFF08${report.credentials.mode ?? "\u6743\u9650\u672A\u77E5"}\uFF09`
|
|
4816
|
+
);
|
|
4817
|
+
if (report.credentials.warning !== void 0) lines.push(` ! ${report.credentials.warning}`);
|
|
4818
|
+
} else {
|
|
4819
|
+
lines.push(` \u2717 \u672A\u767B\u5F55\uFF08\u65E0 ${report.credentials.file}\uFF09`);
|
|
4820
|
+
lines.push(" \u63D0\u793A\uFF1A\u5148\u6267\u884C adep login");
|
|
4821
|
+
}
|
|
4822
|
+
lines.push("", "\u7F51\u7EDC\u4E0E\u670D\u52A1\u7AEF");
|
|
4823
|
+
lines.push(
|
|
4824
|
+
report.network.offline ? " \u2717 \u5916\u7F51\u4E0D\u53EF\u8FBE\uFF08\u4F9D\u8D56\u5B89\u88C5 / \u90E8\u7F72\u7B49\u547D\u4EE4\u5C06\u660E\u786E\u5931\u8D25\uFF09" : " \u2713 \u5916\u7F51\u53EF\u8FBE"
|
|
4825
|
+
);
|
|
4826
|
+
if (report.serverHealth.reachable) {
|
|
4827
|
+
lines.push(` \u2713 \u5E73\u53F0\u53EF\u8FBE ${report.server}\uFF08/api/v1/health \u2192 ${report.serverHealth.status}\uFF09`);
|
|
4828
|
+
} else {
|
|
4829
|
+
lines.push(
|
|
4830
|
+
` \u2717 \u5E73\u53F0\u4E0D\u53EF\u8FBE ${report.server}\uFF1A${report.serverHealth.error ?? "\u65E0\u5E94\u7B54"}`,
|
|
4831
|
+
" \u63D0\u793A\uFF1A\u68C0\u67E5 ADEP_SERVER / \u767B\u5F55\u65F6\u7684 --server\uFF0C\u6216\u5148\u8D77\u672C\u5730 pnpm run dev"
|
|
4832
|
+
);
|
|
4833
|
+
}
|
|
4834
|
+
lines.push("", "\u79BB\u7EBF\u53EF\u7528\u8303\u56F4\uFF08\u65AD\u7F51\u65F6\u4ECD\u53EF\u6267\u884C\uFF09");
|
|
4835
|
+
for (const command of report.offlineCommands) lines.push(` \xB7 ${command}`);
|
|
4836
|
+
lines.push("", "\u672C\u5730\u6A21\u62DF\u8FD0\u884C\u65F6\u7684\u80FD\u529B\u8FB9\u754C\uFF08\u4E0E adep dev \u542F\u52A8\u6A2A\u5E45\u540C\u6E90\uFF09");
|
|
4837
|
+
for (const boundary of report.boundaries) {
|
|
4838
|
+
lines.push(` \xB7 [${boundary.kind}] ${boundary.title}\uFF1A${boundary.detail}`);
|
|
4839
|
+
}
|
|
4840
|
+
return lines;
|
|
4841
|
+
}
|
|
4842
|
+
var SERVER_PROBE_TIMEOUT_MS, OFFLINE_COMMANDS;
|
|
4843
|
+
var init_doctor = __esm({
|
|
4844
|
+
"src/doctor.ts"() {
|
|
4389
4845
|
"use strict";
|
|
4390
|
-
|
|
4391
|
-
|
|
4846
|
+
init_credentials();
|
|
4847
|
+
init_config();
|
|
4848
|
+
init_boundary();
|
|
4849
|
+
init_net();
|
|
4850
|
+
SERVER_PROBE_TIMEOUT_MS = 5e3;
|
|
4851
|
+
OFFLINE_COMMANDS = [
|
|
4852
|
+
"adep init",
|
|
4853
|
+
"adep dev",
|
|
4854
|
+
"adep serve",
|
|
4855
|
+
"adep db\uFF08\u672C\u5730\u6A21\u62DF\uFF09",
|
|
4856
|
+
"adep doctor"
|
|
4857
|
+
];
|
|
4392
4858
|
}
|
|
4393
4859
|
});
|
|
4394
4860
|
|
|
4395
|
-
//
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4861
|
+
// src/mcp.ts
|
|
4862
|
+
var mcp_exports = {};
|
|
4863
|
+
__export(mcp_exports, {
|
|
4864
|
+
mcpList: () => mcpList,
|
|
4865
|
+
mcpPublish: () => mcpPublish,
|
|
4866
|
+
mcpUnpublish: () => mcpUnpublish
|
|
4867
|
+
});
|
|
4868
|
+
import { resolve as resolve9 } from "node:path";
|
|
4869
|
+
async function mcpPublish(paths, options) {
|
|
4870
|
+
const fn = requireFunctionName(options.fn);
|
|
4871
|
+
const client = await createClient(paths);
|
|
4872
|
+
const project2 = await resolveProject(client, options);
|
|
4873
|
+
const target = await resolveFunction(client, project2, fn);
|
|
4874
|
+
const body = {};
|
|
4875
|
+
if (options.toolName !== void 0 && options.toolName.trim().length > 0) {
|
|
4876
|
+
body.toolName = options.toolName.trim();
|
|
4877
|
+
}
|
|
4878
|
+
if (options.description !== void 0 && options.description.length > 0) {
|
|
4879
|
+
body.description = options.description;
|
|
4880
|
+
}
|
|
4881
|
+
const tool = await client.request(
|
|
4882
|
+
`/api/v1/functions/${target.id}/mcp-publish`,
|
|
4883
|
+
{ method: "POST", ...Object.keys(body).length === 0 ? {} : { body } },
|
|
4884
|
+
"MCP_PUBLISH_FAILED"
|
|
4885
|
+
);
|
|
4886
|
+
return { projectId: project2.id, tool };
|
|
4887
|
+
}
|
|
4888
|
+
async function mcpUnpublish(paths, options) {
|
|
4889
|
+
const fn = requireFunctionName(options.fn);
|
|
4890
|
+
const client = await createClient(paths);
|
|
4891
|
+
const project2 = await resolveProject(client, options);
|
|
4892
|
+
const target = await resolveFunction(client, project2, fn);
|
|
4893
|
+
const toolName = options.toolName?.trim() || fn;
|
|
4894
|
+
const result = await client.request(
|
|
4895
|
+
`/api/v1/functions/${target.id}/mcp-publish?tool=${encodeURIComponent(toolName)}`,
|
|
4896
|
+
{ method: "DELETE" },
|
|
4897
|
+
"MCP_UNPUBLISH_FAILED"
|
|
4898
|
+
);
|
|
4899
|
+
return { projectId: project2.id, toolName, removed: result.unpublished === true };
|
|
4900
|
+
}
|
|
4901
|
+
async function mcpList(paths, options) {
|
|
4902
|
+
const client = await createClient(paths);
|
|
4903
|
+
const project2 = await resolveProject(client, options);
|
|
4904
|
+
const prefix = project2.functionsPrefix ?? "/api";
|
|
4905
|
+
const prefixBase = prefix.trim() === "/" ? "" : prefix.trim().replace(/\/+$/, "");
|
|
4906
|
+
const endpoint = `${project2.url.replace(/\/+$/, "")}${prefixBase}/mcp`;
|
|
4907
|
+
let response;
|
|
4908
|
+
try {
|
|
4909
|
+
response = await fetch(endpoint, {
|
|
4910
|
+
method: "POST",
|
|
4911
|
+
headers: { "content-type": "application/json", cookie: client.cookie },
|
|
4912
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" })
|
|
4913
|
+
});
|
|
4914
|
+
} catch (error) {
|
|
4915
|
+
throw new CliError(
|
|
4916
|
+
"SERVER_UNREACHABLE",
|
|
4917
|
+
`\u65E0\u6CD5\u8FDE\u63A5 MCP \u7AEF\u70B9 ${endpoint}\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4918
|
+
);
|
|
4919
|
+
}
|
|
4920
|
+
const parsed = await response.json().catch(() => null);
|
|
4921
|
+
if (!response.ok) {
|
|
4922
|
+
const envelope = parsed ?? null;
|
|
4923
|
+
throw new CliError(
|
|
4924
|
+
envelope?.error?.code ?? "MCP_LIST_FAILED",
|
|
4925
|
+
envelope?.error?.message ?? `MCP \u7AEF\u70B9\u8FD4\u56DE HTTP ${response.status}`
|
|
4926
|
+
);
|
|
4927
|
+
}
|
|
4928
|
+
const rpcError = parsed?.error;
|
|
4929
|
+
if (rpcError !== void 0) {
|
|
4930
|
+
throw new CliError(
|
|
4931
|
+
rpcError.code ?? "MCP_LIST_FAILED",
|
|
4932
|
+
rpcError.message ?? "MCP tools/list \u5931\u8D25"
|
|
4933
|
+
);
|
|
4423
4934
|
}
|
|
4424
|
-
return
|
|
4935
|
+
return {
|
|
4936
|
+
projectId: project2.id,
|
|
4937
|
+
slug: project2.slug,
|
|
4938
|
+
endpoint,
|
|
4939
|
+
tools: parsed?.result?.tools ?? []
|
|
4940
|
+
};
|
|
4425
4941
|
}
|
|
4426
|
-
function
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
for (let i = buf.length - 22; i >= min; i--) {
|
|
4430
|
-
if (view.getUint32(i, true) === SIG_EOCD) return i;
|
|
4942
|
+
function requireFunctionName(fn) {
|
|
4943
|
+
if (fn === void 0 || fn.trim().length === 0) {
|
|
4944
|
+
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11\u51FD\u6570\u540D\uFF1Aadep mcp publish --function <fn>");
|
|
4431
4945
|
}
|
|
4432
|
-
return
|
|
4946
|
+
return fn.trim();
|
|
4433
4947
|
}
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
"
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
let c = i;
|
|
4444
|
-
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
4445
|
-
table[i] = c >>> 0;
|
|
4446
|
-
}
|
|
4447
|
-
return table;
|
|
4448
|
-
})();
|
|
4449
|
-
Reader = class {
|
|
4450
|
-
constructor(buf) {
|
|
4451
|
-
this.buf = buf;
|
|
4452
|
-
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4453
|
-
}
|
|
4454
|
-
view;
|
|
4455
|
-
u16(offset) {
|
|
4456
|
-
return this.view.getUint16(offset, true);
|
|
4457
|
-
}
|
|
4458
|
-
u32(offset) {
|
|
4459
|
-
return this.view.getUint32(offset, true);
|
|
4460
|
-
}
|
|
4461
|
-
slice(start, length) {
|
|
4462
|
-
return this.buf.subarray(start, start + length);
|
|
4463
|
-
}
|
|
4464
|
-
};
|
|
4465
|
-
ZipFormatError = class extends Error {
|
|
4466
|
-
constructor(message) {
|
|
4467
|
-
super(`[appexport] \u975E\u6CD5 zip\uFF1A${message}`);
|
|
4468
|
-
this.name = "ZipFormatError";
|
|
4469
|
-
}
|
|
4470
|
-
};
|
|
4948
|
+
async function resolveProject(client, options) {
|
|
4949
|
+
const slug = await resolveSlug(resolve9(options.cwd), options.slug);
|
|
4950
|
+
const listed = await client.request("/api/v1/projects", {}, "PROJECT_LIST_FAILED");
|
|
4951
|
+
const match = listed.projects.find((project2) => project2.slug === slug);
|
|
4952
|
+
if (match === void 0) {
|
|
4953
|
+
throw new CliError(
|
|
4954
|
+
"PROJECT_NOT_FOUND",
|
|
4955
|
+
`\u5E73\u53F0\u9879\u76EE "${slug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650\uFF1A\u5148\u6267\u884C adep projects create ${slug}`
|
|
4956
|
+
);
|
|
4471
4957
|
}
|
|
4472
|
-
});
|
|
4473
|
-
|
|
4474
|
-
// packages/cli/src/export/fs.ts
|
|
4475
|
-
var fs_exports = {};
|
|
4476
|
-
__export(fs_exports, {
|
|
4477
|
-
createExportFileSystem: () => createExportFileSystem
|
|
4478
|
-
});
|
|
4479
|
-
import { mkdir as mkdir8, readFile as readFile10, rm as rm3, stat as stat9, writeFile as writeFile7 } from "node:fs/promises";
|
|
4480
|
-
import { dirname as dirname8, join as join12 } from "node:path";
|
|
4481
|
-
function createExportFileSystem() {
|
|
4482
4958
|
return {
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
await rm3(path, { recursive: true, force: true });
|
|
4488
|
-
},
|
|
4489
|
-
fileExists: async (path) => {
|
|
4490
|
-
try {
|
|
4491
|
-
await stat9(path);
|
|
4492
|
-
return true;
|
|
4493
|
-
} catch {
|
|
4494
|
-
return false;
|
|
4495
|
-
}
|
|
4496
|
-
},
|
|
4497
|
-
mkdir: async (path) => {
|
|
4498
|
-
await mkdir8(path, { recursive: true });
|
|
4499
|
-
},
|
|
4500
|
-
unzip: async (zipPath, targetDir) => {
|
|
4501
|
-
const entries = zipRead(await readFile10(zipPath));
|
|
4502
|
-
for (const [name, data] of entries) {
|
|
4503
|
-
const dest = join12(targetDir, name);
|
|
4504
|
-
await mkdir8(dirname8(dest), { recursive: true });
|
|
4505
|
-
await writeFile7(dest, data);
|
|
4506
|
-
}
|
|
4507
|
-
}
|
|
4959
|
+
id: match.id,
|
|
4960
|
+
slug: match.slug,
|
|
4961
|
+
url: match.url,
|
|
4962
|
+
...match.functionsPrefix === void 0 ? {} : { functionsPrefix: match.functionsPrefix }
|
|
4508
4963
|
};
|
|
4509
4964
|
}
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4965
|
+
async function resolveFunction(client, project2, name) {
|
|
4966
|
+
const listed = await client.request(`/api/v1/projects/${project2.id}/functions`, {}, "FUNCTION_LIST_FAILED");
|
|
4967
|
+
const target = listed.functions.find((fn) => fn.name === name);
|
|
4968
|
+
if (target === void 0) {
|
|
4969
|
+
throw new CliError("FN_NOT_FOUND", `\u51FD\u6570 "${name}" \u4E0D\u5B58\u5728\u4E8E\u9879\u76EE "${project2.slug}"`);
|
|
4514
4970
|
}
|
|
4515
|
-
}
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
var init_manifest2 = __esm({
|
|
4520
|
-
"shared/deploy-bundle/manifest.ts"() {
|
|
4971
|
+
return { id: target.id, name: target.name };
|
|
4972
|
+
}
|
|
4973
|
+
var init_mcp = __esm({
|
|
4974
|
+
"src/mcp.ts"() {
|
|
4521
4975
|
"use strict";
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
/** 云函数代码与配置。 */
|
|
4525
|
-
Functions: "functions",
|
|
4526
|
-
/** 数据库 schema 与种子数据。 */
|
|
4527
|
-
Database: "database",
|
|
4528
|
-
/** 前端静态资源。 */
|
|
4529
|
-
Web: "web",
|
|
4530
|
-
/** 运行时配置(Dockerfile / docker-compose.yml)。 */
|
|
4531
|
-
Runtime: "runtime",
|
|
4532
|
-
/** 启动 / 备份 / 恢复脚本。 */
|
|
4533
|
-
Scripts: "scripts",
|
|
4534
|
-
/** 文档(README / 部署手册)。 */
|
|
4535
|
-
Docs: "docs"
|
|
4536
|
-
};
|
|
4537
|
-
ALLOWED_CONTENT_KINDS = Object.values(BundleContentKind);
|
|
4976
|
+
init_auth();
|
|
4977
|
+
init_client();
|
|
4538
4978
|
}
|
|
4539
4979
|
});
|
|
4540
4980
|
|
|
4541
|
-
//
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
};
|
|
4551
|
-
}
|
|
4552
|
-
const m = manifest;
|
|
4553
|
-
const schemaVersion = m.schemaVersion;
|
|
4554
|
-
if (typeof schemaVersion !== "number" || !Number.isInteger(schemaVersion)) {
|
|
4555
|
-
errors.push({
|
|
4556
|
-
code: "INVALID_SCHEMA_VERSION",
|
|
4557
|
-
message: "schemaVersion \u5FC5\u987B\u662F\u6574\u6570",
|
|
4558
|
-
field: "schemaVersion"
|
|
4559
|
-
});
|
|
4560
|
-
} else if (schemaVersion > CURRENT_SCHEMA_VERSION) {
|
|
4561
|
-
errors.push({
|
|
4562
|
-
code: "SCHEMA_VERSION_TOO_HIGH",
|
|
4563
|
-
message: `schemaVersion ${schemaVersion} \u9AD8\u4E8E\u5F53\u524D\u652F\u6301\u7248\u672C ${CURRENT_SCHEMA_VERSION}\uFF0C\u9700\u5347\u7EA7\u5BFC\u51FA\u7AEF`,
|
|
4564
|
-
field: "schemaVersion"
|
|
4565
|
-
});
|
|
4566
|
-
} else if (schemaVersion < CURRENT_SCHEMA_VERSION) {
|
|
4567
|
-
warnings.push({
|
|
4568
|
-
code: "SCHEMA_VERSION_LOW",
|
|
4569
|
-
message: `schemaVersion ${schemaVersion} \u4F4E\u4E8E\u5F53\u524D\u7248\u672C ${CURRENT_SCHEMA_VERSION}\uFF0C\u5EFA\u8BAE\u91CD\u65B0\u5BFC\u51FA`,
|
|
4570
|
-
field: "schemaVersion"
|
|
4571
|
-
});
|
|
4572
|
-
}
|
|
4573
|
-
if (typeof m.platformVersion !== "string" || m.platformVersion.trim() === "") {
|
|
4574
|
-
errors.push({
|
|
4575
|
-
code: "MISSING_PLATFORM_VERSION",
|
|
4576
|
-
message: "platformVersion \u5FC5\u987B\u975E\u7A7A",
|
|
4577
|
-
field: "platformVersion"
|
|
4578
|
-
});
|
|
4579
|
-
}
|
|
4580
|
-
if (typeof m.project !== "object" || m.project === null) {
|
|
4581
|
-
errors.push({
|
|
4582
|
-
code: "MISSING_PROJECT",
|
|
4583
|
-
message: "project \u5FC5\u987B\u662F\u5BF9\u8C61",
|
|
4584
|
-
field: "project"
|
|
4585
|
-
});
|
|
4586
|
-
} else {
|
|
4587
|
-
const project2 = m.project;
|
|
4588
|
-
if (typeof project2.id !== "string" || project2.id.trim() === "") {
|
|
4589
|
-
errors.push({
|
|
4590
|
-
code: "MISSING_PROJECT_ID",
|
|
4591
|
-
message: "project.id \u5FC5\u987B\u975E\u7A7A",
|
|
4592
|
-
field: "project.id"
|
|
4593
|
-
});
|
|
4594
|
-
}
|
|
4595
|
-
if (typeof project2.name !== "string" || project2.name.trim() === "") {
|
|
4596
|
-
errors.push({
|
|
4597
|
-
code: "MISSING_PROJECT_NAME",
|
|
4598
|
-
message: "project.name \u5FC5\u987B\u975E\u7A7A",
|
|
4599
|
-
field: "project.name"
|
|
4600
|
-
});
|
|
4601
|
-
}
|
|
4602
|
-
if (typeof project2.slug !== "string" || project2.slug.trim() === "") {
|
|
4603
|
-
errors.push({
|
|
4604
|
-
code: "MISSING_PROJECT_SLUG",
|
|
4605
|
-
message: "project.slug \u5FC5\u987B\u975E\u7A7A",
|
|
4606
|
-
field: "project.slug"
|
|
4607
|
-
});
|
|
4608
|
-
}
|
|
4609
|
-
if (typeof project2.version !== "number" || !Number.isInteger(project2.version) || project2.version < 1) {
|
|
4610
|
-
errors.push({
|
|
4611
|
-
code: "INVALID_PROJECT_VERSION",
|
|
4612
|
-
message: "project.version \u5FC5\u987B\u662F\u6B63\u6574\u6570",
|
|
4613
|
-
field: "project.version"
|
|
4614
|
-
});
|
|
4615
|
-
}
|
|
4616
|
-
}
|
|
4617
|
-
if (!Array.isArray(m.contents)) {
|
|
4618
|
-
errors.push({
|
|
4619
|
-
code: "MISSING_CONTENTS",
|
|
4620
|
-
message: "contents \u5FC5\u987B\u662F\u6570\u7EC4",
|
|
4621
|
-
field: "contents"
|
|
4622
|
-
});
|
|
4623
|
-
} else if (m.contents.length === 0) {
|
|
4624
|
-
errors.push({
|
|
4625
|
-
code: "EMPTY_CONTENTS",
|
|
4626
|
-
message: "contents \u4E0D\u80FD\u4E3A\u7A7A",
|
|
4627
|
-
field: "contents"
|
|
4628
|
-
});
|
|
4629
|
-
} else {
|
|
4630
|
-
m.contents.forEach((content, index) => {
|
|
4631
|
-
validateContent(content, index, errors, warnings);
|
|
4632
|
-
});
|
|
4633
|
-
}
|
|
4634
|
-
if (typeof m.runtime !== "object" || m.runtime === null) {
|
|
4635
|
-
errors.push({
|
|
4636
|
-
code: "MISSING_RUNTIME",
|
|
4637
|
-
message: "runtime \u5FC5\u987B\u662F\u5BF9\u8C61",
|
|
4638
|
-
field: "runtime"
|
|
4639
|
-
});
|
|
4640
|
-
} else {
|
|
4641
|
-
const runtime = m.runtime;
|
|
4642
|
-
if (typeof runtime.engine !== "string" || runtime.engine.trim() === "") {
|
|
4643
|
-
errors.push({
|
|
4644
|
-
code: "MISSING_ENGINE",
|
|
4645
|
-
message: "runtime.engine \u5FC5\u987B\u975E\u7A7A",
|
|
4646
|
-
field: "runtime.engine"
|
|
4647
|
-
});
|
|
4648
|
-
}
|
|
4649
|
-
if (typeof runtime.engineVersion !== "string" || runtime.engineVersion.trim() === "") {
|
|
4650
|
-
errors.push({
|
|
4651
|
-
code: "MISSING_ENGINE_VERSION",
|
|
4652
|
-
message: "runtime.engineVersion \u5FC5\u987B\u975E\u7A7A",
|
|
4653
|
-
field: "runtime.engineVersion"
|
|
4654
|
-
});
|
|
4655
|
-
}
|
|
4656
|
-
if (typeof runtime.port !== "number" || !Number.isInteger(runtime.port) || runtime.port < 1 || runtime.port > 65535) {
|
|
4657
|
-
errors.push({
|
|
4658
|
-
code: "INVALID_PORT",
|
|
4659
|
-
message: "runtime.port \u5FC5\u987B\u662F 1-65535 \u7684\u6574\u6570",
|
|
4660
|
-
field: "runtime.port"
|
|
4661
|
-
});
|
|
4662
|
-
}
|
|
4663
|
-
if (typeof runtime.startCommand !== "string" || runtime.startCommand.trim() === "") {
|
|
4664
|
-
errors.push({
|
|
4665
|
-
code: "MISSING_START_COMMAND",
|
|
4666
|
-
message: "runtime.startCommand \u5FC5\u987B\u975E\u7A7A",
|
|
4667
|
-
field: "runtime.startCommand"
|
|
4668
|
-
});
|
|
4669
|
-
}
|
|
4981
|
+
// src/projects.ts
|
|
4982
|
+
var projects_exports = {};
|
|
4983
|
+
__export(projects_exports, {
|
|
4984
|
+
projectsCreate: () => projectsCreate,
|
|
4985
|
+
projectsInfo: () => projectsInfo,
|
|
4986
|
+
projectsList: () => projectsList
|
|
4987
|
+
});
|
|
4988
|
+
function requireSlug(slug, hint) {
|
|
4989
|
+
if (slug === void 0 || slug.trim().length === 0) {
|
|
4990
|
+
throw new CliError("INVALID_SLUG", `\u7F3A\u5C11\u9879\u76EE slug\uFF1A${hint}`);
|
|
4670
4991
|
}
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4992
|
+
return slug.trim();
|
|
4993
|
+
}
|
|
4994
|
+
async function projectsCreate(paths, options) {
|
|
4995
|
+
await requireNetworkGuard();
|
|
4996
|
+
const client = await createClient(paths);
|
|
4997
|
+
const slug = requireSlug(options.slug, "adep projects create <slug>");
|
|
4998
|
+
const name = options.name ?? slug;
|
|
4999
|
+
const body = { slug, name };
|
|
5000
|
+
if (options.spaceId !== void 0) body.spaceId = options.spaceId;
|
|
5001
|
+
const created = await client.request(
|
|
5002
|
+
"/api/v1/projects",
|
|
5003
|
+
{ body },
|
|
5004
|
+
"PROJECT_CREATE_FAILED"
|
|
5005
|
+
);
|
|
5006
|
+
if (created.url === void 0 || created.url.length === 0) {
|
|
5007
|
+
throw new CliError("PROJECT_CREATE_FAILED", "\u5E73\u53F0\u672A\u8FD4\u56DE\u9879\u76EE\u5730\u5740\uFF0C\u65E0\u6CD5\u8F93\u51FA\u5B50\u57DF URL");
|
|
5008
|
+
}
|
|
5009
|
+
return created;
|
|
5010
|
+
}
|
|
5011
|
+
async function projectsList(paths) {
|
|
5012
|
+
await requireNetworkGuard();
|
|
5013
|
+
const client = await createClient(paths);
|
|
5014
|
+
const result = await client.request(
|
|
5015
|
+
"/api/v1/projects",
|
|
5016
|
+
{},
|
|
5017
|
+
"PROJECT_LIST_FAILED"
|
|
5018
|
+
);
|
|
5019
|
+
return result.projects;
|
|
5020
|
+
}
|
|
5021
|
+
async function projectsInfo(paths, options) {
|
|
5022
|
+
await requireNetworkGuard();
|
|
5023
|
+
const slug = requireSlug(options.slug, "adep projects info <slug>");
|
|
5024
|
+
const projects = await projectsList(paths);
|
|
5025
|
+
const match = projects.find((project2) => project2.slug === slug);
|
|
5026
|
+
if (match === void 0) {
|
|
5027
|
+
throw new CliError("PROJECT_NOT_FOUND", `\u9879\u76EE "${slug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650`);
|
|
5028
|
+
}
|
|
5029
|
+
return match;
|
|
5030
|
+
}
|
|
5031
|
+
async function requireNetworkGuard() {
|
|
5032
|
+
const { requireNetwork: requireNetwork2 } = await Promise.resolve().then(() => (init_net(), net_exports));
|
|
5033
|
+
await requireNetwork2("adep projects");
|
|
5034
|
+
}
|
|
5035
|
+
var init_projects = __esm({
|
|
5036
|
+
"src/projects.ts"() {
|
|
5037
|
+
"use strict";
|
|
5038
|
+
init_auth();
|
|
5039
|
+
init_client();
|
|
4686
5040
|
}
|
|
5041
|
+
});
|
|
5042
|
+
|
|
5043
|
+
// src/functions.ts
|
|
5044
|
+
var functions_exports = {};
|
|
5045
|
+
__export(functions_exports, {
|
|
5046
|
+
functionsDeploy: () => functionsDeploy,
|
|
5047
|
+
functionsList: () => functionsList,
|
|
5048
|
+
functionsLogs: () => functionsLogs
|
|
5049
|
+
});
|
|
5050
|
+
import { resolve as resolve10 } from "node:path";
|
|
5051
|
+
async function functionsDeploy(paths, options) {
|
|
5052
|
+
const startedAt = Date.now();
|
|
5053
|
+
const result = await deploy(paths, {
|
|
5054
|
+
cwd: options.cwd,
|
|
5055
|
+
...options.slug === void 0 ? {} : { slug: options.slug },
|
|
5056
|
+
...options.dir === void 0 ? {} : { functionsDir: resolve10(options.cwd, options.dir) },
|
|
5057
|
+
silent: true
|
|
5058
|
+
});
|
|
5059
|
+
return { ...result, elapsedSeconds: (Date.now() - startedAt) / 1e3 };
|
|
5060
|
+
}
|
|
5061
|
+
async function functionsList(paths, options) {
|
|
5062
|
+
const client = await createClient(paths);
|
|
5063
|
+
const project2 = await resolveProject2(client, options);
|
|
5064
|
+
const result = await client.request(
|
|
5065
|
+
`/api/v1/projects/${project2.id}/functions`,
|
|
5066
|
+
{},
|
|
5067
|
+
"FUNCTION_LIST_FAILED"
|
|
5068
|
+
);
|
|
5069
|
+
const prefix = project2.functionsPrefix ?? "/api";
|
|
5070
|
+
const prefixBase = prefix.trim() === "/" ? "" : prefix.trim().replace(/\/+$/, "");
|
|
4687
5071
|
return {
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
5072
|
+
projectId: project2.id,
|
|
5073
|
+
slug: project2.slug,
|
|
5074
|
+
baseUrl: `${project2.url.replace(/\/+$/, "")}${prefixBase}`,
|
|
5075
|
+
functions: result.functions
|
|
4691
5076
|
};
|
|
4692
5077
|
}
|
|
4693
|
-
function
|
|
4694
|
-
if (
|
|
4695
|
-
|
|
4696
|
-
code: "INVALID_CONTENT",
|
|
4697
|
-
message: `contents[${index}] \u5FC5\u987B\u662F\u5BF9\u8C61`,
|
|
4698
|
-
field: `contents[${index}]`
|
|
4699
|
-
});
|
|
4700
|
-
return;
|
|
5078
|
+
async function functionsLogs(paths, options) {
|
|
5079
|
+
if (options.name === void 0 || options.name.trim().length === 0) {
|
|
5080
|
+
throw new CliError("INVALID_ARGUMENT", "\u7F3A\u5C11\u51FD\u6570\u540D\uFF1Aadep functions logs <name>");
|
|
4701
5081
|
}
|
|
4702
|
-
const
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
5082
|
+
const client = await createClient(paths);
|
|
5083
|
+
const project2 = await resolveProject2(client, options);
|
|
5084
|
+
const listed = await client.request(
|
|
5085
|
+
`/api/v1/projects/${project2.id}/functions`,
|
|
5086
|
+
{},
|
|
5087
|
+
"FUNCTION_LIST_FAILED"
|
|
5088
|
+
);
|
|
5089
|
+
const target = listed.functions.find((fn) => fn.name === options.name);
|
|
5090
|
+
if (target === void 0) {
|
|
5091
|
+
throw new CliError("FN_NOT_FOUND", `\u51FD\u6570 "${options.name}" \u4E0D\u5B58\u5728\u4E8E\u9879\u76EE "${project2.slug}"`);
|
|
4709
5092
|
}
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
5093
|
+
const tail = options.tail === void 0 ? "" : `?tail=${encodeURIComponent(String(options.tail))}`;
|
|
5094
|
+
const result = await client.request(
|
|
5095
|
+
`/api/v1/functions/${target.id}/logs${tail}`,
|
|
5096
|
+
{},
|
|
5097
|
+
"FUNCTION_LOGS_FAILED"
|
|
5098
|
+
);
|
|
5099
|
+
return { functionId: target.id, name: target.name, logs: result.logs };
|
|
5100
|
+
}
|
|
5101
|
+
async function resolveProject2(client, options) {
|
|
5102
|
+
const slug = await resolveSlug(resolve10(options.cwd), options.slug);
|
|
5103
|
+
const projects = await projectsListFrom(client);
|
|
5104
|
+
const match = projects.find((project2) => project2.slug === slug);
|
|
5105
|
+
if (match === void 0) {
|
|
5106
|
+
throw new CliError(
|
|
5107
|
+
"PROJECT_NOT_FOUND",
|
|
5108
|
+
`\u5E73\u53F0\u9879\u76EE "${slug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650\uFF1A\u5148\u6267\u884C adep projects create ${slug}`
|
|
5109
|
+
);
|
|
4722
5110
|
}
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
5111
|
+
return match;
|
|
5112
|
+
}
|
|
5113
|
+
async function projectsListFrom(client) {
|
|
5114
|
+
const result = await client.request("/api/v1/projects", {}, "PROJECT_LIST_FAILED");
|
|
5115
|
+
return result.projects;
|
|
5116
|
+
}
|
|
5117
|
+
var init_functions = __esm({
|
|
5118
|
+
"src/functions.ts"() {
|
|
5119
|
+
"use strict";
|
|
5120
|
+
init_auth();
|
|
5121
|
+
init_client();
|
|
5122
|
+
init_deploy();
|
|
4735
5123
|
}
|
|
5124
|
+
});
|
|
5125
|
+
|
|
5126
|
+
// src/hosting.ts
|
|
5127
|
+
var hosting_exports = {};
|
|
5128
|
+
__export(hosting_exports, {
|
|
5129
|
+
hostingConfig: () => hostingConfig,
|
|
5130
|
+
hostingDeploy: () => hostingDeploy,
|
|
5131
|
+
hostingInfo: () => hostingInfo,
|
|
5132
|
+
hostingPull: () => hostingPull
|
|
5133
|
+
});
|
|
5134
|
+
import { readdir as readdir5, readFile as readFile11, stat as stat9 } from "node:fs/promises";
|
|
5135
|
+
import { dirname as dirname8, join as join13, relative as relative2, resolve as resolve11, sep } from "node:path";
|
|
5136
|
+
async function open4(paths, options) {
|
|
5137
|
+
const client = await createClient(paths);
|
|
5138
|
+
const project2 = await resolveSlug(resolve11(options.cwd), options.slug);
|
|
5139
|
+
return { client, project: project2 };
|
|
4736
5140
|
}
|
|
4737
|
-
function
|
|
4738
|
-
const
|
|
4739
|
-
const
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
5141
|
+
async function hostingInfo(paths, options) {
|
|
5142
|
+
const { client, project: project2 } = await open4(paths, options);
|
|
5143
|
+
const body = await client.request(`/api/v1/projects/${project2}/hosting`);
|
|
5144
|
+
return {
|
|
5145
|
+
config: body.config,
|
|
5146
|
+
siteUrl: body.siteUrl,
|
|
5147
|
+
files: body.files ?? []
|
|
5148
|
+
};
|
|
5149
|
+
}
|
|
5150
|
+
async function collectSiteFiles(dir) {
|
|
5151
|
+
const root = resolve11(dir);
|
|
5152
|
+
const files = /* @__PURE__ */ new Map();
|
|
5153
|
+
const walk = async (sub) => {
|
|
5154
|
+
let entries;
|
|
5155
|
+
try {
|
|
5156
|
+
entries = await readdir5(sub, { withFileTypes: true });
|
|
5157
|
+
} catch {
|
|
5158
|
+
return;
|
|
4749
5159
|
}
|
|
4750
|
-
const
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
5160
|
+
for (const entry of entries) {
|
|
5161
|
+
const full = join13(sub, entry.name);
|
|
5162
|
+
if (entry.isDirectory()) {
|
|
5163
|
+
await walk(full);
|
|
5164
|
+
} else if (entry.isFile()) {
|
|
5165
|
+
const rel = relative2(root, full).split(sep).join("/");
|
|
5166
|
+
files.set(rel, full);
|
|
5167
|
+
}
|
|
4757
5168
|
}
|
|
5169
|
+
};
|
|
5170
|
+
await walk(root);
|
|
5171
|
+
return files;
|
|
5172
|
+
}
|
|
5173
|
+
async function hostingDeploy(paths, options) {
|
|
5174
|
+
const { client, project: project2 } = await open4(paths, options);
|
|
5175
|
+
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
5176
|
+
`));
|
|
5177
|
+
const files = await collectSiteFiles(options.dir);
|
|
5178
|
+
if (files.size === 0) {
|
|
5179
|
+
throw new CliError("NO_SITE_FILES", `\u7AD9\u70B9\u76EE\u5F55\u4E3A\u7A7A\uFF1A${resolve11(options.dir)}`);
|
|
5180
|
+
}
|
|
5181
|
+
const uploaded = [];
|
|
5182
|
+
for (const [rel, full] of files) {
|
|
5183
|
+
log(`[adep] \u4E0A\u4F20 site/${rel}`);
|
|
5184
|
+
const info2 = await stat9(full);
|
|
5185
|
+
const bytes = await readFile11(full);
|
|
5186
|
+
const form = new FormData();
|
|
5187
|
+
form.set("path", `site/${rel}`);
|
|
5188
|
+
form.set("visibility", "public");
|
|
5189
|
+
form.set(
|
|
5190
|
+
"file",
|
|
5191
|
+
new Blob([bytes], { type: contentTypeOf(rel) }),
|
|
5192
|
+
rel.split("/").pop()
|
|
5193
|
+
);
|
|
5194
|
+
await client.upload(`/api/v1/projects/${project2}/files`, form, "HOSTING_UPLOAD_FAILED");
|
|
5195
|
+
uploaded.push({ path: `site/${rel}`, size: info2.size });
|
|
4758
5196
|
}
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
field: `contents[${path}]`
|
|
4765
|
-
});
|
|
5197
|
+
const config = await client.request(
|
|
5198
|
+
`/api/v1/projects/${project2}/hosting`,
|
|
5199
|
+
{
|
|
5200
|
+
method: "PUT",
|
|
5201
|
+
body: options.spa === void 0 ? { enabled: true } : { enabled: true, spaMode: options.spa }
|
|
4766
5202
|
}
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
errors,
|
|
4771
|
-
warnings
|
|
4772
|
-
};
|
|
5203
|
+
);
|
|
5204
|
+
const info = await hostingInfo(paths, options);
|
|
5205
|
+
return { config: config.config, siteUrl: info.siteUrl, uploaded };
|
|
4773
5206
|
}
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
});
|
|
4817
|
-
if (!jsonOutput) {
|
|
4818
|
-
console.log(`\u5BFC\u51FA\u4EFB\u52A1\u5DF2\u521B\u5EFA\uFF1A${job.id}`);
|
|
4819
|
-
}
|
|
4820
|
-
const completedJob = await this.pollJobStatus(job.id, jsonOutput);
|
|
4821
|
-
if (completedJob.status === "failed") {
|
|
4822
|
-
return {
|
|
4823
|
-
success: false,
|
|
4824
|
-
jobId: job.id,
|
|
4825
|
-
status: "failed",
|
|
4826
|
-
error: completedJob.error ?? "\u5BFC\u51FA\u5931\u8D25"
|
|
4827
|
-
};
|
|
4828
|
-
}
|
|
4829
|
-
if (!jsonOutput) {
|
|
4830
|
-
console.log("\u4E0B\u8F7D\u5BFC\u51FA\u4EA7\u7269...");
|
|
4831
|
-
}
|
|
4832
|
-
const outputPath = `${outputDir}/${projectId}-export-${Date.now()}.zip`;
|
|
4833
|
-
await this.fs.mkdir(outputDir);
|
|
4834
|
-
const downloadResult = await this.apiClient.downloadBundle(job.id, outputPath);
|
|
4835
|
-
if (!jsonOutput) {
|
|
4836
|
-
console.log(`\u4EA7\u7269\u5DF2\u4E0B\u8F7D\uFF1A${downloadResult.path}\uFF08${this.formatSize(downloadResult.size)}\uFF09`);
|
|
4837
|
-
}
|
|
4838
|
-
if (!jsonOutput) {
|
|
4839
|
-
console.log("\u6267\u884C manifest \u81EA\u68C0...");
|
|
4840
|
-
}
|
|
4841
|
-
const manifest = await this.verifyManifest(downloadResult.path);
|
|
4842
|
-
if (!jsonOutput) {
|
|
4843
|
-
this.printContentList(manifest);
|
|
4844
|
-
}
|
|
4845
|
-
return {
|
|
4846
|
-
success: true,
|
|
4847
|
-
jobId: job.id,
|
|
4848
|
-
status: "completed",
|
|
4849
|
-
downloadPath: downloadResult.path,
|
|
4850
|
-
manifest: {
|
|
4851
|
-
projectName: manifest.project.name,
|
|
4852
|
-
platformVersion: manifest.platformVersion,
|
|
4853
|
-
exportedAt: manifest.exportedAt,
|
|
4854
|
-
contents: this.countContents(manifest.contents)
|
|
4855
|
-
}
|
|
4856
|
-
};
|
|
4857
|
-
} catch (error) {
|
|
4858
|
-
const message = error instanceof Error ? error.message : "unknown_error";
|
|
4859
|
-
if (message.includes("ECONNREFUSED") || message.includes("ENOTFOUND") || message.includes("network")) {
|
|
4860
|
-
return {
|
|
4861
|
-
success: false,
|
|
4862
|
-
error: `\u5E73\u53F0\u7AEF\u70B9\u4E0D\u53EF\u8FBE\uFF1A${message}\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5\u548C\u5E73\u53F0\u5730\u5740\u914D\u7F6E\uFF0C\u7136\u540E\u91CD\u8BD5\u3002`
|
|
4863
|
-
};
|
|
4864
|
-
}
|
|
4865
|
-
return {
|
|
4866
|
-
success: false,
|
|
4867
|
-
error: message
|
|
4868
|
-
};
|
|
4869
|
-
}
|
|
4870
|
-
}
|
|
4871
|
-
/**
|
|
4872
|
-
* 轮询任务状态。
|
|
4873
|
-
*
|
|
4874
|
-
* @param jobId 任务 ID
|
|
4875
|
-
* @param jsonOutput 是否 JSON 输出
|
|
4876
|
-
* @returns 完成的任务
|
|
4877
|
-
*/
|
|
4878
|
-
async pollJobStatus(jobId, jsonOutput) {
|
|
4879
|
-
let attempts = 0;
|
|
4880
|
-
let lastProgress = -1;
|
|
4881
|
-
while (attempts < this.maxPollAttempts) {
|
|
4882
|
-
const job = await this.apiClient.getJobStatus(jobId);
|
|
4883
|
-
if (!jsonOutput && job.progress !== lastProgress) {
|
|
4884
|
-
const stage = job.stage ? `\uFF08${job.stage}\uFF09` : "";
|
|
4885
|
-
console.log(`\u8FDB\u5EA6\uFF1A${job.progress}%${stage}`);
|
|
4886
|
-
lastProgress = job.progress;
|
|
4887
|
-
}
|
|
4888
|
-
if (job.status === "completed" || job.status === "failed") {
|
|
4889
|
-
return job;
|
|
4890
|
-
}
|
|
4891
|
-
attempts++;
|
|
4892
|
-
await this.sleep(this.pollInterval);
|
|
4893
|
-
}
|
|
4894
|
-
throw new Error(`\u5BFC\u51FA\u4EFB\u52A1\u8D85\u65F6\uFF1A\u8F6E\u8BE2 ${this.maxPollAttempts} \u6B21\u540E\u4ECD\u672A\u5B8C\u6210`);
|
|
4895
|
-
}
|
|
4896
|
-
/**
|
|
4897
|
-
* 验证 Manifest:解压 → 契约校验 → 逐项 sha256 校验 → 清理临时目录。
|
|
4898
|
-
*
|
|
4899
|
-
* 逐项校验与导出端同法:内容物以 latin1 承载(逐字节双射,二进制条目不被解码改写),
|
|
4900
|
-
* 比对时对原字节做真实 sha256;任一不匹配即判定包损坏并抛错,不静默放行。
|
|
4901
|
-
* 无论成功失败,`${zip}.tmp` 临时目录都在 finally 里删除,不留残余。
|
|
4902
|
-
*
|
|
4903
|
-
* @param zipPath ZIP 文件路径
|
|
4904
|
-
* @returns Manifest
|
|
4905
|
-
*/
|
|
4906
|
-
async verifyManifest(zipPath) {
|
|
4907
|
-
const tempDir = `${zipPath}.tmp`;
|
|
4908
|
-
try {
|
|
4909
|
-
await this.fs.mkdir(tempDir);
|
|
4910
|
-
await this.fs.unzip(zipPath, tempDir);
|
|
4911
|
-
const manifestPath = `${tempDir}/manifest.json`;
|
|
4912
|
-
if (!await this.fs.fileExists(manifestPath)) {
|
|
4913
|
-
throw new Error("manifest.json \u4E0D\u5B58\u5728\uFF0C\u5305\u53EF\u80FD\u5DF2\u635F\u574F");
|
|
4914
|
-
}
|
|
4915
|
-
const manifestContent = await this.fs.readFile(manifestPath);
|
|
4916
|
-
const manifest = JSON.parse(manifestContent.toString("utf-8"));
|
|
4917
|
-
const validationResult = validateBundleManifest(manifest);
|
|
4918
|
-
if (!validationResult.valid) {
|
|
4919
|
-
const errors = validationResult.errors.map((e) => `${e.field ?? ""}: ${e.message}`).join("\n");
|
|
4920
|
-
throw new Error(`manifest \u6821\u9A8C\u5931\u8D25\uFF1A
|
|
4921
|
-
${errors}`);
|
|
4922
|
-
}
|
|
4923
|
-
const actual = /* @__PURE__ */ new Map();
|
|
4924
|
-
for (const content of manifest.contents) {
|
|
4925
|
-
const filePath = `${tempDir}/${content.path}`;
|
|
4926
|
-
if (await this.fs.fileExists(filePath)) {
|
|
4927
|
-
const bytes = await this.fs.readFile(filePath);
|
|
4928
|
-
actual.set(content.path, bytes.toString("latin1"));
|
|
4929
|
-
}
|
|
4930
|
-
}
|
|
4931
|
-
const contentResult = verifyContents(
|
|
4932
|
-
manifest.contents,
|
|
4933
|
-
actual,
|
|
4934
|
-
(text) => createHash3("sha256").update(Buffer.from(text, "latin1")).digest("hex")
|
|
4935
|
-
);
|
|
4936
|
-
if (!contentResult.valid) {
|
|
4937
|
-
const detail = contentResult.errors.map((e) => e.message).join("\n");
|
|
4938
|
-
throw new Error(`\u5185\u5BB9\u7269\u6821\u9A8C\u548C\u4E0D\u5339\u914D\uFF1A
|
|
4939
|
-
${detail}`);
|
|
4940
|
-
}
|
|
4941
|
-
return manifest;
|
|
4942
|
-
} finally {
|
|
4943
|
-
await this.fs.deleteFile(tempDir);
|
|
4944
|
-
}
|
|
4945
|
-
}
|
|
4946
|
-
/**
|
|
4947
|
-
* 统计内容物数量。
|
|
4948
|
-
*
|
|
4949
|
-
* @param contents 内容物列表
|
|
4950
|
-
* @returns 统计结果
|
|
4951
|
-
*/
|
|
4952
|
-
countContents(contents) {
|
|
4953
|
-
return {
|
|
4954
|
-
functions: contents.filter((c) => c.kind === "functions").length,
|
|
4955
|
-
database: contents.filter((c) => c.kind === "database").length,
|
|
4956
|
-
web: contents.filter((c) => c.kind === "web").length,
|
|
4957
|
-
runtime: contents.filter((c) => c.kind === "runtime").length,
|
|
4958
|
-
scripts: contents.filter((c) => c.kind === "scripts").length,
|
|
4959
|
-
docs: contents.filter((c) => c.kind === "docs").length,
|
|
4960
|
-
total: contents.length
|
|
4961
|
-
};
|
|
4962
|
-
}
|
|
4963
|
-
/**
|
|
4964
|
-
* 打印内容清单。
|
|
4965
|
-
*
|
|
4966
|
-
* @param manifest Manifest
|
|
4967
|
-
*/
|
|
4968
|
-
printContentList(manifest) {
|
|
4969
|
-
const counts = this.countContents(manifest.contents);
|
|
4970
|
-
console.log("");
|
|
4971
|
-
console.log("==========================================");
|
|
4972
|
-
console.log("\u5BFC\u51FA\u5185\u5BB9\u6E05\u5355");
|
|
4973
|
-
console.log("==========================================");
|
|
4974
|
-
console.log(`\u9879\u76EE\uFF1A${manifest.project.name}`);
|
|
4975
|
-
console.log(`\u5E73\u53F0\u7248\u672C\uFF1A${manifest.platformVersion}`);
|
|
4976
|
-
console.log(`\u5BFC\u51FA\u65F6\u95F4\uFF1A${manifest.exportedAt}`);
|
|
4977
|
-
console.log("");
|
|
4978
|
-
console.log(`\u51FD\u6570\u6587\u4EF6\uFF1A${counts.functions}`);
|
|
4979
|
-
console.log(`\u6570\u636E\u5E93\u6587\u4EF6\uFF1A${counts.database}`);
|
|
4980
|
-
console.log(`\u524D\u7AEF\u6587\u4EF6\uFF1A${counts.web}`);
|
|
4981
|
-
console.log(`\u8FD0\u884C\u65F6\u6587\u4EF6\uFF1A${counts.runtime}`);
|
|
4982
|
-
console.log(`\u811A\u672C\u6587\u4EF6\uFF1A${counts.scripts}`);
|
|
4983
|
-
console.log(`\u6587\u6863\u6587\u4EF6\uFF1A${counts.docs}`);
|
|
4984
|
-
console.log(`\u603B\u6587\u4EF6\u6570\uFF1A${counts.total}`);
|
|
4985
|
-
console.log("==========================================");
|
|
4986
|
-
}
|
|
4987
|
-
/**
|
|
4988
|
-
* 格式化文件大小。
|
|
4989
|
-
*
|
|
4990
|
-
* @param bytes 字节数
|
|
4991
|
-
* @returns 格式化后的大小
|
|
4992
|
-
*/
|
|
4993
|
-
formatSize(bytes) {
|
|
4994
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
4995
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
4996
|
-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
4997
|
-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
4998
|
-
}
|
|
4999
|
-
/**
|
|
5000
|
-
* 睡眠指定毫秒数。
|
|
5001
|
-
*
|
|
5002
|
-
* @param ms 毫秒数
|
|
5003
|
-
*/
|
|
5004
|
-
sleep(ms) {
|
|
5005
|
-
return new Promise((resolve11) => setTimeout(resolve11, ms));
|
|
5006
|
-
}
|
|
5007
|
-
};
|
|
5207
|
+
async function hostingPull(paths, options) {
|
|
5208
|
+
const { client } = await open4(paths, options);
|
|
5209
|
+
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
5210
|
+
`));
|
|
5211
|
+
const info = await hostingInfo(paths, options);
|
|
5212
|
+
const outputDir = resolve11(options.output ?? resolve11(options.cwd));
|
|
5213
|
+
const { mkdir: mkdir9, writeFile: writeFile8 } = await import("node:fs/promises");
|
|
5214
|
+
const files = [];
|
|
5215
|
+
for (const entry of info.files) {
|
|
5216
|
+
if (entry.visibility !== "public" || entry.path === HOSTING_CONFIG_PATH) continue;
|
|
5217
|
+
const url = entry.url;
|
|
5218
|
+
if (url === void 0 || url.length === 0) continue;
|
|
5219
|
+
log(`[adep] \u4E0B\u8F7D ${entry.path}`);
|
|
5220
|
+
const response = await client.download(url, "HOSTING_DOWNLOAD_FAILED");
|
|
5221
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
5222
|
+
const rel = entry.path.replace(/^site\//, "");
|
|
5223
|
+
const target = join13(outputDir, ...rel.split("/"));
|
|
5224
|
+
await mkdir9(dirname8(target), { recursive: true });
|
|
5225
|
+
await writeFile8(target, bytes);
|
|
5226
|
+
files.push({ path: entry.path, size: bytes.length });
|
|
5227
|
+
}
|
|
5228
|
+
return { siteUrl: info.siteUrl, outputDir, files };
|
|
5229
|
+
}
|
|
5230
|
+
async function hostingConfig(paths, options) {
|
|
5231
|
+
const { client, project: project2 } = await open4(paths, options);
|
|
5232
|
+
const body = {};
|
|
5233
|
+
if (options.enabled !== void 0) body["enabled"] = options.enabled;
|
|
5234
|
+
if (options.spa !== void 0) body["spaMode"] = options.spa;
|
|
5235
|
+
const result = await client.request(
|
|
5236
|
+
`/api/v1/projects/${project2}/hosting`,
|
|
5237
|
+
{ method: "PUT", body }
|
|
5238
|
+
);
|
|
5239
|
+
return result.config;
|
|
5240
|
+
}
|
|
5241
|
+
var HOSTING_CONFIG_PATH;
|
|
5242
|
+
var init_hosting = __esm({
|
|
5243
|
+
"src/hosting.ts"() {
|
|
5244
|
+
"use strict";
|
|
5245
|
+
init_client();
|
|
5246
|
+
init_auth();
|
|
5247
|
+
init_storage2();
|
|
5248
|
+
HOSTING_CONFIG_PATH = "site/.hosting.json";
|
|
5008
5249
|
}
|
|
5009
5250
|
});
|
|
5010
5251
|
|
|
5011
|
-
//
|
|
5252
|
+
// src/cli.ts
|
|
5012
5253
|
init_config();
|
|
5013
5254
|
import { Command } from "commander";
|
|
5014
|
-
import { createRequire } from "node:module";
|
|
5255
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
5015
5256
|
|
|
5016
|
-
//
|
|
5257
|
+
// src/output.ts
|
|
5017
5258
|
init_auth();
|
|
5018
5259
|
|
|
5019
|
-
//
|
|
5260
|
+
// src/init.ts
|
|
5020
5261
|
import { mkdir as mkdir2, stat as stat2, writeFile } from "node:fs/promises";
|
|
5262
|
+
import { createRequire } from "node:module";
|
|
5021
5263
|
import { dirname as dirname2, join, resolve } from "node:path";
|
|
5022
5264
|
|
|
5023
|
-
// shared/sdk/adep-env.ts
|
|
5265
|
+
// ../../shared/sdk/adep-env.ts
|
|
5024
5266
|
var ADEP_ENV_DTS = `/**
|
|
5025
5267
|
* AgentDeploy \u4E91\u51FD\u6570\u5F00\u53D1\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08\u90E8\u7F72\u5305 / adep init \u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u6539\uFF09\u3002
|
|
5026
5268
|
*
|
|
@@ -5296,7 +5538,109 @@ var ADEP_TSCONFIG_JSON = `{
|
|
|
5296
5538
|
}
|
|
5297
5539
|
`;
|
|
5298
5540
|
|
|
5299
|
-
//
|
|
5541
|
+
// src/init.ts
|
|
5542
|
+
init_adep_config();
|
|
5543
|
+
|
|
5544
|
+
// ../../shared/sdk/web-project-template.ts
|
|
5545
|
+
var WEB_DEPENDENCIES = {
|
|
5546
|
+
vue: "^3.3.4"
|
|
5547
|
+
};
|
|
5548
|
+
var WEB_DEV_DEPENDENCIES = {
|
|
5549
|
+
vite: "^4.4.0",
|
|
5550
|
+
"@vitejs/plugin-vue": "^4.3.0",
|
|
5551
|
+
// vite 内部动态 import('esbuild-wasm'),必须在 package.json 显式声明才能被 Nodebox 解析
|
|
5552
|
+
"esbuild-wasm": "0.18.20"
|
|
5553
|
+
};
|
|
5554
|
+
var WEB_FN_PROXY_SCRIPT = `(function () {
|
|
5555
|
+
if (window.__adepFnProxyInstalled) return;
|
|
5556
|
+
window.__adepFnProxyInstalled = true;
|
|
5557
|
+
var ORIGINAL_FETCH = window.fetch.bind(window);
|
|
5558
|
+
var pending = {};
|
|
5559
|
+
var nextId = 1;
|
|
5560
|
+
var TIMEOUT_MS = 15000;
|
|
5561
|
+
|
|
5562
|
+
window.addEventListener("message", function (event) {
|
|
5563
|
+
var data = event.data;
|
|
5564
|
+
if (!data || data.__adepFnResponse !== true) return;
|
|
5565
|
+
var entry = pending[data.id];
|
|
5566
|
+
if (!entry) return;
|
|
5567
|
+
delete pending[data.id];
|
|
5568
|
+
clearTimeout(entry.timer);
|
|
5569
|
+
var headers;
|
|
5570
|
+
try { headers = new Headers(data.headers || {}); }
|
|
5571
|
+
catch (e) { headers = new Headers({ "content-type": "text/plain" }); }
|
|
5572
|
+
var body = data.body == null ? null : data.body;
|
|
5573
|
+
try {
|
|
5574
|
+
entry.resolve(new Response(body, { status: data.status || 200, statusText: "", headers: headers }));
|
|
5575
|
+
} catch (e2) {
|
|
5576
|
+
entry.resolve(new Response(String(body), { status: data.status || 200, headers: { "content-type": "text/plain" } }));
|
|
5577
|
+
}
|
|
5578
|
+
});
|
|
5579
|
+
|
|
5580
|
+
function readBody(input, init) {
|
|
5581
|
+
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
5582
|
+
return input.text().catch(function () { return null; });
|
|
5583
|
+
}
|
|
5584
|
+
var body = init && init.body !== undefined ? init.body : input;
|
|
5585
|
+
if (body == null) return Promise.resolve(null);
|
|
5586
|
+
if (typeof body === "string") return Promise.resolve(body);
|
|
5587
|
+
if (typeof ArrayBuffer !== "undefined" && body instanceof ArrayBuffer) {
|
|
5588
|
+
return Promise.resolve(new TextDecoder().decode(body));
|
|
5589
|
+
}
|
|
5590
|
+
if (typeof Blob !== "undefined" && body instanceof Blob) return body.text();
|
|
5591
|
+
if (typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams) {
|
|
5592
|
+
return Promise.resolve(body.toString());
|
|
5593
|
+
}
|
|
5594
|
+
try { return Promise.resolve(String(body)); } catch (e) { return Promise.resolve(null); }
|
|
5595
|
+
}
|
|
5596
|
+
|
|
5597
|
+
function collectHeaders(input, init) {
|
|
5598
|
+
var out = {};
|
|
5599
|
+
try { input.headers.forEach(function (v, k) { out[k] = v; }); } catch (e) {}
|
|
5600
|
+
if (init && init.headers) {
|
|
5601
|
+
try { new Headers(init.headers).forEach(function (v, k) { out[k] = v; }); } catch (e2) {}
|
|
5602
|
+
}
|
|
5603
|
+
return out;
|
|
5604
|
+
}
|
|
5605
|
+
|
|
5606
|
+
window.fetch = function (input, init) {
|
|
5607
|
+
var urlStr;
|
|
5608
|
+
var method;
|
|
5609
|
+
var headers = {};
|
|
5610
|
+
var isRequest = typeof Request !== "undefined" && input instanceof Request;
|
|
5611
|
+
if (isRequest) {
|
|
5612
|
+
urlStr = String(input.url);
|
|
5613
|
+
method = (init && init.method) || input.method || "GET";
|
|
5614
|
+
headers = collectHeaders(input, init);
|
|
5615
|
+
} else if (typeof input === "string" || (typeof URL !== "undefined" && input instanceof URL)) {
|
|
5616
|
+
urlStr = String(input);
|
|
5617
|
+
method = (init && init.method) || "GET";
|
|
5618
|
+
try { new Headers(init && init.headers || {}).forEach(function (v, k) { headers[k] = v; }); } catch (e) {}
|
|
5619
|
+
} else {
|
|
5620
|
+
return ORIGINAL_FETCH(input, init);
|
|
5621
|
+
}
|
|
5622
|
+
var u;
|
|
5623
|
+
try { u = new URL(urlStr, document.baseURI); }
|
|
5624
|
+
catch (e) { return ORIGINAL_FETCH(input, init); }
|
|
5625
|
+
if (u.pathname.indexOf("/api/") !== 0 && u.pathname !== "/api") {
|
|
5626
|
+
return ORIGINAL_FETCH(input, init);
|
|
5627
|
+
}
|
|
5628
|
+
if (window.parent === window) return ORIGINAL_FETCH(input, init);
|
|
5629
|
+
method = (method || "GET").toUpperCase();
|
|
5630
|
+
var target = u.pathname + u.search;
|
|
5631
|
+
return readBody(input, init).then(function (textBody) {
|
|
5632
|
+
return new Promise(function (resolve) {
|
|
5633
|
+
var id = nextId++;
|
|
5634
|
+
var timer = setTimeout(function () {
|
|
5635
|
+
delete pending[id];
|
|
5636
|
+
resolve(new Response('{"error":{"code":"FN_PROXY_TIMEOUT","message":"\\u4e91\\u51fd\\u6570\\u6267\\u884c\\u8d85\\u65f6"}}', { status: 504, headers: { "content-type": "application/json" } }));
|
|
5637
|
+
}, TIMEOUT_MS);
|
|
5638
|
+
pending[id] = { resolve: resolve, timer: timer };
|
|
5639
|
+
window.parent.postMessage({ __adepFnRequest: true, id: id, method: method, url: target, headers: headers, body: textBody }, "*");
|
|
5640
|
+
});
|
|
5641
|
+
});
|
|
5642
|
+
};
|
|
5643
|
+
})();`;
|
|
5300
5644
|
function webProjectFiles() {
|
|
5301
5645
|
return [
|
|
5302
5646
|
{
|
|
@@ -5307,13 +5651,8 @@ function webProjectFiles() {
|
|
|
5307
5651
|
version: "0.0.0",
|
|
5308
5652
|
type: "module",
|
|
5309
5653
|
scripts: { dev: "vite" },
|
|
5310
|
-
dependencies:
|
|
5311
|
-
devDependencies:
|
|
5312
|
-
vite: "^4.4.0",
|
|
5313
|
-
"@vitejs/plugin-vue": "^4.3.0",
|
|
5314
|
-
// vite 内部动态 import('esbuild-wasm'),必须在 package.json 显式声明才能被 Nodebox 解析
|
|
5315
|
-
"esbuild-wasm": "0.18.20"
|
|
5316
|
-
}
|
|
5654
|
+
dependencies: WEB_DEPENDENCIES,
|
|
5655
|
+
devDependencies: WEB_DEV_DEPENDENCIES
|
|
5317
5656
|
},
|
|
5318
5657
|
null,
|
|
5319
5658
|
2
|
|
@@ -5340,12 +5679,37 @@ function webProjectFiles() {
|
|
|
5340
5679
|
{
|
|
5341
5680
|
path: "vite.config.ts",
|
|
5342
5681
|
content: [
|
|
5343
|
-
`// web/vite.config.ts \u2014\u2014 \u6807\u51C6 Vite \u914D\u7F6E\uFF08Vue 3 \u63D2\u4EF6\uFF09\u3002`,
|
|
5682
|
+
`// web/vite.config.ts \u2014\u2014 \u6807\u51C6 Vite \u914D\u7F6E\uFF08Vue 3 \u63D2\u4EF6\uFF09+ Web IDE \u9884\u89C8\u4E91\u51FD\u6570\u4EE3\u7406\u3002`,
|
|
5683
|
+
`// \u4E0B\u9762\u7684 adepFunctionsPlugin \u4EC5\u5728 Nodebox \u771F vite \u9884\u89C8\u4E0B\u751F\u6548\uFF1Adev \u65F6\u628A fetch \u62E6\u622A\u5668\u6CE8\u5165`,
|
|
5684
|
+
`// index.html\uFF0C\u9884\u89C8\u91CC fetch('/api/*') \u7ECF postMessage \u8F6C\u53D1\u5230 IDE \u4E3B\u7EBF\u7A0B\u6267\u884C\u5F53\u524D\u9879\u76EE\u4E91\u51FD\u6570\u8349\u7A3F\u3002`,
|
|
5685
|
+
`// \uFF08\u6D4F\u89C8\u5668\u5185 vite-dev \u9884\u89C8\u7531 @adep/web-container \u5728 buildDocument \u91CC\u6CE8\u5165\u540C\u4E00\u4EFD\u811A\u672C\u3002\uFF09`,
|
|
5344
5686
|
`import { defineConfig } from 'vite'`,
|
|
5345
5687
|
`import vue from '@vitejs/plugin-vue'`,
|
|
5346
5688
|
``,
|
|
5689
|
+
`// \u6CE8\u610F\uFF1AFN_PROXY_SCRIPT \u4E0E packages/web-container/src/function-fetch-proxy.ts \u7684`,
|
|
5690
|
+
`// FN_FETCH_INTERCEPTOR_SCRIPT \u5FC5\u987B\u9010\u5B57\u4E00\u81F4\uFF08\u4E24\u5904\u590D\u5236\u7C98\u8D34\uFF0C\u6539\u62E6\u622A\u5668\u52A1\u5FC5\u540C\u6B65\uFF09\u3002`,
|
|
5691
|
+
`const FN_PROXY_SCRIPT = \`${WEB_FN_PROXY_SCRIPT}\``,
|
|
5692
|
+
``,
|
|
5693
|
+
`const adepFunctionsPlugin = {`,
|
|
5694
|
+
` name: 'adep-fn-proxy',`,
|
|
5695
|
+
` configureServer(server) {`,
|
|
5696
|
+
` server.middlewares.use((req, res, next) => {`,
|
|
5697
|
+
` const pathname = (req.url ?? '').split('?')[0]`,
|
|
5698
|
+
` if (pathname === '/@adep/fn-proxy.js') {`,
|
|
5699
|
+
` res.setHeader('content-type', 'application/javascript; charset=utf-8')`,
|
|
5700
|
+
` res.end(FN_PROXY_SCRIPT)`,
|
|
5701
|
+
` return`,
|
|
5702
|
+
` }`,
|
|
5703
|
+
` next()`,
|
|
5704
|
+
` })`,
|
|
5705
|
+
` },`,
|
|
5706
|
+
` transformIndexHtml(html) {`,
|
|
5707
|
+
` return html.replace('</head>', '<script src="/@adep/fn-proxy.js"></script></head>')`,
|
|
5708
|
+
` },`,
|
|
5709
|
+
`}`,
|
|
5710
|
+
``,
|
|
5347
5711
|
`export default defineConfig({`,
|
|
5348
|
-
` plugins: [vue()],`,
|
|
5712
|
+
` plugins: [vue(), adepFunctionsPlugin],`,
|
|
5349
5713
|
`})`,
|
|
5350
5714
|
``
|
|
5351
5715
|
].join("\n")
|
|
@@ -5398,8 +5762,11 @@ function webProjectFiles() {
|
|
|
5398
5762
|
}
|
|
5399
5763
|
];
|
|
5400
5764
|
}
|
|
5765
|
+
function webSrcFiles() {
|
|
5766
|
+
return webProjectFiles().filter((file) => file.path.startsWith("src/"));
|
|
5767
|
+
}
|
|
5401
5768
|
|
|
5402
|
-
//
|
|
5769
|
+
// src/init.ts
|
|
5403
5770
|
var TEMPLATE_NAMES = ["empty", "function", "fullstack"];
|
|
5404
5771
|
var InitError = class extends Error {
|
|
5405
5772
|
constructor(code, message) {
|
|
@@ -5408,31 +5775,96 @@ var InitError = class extends Error {
|
|
|
5408
5775
|
this.name = "InitError";
|
|
5409
5776
|
}
|
|
5410
5777
|
};
|
|
5411
|
-
var
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5778
|
+
var requireJson = createRequire(import.meta.url);
|
|
5779
|
+
var CLI_VERSION = requireJson("../package.json").version;
|
|
5780
|
+
var ADEP_CONFIG_HEADER = `// adep \u9879\u76EE\u914D\u7F6E\uFF1ACLI\uFF08dev / serve / deploy\uFF09\u4E0E\u4E91\u51FD\u6570 vite \u63D2\u4EF6\u6309 default export \u8BFB\u53D6\u3002
|
|
5781
|
+
// - name\uFF1A\u9879\u76EE\u6807\u8BC6\uFF08deploy / db \u7B49\u547D\u4EE4\u7684\u7F3A\u7701 project slug\uFF09
|
|
5782
|
+
// - template\uFF1A\u811A\u624B\u67B6\u6A21\u677F\uFF08empty / function / fullstack\uFF0Cinit \u65F6\u786E\u5B9A\uFF09
|
|
5783
|
+
// - functionsDir\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\uFF08dev / serve / deploy \u8BFB\u53D6\uFF0C\u7F3A\u7701 functions/\uFF09
|
|
5784
|
+
// - functions_prefix\uFF1A\u4E91\u51FD\u6570\u8DEF\u7531\u524D\u7F00\uFF0C**\u9ED8\u8BA4 /api**\uFF08\u4E0E\u7EBF\u4E0A\u51FD\u6570\u8DEF\u7531 /api/{fn} \u5BF9\u9F50\uFF09\u3002
|
|
5785
|
+
// dev \u8BBF\u95EE\u8DEF\u5F84\u4E3A /{prefix}/{fnName}\uFF08\u5982 /api/hello\uFF09\uFF1Bserve \u4E3A /api/{prefix}/{fnName}\u3002
|
|
5786
|
+
// vite \u63D2\u4EF6\uFF08vite.config.ts \u7684 adep()\uFF09\u6309\u6B64\u524D\u7F00\u628A\u524D\u7AEF /{prefix}/* \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\u3002
|
|
5787
|
+
// \u8FB9\u754C\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\u8DEF\u7531\uFF1B\u51FD\u6570\u4E92\u8C03\uFF08ctx.cloud.invoke\uFF09\u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C\u4E0D\u53D7\u5F71\u54CD\u3002`;
|
|
5788
|
+
var PACKAGE_JSON = (name, template) => {
|
|
5789
|
+
const pkg = {
|
|
5790
|
+
name,
|
|
5791
|
+
version: "0.1.0",
|
|
5792
|
+
private: true,
|
|
5793
|
+
type: "module",
|
|
5794
|
+
description: `AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570 + web/src/ \u524D\u7AEF\u6E90\u7801 + site/ \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269`,
|
|
5795
|
+
scripts: {
|
|
5796
|
+
dev: "vite",
|
|
5797
|
+
build: "vite build",
|
|
5798
|
+
"site:deploy": "adep hosting deploy site --spa",
|
|
5799
|
+
serve: "adep serve",
|
|
5800
|
+
deploy: "adep deploy",
|
|
5801
|
+
doctor: "adep doctor"
|
|
5802
|
+
},
|
|
5803
|
+
dependencies: {
|
|
5804
|
+
"@adep/cli": CLI_VERSION,
|
|
5805
|
+
...WEB_DEPENDENCIES
|
|
5806
|
+
},
|
|
5807
|
+
devDependencies: WEB_DEV_DEPENDENCIES,
|
|
5808
|
+
engines: {
|
|
5809
|
+
node: ">=18",
|
|
5810
|
+
bun: ">=1.0"
|
|
5811
|
+
}
|
|
5812
|
+
};
|
|
5813
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
5416
5814
|
`;
|
|
5815
|
+
};
|
|
5417
5816
|
var README = (name, template) => `# ${name}
|
|
5418
5817
|
|
|
5419
5818
|
AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3002
|
|
5420
5819
|
|
|
5421
5820
|
## \u5E38\u7528\u547D\u4EE4
|
|
5422
5821
|
|
|
5423
|
-
- \`
|
|
5424
|
-
|
|
5425
|
-
|
|
5822
|
+
- \`pnpm dev\`\uFF08= \`vite\`\uFF09\uFF1A**\u5168\u6808\u5F00\u53D1**\u2014\u2014vite \u542F\u52A8\u524D\u7AEF\uFF08HMR\uFF09\uFF0C\u4E91\u51FD\u6570 vite \u63D2\u4EF6\u5185\u7F6E
|
|
5823
|
+
\`adep dev\` \u5E76\u628A \`/api/*\` \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\uFF0C\u4E00\u4E2A\u547D\u4EE4\u8C03\u8BD5\u524D\u7AEF + \u51FD\u6570
|
|
5824
|
+
\uFF08\`curl http://localhost:5173/api/hello\`\uFF09\u3002
|
|
5825
|
+
- \`pnpm build\`\uFF08= \`vite build\`\uFF09\uFF1A\u6784\u5EFA\u524D\u7AEF \u2192 \`site/\`\uFF08\u4E91\u51FD\u6570\u5DE5\u7A0B\u7AD9\u70B9\u6258\u7BA1\u76EE\u5F55\uFF09\u3002
|
|
5826
|
+
- \`pnpm site:deploy\`\uFF08= \`adep hosting deploy site --spa\`\uFF09\uFF1A\u628A \`site/\` \u4E0A\u4F20\u5230\u5E73\u53F0
|
|
5827
|
+
\u9759\u6001\u6258\u7BA1\u5E76\u5F00\u542F SPA \u56DE\u9000\uFF0C\u8F93\u51FA\u7AD9\u70B9\u5730\u5740\u3002
|
|
5828
|
+
- \`pnpm serve\`\uFF08= \`adep serve\`\uFF09\uFF1A\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF08\u51FD\u6570 /api/{prefix}/{fn} + /healthz + \u9759\u6001\u6258\u7BA1\uFF09
|
|
5829
|
+
- \`pnpm deploy\`\uFF08= \`adep deploy\`\uFF09\uFF1A\u589E\u91CF\u90E8\u7F72\u4E91\u51FD\u6570\uFF08\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D\uFF09
|
|
5830
|
+
- \`pnpm doctor\`\uFF08= \`adep doctor\`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD
|
|
5426
5831
|
|
|
5427
5832
|
## \u76EE\u5F55\u7ED3\u6784
|
|
5428
5833
|
|
|
5429
|
-
- \`
|
|
5834
|
+
- \`package.json\`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08@adep/cli + \u524D\u7AEF\u4F9D\u8D56\u540C\u6839\u58F0\u660E\uFF1Bvite \u5DE5\u7A0B\u6839\u5728\u9879\u76EE\u6839\u76EE\u5F55\uFF09
|
|
5835
|
+
- \`vite.config.ts\`\uFF1Avite \u914D\u7F6E\uFF08vue \u63D2\u4EF6 + \`adep()\` \u4E91\u51FD\u6570\u63D2\u4EF6\uFF1Bbuild.outDir = site/\uFF09
|
|
5836
|
+
- \`index.html\`\uFF1Avite \u5165\u53E3\uFF08\u5F15\u7528 \`/web/src/main.ts\`\uFF09
|
|
5837
|
+
- \`adep.config.ts\`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 /api\uFF09
|
|
5430
5838
|
- \`functions/\`\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\uFF08\u6BCF\u4E2A\u6587\u4EF6 = \u4E00\u4E2A\u51FD\u6570\uFF0C\u9ED8\u8BA4\u5BFC\u51FA \`(ctx: AdepContext) => Response\`\uFF09
|
|
5431
|
-
- \`web/\`\uFF1A\u524D\u7AEF\
|
|
5839
|
+
- \`web/src/\`\uFF1A\u524D\u7AEF\u6E90\u7801\uFF08Vue 3\uFF1B\u4E0E Web IDE \u7684 \`web/\` \u5DE5\u7A0B\u5171\u7528\u540C\u4E00\u4EFD \`src/\`\uFF09
|
|
5840
|
+
- \`site/\`\uFF1A\`vite build\` \u7684\u524D\u7AEF\u6784\u5EFA\u4EA7\u7269\uFF08\u7AD9\u70B9\u6258\u7BA1\u76EE\u5F55\uFF0C\`adep hosting deploy site\` \u4E0A\u4F20\uFF1B\u5DF2 gitignore\uFF09
|
|
5432
5841
|
- \`database/schema.sql\`\uFF1A\u6570\u636E\u5E93\u7ED3\u6784\uFF08\u8868\u7531\u5E73\u53F0\u63A7\u5236\u53F0 / \`adep db\` \u7BA1\u7406\uFF0C\u6B64\u5904\u4E3A\u7ED3\u6784\u8BB0\u5F55\uFF09
|
|
5433
|
-
- \`tsconfig.json\`\
|
|
5842
|
+
- \`tsconfig.json\`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09
|
|
5434
5843
|
- \`adep.d.ts\`\uFF1A\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08\`ctx: AdepContext\` \u8865\u5168\uFF0C\u65E0\u9700\u88C5\u4F9D\u8D56\uFF09
|
|
5435
5844
|
|
|
5845
|
+
## \u5168\u6808\u5F00\u53D1\uFF08vite + \u4E91\u51FD\u6570\u4EE3\u7406\uFF09
|
|
5846
|
+
|
|
5847
|
+
\`pnpm dev\` \u542F\u52A8 vite \u540E\uFF0C\u4E91\u51FD\u6570\u63D2\u4EF6\u81EA\u52A8\u505A\u4E24\u4EF6\u4E8B\uFF1A
|
|
5848
|
+
1. \u5728 vite \u8FDB\u7A0B\u5185\u542F\u52A8 \`adep dev\`\uFF08\u6A21\u62DF\u8FD0\u884C\u65F6\uFF0C\u51FD\u6570\u70ED\u91CD\u8F7D\u3001\`.env.local\`\u3001cloud.db/storage/realtime \u5168\u53EF\u7528\uFF09\uFF1B
|
|
5849
|
+
2. \u628A \`/{functions_prefix}/*\` \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\u2014\u2014\`adep.config.ts\` \u9ED8\u8BA4
|
|
5850
|
+
\`functions_prefix: '/api'\`\uFF0C\u56E0\u6B64\u524D\u7AEF \`fetch('/api/hello')\` \u5373\u8C03\u7528 \`functions/hello.ts\`\uFF0C
|
|
5851
|
+
\u4E0E\u7EBF\u4E0A\u90E8\u7F72\u540E\u7684\u51FD\u6570\u8DEF\u7531 \`/api/{fn}\` \u4E00\u81F4\u3002
|
|
5852
|
+
|
|
5853
|
+
## \u4E91\u51FD\u6570\u8DEF\u7531\u524D\u7F00\uFF08functions_prefix\uFF09
|
|
5854
|
+
|
|
5855
|
+
\`adep.config.ts\` \u7684 \`functions_prefix\`\uFF08\u9ED8\u8BA4 \`/api\`\uFF09\uFF1A
|
|
5856
|
+
- \`adep dev\`\uFF1A\`/{prefix}/{fn}\`\uFF0C\u5982 \`/api/hello\`\uFF1Bvite \u63D2\u4EF6\u6309\u540C\u4E00\u524D\u7F00\u4EE3\u7406\u3002
|
|
5857
|
+
- \`adep serve\`\uFF1A\`/api/{prefix}/{fn}\`\uFF08\u524D\u7F00\u62FC\u63A5\uFF09\u3002
|
|
5858
|
+
- **\u8FB9\u754C**\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\uFF1B\u51FD\u6570\u4E92\u8C03 \`ctx.cloud.invoke('name')\` \u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C
|
|
5859
|
+
\u4E0D\u968F\u524D\u7F00\u53D8\u5316\uFF08\u4E0E\u7EBF\u4E0A\u540C\u6784\uFF09\u3002
|
|
5860
|
+
|
|
5861
|
+
## \u7AD9\u70B9\u6258\u7BA1\uFF08\u6784\u5EFA \u2192 \u4E0A\u4F20 \u2192 \u4E0A\u7EBF\uFF09
|
|
5862
|
+
|
|
5863
|
+
1. \`pnpm build\`\uFF1Avite \u6784\u5EFA\u524D\u7AEF\u5230 \`site/\`\uFF08\u7AD9\u70B9\u6258\u7BA1\u76EE\u5F55\uFF09\u3002
|
|
5864
|
+
2. \`pnpm site:deploy\`\uFF1A\`adep hosting deploy site --spa\` \u9012\u5F52\u4E0A\u4F20 \`site/\` \u5230\u5E73\u53F0\u9759\u6001\u6258\u7BA1
|
|
5865
|
+
\uFF08site/ \u524D\u7F00\uFF09\uFF0C\u6253\u5F00\u6258\u7BA1\u5F00\u5173\u5E76\u542F\u7528 SPA \u56DE\u9000\uFF0C\u8FD4\u56DE\u7AD9\u70B9\u5730\u5740\u3002
|
|
5866
|
+
\uFF08\u7B49\u4EF7\u547D\u4EE4\uFF1A\`npx adep hosting deploy site --spa\`\uFF1B\u67E5\u770B\uFF1A\`npx adep hosting info\`\uFF09
|
|
5867
|
+
|
|
5436
5868
|
## \u4E91\u51FD\u6570\u7C7B\u578B\u63D0\u793A
|
|
5437
5869
|
|
|
5438
5870
|
\u7528 VSCode \u6253\u5F00\u672C\u76EE\u5F55\uFF0C\u4EFB\u610F \`functions/**\` \u4E0B\u7684 TS \u6587\u4EF6\u5373\u53EF\u83B7\u5F97 \`AdepContext\` / \`ctx.cloud.*\` \u8865\u5168\uFF1A
|
|
@@ -5441,19 +5873,18 @@ AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3
|
|
|
5441
5873
|
|
|
5442
5874
|
## \u6A21\u677F\u8BF4\u660E\uFF08adep init\uFF09
|
|
5443
5875
|
|
|
5444
|
-
- \`adep init <name>\`\uFF1A\u9ED8\u8BA4 \`fullstack\` \u6A21\u677F\uFF08functions/ + web/ \u524D\u7AEF\
|
|
5876
|
+
- \`adep init <name>\`\uFF1A\u9ED8\u8BA4 \`fullstack\` \u6A21\u677F\uFF08functions/ + web/src/ \u524D\u7AEF\u6E90\u7801 + database/\uFF09
|
|
5445
5877
|
- \`adep init <name> -t function\`\uFF1A\u4EC5\u4E91\u51FD\u6570\uFF08\u5355\u4E2A\u793A\u4F8B\u51FD\u6570\uFF09
|
|
5446
5878
|
- \`adep init <name> -t empty\`\uFF1A\u7A7A\u6A21\u677F\uFF08\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF09
|
|
5447
5879
|
- \`adep init --list\`\uFF1A\u4ECE\u5E73\u53F0 /api/v1/templates \u5217\u51FA\u53EF\u7528\u6A21\u677F
|
|
5448
5880
|
- \`adep init --list -s <server>\`\uFF1A\u6307\u5B9A\u5E73\u53F0\u5730\u5740
|
|
5449
5881
|
|
|
5450
|
-
## \u524D\u7AEF\
|
|
5882
|
+
## \u524D\u7AEF\u6E90\u7801\uFF08web/src/\uFF09
|
|
5451
5883
|
|
|
5452
|
-
\`web/\` \
|
|
5453
|
-
|
|
5454
|
-
\u672C\u5730\u5F00\u53D1\uFF1A\`cd web && npm install && npm run dev\`\uFF1B\u90E8\u7F72\u7531 \`adep deploy\` \u7EDF\u4E00\u6784\u5EFA\u53D1\u5E03\u3002
|
|
5884
|
+
\`web/src/\` \u5B58\u653E\u524D\u7AEF\u6E90\u7801\uFF08\`main.ts\` / \`App.vue\`\uFF09\uFF0C\u4E0E Web IDE \u5185 \`web/\` \u5DE5\u7A0B\u7684 \`src/\`
|
|
5885
|
+
\u5B8C\u5168\u540C\u6784\uFF1Bvite \u5DE5\u7A0B\u6839\u5728\u9879\u76EE\u6839\u76EE\u5F55\uFF08\`vite.config.ts\` / \`index.html\` / \`package.json\`\uFF09\u3002
|
|
5455
5886
|
`;
|
|
5456
|
-
var HELLO_FUNCTION = `// \u793A\u4F8B\u51FD\u6570\uFF1Aadep deploy \u540E\u7ECF https://<project-slug>.<platform-domain>/hello \u89E6\u53D1\u3002
|
|
5887
|
+
var HELLO_FUNCTION = `// \u793A\u4F8B\u51FD\u6570\uFF1Aadep deploy \u540E\u7ECF https://<project-slug>.<platform-domain>/api/hello \u89E6\u53D1\u3002
|
|
5457
5888
|
// \u7528\u6237\u51FD\u6570\u5373 functions/ \u4E0B\u7684\u72EC\u7ACB\u6587\u4EF6\uFF0C\u9ED8\u8BA4\u5BFC\u51FA (ctx: AdepContext) => Response \u5F62\u72B6\u7684\u5904\u7406\u5668
|
|
5458
5889
|
//\uFF08ctx \u5951\u7EA6\u89C1 adep.d.ts\uFF1Amethod / path / query / headers / body / files / user / cloud.*\uFF09\u3002
|
|
5459
5890
|
export default async (ctx: AdepContext) => {
|
|
@@ -5464,11 +5895,39 @@ export default async (ctx: AdepContext) => {
|
|
|
5464
5895
|
var FUNCTION_INDEX = `// \u51FD\u6570\u6A21\u5757\u5165\u53E3\uFF1A\u9879\u76EE\u91CC\u7684\u6BCF\u4E2A\u51FD\u6570\u662F functions/ \u4E0B\u7684\u72EC\u7ACB\u6587\u4EF6\uFF0C
|
|
5465
5896
|
// \u9ED8\u8BA4\u5BFC\u51FA (ctx: AdepContext) => Response \u5F62\u72B6\u7684\u5904\u7406\u5668\uFF08\u5951\u7EA6\u89C1 adep.d.ts\uFF09\u3002
|
|
5466
5897
|
`;
|
|
5467
|
-
var EMPTY_INDEX = `// AgentDeploy \u9879\u76EE\u5165\u53E3\u3002\u6A21\u677F\u6682\u65E0\u66F4\u591A\u5185\u5BB9\u2014\u2014\u51FD\u6570\u653E functions/\uFF0C\u524D\u7AEF\u653E web/\uFF0C\u914D\u7F6E\u89C1 adep.config.ts\u3002
|
|
5898
|
+
var EMPTY_INDEX = `// AgentDeploy \u9879\u76EE\u5165\u53E3\u3002\u6A21\u677F\u6682\u65E0\u66F4\u591A\u5185\u5BB9\u2014\u2014\u51FD\u6570\u653E functions/\uFF0C\u524D\u7AEF\u653E web/src/\uFF0C\u914D\u7F6E\u89C1 adep.config.ts\u3002
|
|
5468
5899
|
`;
|
|
5469
5900
|
var SCHEMA_SQL = `-- AgentDeploy \u9879\u76EE\u6570\u636E\u5E93\u7ED3\u6784\uFF08\u5360\u4F4D\uFF09\u3002
|
|
5470
5901
|
-- \u8868\u7ED3\u6784\u8BF7\u5728\u5E73\u53F0\u63A7\u5236\u53F0\u300C\u6570\u636E\u5E93\u300D\u6216\u672C\u5730 \`adep db\` \u4E2D\u521B\u5EFA\u540E\u56DE\u586B\uFF0C\u4FDD\u6301\u4E0E\u7EBF\u4E0A schema \u4E00\u81F4\u3002
|
|
5471
5902
|
`;
|
|
5903
|
+
var INDEX_HTML = `<!doctype html>
|
|
5904
|
+
<html lang="zh-CN">
|
|
5905
|
+
<head>
|
|
5906
|
+
<meta charset="utf-8" />
|
|
5907
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
5908
|
+
<title>adep web</title>
|
|
5909
|
+
</head>
|
|
5910
|
+
<body>
|
|
5911
|
+
<div id="app"></div>
|
|
5912
|
+
<script type="module" src="/web/src/main.ts"></script>
|
|
5913
|
+
</body>
|
|
5914
|
+
</html>
|
|
5915
|
+
`;
|
|
5916
|
+
var VITE_CONFIG = `// vite.config.ts \u2014\u2014 \u9879\u76EE\u6839 vite \u914D\u7F6E\uFF08CLI-014 \u5168\u6808\u5F00\u53D1\u4F53\u9A8C\uFF09\u3002
|
|
5917
|
+
// adep() \u662F @adep/cli \u7684\u4E91\u51FD\u6570 vite \u63D2\u4EF6\uFF1A\u5185\u7F6E adep dev server \u5E76\u6309 adep.config.ts \u7684
|
|
5918
|
+
// functions_prefix\uFF08\u9ED8\u8BA4 /api\uFF09\u628A /api/* \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\u2014\u2014vite dev \u5373\u53EF\u8C03\u8BD5\u524D\u7AEF + \u51FD\u6570\u3002
|
|
5919
|
+
import { defineConfig } from 'vite'
|
|
5920
|
+
import vue from '@vitejs/plugin-vue'
|
|
5921
|
+
import adep from '@adep/cli/vite'
|
|
5922
|
+
|
|
5923
|
+
export default defineConfig({
|
|
5924
|
+
plugins: [vue(), adep()],
|
|
5925
|
+
build: {
|
|
5926
|
+
// \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269 \u2192 site/\uFF08\u4E91\u51FD\u6570\u5DE5\u7A0B\u7AD9\u70B9\u6258\u7BA1\u76EE\u5F55\uFF1Bpnpm site:deploy \u4E0A\u4F20\u90E8\u7F72\uFF09
|
|
5927
|
+
outDir: 'site',
|
|
5928
|
+
},
|
|
5929
|
+
})
|
|
5930
|
+
`;
|
|
5472
5931
|
async function initProject(cwd, name, template) {
|
|
5473
5932
|
if (!/^[a-z][a-z0-9-]{0,62}$/.test(name)) {
|
|
5474
5933
|
throw new InitError(
|
|
@@ -5493,12 +5952,22 @@ async function initProject(cwd, name, template) {
|
|
|
5493
5952
|
throw new InitError("DIR_EXISTS", `\u76EE\u5F55 ${projectPath} \u5DF2\u5B58\u5728\uFF1A\u8BF7\u6362\u4E00\u4E2A\u540D\u5B57\u6216\u5148\u5220\u9664`);
|
|
5494
5953
|
}
|
|
5495
5954
|
const files = [
|
|
5496
|
-
|
|
5955
|
+
// 根 package.json:应用定义(@adep/cli + 前端依赖同根声明;与导出的离线部署包同构键集)。
|
|
5956
|
+
{ path: "package.json", content: PACKAGE_JSON(name, template) },
|
|
5957
|
+
// adep.config.ts:经 shared/sdk/adep-config 的 renderAdepConfig 渲染(schema 唯一真相源)。
|
|
5958
|
+
// template 是 init 元数据(不在 AdepConfig 中),经 extraFields 传入。
|
|
5959
|
+
{
|
|
5960
|
+
path: "adep.config.ts",
|
|
5961
|
+
content: renderAdepConfig(
|
|
5962
|
+
{ name, functionsDir: "functions", functions_prefix: "/api" },
|
|
5963
|
+
{ header: ADEP_CONFIG_HEADER, extraFields: { template } }
|
|
5964
|
+
)
|
|
5965
|
+
},
|
|
5497
5966
|
// 云函数 TypeScript 类型提示:tsconfig 把 adep.d.ts 纳入 include,写 ctx: AdepContext 即有补全。
|
|
5498
5967
|
{ path: "tsconfig.json", content: ADEP_TSCONFIG_JSON },
|
|
5499
5968
|
{ path: "adep.d.ts", content: ADEP_ENV_DTS },
|
|
5500
5969
|
{ path: "README.md", content: README(name, template) },
|
|
5501
|
-
{ path: ".gitignore", content: "node_modules/\ndata/\n.adep/\
|
|
5970
|
+
{ path: ".gitignore", content: "node_modules/\ndata/\n.adep/\nsite/\n" }
|
|
5502
5971
|
];
|
|
5503
5972
|
if (template === "function") {
|
|
5504
5973
|
files.push({ path: "functions/hello.ts", content: HELLO_FUNCTION });
|
|
@@ -5507,7 +5976,9 @@ async function initProject(cwd, name, template) {
|
|
|
5507
5976
|
files.push({ path: "functions/hello.ts", content: HELLO_FUNCTION });
|
|
5508
5977
|
files.push({ path: "functions/README.md", content: FUNCTION_INDEX });
|
|
5509
5978
|
files.push({ path: "database/schema.sql", content: SCHEMA_SQL });
|
|
5510
|
-
|
|
5979
|
+
files.push({ path: "index.html", content: INDEX_HTML });
|
|
5980
|
+
files.push({ path: "vite.config.ts", content: VITE_CONFIG });
|
|
5981
|
+
for (const file of webSrcFiles()) {
|
|
5511
5982
|
files.push({ path: `web/${file.path}`, content: file.content });
|
|
5512
5983
|
}
|
|
5513
5984
|
} else {
|
|
@@ -5524,7 +5995,7 @@ async function initProject(cwd, name, template) {
|
|
|
5524
5995
|
return { projectPath, files: files.map((file) => file.path) };
|
|
5525
5996
|
}
|
|
5526
5997
|
|
|
5527
|
-
//
|
|
5998
|
+
// src/output.ts
|
|
5528
5999
|
function isCommandError(error) {
|
|
5529
6000
|
return error instanceof CliError || error instanceof InitError;
|
|
5530
6001
|
}
|
|
@@ -5605,7 +6076,7 @@ function formatSeconds(seconds) {
|
|
|
5605
6076
|
return `${Math.max(0.1, Math.round(seconds * 10) / 10)}s`;
|
|
5606
6077
|
}
|
|
5607
6078
|
|
|
5608
|
-
//
|
|
6079
|
+
// src/commands/context.ts
|
|
5609
6080
|
function createCliContext(deps) {
|
|
5610
6081
|
const { output, paths, cwd, json } = deps;
|
|
5611
6082
|
return {
|
|
@@ -5616,7 +6087,7 @@ function createCliContext(deps) {
|
|
|
5616
6087
|
};
|
|
5617
6088
|
}
|
|
5618
6089
|
|
|
5619
|
-
//
|
|
6090
|
+
// src/commands/auth.ts
|
|
5620
6091
|
init_auth();
|
|
5621
6092
|
init_config();
|
|
5622
6093
|
function registerAuth(program2, ctx) {
|
|
@@ -5663,10 +6134,10 @@ function registerAuth(program2, ctx) {
|
|
|
5663
6134
|
});
|
|
5664
6135
|
}
|
|
5665
6136
|
|
|
5666
|
-
//
|
|
6137
|
+
// src/commands/init.ts
|
|
5667
6138
|
init_config();
|
|
5668
6139
|
|
|
5669
|
-
//
|
|
6140
|
+
// src/templates.ts
|
|
5670
6141
|
init_auth();
|
|
5671
6142
|
async function fetchTemplates(server) {
|
|
5672
6143
|
let response;
|
|
@@ -5693,7 +6164,7 @@ async function fetchTemplates(server) {
|
|
|
5693
6164
|
return templates ?? [];
|
|
5694
6165
|
}
|
|
5695
6166
|
|
|
5696
|
-
//
|
|
6167
|
+
// src/commands/init.ts
|
|
5697
6168
|
function registerInit(program2, ctx) {
|
|
5698
6169
|
program2.command("init").description("\u521D\u59CB\u5316\u9879\u76EE\uFF08\u6A21\u677F\uFF1Aempty / function / fullstack\uFF09\uFF0C\u6216 --list \u4ECE\u5E73\u53F0\u53D6\u6A21\u677F\u6E05\u5355").argument("[name]", "\u9879\u76EE\u76EE\u5F55\u540D\uFF08\u914D\u5408 --list \u65F6\u53EF\u7701\u7565\uFF09").option("-t, --template <template>", "\u6A21\u677F\uFF1Aempty | function | fullstack", "fullstack").option("-l, --list", "\u4ECE\u5E73\u53F0 /api/v1/templates \u5217\u51FA\u53EF\u7528\u6A21\u677F\uFF08\u4E0D\u811A\u624B\u67B6\uFF09", false).option(
|
|
5699
6170
|
"-s, --server <url>",
|
|
@@ -5730,7 +6201,7 @@ function registerInit(program2, ctx) {
|
|
|
5730
6201
|
);
|
|
5731
6202
|
}
|
|
5732
6203
|
|
|
5733
|
-
//
|
|
6204
|
+
// src/commands/dev.ts
|
|
5734
6205
|
function registerDevServers(program2, ctx) {
|
|
5735
6206
|
program2.command("dev").description("\u672C\u5730\u8C03\u8BD5\uFF1A\u76D1\u542C functions/ \u70ED\u91CD\u8F7D\uFF0Chttp://localhost:<port>/<fnName>").option("-p, --port <port>", "\u76D1\u542C\u7AEF\u53E3\uFF08\u7F3A\u7701 8787\uFF09", "8787").action(async (flags) => {
|
|
5736
6207
|
const command = ctx.io("dev");
|
|
@@ -5768,7 +6239,123 @@ function registerDevServers(program2, ctx) {
|
|
|
5768
6239
|
});
|
|
5769
6240
|
}
|
|
5770
6241
|
|
|
5771
|
-
//
|
|
6242
|
+
// src/commands/publish.ts
|
|
6243
|
+
init_auth();
|
|
6244
|
+
init_client();
|
|
6245
|
+
init_deploy();
|
|
6246
|
+
import { resolve as resolve6 } from "node:path";
|
|
6247
|
+
async function resolveProjectId(client, cwd, slug) {
|
|
6248
|
+
const resolvedSlug = await resolveSlug(resolve6(cwd), slug);
|
|
6249
|
+
const listed = await client.request("/api/v1/projects", {}, "PROJECT_LIST_FAILED");
|
|
6250
|
+
const match = listed.projects.find((project2) => project2.slug === resolvedSlug);
|
|
6251
|
+
if (match === void 0) {
|
|
6252
|
+
throw new CliError(
|
|
6253
|
+
"PROJECT_NOT_FOUND",
|
|
6254
|
+
`\u5E73\u53F0\u9879\u76EE "${resolvedSlug}" \u4E0D\u5B58\u5728\u6216\u4F60\u6CA1\u6709\u8BBF\u95EE\u6743\u9650\uFF1A\u5148\u6267\u884C adep projects create ${resolvedSlug}`
|
|
6255
|
+
);
|
|
6256
|
+
}
|
|
6257
|
+
return { id: match.id, slug: match.slug };
|
|
6258
|
+
}
|
|
6259
|
+
async function publishFrontend(paths, options) {
|
|
6260
|
+
const log = options.silent === true ? () => void 0 : options.log ?? ((line) => process.stdout.write(`${line}
|
|
6261
|
+
`));
|
|
6262
|
+
const client = await createClient(paths);
|
|
6263
|
+
const project2 = await resolveProjectId(client, options.cwd, options.slug);
|
|
6264
|
+
log(`[adep] \u89E6\u53D1\u5E73\u53F0\u4FA7\u524D\u7AEF\u6784\u5EFA\uFF08\u9879\u76EE ${project2.slug}\uFF09\u2026`);
|
|
6265
|
+
const published = await client.request(
|
|
6266
|
+
`/api/v1/projects/${project2.id}/frontend/publish`,
|
|
6267
|
+
{ method: "POST" },
|
|
6268
|
+
"FRONTEND_PUBLISH_FAILED"
|
|
6269
|
+
);
|
|
6270
|
+
const versions = await client.request(
|
|
6271
|
+
`/api/v1/projects/${project2.id}/frontend/versions`,
|
|
6272
|
+
{},
|
|
6273
|
+
"FRONTEND_VERSIONS_FAILED"
|
|
6274
|
+
);
|
|
6275
|
+
return {
|
|
6276
|
+
version: published.version,
|
|
6277
|
+
hash: published.hash,
|
|
6278
|
+
createdAt: published.createdAt,
|
|
6279
|
+
reused: published.reused,
|
|
6280
|
+
siteUrl: versions.siteUrl
|
|
6281
|
+
};
|
|
6282
|
+
}
|
|
6283
|
+
async function publishFunctions(paths, options) {
|
|
6284
|
+
const startedAt = Date.now();
|
|
6285
|
+
const result = await deploy(paths, {
|
|
6286
|
+
cwd: options.cwd,
|
|
6287
|
+
...options.slug === void 0 ? {} : { slug: options.slug },
|
|
6288
|
+
silent: options.silent ?? false,
|
|
6289
|
+
...options.log === void 0 ? {} : { log: options.log }
|
|
6290
|
+
});
|
|
6291
|
+
const elapsedSeconds = (Date.now() - startedAt) / 1e3;
|
|
6292
|
+
const deployedCount = result.functions.filter((fn) => fn.action !== "none").length;
|
|
6293
|
+
return { ...result, elapsedSeconds, deployedCount };
|
|
6294
|
+
}
|
|
6295
|
+
async function runPublish(paths, io, cwd, flags) {
|
|
6296
|
+
const scope = flags.only === void 0 ? "fullstack" : flags.only;
|
|
6297
|
+
if (flags.only !== void 0 && flags.only !== "functions" && flags.only !== "frontend") {
|
|
6298
|
+
throw new CliError("INVALID_SCOPE", `--only \u987B\u4E3A functions \u6216 frontend\uFF0C\u6536\u5230 "${flags.only}"`);
|
|
6299
|
+
}
|
|
6300
|
+
const wantFunctions = scope === "fullstack" || scope === "functions";
|
|
6301
|
+
const wantFrontend = scope === "fullstack" || scope === "frontend";
|
|
6302
|
+
const result = { scope };
|
|
6303
|
+
if (wantFunctions) {
|
|
6304
|
+
result.functions = await publishFunctions(paths, {
|
|
6305
|
+
cwd,
|
|
6306
|
+
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
6307
|
+
silent: io.json,
|
|
6308
|
+
log: (line) => io.line(line)
|
|
6309
|
+
});
|
|
6310
|
+
}
|
|
6311
|
+
if (wantFrontend) {
|
|
6312
|
+
result.frontend = await publishFrontend(paths, {
|
|
6313
|
+
cwd,
|
|
6314
|
+
...flags.project === void 0 ? {} : { slug: flags.project },
|
|
6315
|
+
silent: io.json,
|
|
6316
|
+
log: (line) => io.line(line)
|
|
6317
|
+
});
|
|
6318
|
+
}
|
|
6319
|
+
return result;
|
|
6320
|
+
}
|
|
6321
|
+
function renderPublish(data) {
|
|
6322
|
+
const result = data;
|
|
6323
|
+
const lines = [];
|
|
6324
|
+
if (result.functions !== void 0) {
|
|
6325
|
+
for (const fn of result.functions.functions) {
|
|
6326
|
+
lines.push(`${fn.name} v${fn.version} ${fn.url}`);
|
|
6327
|
+
}
|
|
6328
|
+
if (result.functions.noChanges) {
|
|
6329
|
+
lines.push(
|
|
6330
|
+
`\u2713 no changes \xB7 ${result.functions.functions.length} functions up to date in ${formatSeconds(result.functions.elapsedSeconds)}`
|
|
6331
|
+
);
|
|
6332
|
+
} else {
|
|
6333
|
+
lines.push(
|
|
6334
|
+
`\u2713 ${result.functions.deployedCount} functions deployed in ${formatSeconds(result.functions.elapsedSeconds)}`
|
|
6335
|
+
);
|
|
6336
|
+
}
|
|
6337
|
+
}
|
|
6338
|
+
if (result.frontend !== void 0) {
|
|
6339
|
+
const fe = result.frontend;
|
|
6340
|
+
const status = fe.reused ? `\uFF08\u590D\u7528 v${fe.version}\uFF0C\u65E0\u53D8\u66F4\uFF09` : `v${fe.version}`;
|
|
6341
|
+
lines.push(`\u2713 frontend built ${status} \xB7 ${fe.siteUrl}`);
|
|
6342
|
+
}
|
|
6343
|
+
return lines;
|
|
6344
|
+
}
|
|
6345
|
+
function registerPublish(program2, ctx) {
|
|
6346
|
+
program2.command("publish").description("\u5168\u6808\u53D1\u5E03\uFF1A\u51FD\u6570\u90E8\u7F72 + \u524D\u7AEF\u6784\u5EFA\u6258\u7BA1\uFF08--only functions|frontend \u53EF\u5355\u72EC\u53D1\u5E03\u4E00\u4FA7\uFF09").option(
|
|
6347
|
+
"--only <scope>",
|
|
6348
|
+
"\u4EC5\u53D1\u5E03\u4E00\u4FA7\uFF1Afunctions\uFF08\u53EA\u90E8\u7F72\u4E91\u51FD\u6570\uFF09| frontend\uFF08\u53EA\u6784\u5EFA\u6258\u7BA1\u524D\u7AEF\uFF09\uFF1B\u7F3A\u7701\u5168\u6808\u53D1\u5E03"
|
|
6349
|
+
).option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
6350
|
+
const command = ctx.io("publish");
|
|
6351
|
+
await command.run(async () => {
|
|
6352
|
+
const result = await runPublish(ctx.paths, command, ctx.cwd, flags);
|
|
6353
|
+
command.ok(result, renderPublish);
|
|
6354
|
+
});
|
|
6355
|
+
});
|
|
6356
|
+
}
|
|
6357
|
+
|
|
6358
|
+
// src/commands/deploy.ts
|
|
5772
6359
|
async function runDeploy(paths, io, cwd, slug, dir) {
|
|
5773
6360
|
const { deploy: deploy2 } = await Promise.resolve().then(() => (init_deploy(), deploy_exports));
|
|
5774
6361
|
const startedAt = Date.now();
|
|
@@ -5798,178 +6385,58 @@ async function runDeploy(paths, io, cwd, slug, dir) {
|
|
|
5798
6385
|
});
|
|
5799
6386
|
}
|
|
5800
6387
|
function registerDeploy(program2, ctx) {
|
|
5801
|
-
program2.command("deploy").description(
|
|
6388
|
+
program2.command("deploy").description(
|
|
6389
|
+
"[deprecated] \u63A8\u8350\u4F7F\u7528 adep publish\u3002\u589E\u91CF\u90E8\u7F72\u51FD\u6570\uFF1A\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D"
|
|
6390
|
+
).option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
5802
6391
|
const command = ctx.io("deploy");
|
|
6392
|
+
if (!command.json) {
|
|
6393
|
+
process.stderr.write(
|
|
6394
|
+
"\u63D0\u793A\uFF1Aadep deploy \u5DF2\u5E9F\u5F03\uFF0C\u63A8\u8350\u4F7F\u7528 adep publish\uFF08\u5168\u6808\u53D1\u5E03\uFF09\u6216 adep publish --only functions\uFF08\u4EC5\u51FD\u6570\uFF09\n"
|
|
6395
|
+
);
|
|
6396
|
+
}
|
|
5803
6397
|
await command.run(() => runDeploy(ctx.paths, command, ctx.cwd, flags.project));
|
|
5804
6398
|
});
|
|
5805
6399
|
}
|
|
5806
6400
|
|
|
5807
|
-
//
|
|
5808
|
-
function
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
const { projectsCreate: projectsCreate2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
5814
|
-
const created = await projectsCreate2(ctx.paths, {
|
|
5815
|
-
slug,
|
|
5816
|
-
...flags.name === void 0 ? {} : { name: flags.name },
|
|
5817
|
-
...flags.space === void 0 ? {} : { spaceId: flags.space }
|
|
5818
|
-
});
|
|
5819
|
-
command.ok(created, (data) => `\u2713 Project created \xB7 ${data.url}`);
|
|
5820
|
-
});
|
|
5821
|
-
});
|
|
5822
|
-
projects.command("list").description("\u5217\u51FA\u5F53\u524D\u7528\u6237\u53EF\u8BBF\u95EE\u7684\u9879\u76EE").action(async () => {
|
|
5823
|
-
const command = ctx.io("projects list");
|
|
5824
|
-
await command.run(async () => {
|
|
5825
|
-
const { projectsList: projectsList2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
5826
|
-
const list = await projectsList2(ctx.paths);
|
|
5827
|
-
command.ok({ projects: list }, (data) => {
|
|
5828
|
-
const projectsData = data.projects;
|
|
5829
|
-
if (projectsData.length === 0) return "\uFF08\u8FD8\u6CA1\u6709\u9879\u76EE\uFF1Aadep projects create <slug>\uFF09";
|
|
5830
|
-
return projectsData.map((p) => `${p.slug} ${p.name} ${p.url}`);
|
|
5831
|
-
});
|
|
5832
|
-
});
|
|
5833
|
-
});
|
|
5834
|
-
projects.command("info").description("\u67E5\u770B\u5355\u4E2A\u9879\u76EE\u7684 id / slug / \u5B50\u57DF\u5730\u5740").argument("<slug>", "\u9879\u76EE slug").action(async (slug) => {
|
|
5835
|
-
const command = ctx.io("projects info");
|
|
5836
|
-
await command.run(async () => {
|
|
5837
|
-
const { projectsInfo: projectsInfo2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
5838
|
-
const project2 = await projectsInfo2(ctx.paths, { slug });
|
|
5839
|
-
command.ok(project2, (data) => {
|
|
5840
|
-
const p = data;
|
|
5841
|
-
return `${p.id} ${p.slug} ${p.name} ${p.url}`;
|
|
5842
|
-
});
|
|
5843
|
-
});
|
|
5844
|
-
});
|
|
5845
|
-
}
|
|
5846
|
-
|
|
5847
|
-
// packages/cli/src/commands/functions.ts
|
|
5848
|
-
init_auth();
|
|
5849
|
-
function registerFunctions(program2, ctx) {
|
|
5850
|
-
const functions = program2.command("functions").description("\u4E91\u51FD\u6570\uFF1A\u90E8\u7F72\uFF08\u53EF\u6307\u5B9A\u76EE\u5F55\uFF09/ \u5217\u51FA / \u67E5\u65E5\u5FD7");
|
|
5851
|
-
functions.command("deploy").description(
|
|
5852
|
-
"\u90E8\u7F72\u51FD\u6570\u76EE\u5F55\uFF08`adep deploy` \u7684\u547D\u4EE4\u65CF\u5165\u53E3\uFF1Bdir \u8986\u76D6 adep.config.ts \u7684 functionsDir\uFF09"
|
|
5853
|
-
).argument("[dir]", "\u51FD\u6570\u76EE\u5F55\uFF08\u76F8\u5BF9\u9879\u76EE\u6839\u6216\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u7F3A\u7701\u53D6\u914D\u7F6E\u91CC\u7684 functionsDir\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (dir, flags) => {
|
|
5854
|
-
const command = ctx.io("functions deploy");
|
|
5855
|
-
await command.run(() => runDeploy(ctx.paths, command, ctx.cwd, flags.project, dir));
|
|
5856
|
-
});
|
|
5857
|
-
functions.command("list").description("\u5217\u51FA\u9879\u76EE\u4E0B\u7684\u4E91\u51FD\u6570\uFF08\u542B\u516C\u7F51\u8BBF\u95EE\u524D\u7F00\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
5858
|
-
const command = ctx.io("functions list");
|
|
5859
|
-
await command.run(async () => {
|
|
5860
|
-
const { functionsList: functionsList2 } = await Promise.resolve().then(() => (init_functions(), functions_exports));
|
|
5861
|
-
const result = await functionsList2(ctx.paths, {
|
|
5862
|
-
cwd: ctx.cwd,
|
|
5863
|
-
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
5864
|
-
});
|
|
5865
|
-
command.ok(result, (data) => {
|
|
5866
|
-
const r = data;
|
|
5867
|
-
if (r.functions.length === 0) return "\uFF08\u8BE5\u9879\u76EE\u4E0B\u8FD8\u6CA1\u6709\u51FD\u6570\uFF09";
|
|
5868
|
-
return r.functions.map((fn) => `${fn.name} ${r.baseUrl}/${fn.name}`);
|
|
5869
|
-
});
|
|
5870
|
-
});
|
|
5871
|
-
});
|
|
5872
|
-
functions.command("logs").description("\u67E5\u8BE2\u51FD\u6570\u6700\u8FD1\u6267\u884C\u65E5\u5FD7\uFF08\u7F13\u51B2\u5728\u5E73\u53F0\u8FDB\u7A0B\u5185\uFF0C\u672A\u6267\u884C\u8FC7\u7684\u51FD\u6570\u4E3A\u7A7A\uFF09").argument("<name>", "\u51FD\u6570\u540D").option("--tail <count>", "\u53D6\u6700\u8FD1\u591A\u5C11\u6761\uFF08\u7F3A\u7701 100\uFF0C\u670D\u52A1\u7AEF\u6709\u4E0A\u9650\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (name, flags) => {
|
|
5873
|
-
const command = ctx.io("functions logs");
|
|
5874
|
-
await command.run(async () => {
|
|
5875
|
-
const { functionsLogs: functionsLogs2 } = await Promise.resolve().then(() => (init_functions(), functions_exports));
|
|
5876
|
-
const tail = flags.tail === void 0 ? void 0 : Number(flags.tail);
|
|
5877
|
-
if (tail !== void 0 && (!Number.isFinite(tail) || tail <= 0)) {
|
|
5878
|
-
throw new CliError("INVALID_TAIL", `--tail \u987B\u4E3A\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${flags.tail}"`);
|
|
5879
|
-
}
|
|
5880
|
-
const result = await functionsLogs2(ctx.paths, {
|
|
5881
|
-
cwd: ctx.cwd,
|
|
5882
|
-
name,
|
|
5883
|
-
...tail === void 0 ? {} : { tail },
|
|
5884
|
-
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
5885
|
-
});
|
|
5886
|
-
command.ok(result, (data) => {
|
|
5887
|
-
const r = data;
|
|
5888
|
-
if (r.logs.length === 0) {
|
|
5889
|
-
return `\uFF08\u51FD\u6570 ${name} \u6682\u65E0\u6267\u884C\u65E5\u5FD7\uFF1A\u5148\u7528 adep deploy \u53D1\u5E03\u5E76\u7ECF\u7F51\u5173\u6216\u8C03\u8BD5\u9762\u677F\u6267\u884C\u4E00\u6B21\uFF09`;
|
|
5890
|
-
}
|
|
5891
|
-
return r.logs.map((log) => `${log.at} [${log.level}] ${log.message}`);
|
|
5892
|
-
});
|
|
5893
|
-
});
|
|
5894
|
-
});
|
|
5895
|
-
}
|
|
5896
|
-
|
|
5897
|
-
// packages/cli/src/commands/mcp.ts
|
|
5898
|
-
function registerMcp(program2, ctx) {
|
|
5899
|
-
const mcp = program2.command("mcp").description("MCP Tool\uFF1A\u628A\u4E91\u51FD\u6570\u53D1\u5E03\u4E3A\u5DE5\u5177 / \u53D6\u6D88\u53D1\u5E03 / \u5217\u51FA");
|
|
5900
|
-
mcp.command("publish").description("\u53D1\u5E03\u4E91\u51FD\u6570\u4E3A\u9879\u76EE MCP Tool\uFF08Tool \u540D\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF0C--name \u53EF\u8986\u76D6\uFF09").requiredOption("--function <fn>", "\u8981\u53D1\u5E03\u7684\u51FD\u6570\u540D").option("--name <tool>", "\u6CE8\u518C\u7684 Tool \u540D\uFF08\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF09").option(
|
|
5901
|
-
"--description <text>",
|
|
5902
|
-
"\u8986\u76D6\u9762\u5411 Agent \u7684\u5DE5\u5177\u63CF\u8FF0\uFF08\u7F3A\u7701\u7528\u6E90\u7801 @description / \u63A8\u5BFC\u63CF\u8FF0\uFF09"
|
|
5903
|
-
).option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(
|
|
6401
|
+
// src/commands/export.ts
|
|
6402
|
+
function registerExport(program2, ctx) {
|
|
6403
|
+
program2.command("export").description("\u5BFC\u51FA\u81EA\u6258\u7BA1\u90E8\u7F72\u5305\uFF1A\u89E6\u53D1\u957F\u4EFB\u52A1 \u2192 \u8F6E\u8BE2\u8FDB\u5EA6 \u2192 \u4E0B\u8F7D zip \u2192 manifest \u9010\u9879\u81EA\u68C0").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").option("--with-data", "\u5305\u542B\u6570\u636E\u5E93\u884C\u6570\u636E\uFF08\u7F3A\u7701\u4EC5 schema\uFF09").option("--with-source", "[\u5DF2\u5E9F\u5F03] \u542B\u6E90\u7801\u5DF2\u4E3A\u9ED8\u8BA4\u884C\u4E3A\uFF1B\u4FDD\u7559\u4E0D\u62A5\u9519\uFF0C\u4EC5\u63D0\u793A\uFF0C\u5C06\u5728\u672A\u6765\u7248\u672C\u79FB\u9664").option(
|
|
6404
|
+
"--without-source",
|
|
6405
|
+
"\u51FA\u7EAF\u4EA7\u7269\u5305\uFF1A\u4E0D\u5305\u542B\u51FD\u6570\u6E90\u7801\u4E0E web/src/ \u524D\u7AEF\u6E90\u7801\uFF08\u4EC5 site/ \u9884\u6784\u5EFA\u4EA7\u7269\uFF09"
|
|
6406
|
+
).option("--out <dir>", "\u8F93\u51FA\u76EE\u5F55\uFF08\u7F3A\u7701 ./exports\uFF09").action(
|
|
5904
6407
|
async (flags) => {
|
|
5905
|
-
const command = ctx.io("
|
|
6408
|
+
const command = ctx.io("export");
|
|
5906
6409
|
await command.run(async () => {
|
|
5907
|
-
const {
|
|
5908
|
-
const
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
6410
|
+
const { createExportApiClient: createExportApiClient2 } = await Promise.resolve().then(() => (init_client2(), client_exports2));
|
|
6411
|
+
const { createExportFileSystem: createExportFileSystem2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
6412
|
+
const { ExportCommand: ExportCommand2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
6413
|
+
const { resolveSlug: resolveSlug2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
6414
|
+
if (flags.withSource === true) {
|
|
6415
|
+
process.stderr.write(
|
|
6416
|
+
"adep: --with-source \u5DF2\u4E3A\u9ED8\u8BA4\u884C\u4E3A\uFF08\u5BFC\u51FA\u5305\u9ED8\u8BA4\u542B\u51FD\u6570\u6E90\u7801\u4E0E web/src/ \u524D\u7AEF\u6E90\u7801\uFF09\uFF0C\u8BE5\u9009\u9879\u5C06\u5728\u672A\u6765\u7248\u672C\u79FB\u9664\n"
|
|
6417
|
+
);
|
|
6418
|
+
}
|
|
6419
|
+
const project2 = await resolveSlug2(ctx.cwd, flags.project);
|
|
6420
|
+
const apiClient = await createExportApiClient2(ctx.paths);
|
|
6421
|
+
const exportCommand = new ExportCommand2(apiClient, createExportFileSystem2());
|
|
6422
|
+
const result = await exportCommand.execute({
|
|
6423
|
+
project: project2,
|
|
6424
|
+
...flags.withData === true ? { withData: true } : {},
|
|
6425
|
+
...flags.withoutSource === true ? { withoutSource: true } : {},
|
|
6426
|
+
...flags.out === void 0 ? {} : { out: flags.out },
|
|
6427
|
+
json: command.json
|
|
5918
6428
|
});
|
|
6429
|
+
if (!result.success) {
|
|
6430
|
+
command.fail("EXPORT_FAILED", result.error ?? "\u5BFC\u51FA\u5931\u8D25");
|
|
6431
|
+
return;
|
|
6432
|
+
}
|
|
6433
|
+
command.ok(result);
|
|
5919
6434
|
});
|
|
5920
6435
|
}
|
|
5921
6436
|
);
|
|
5922
|
-
mcp.command("unpublish").description("\u53D6\u6D88\u53D1\u5E03\u4E91\u51FD\u6570\u5BF9\u5E94\u7684 MCP Tool\uFF08\u7ACB\u5373\u4ECE\u9879\u76EE tools/list \u79FB\u9664\uFF09").requiredOption("--function <fn>", "\u51FD\u6570\u540D").option("--name <tool>", "\u5DF2\u6CE8\u518C\u7684 Tool \u540D\uFF08\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF1B\u53D1\u5E03\u65F6\u7528\u4E86\u522B\u540D\u624D\u9700\u7ED9\u51FA\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
5923
|
-
const command = ctx.io("mcp unpublish");
|
|
5924
|
-
await command.run(async () => {
|
|
5925
|
-
const { mcpUnpublish: mcpUnpublish2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
5926
|
-
const result = await mcpUnpublish2(ctx.paths, {
|
|
5927
|
-
cwd: ctx.cwd,
|
|
5928
|
-
fn: flags.function,
|
|
5929
|
-
...flags.name === void 0 ? {} : { toolName: flags.name },
|
|
5930
|
-
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
5931
|
-
});
|
|
5932
|
-
command.ok(result, (data) => {
|
|
5933
|
-
const r = data;
|
|
5934
|
-
return r.removed ? `\u2713 MCP tool unpublished \xB7 ${r.toolName}` : `\uFF08\u9879\u76EE\u672A\u53D1\u5E03\u540D\u4E3A ${r.toolName} \u7684 MCP tool\uFF0C\u65E0\u9700\u53D6\u6D88\uFF09`;
|
|
5935
|
-
});
|
|
5936
|
-
});
|
|
5937
|
-
});
|
|
5938
|
-
mcp.command("list").description("\u5217\u51FA\u9879\u76EE\u5DF2\u53D1\u5E03\u7684 MCP Tool \u4E0E\u7AEF\u70B9\u5730\u5740\uFF08\u8BFB\u9879\u76EE /mcp \u7684 tools/list\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
5939
|
-
const command = ctx.io("mcp list");
|
|
5940
|
-
await command.run(async () => {
|
|
5941
|
-
const { mcpList: mcpList2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
5942
|
-
const result = await mcpList2(ctx.paths, {
|
|
5943
|
-
cwd: ctx.cwd,
|
|
5944
|
-
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
5945
|
-
});
|
|
5946
|
-
command.ok(result, (data) => {
|
|
5947
|
-
const r = data;
|
|
5948
|
-
const lines = [`\u7AEF\u70B9\uFF1A${r.endpoint}`];
|
|
5949
|
-
if (r.tools.length === 0) {
|
|
5950
|
-
lines.push("\uFF08\u8FD8\u6CA1\u6709\u5DF2\u53D1\u5E03\u7684 MCP tool\uFF1Aadep mcp publish --function <fn>\uFF09");
|
|
5951
|
-
} else {
|
|
5952
|
-
for (const tool of r.tools) lines.push(`${tool.name} ${tool.description ?? ""}`);
|
|
5953
|
-
}
|
|
5954
|
-
return lines;
|
|
5955
|
-
});
|
|
5956
|
-
});
|
|
5957
|
-
});
|
|
5958
|
-
}
|
|
5959
|
-
|
|
5960
|
-
// packages/cli/src/commands/doctor.ts
|
|
5961
|
-
function registerDoctor(program2, ctx) {
|
|
5962
|
-
program2.command("doctor").description("\u73AF\u5883\u81EA\u68C0\uFF1A\u51ED\u636E\u72B6\u6001 / \u5E73\u53F0\u53EF\u8FBE\u6027 / \u79BB\u7EBF\u53EF\u7528\u8303\u56F4\uFF08\u8865\u9F50\u65AD\u7F51\u6587\u6848\u5F15\u7528\u7684\u60AC\u7A7A\u547D\u4EE4\uFF09").action(async () => {
|
|
5963
|
-
const command = ctx.io("doctor");
|
|
5964
|
-
await command.run(async () => {
|
|
5965
|
-
const { runDoctor: runDoctor2, formatDoctorReport: formatDoctorReport2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
5966
|
-
const report = await runDoctor2(ctx.paths);
|
|
5967
|
-
command.ok(report, () => formatDoctorReport2(report));
|
|
5968
|
-
});
|
|
5969
|
-
});
|
|
5970
6437
|
}
|
|
5971
6438
|
|
|
5972
|
-
//
|
|
6439
|
+
// src/commands/db.ts
|
|
5973
6440
|
function registerDb(program2, ctx) {
|
|
5974
6441
|
const db = program2.command("db").description("\u9879\u76EE\u6570\u636E\u5E93\u7EF4\u62A4\uFF1A\u542F\u52A8 / \u72B6\u6001 / \u505C\u6B62 / SQL / \u5FEB\u7167 / \u56DE\u6EDA").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09");
|
|
5975
6442
|
db.command("start").description("\u542F\u52A8\u9879\u76EE\u6570\u636E\u5E93\uFF08\u5DF2\u5B58\u5728\u5219\u91CD\u65B0\u6FC0\u6D3B\uFF0C\u4E0D\u91CD\u5EFA\u6570\u636E\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
@@ -6098,7 +6565,7 @@ function registerDb(program2, ctx) {
|
|
|
6098
6565
|
});
|
|
6099
6566
|
}
|
|
6100
6567
|
|
|
6101
|
-
//
|
|
6568
|
+
// src/commands/storage.ts
|
|
6102
6569
|
function registerStorage(program2, ctx) {
|
|
6103
6570
|
const storage = program2.command("storage").description("\u4E91\u5B58\u50A8 / \u6587\u4EF6\u5B58\u50A8\uFF1A\u4E0A\u4F20 / \u4E0B\u8F7D / \u5217\u8868 / \u5220\u9664").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09");
|
|
6104
6571
|
storage.command("upload").description("\u4E0A\u4F20\u5355\u4E2A\u6587\u4EF6\uFF08multipart\uFF1B\u5355\u6587\u4EF6 \u2264 50MB\uFF09").argument("<file>", "\u672C\u5730\u6587\u4EF6\u8DEF\u5F84").requiredOption("--path <remote-path>", "\u6876\u5185\u76EE\u6807\u8DEF\u5F84\uFF08\u5982 avatars/a.png\uFF09").option(
|
|
@@ -6172,7 +6639,177 @@ function registerStorage(program2, ctx) {
|
|
|
6172
6639
|
});
|
|
6173
6640
|
}
|
|
6174
6641
|
|
|
6175
|
-
//
|
|
6642
|
+
// src/commands/doctor.ts
|
|
6643
|
+
function registerDoctor(program2, ctx) {
|
|
6644
|
+
program2.command("doctor").description("\u73AF\u5883\u81EA\u68C0\uFF1A\u51ED\u636E\u72B6\u6001 / \u5E73\u53F0\u53EF\u8FBE\u6027 / \u79BB\u7EBF\u53EF\u7528\u8303\u56F4\uFF08\u8865\u9F50\u65AD\u7F51\u6587\u6848\u5F15\u7528\u7684\u60AC\u7A7A\u547D\u4EE4\uFF09").action(async () => {
|
|
6645
|
+
const command = ctx.io("doctor");
|
|
6646
|
+
await command.run(async () => {
|
|
6647
|
+
const { runDoctor: runDoctor2, formatDoctorReport: formatDoctorReport2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6648
|
+
const report = await runDoctor2(ctx.paths);
|
|
6649
|
+
command.ok(report, () => formatDoctorReport2(report));
|
|
6650
|
+
});
|
|
6651
|
+
});
|
|
6652
|
+
}
|
|
6653
|
+
|
|
6654
|
+
// src/commands/mcp.ts
|
|
6655
|
+
function registerMcp(program2, ctx) {
|
|
6656
|
+
const mcp = program2.command("mcp").description("MCP Tool\uFF1A\u628A\u4E91\u51FD\u6570\u53D1\u5E03\u4E3A\u5DE5\u5177 / \u53D6\u6D88\u53D1\u5E03 / \u5217\u51FA");
|
|
6657
|
+
mcp.command("publish").description("\u53D1\u5E03\u4E91\u51FD\u6570\u4E3A\u9879\u76EE MCP Tool\uFF08Tool \u540D\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF0C--name \u53EF\u8986\u76D6\uFF09").requiredOption("--function <fn>", "\u8981\u53D1\u5E03\u7684\u51FD\u6570\u540D").option("--name <tool>", "\u6CE8\u518C\u7684 Tool \u540D\uFF08\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF09").option(
|
|
6658
|
+
"--description <text>",
|
|
6659
|
+
"\u8986\u76D6\u9762\u5411 Agent \u7684\u5DE5\u5177\u63CF\u8FF0\uFF08\u7F3A\u7701\u7528\u6E90\u7801 @description / \u63A8\u5BFC\u63CF\u8FF0\uFF09"
|
|
6660
|
+
).option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(
|
|
6661
|
+
async (flags) => {
|
|
6662
|
+
const command = ctx.io("mcp publish");
|
|
6663
|
+
await command.run(async () => {
|
|
6664
|
+
const { mcpPublish: mcpPublish2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
6665
|
+
const result = await mcpPublish2(ctx.paths, {
|
|
6666
|
+
cwd: ctx.cwd,
|
|
6667
|
+
fn: flags.function,
|
|
6668
|
+
...flags.name === void 0 ? {} : { toolName: flags.name },
|
|
6669
|
+
...flags.description === void 0 ? {} : { description: flags.description },
|
|
6670
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
6671
|
+
});
|
|
6672
|
+
command.ok(result, (data) => {
|
|
6673
|
+
const r = data;
|
|
6674
|
+
return `\u2713 MCP tool published \xB7 ${r.tool.name}`;
|
|
6675
|
+
});
|
|
6676
|
+
});
|
|
6677
|
+
}
|
|
6678
|
+
);
|
|
6679
|
+
mcp.command("unpublish").description("\u53D6\u6D88\u53D1\u5E03\u4E91\u51FD\u6570\u5BF9\u5E94\u7684 MCP Tool\uFF08\u7ACB\u5373\u4ECE\u9879\u76EE tools/list \u79FB\u9664\uFF09").requiredOption("--function <fn>", "\u51FD\u6570\u540D").option("--name <tool>", "\u5DF2\u6CE8\u518C\u7684 Tool \u540D\uFF08\u7F3A\u7701\u53D6\u51FD\u6570\u540D\uFF1B\u53D1\u5E03\u65F6\u7528\u4E86\u522B\u540D\u624D\u9700\u7ED9\u51FA\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
6680
|
+
const command = ctx.io("mcp unpublish");
|
|
6681
|
+
await command.run(async () => {
|
|
6682
|
+
const { mcpUnpublish: mcpUnpublish2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
6683
|
+
const result = await mcpUnpublish2(ctx.paths, {
|
|
6684
|
+
cwd: ctx.cwd,
|
|
6685
|
+
fn: flags.function,
|
|
6686
|
+
...flags.name === void 0 ? {} : { toolName: flags.name },
|
|
6687
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
6688
|
+
});
|
|
6689
|
+
command.ok(result, (data) => {
|
|
6690
|
+
const r = data;
|
|
6691
|
+
return r.removed ? `\u2713 MCP tool unpublished \xB7 ${r.toolName}` : `\uFF08\u9879\u76EE\u672A\u53D1\u5E03\u540D\u4E3A ${r.toolName} \u7684 MCP tool\uFF0C\u65E0\u9700\u53D6\u6D88\uFF09`;
|
|
6692
|
+
});
|
|
6693
|
+
});
|
|
6694
|
+
});
|
|
6695
|
+
mcp.command("list").description("\u5217\u51FA\u9879\u76EE\u5DF2\u53D1\u5E03\u7684 MCP Tool \u4E0E\u7AEF\u70B9\u5730\u5740\uFF08\u8BFB\u9879\u76EE /mcp \u7684 tools/list\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
6696
|
+
const command = ctx.io("mcp list");
|
|
6697
|
+
await command.run(async () => {
|
|
6698
|
+
const { mcpList: mcpList2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
6699
|
+
const result = await mcpList2(ctx.paths, {
|
|
6700
|
+
cwd: ctx.cwd,
|
|
6701
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
6702
|
+
});
|
|
6703
|
+
command.ok(result, (data) => {
|
|
6704
|
+
const r = data;
|
|
6705
|
+
const lines = [`\u7AEF\u70B9\uFF1A${r.endpoint}`];
|
|
6706
|
+
if (r.tools.length === 0) {
|
|
6707
|
+
lines.push("\uFF08\u8FD8\u6CA1\u6709\u5DF2\u53D1\u5E03\u7684 MCP tool\uFF1Aadep mcp publish --function <fn>\uFF09");
|
|
6708
|
+
} else {
|
|
6709
|
+
for (const tool of r.tools) lines.push(`${tool.name} ${tool.description ?? ""}`);
|
|
6710
|
+
}
|
|
6711
|
+
return lines;
|
|
6712
|
+
});
|
|
6713
|
+
});
|
|
6714
|
+
});
|
|
6715
|
+
}
|
|
6716
|
+
|
|
6717
|
+
// src/commands/projects.ts
|
|
6718
|
+
function registerProjects(program2, ctx) {
|
|
6719
|
+
const projects = program2.command("projects").description("\u9879\u76EE\uFF1A\u521B\u5EFA / \u5217\u51FA / \u67E5\u770B\uFF08\u5B50\u57DF\u5730\u5740\u7531\u5E73\u53F0\u56DE\u663E\uFF0C\u4E0D\u5728 CLI \u4FA7\u62FC\uFF09");
|
|
6720
|
+
projects.command("create").description("\u521B\u5EFA\u9879\u76EE\u5E76\u8F93\u51FA\u5B50\u57DF\u5730\u5740").argument("<slug>", "\u9879\u76EE slug\uFF08\u5168\u5C40\u552F\u4E00\uFF0C\u5373\u5B50\u57DF\u540D\uFF09").option("-n, --name <name>", "\u9879\u76EE\u5C55\u793A\u540D\uFF08\u7F3A\u7701\u53D6 slug\uFF09").option("--space <spaceId>", "\u5F52\u5C5E\u7A7A\u95F4\uFF08\u7F3A\u7701\u4E2A\u4EBA\u7A7A\u95F4\uFF09").action(async (slug, flags) => {
|
|
6721
|
+
const command = ctx.io("projects create");
|
|
6722
|
+
await command.run(async () => {
|
|
6723
|
+
const { projectsCreate: projectsCreate2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
6724
|
+
const created = await projectsCreate2(ctx.paths, {
|
|
6725
|
+
slug,
|
|
6726
|
+
...flags.name === void 0 ? {} : { name: flags.name },
|
|
6727
|
+
...flags.space === void 0 ? {} : { spaceId: flags.space }
|
|
6728
|
+
});
|
|
6729
|
+
command.ok(created, (data) => `\u2713 Project created \xB7 ${data.url}`);
|
|
6730
|
+
});
|
|
6731
|
+
});
|
|
6732
|
+
projects.command("list").description("\u5217\u51FA\u5F53\u524D\u7528\u6237\u53EF\u8BBF\u95EE\u7684\u9879\u76EE").action(async () => {
|
|
6733
|
+
const command = ctx.io("projects list");
|
|
6734
|
+
await command.run(async () => {
|
|
6735
|
+
const { projectsList: projectsList2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
6736
|
+
const list = await projectsList2(ctx.paths);
|
|
6737
|
+
command.ok({ projects: list }, (data) => {
|
|
6738
|
+
const projectsData = data.projects;
|
|
6739
|
+
if (projectsData.length === 0) return "\uFF08\u8FD8\u6CA1\u6709\u9879\u76EE\uFF1Aadep projects create <slug>\uFF09";
|
|
6740
|
+
return projectsData.map((p) => `${p.slug} ${p.name} ${p.url}`);
|
|
6741
|
+
});
|
|
6742
|
+
});
|
|
6743
|
+
});
|
|
6744
|
+
projects.command("info").description("\u67E5\u770B\u5355\u4E2A\u9879\u76EE\u7684 id / slug / \u5B50\u57DF\u5730\u5740").argument("<slug>", "\u9879\u76EE slug").action(async (slug) => {
|
|
6745
|
+
const command = ctx.io("projects info");
|
|
6746
|
+
await command.run(async () => {
|
|
6747
|
+
const { projectsInfo: projectsInfo2 } = await Promise.resolve().then(() => (init_projects(), projects_exports));
|
|
6748
|
+
const project2 = await projectsInfo2(ctx.paths, { slug });
|
|
6749
|
+
command.ok(project2, (data) => {
|
|
6750
|
+
const p = data;
|
|
6751
|
+
return `${p.id} ${p.slug} ${p.name} ${p.url}`;
|
|
6752
|
+
});
|
|
6753
|
+
});
|
|
6754
|
+
});
|
|
6755
|
+
}
|
|
6756
|
+
|
|
6757
|
+
// src/commands/functions.ts
|
|
6758
|
+
init_auth();
|
|
6759
|
+
function registerFunctions(program2, ctx) {
|
|
6760
|
+
const functions = program2.command("functions").description("\u4E91\u51FD\u6570\uFF1A\u90E8\u7F72\uFF08\u53EF\u6307\u5B9A\u76EE\u5F55\uFF09/ \u5217\u51FA / \u67E5\u65E5\u5FD7");
|
|
6761
|
+
functions.command("deploy").description(
|
|
6762
|
+
"[deprecated] \u63A8\u8350\u4F7F\u7528 adep publish --only functions\u3002\u90E8\u7F72\u51FD\u6570\u76EE\u5F55\uFF08dir \u8986\u76D6 adep.config.ts \u7684 functionsDir\uFF09"
|
|
6763
|
+
).argument("[dir]", "\u51FD\u6570\u76EE\u5F55\uFF08\u76F8\u5BF9\u9879\u76EE\u6839\u6216\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u7F3A\u7701\u53D6\u914D\u7F6E\u91CC\u7684 functionsDir\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (dir, flags) => {
|
|
6764
|
+
const command = ctx.io("functions deploy");
|
|
6765
|
+
if (!command.json) {
|
|
6766
|
+
process.stderr.write(
|
|
6767
|
+
"\u63D0\u793A\uFF1Aadep functions deploy \u5DF2\u5E9F\u5F03\uFF0C\u63A8\u8350\u4F7F\u7528 adep publish --only functions\n"
|
|
6768
|
+
);
|
|
6769
|
+
}
|
|
6770
|
+
await command.run(() => runDeploy(ctx.paths, command, ctx.cwd, flags.project, dir));
|
|
6771
|
+
});
|
|
6772
|
+
functions.command("list").description("\u5217\u51FA\u9879\u76EE\u4E0B\u7684\u4E91\u51FD\u6570\uFF08\u542B\u516C\u7F51\u8BBF\u95EE\u524D\u7F00\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (flags) => {
|
|
6773
|
+
const command = ctx.io("functions list");
|
|
6774
|
+
await command.run(async () => {
|
|
6775
|
+
const { functionsList: functionsList2 } = await Promise.resolve().then(() => (init_functions(), functions_exports));
|
|
6776
|
+
const result = await functionsList2(ctx.paths, {
|
|
6777
|
+
cwd: ctx.cwd,
|
|
6778
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
6779
|
+
});
|
|
6780
|
+
command.ok(result, (data) => {
|
|
6781
|
+
const r = data;
|
|
6782
|
+
if (r.functions.length === 0) return "\uFF08\u8BE5\u9879\u76EE\u4E0B\u8FD8\u6CA1\u6709\u51FD\u6570\uFF09";
|
|
6783
|
+
return r.functions.map((fn) => `${fn.name} ${r.baseUrl}/${fn.name}`);
|
|
6784
|
+
});
|
|
6785
|
+
});
|
|
6786
|
+
});
|
|
6787
|
+
functions.command("logs").description("\u67E5\u8BE2\u51FD\u6570\u6700\u8FD1\u6267\u884C\u65E5\u5FD7\uFF08\u7F13\u51B2\u5728\u5E73\u53F0\u8FDB\u7A0B\u5185\uFF0C\u672A\u6267\u884C\u8FC7\u7684\u51FD\u6570\u4E3A\u7A7A\uFF09").argument("<name>", "\u51FD\u6570\u540D").option("--tail <count>", "\u53D6\u6700\u8FD1\u591A\u5C11\u6761\uFF08\u7F3A\u7701 100\uFF0C\u670D\u52A1\u7AEF\u6709\u4E0A\u9650\uFF09").option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (name, flags) => {
|
|
6788
|
+
const command = ctx.io("functions logs");
|
|
6789
|
+
await command.run(async () => {
|
|
6790
|
+
const { functionsLogs: functionsLogs2 } = await Promise.resolve().then(() => (init_functions(), functions_exports));
|
|
6791
|
+
const tail = flags.tail === void 0 ? void 0 : Number(flags.tail);
|
|
6792
|
+
if (tail !== void 0 && (!Number.isFinite(tail) || tail <= 0)) {
|
|
6793
|
+
throw new CliError("INVALID_TAIL", `--tail \u987B\u4E3A\u6B63\u6574\u6570\uFF0C\u6536\u5230 "${flags.tail}"`);
|
|
6794
|
+
}
|
|
6795
|
+
const result = await functionsLogs2(ctx.paths, {
|
|
6796
|
+
cwd: ctx.cwd,
|
|
6797
|
+
name,
|
|
6798
|
+
...tail === void 0 ? {} : { tail },
|
|
6799
|
+
...flags.project === void 0 ? {} : { slug: flags.project }
|
|
6800
|
+
});
|
|
6801
|
+
command.ok(result, (data) => {
|
|
6802
|
+
const r = data;
|
|
6803
|
+
if (r.logs.length === 0) {
|
|
6804
|
+
return `\uFF08\u51FD\u6570 ${name} \u6682\u65E0\u6267\u884C\u65E5\u5FD7\uFF1A\u5148\u7528 adep deploy \u53D1\u5E03\u5E76\u7ECF\u7F51\u5173\u6216\u8C03\u8BD5\u9762\u677F\u6267\u884C\u4E00\u6B21\uFF09`;
|
|
6805
|
+
}
|
|
6806
|
+
return r.logs.map((log) => `${log.at} [${log.level}] ${log.message}`);
|
|
6807
|
+
});
|
|
6808
|
+
});
|
|
6809
|
+
});
|
|
6810
|
+
}
|
|
6811
|
+
|
|
6812
|
+
// src/commands/hosting.ts
|
|
6176
6813
|
init_auth();
|
|
6177
6814
|
function parseBool(raw) {
|
|
6178
6815
|
if (raw === void 0) return void 0;
|
|
@@ -6200,8 +6837,15 @@ function registerHosting(program2, ctx) {
|
|
|
6200
6837
|
});
|
|
6201
6838
|
});
|
|
6202
6839
|
});
|
|
6203
|
-
hosting.command("deploy").description(
|
|
6840
|
+
hosting.command("deploy").description(
|
|
6841
|
+
"[deprecated] \u63A8\u8350\u4F7F\u7528 adep publish --only frontend\u3002\u90E8\u7F72\u672C\u5730\u76EE\u5F55\u4E3A\u9759\u6001\u7AD9\u70B9\uFF1A\u9012\u5F52\u4E0A\u4F20\u5230 site/ \u5E76\u6253\u5F00\u6258\u7BA1"
|
|
6842
|
+
).argument("<dir>", "\u672C\u5730\u7AD9\u70B9\u76EE\u5F55").option("--spa", "\u6253\u5F00\u6258\u7BA1\u5E76\u542F\u7528 SPA \u56DE\u9000\uFF08\u7F3A\u7701\u4EC5\u6253\u5F00\u6258\u7BA1\uFF09", false).option("-p, --project <slug>", "\u76EE\u6807\u5E73\u53F0\u9879\u76EE slug\uFF08\u7F3A\u7701\u53D6 adep.config.ts \u7684 name\uFF09").action(async (dir, flags) => {
|
|
6204
6843
|
const command = ctx.io("hosting deploy");
|
|
6844
|
+
if (!command.json) {
|
|
6845
|
+
process.stderr.write(
|
|
6846
|
+
"\u63D0\u793A\uFF1Aadep hosting deploy \u5DF2\u5E9F\u5F03\uFF0C\u63A8\u8350\u4F7F\u7528 adep publish --only frontend\uFF08\u5E73\u53F0\u4FA7\u6784\u5EFA web/ \u8349\u7A3F\uFF09\uFF1B\u5982\u786E\u9700\u4E0A\u4F20\u9884\u6784\u5EFA\u76EE\u5F55\uFF0C\u4ECD\u53EF\u7EE7\u7EED\u4F7F\u7528\u672C\u547D\u4EE4\n"
|
|
6847
|
+
);
|
|
6848
|
+
}
|
|
6205
6849
|
await command.run(async () => {
|
|
6206
6850
|
const { hostingDeploy: hostingDeploy2 } = await Promise.resolve().then(() => (init_hosting(), hosting_exports));
|
|
6207
6851
|
const result = await hostingDeploy2(ctx.paths, {
|
|
@@ -6251,39 +6895,9 @@ function registerHosting(program2, ctx) {
|
|
|
6251
6895
|
});
|
|
6252
6896
|
}
|
|
6253
6897
|
|
|
6254
|
-
//
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
async (flags) => {
|
|
6258
|
-
const command = ctx.io("export");
|
|
6259
|
-
await command.run(async () => {
|
|
6260
|
-
const { createExportApiClient: createExportApiClient2 } = await Promise.resolve().then(() => (init_client2(), client_exports2));
|
|
6261
|
-
const { createExportFileSystem: createExportFileSystem2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
6262
|
-
const { ExportCommand: ExportCommand2 } = await Promise.resolve().then(() => (init_command(), command_exports));
|
|
6263
|
-
const { resolveSlug: resolveSlug2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
6264
|
-
const project2 = await resolveSlug2(ctx.cwd, flags.project);
|
|
6265
|
-
const apiClient = await createExportApiClient2(ctx.paths);
|
|
6266
|
-
const exportCommand = new ExportCommand2(apiClient, createExportFileSystem2());
|
|
6267
|
-
const result = await exportCommand.execute({
|
|
6268
|
-
project: project2,
|
|
6269
|
-
...flags.withData === true ? { withData: true } : {},
|
|
6270
|
-
...flags.withSource === true ? { withSource: true } : {},
|
|
6271
|
-
...flags.out === void 0 ? {} : { out: flags.out },
|
|
6272
|
-
json: command.json
|
|
6273
|
-
});
|
|
6274
|
-
if (!result.success) {
|
|
6275
|
-
command.fail("EXPORT_FAILED", result.error ?? "\u5BFC\u51FA\u5931\u8D25");
|
|
6276
|
-
return;
|
|
6277
|
-
}
|
|
6278
|
-
command.ok(result);
|
|
6279
|
-
});
|
|
6280
|
-
}
|
|
6281
|
-
);
|
|
6282
|
-
}
|
|
6283
|
-
|
|
6284
|
-
// packages/cli/src/cli.ts
|
|
6285
|
-
var requireJson = createRequire(import.meta.url);
|
|
6286
|
-
var APP_VERSION = requireJson("../package.json").version;
|
|
6898
|
+
// src/cli.ts
|
|
6899
|
+
var requireJson2 = createRequire2(import.meta.url);
|
|
6900
|
+
var APP_VERSION = requireJson2("../package.json").version;
|
|
6287
6901
|
function buildProgram(options = {}) {
|
|
6288
6902
|
const output = options.output ?? ((line) => process.stdout.write(`${line}
|
|
6289
6903
|
`));
|
|
@@ -6294,21 +6908,22 @@ function buildProgram(options = {}) {
|
|
|
6294
6908
|
program2.option("--json", "\u4EE5\u673A\u5668\u53EF\u8BFB JSON \u8F93\u51FA\uFF08Agent / \u811A\u672C\u8C03\u7528\uFF09", false);
|
|
6295
6909
|
const jsonMode = () => program2.opts()["json"] === true;
|
|
6296
6910
|
const ctx = createCliContext({ output, paths, cwd, json: jsonMode });
|
|
6297
|
-
registerAuth(program2, ctx);
|
|
6298
6911
|
registerInit(program2, ctx);
|
|
6299
6912
|
registerDevServers(program2, ctx);
|
|
6913
|
+
registerPublish(program2, ctx);
|
|
6914
|
+
registerExport(program2, ctx);
|
|
6915
|
+
registerDb(program2, ctx);
|
|
6916
|
+
registerStorage(program2, ctx);
|
|
6917
|
+
registerDoctor(program2, ctx);
|
|
6918
|
+
registerAuth(program2, ctx);
|
|
6919
|
+
registerMcp(program2, ctx);
|
|
6300
6920
|
registerDeploy(program2, ctx);
|
|
6301
6921
|
registerProjects(program2, ctx);
|
|
6302
6922
|
registerFunctions(program2, ctx);
|
|
6303
|
-
registerMcp(program2, ctx);
|
|
6304
|
-
registerDoctor(program2, ctx);
|
|
6305
|
-
registerDb(program2, ctx);
|
|
6306
|
-
registerStorage(program2, ctx);
|
|
6307
6923
|
registerHosting(program2, ctx);
|
|
6308
|
-
registerExport(program2, ctx);
|
|
6309
6924
|
return program2;
|
|
6310
6925
|
}
|
|
6311
6926
|
|
|
6312
|
-
//
|
|
6927
|
+
// src/index.ts
|
|
6313
6928
|
var program = buildProgram();
|
|
6314
6929
|
await program.parseAsync(process.argv);
|