@lark-apaas/fullstack-cli 1.1.16-beta.10 → 1.1.16-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +65 -38
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7264,26 +7264,48 @@ var UPLOAD_STATIC_DEFAULTS = {
|
|
|
7264
7264
|
};
|
|
7265
7265
|
|
|
7266
7266
|
// src/commands/build/api-client.ts
|
|
7267
|
+
var ERROR_RESPONSE_PREVIEW_LIMIT = 2e3;
|
|
7268
|
+
async function getErrorResponseDetails(response) {
|
|
7269
|
+
try {
|
|
7270
|
+
if (typeof response.text === "function") {
|
|
7271
|
+
const text = await response.text();
|
|
7272
|
+
if (!text) {
|
|
7273
|
+
return "";
|
|
7274
|
+
}
|
|
7275
|
+
return `, response: ${text.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT)}`;
|
|
7276
|
+
}
|
|
7277
|
+
if (typeof response.json === "function") {
|
|
7278
|
+
const data = await response.json();
|
|
7279
|
+
const serialized = JSON.stringify(data);
|
|
7280
|
+
if (!serialized) {
|
|
7281
|
+
return "";
|
|
7282
|
+
}
|
|
7283
|
+
return `, response: ${serialized.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT)}`;
|
|
7284
|
+
}
|
|
7285
|
+
} catch {
|
|
7286
|
+
return "";
|
|
7287
|
+
}
|
|
7288
|
+
return "";
|
|
7289
|
+
}
|
|
7290
|
+
async function throwIfResponseNotOk(response, message) {
|
|
7291
|
+
if (response.ok && response.status === 200) {
|
|
7292
|
+
return;
|
|
7293
|
+
}
|
|
7294
|
+
const details = await getErrorResponseDetails(response);
|
|
7295
|
+
throw new Error(`${message}: ${response.status} ${response.statusText}${details}`);
|
|
7296
|
+
}
|
|
7267
7297
|
async function genArtifactUploadCredential(appId, body) {
|
|
7268
7298
|
const client = getHttpClient();
|
|
7269
7299
|
const url = `/v1/app/${appId}/pipeline/gen_artifact_upload_credential`;
|
|
7270
7300
|
const response = await client.post(url, body);
|
|
7271
|
-
|
|
7272
|
-
throw new Error(
|
|
7273
|
-
`gen_artifact_upload_credential \u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`
|
|
7274
|
-
);
|
|
7275
|
-
}
|
|
7301
|
+
await throwIfResponseNotOk(response, "gen_artifact_upload_credential \u8BF7\u6C42\u5931\u8D25");
|
|
7276
7302
|
return response.json();
|
|
7277
7303
|
}
|
|
7278
7304
|
async function getDefaultBucketId(appId) {
|
|
7279
7305
|
const client = getHttpClient();
|
|
7280
7306
|
const url = `/v1/app/${appId}/storage/inner/staticBucket`;
|
|
7281
7307
|
const response = await client.post(url, {});
|
|
7282
|
-
|
|
7283
|
-
throw new Error(
|
|
7284
|
-
`getOrCreateStaticBucket \u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`
|
|
7285
|
-
);
|
|
7286
|
-
}
|
|
7308
|
+
await throwIfResponseNotOk(response, "getOrCreateStaticBucket \u8BF7\u6C42\u5931\u8D25");
|
|
7287
7309
|
const data = await response.json();
|
|
7288
7310
|
if (data.status_code !== "0") {
|
|
7289
7311
|
throw new Error(`getOrCreateStaticBucket \u8FD4\u56DE\u5F02\u5E38, status_code: ${data.status_code}`);
|
|
@@ -7298,22 +7320,14 @@ async function preUploadStaticAttachment(appId, bucketId) {
|
|
|
7298
7320
|
const client = getHttpClient();
|
|
7299
7321
|
const url = `/v1/app/${appId}/storage/bucket/${bucketId}/preUploadStatic`;
|
|
7300
7322
|
const response = await client.post(url, {});
|
|
7301
|
-
|
|
7302
|
-
throw new Error(
|
|
7303
|
-
`preUploadStatic \u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`
|
|
7304
|
-
);
|
|
7305
|
-
}
|
|
7323
|
+
await throwIfResponseNotOk(response, "preUploadStatic \u8BF7\u6C42\u5931\u8D25");
|
|
7306
7324
|
return response.json();
|
|
7307
7325
|
}
|
|
7308
7326
|
async function uploadStaticAttachmentCallback(appId, bucketId, body) {
|
|
7309
7327
|
const client = getHttpClient();
|
|
7310
7328
|
const url = `/v1/app/${appId}/storage/bucket/${bucketId}/object/callbackStatic`;
|
|
7311
7329
|
const response = await client.post(url, body);
|
|
7312
|
-
|
|
7313
|
-
throw new Error(
|
|
7314
|
-
`callbackStatic \u8BF7\u6C42\u5931\u8D25: ${response.status} ${response.statusText}`
|
|
7315
|
-
);
|
|
7316
|
-
}
|
|
7330
|
+
await throwIfResponseNotOk(response, "callbackStatic \u8BF7\u6C42\u5931\u8D25");
|
|
7317
7331
|
return response.json();
|
|
7318
7332
|
}
|
|
7319
7333
|
|
|
@@ -7351,6 +7365,7 @@ function camelToKebab(str) {
|
|
|
7351
7365
|
|
|
7352
7366
|
// src/commands/build/upload-static.handler.ts
|
|
7353
7367
|
import * as fs25 from "fs";
|
|
7368
|
+
import * as os2 from "os";
|
|
7354
7369
|
import * as path21 from "path";
|
|
7355
7370
|
import { execFileSync } from "child_process";
|
|
7356
7371
|
function readCredentialsFromEnv() {
|
|
@@ -7409,21 +7424,30 @@ async function uploadStatic(options) {
|
|
|
7409
7424
|
({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
|
|
7410
7425
|
}
|
|
7411
7426
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7427
|
+
const confPath = path21.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
|
|
7428
|
+
fs25.writeFileSync(confPath, "");
|
|
7429
|
+
try {
|
|
7430
|
+
console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
|
|
7431
|
+
configureTosutil(resolvedTosutil, confPath, {
|
|
7432
|
+
endpoint,
|
|
7433
|
+
region,
|
|
7434
|
+
accessKeyID,
|
|
7435
|
+
secretAccessKey,
|
|
7436
|
+
sessionToken
|
|
7437
|
+
});
|
|
7438
|
+
console.error(`${LOG_PREFIX} \u4E0A\u4F20 ${resolvedStaticDir} -> ${uploadPrefix}`);
|
|
7439
|
+
uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
|
|
7440
|
+
} finally {
|
|
7441
|
+
try {
|
|
7442
|
+
fs25.unlinkSync(confPath);
|
|
7443
|
+
} catch {
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7422
7446
|
console.error(`${LOG_PREFIX} tosutil \u4E0A\u4F20\u5B8C\u6210`);
|
|
7423
7447
|
console.error(`${LOG_PREFIX} \u8C03\u7528 callbackStatic (uploadID: ${uploadID})...`);
|
|
7424
7448
|
const callbackResp = await uploadStaticAttachmentCallback(appId, bucketId, { uploadID });
|
|
7425
7449
|
if (callbackResp.status_code !== "0") {
|
|
7426
|
-
throw new Error(`callbackStatic \u8FD4\u56DE\u5F02\u5E38, status_code: ${callbackResp.status_code}`);
|
|
7450
|
+
throw new Error(`callbackStatic \u8FD4\u56DE\u5F02\u5E38, status_code: ${callbackResp.status_code}, response: ${JSON.stringify(callbackResp)}`);
|
|
7427
7451
|
}
|
|
7428
7452
|
const attachments = callbackResp.data?.attachments || [];
|
|
7429
7453
|
console.error(`${LOG_PREFIX} \u4E0A\u4F20\u5B8C\u6210\uFF0C\u5171 ${attachments.length} \u4E2A\u6587\u4EF6`);
|
|
@@ -7448,29 +7472,29 @@ function resolveTosutilPath(tosutilPath) {
|
|
|
7448
7472
|
async function fetchPreUpload(appId, bucketId) {
|
|
7449
7473
|
const response = await preUploadStaticAttachment(appId, bucketId);
|
|
7450
7474
|
if (response.status_code !== "0") {
|
|
7451
|
-
throw new Error(`preUploadStatic \u8FD4\u56DE\u5F02\u5E38, status_code: ${response.status_code}`);
|
|
7475
|
+
throw new Error(`preUploadStatic \u8FD4\u56DE\u5F02\u5E38, status_code: ${response.status_code}, response: ${JSON.stringify(response)}`);
|
|
7452
7476
|
}
|
|
7453
7477
|
const { uploadPrefix, uploadID, uploadCredential } = response.data || {};
|
|
7454
7478
|
if (!uploadPrefix || !uploadID) {
|
|
7455
|
-
throw new Error(
|
|
7479
|
+
throw new Error(`preUploadStatic \u8FD4\u56DE\u6570\u636E\u4E0D\u5B8C\u6574\uFF0C\u7F3A\u5C11 uploadPrefix \u6216 uploadID, response: ${JSON.stringify(response)}`);
|
|
7456
7480
|
}
|
|
7457
7481
|
if (!uploadCredential?.AccessKeyID || !uploadCredential?.SecretAccessKey || !uploadCredential?.SessionToken) {
|
|
7458
|
-
throw new Error(
|
|
7482
|
+
throw new Error(`preUploadStatic \u8FD4\u56DE\u7684\u51ED\u8BC1\u5B57\u6BB5\u4E0D\u5B8C\u6574, response: ${JSON.stringify(response)}`);
|
|
7459
7483
|
}
|
|
7460
7484
|
return response;
|
|
7461
7485
|
}
|
|
7462
|
-
function configureTosutil(tosutilPath, config) {
|
|
7486
|
+
function configureTosutil(tosutilPath, confPath, config) {
|
|
7463
7487
|
const { endpoint, region, accessKeyID, secretAccessKey, sessionToken } = config;
|
|
7464
7488
|
execFileSync(
|
|
7465
7489
|
tosutilPath,
|
|
7466
|
-
["config", "-e", endpoint, "-i", accessKeyID, "-k", secretAccessKey, "-t", sessionToken, "-re", region],
|
|
7490
|
+
["config", "-conf", confPath, "-e", endpoint, "-i", accessKeyID, "-k", secretAccessKey, "-t", sessionToken, "-re", region],
|
|
7467
7491
|
{ stdio: "pipe" }
|
|
7468
7492
|
);
|
|
7469
7493
|
}
|
|
7470
|
-
function uploadToTos(tosutilPath, sourceDir, destUrl) {
|
|
7494
|
+
function uploadToTos(tosutilPath, confPath, sourceDir, destUrl) {
|
|
7471
7495
|
execFileSync(
|
|
7472
7496
|
tosutilPath,
|
|
7473
|
-
["cp", sourceDir, destUrl, "-r", "-flat", "-j", "5", "-p", "3", "-ps", "10485760", "-f"],
|
|
7497
|
+
["cp", "-conf", confPath, sourceDir, destUrl, "-r", "-flat", "-j", "5", "-p", "3", "-ps", "10485760", "-f"],
|
|
7474
7498
|
{ stdio: "inherit" }
|
|
7475
7499
|
);
|
|
7476
7500
|
}
|
|
@@ -7500,15 +7524,18 @@ async function preUploadStatic(options) {
|
|
|
7500
7524
|
const response = await preUploadStaticAttachment(appId, bucketId);
|
|
7501
7525
|
if (response.status_code !== "0") {
|
|
7502
7526
|
console.error(`${LOG_PREFIX2} preUploadStatic \u8FD4\u56DE\u5F02\u5E38, status_code: ${response.status_code}`);
|
|
7527
|
+
console.error(`${LOG_PREFIX2} preUploadStatic \u54CD\u5E94: ${JSON.stringify(response)}`);
|
|
7503
7528
|
return;
|
|
7504
7529
|
}
|
|
7505
7530
|
const { downloadURLPrefix, uploadPrefix, uploadID, uploadCredential } = response.data || {};
|
|
7506
7531
|
if (!downloadURLPrefix || !uploadPrefix || !uploadID) {
|
|
7507
7532
|
console.error(`${LOG_PREFIX2} preUploadStatic \u8FD4\u56DE\u6570\u636E\u4E0D\u5B8C\u6574`);
|
|
7533
|
+
console.error(`${LOG_PREFIX2} preUploadStatic \u54CD\u5E94: ${JSON.stringify(response)}`);
|
|
7508
7534
|
return;
|
|
7509
7535
|
}
|
|
7510
7536
|
if (!uploadCredential?.AccessKeyID || !uploadCredential?.SecretAccessKey || !uploadCredential?.SessionToken) {
|
|
7511
7537
|
console.error(`${LOG_PREFIX2} preUploadStatic \u8FD4\u56DE\u7684\u51ED\u8BC1\u5B57\u6BB5\u4E0D\u5B8C\u6574`);
|
|
7538
|
+
console.error(`${LOG_PREFIX2} preUploadStatic \u54CD\u5E94: ${JSON.stringify(response)}`);
|
|
7512
7539
|
return;
|
|
7513
7540
|
}
|
|
7514
7541
|
console.log(`export STATIC_ASSETS_BASE_URL="${shellEscape(downloadURLPrefix)}"`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/fullstack-cli",
|
|
3
|
-
"version": "1.1.16-beta.
|
|
3
|
+
"version": "1.1.16-beta.12",
|
|
4
4
|
"description": "CLI tool for fullstack template management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/node": "^22.0.0",
|
|
53
53
|
"tsup": "^8.3.5",
|
|
54
54
|
"typescript": "^5.9.2",
|
|
55
|
-
"vitest": "^2.
|
|
55
|
+
"vitest": "^3.2.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"typescript": "^5.9.2"
|