edgeone 1.0.17 → 1.0.18
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/edgeone-dist/cli.js +67 -58
- package/package.json +1 -1
package/edgeone-dist/cli.js
CHANGED
|
@@ -99086,25 +99086,25 @@ var require_util6 = __commonJS({
|
|
|
99086
99086
|
// node_modules/cos-nodejs-sdk-v5/sdk/event.js
|
|
99087
99087
|
var require_event = __commonJS({
|
|
99088
99088
|
"node_modules/cos-nodejs-sdk-v5/sdk/event.js"(exports2, module2) {
|
|
99089
|
-
var initEvent = function(
|
|
99089
|
+
var initEvent = function(cos) {
|
|
99090
99090
|
var listeners = {};
|
|
99091
99091
|
var getList = function(action) {
|
|
99092
99092
|
!listeners[action] && (listeners[action] = []);
|
|
99093
99093
|
return listeners[action];
|
|
99094
99094
|
};
|
|
99095
|
-
|
|
99095
|
+
cos.on = function(action, callback) {
|
|
99096
99096
|
if (action === "task-list-update") {
|
|
99097
99097
|
console.warn('warning: Event "' + action + '" has been deprecated. Please use "list-update" instead.');
|
|
99098
99098
|
}
|
|
99099
99099
|
getList(action).push(callback);
|
|
99100
99100
|
};
|
|
99101
|
-
|
|
99101
|
+
cos.off = function(action, callback) {
|
|
99102
99102
|
var list = getList(action);
|
|
99103
99103
|
for (var i3 = list.length - 1; i3 >= 0; i3--) {
|
|
99104
99104
|
callback === list[i3] && list.splice(i3, 1);
|
|
99105
99105
|
}
|
|
99106
99106
|
};
|
|
99107
|
-
|
|
99107
|
+
cos.emit = function(action, data) {
|
|
99108
99108
|
var list = getList(action).map(function(cb2) {
|
|
99109
99109
|
return cb2;
|
|
99110
99110
|
});
|
|
@@ -110635,7 +110635,7 @@ var require_task = __commonJS({
|
|
|
110635
110635
|
}
|
|
110636
110636
|
};
|
|
110637
110637
|
};
|
|
110638
|
-
var initTask = function(
|
|
110638
|
+
var initTask = function(cos) {
|
|
110639
110639
|
var queue = [];
|
|
110640
110640
|
var tasks = {};
|
|
110641
110641
|
var uploadingFileCount = 0;
|
|
@@ -110663,8 +110663,8 @@ var require_task = __commonJS({
|
|
|
110663
110663
|
var timer;
|
|
110664
110664
|
var emit = function() {
|
|
110665
110665
|
timer = 0;
|
|
110666
|
-
|
|
110667
|
-
|
|
110666
|
+
cos.emit("task-list-update", { list: util4.map(queue, formatTask) });
|
|
110667
|
+
cos.emit("list-update", { list: util4.map(queue, formatTask) });
|
|
110668
110668
|
};
|
|
110669
110669
|
return function() {
|
|
110670
110670
|
if (!timer)
|
|
@@ -110672,11 +110672,11 @@ var require_task = __commonJS({
|
|
|
110672
110672
|
};
|
|
110673
110673
|
}();
|
|
110674
110674
|
var clearQueue = function() {
|
|
110675
|
-
if (queue.length <=
|
|
110675
|
+
if (queue.length <= cos.options.UploadQueueSize)
|
|
110676
110676
|
return;
|
|
110677
110677
|
for (var i3 = 0; i3 < nextUploadIndex && // 小于当前操作的 index 才清理
|
|
110678
110678
|
i3 < queue.length && // 大于队列才清理
|
|
110679
|
-
queue.length >
|
|
110679
|
+
queue.length > cos.options.UploadQueueSize; ) {
|
|
110680
110680
|
var isActive = queue[i3].state === "waiting" || queue[i3].state === "checking" || queue[i3].state === "uploading";
|
|
110681
110681
|
if (!queue[i3] || !isActive) {
|
|
110682
110682
|
tasks[queue[i3].id] && delete tasks[queue[i3].id];
|
|
@@ -110689,7 +110689,7 @@ var require_task = __commonJS({
|
|
|
110689
110689
|
emitListUpdate();
|
|
110690
110690
|
};
|
|
110691
110691
|
var startNextTask = function() {
|
|
110692
|
-
if (uploadingFileCount >=
|
|
110692
|
+
if (uploadingFileCount >= cos.options.FileParallelLimit)
|
|
110693
110693
|
return;
|
|
110694
110694
|
while (queue[nextUploadIndex] && queue[nextUploadIndex].state !== "waiting")
|
|
110695
110695
|
nextUploadIndex++;
|
|
@@ -110702,8 +110702,8 @@ var require_task = __commonJS({
|
|
|
110702
110702
|
task.params.onTaskStart && task.params.onTaskStart(formatTask(task));
|
|
110703
110703
|
!task.params.UploadData && (task.params.UploadData = {});
|
|
110704
110704
|
var apiParams = util4.formatParams(task.api, task.params);
|
|
110705
|
-
originApiMap[task.api].call(
|
|
110706
|
-
if (!
|
|
110705
|
+
originApiMap[task.api].call(cos, apiParams, function(err2, data) {
|
|
110706
|
+
if (!cos._isRunningTask(task.id))
|
|
110707
110707
|
return;
|
|
110708
110708
|
if (task.state === "checking" || task.state === "uploading") {
|
|
110709
110709
|
task.state = err2 ? "error" : "success";
|
|
@@ -110738,7 +110738,7 @@ var require_task = __commonJS({
|
|
|
110738
110738
|
return;
|
|
110739
110739
|
}
|
|
110740
110740
|
task.state = switchToState;
|
|
110741
|
-
|
|
110741
|
+
cos.emit("inner-kill-task", { TaskId: id, toState: switchToState });
|
|
110742
110742
|
try {
|
|
110743
110743
|
var UploadId = task && task.params && task.params.UploadData.UploadId;
|
|
110744
110744
|
} catch (e2) {
|
|
@@ -110761,14 +110761,14 @@ var require_task = __commonJS({
|
|
|
110761
110761
|
}
|
|
110762
110762
|
clearQueue();
|
|
110763
110763
|
};
|
|
110764
|
-
|
|
110764
|
+
cos._addTasks = function(taskList) {
|
|
110765
110765
|
util4.each(taskList, function(task) {
|
|
110766
|
-
|
|
110766
|
+
cos._addTask(task.api, task.params, task.callback, true);
|
|
110767
110767
|
});
|
|
110768
110768
|
emitListUpdate();
|
|
110769
110769
|
};
|
|
110770
110770
|
var isTaskReadyWarning = true;
|
|
110771
|
-
|
|
110771
|
+
cos._addTask = function(api, params, callback, ignoreAddEvent) {
|
|
110772
110772
|
params = util4.formatParams(api, params);
|
|
110773
110773
|
var id = util4.uuid();
|
|
110774
110774
|
params.TaskId = id;
|
|
@@ -110800,7 +110800,7 @@ var require_task = __commonJS({
|
|
|
110800
110800
|
};
|
|
110801
110801
|
var onHashProgress = params.onHashProgress;
|
|
110802
110802
|
params.onHashProgress = function(info2) {
|
|
110803
|
-
if (!
|
|
110803
|
+
if (!cos._isRunningTask(task.id))
|
|
110804
110804
|
return;
|
|
110805
110805
|
task.hashPercent = info2.percent;
|
|
110806
110806
|
onHashProgress && onHashProgress(info2);
|
|
@@ -110808,7 +110808,7 @@ var require_task = __commonJS({
|
|
|
110808
110808
|
};
|
|
110809
110809
|
var onProgress = params.onProgress;
|
|
110810
110810
|
params.onProgress = function(info2) {
|
|
110811
|
-
if (!
|
|
110811
|
+
if (!cos._isRunningTask(task.id))
|
|
110812
110812
|
return;
|
|
110813
110813
|
task.state === "checking" && (task.state = "uploading");
|
|
110814
110814
|
task.loaded = info2.loaded;
|
|
@@ -110829,20 +110829,20 @@ var require_task = __commonJS({
|
|
|
110829
110829
|
});
|
|
110830
110830
|
return id;
|
|
110831
110831
|
};
|
|
110832
|
-
|
|
110832
|
+
cos._isRunningTask = function(id) {
|
|
110833
110833
|
var task = tasks[id];
|
|
110834
110834
|
return !!(task && (task.state === "checking" || task.state === "uploading"));
|
|
110835
110835
|
};
|
|
110836
|
-
|
|
110836
|
+
cos.getTaskList = function() {
|
|
110837
110837
|
return util4.map(queue, formatTask);
|
|
110838
110838
|
};
|
|
110839
|
-
|
|
110839
|
+
cos.cancelTask = function(id) {
|
|
110840
110840
|
killTask(id, "canceled");
|
|
110841
110841
|
};
|
|
110842
|
-
|
|
110842
|
+
cos.pauseTask = function(id) {
|
|
110843
110843
|
killTask(id, "paused");
|
|
110844
110844
|
};
|
|
110845
|
-
|
|
110845
|
+
cos.restartTask = function(id) {
|
|
110846
110846
|
var task = tasks[id];
|
|
110847
110847
|
if (task && (task.state === "paused" || task.state === "error")) {
|
|
110848
110848
|
task.state = "waiting";
|
|
@@ -110851,7 +110851,7 @@ var require_task = __commonJS({
|
|
|
110851
110851
|
startNextTask();
|
|
110852
110852
|
}
|
|
110853
110853
|
};
|
|
110854
|
-
|
|
110854
|
+
cos.isUploadRunning = function() {
|
|
110855
110855
|
return uploadingFileCount || nextUploadIndex < queue.length;
|
|
110856
110856
|
};
|
|
110857
110857
|
};
|
|
@@ -180275,7 +180275,7 @@ var yargs_default = Yargs;
|
|
|
180275
180275
|
// package.json
|
|
180276
180276
|
var package_default = {
|
|
180277
180277
|
name: "edgeone",
|
|
180278
|
-
version: "1.0.
|
|
180278
|
+
version: "1.0.18",
|
|
180279
180279
|
description: "Command-line interface for TencentCloud Pages Functions",
|
|
180280
180280
|
bin: {
|
|
180281
180281
|
edgeone: "./edgeone-bin/edgeone.js"
|
|
@@ -192130,6 +192130,14 @@ var getAuthorization = () => {
|
|
|
192130
192130
|
return `Bearer ${apiKey}`;
|
|
192131
192131
|
};
|
|
192132
192132
|
var getProjectName = () => process.env.EDGEONE_PAGES_PROJECT_NAME || "";
|
|
192133
|
+
var tokenCache = {
|
|
192134
|
+
token: null,
|
|
192135
|
+
cos: null
|
|
192136
|
+
};
|
|
192137
|
+
var resetTokenCache = () => {
|
|
192138
|
+
tokenCache.token = null;
|
|
192139
|
+
tokenCache.cos = null;
|
|
192140
|
+
};
|
|
192133
192141
|
var sleep = (ms) => {
|
|
192134
192142
|
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
192135
192143
|
};
|
|
@@ -192173,6 +192181,9 @@ var checkAndSetBaseUrl = async () => {
|
|
|
192173
192181
|
}
|
|
192174
192182
|
};
|
|
192175
192183
|
var getCosTempToken = async () => {
|
|
192184
|
+
if (tokenCache.token) {
|
|
192185
|
+
return tokenCache.token;
|
|
192186
|
+
}
|
|
192176
192187
|
let body;
|
|
192177
192188
|
if (getProjectName()) {
|
|
192178
192189
|
const result = await describePagesProjects({
|
|
@@ -192200,7 +192211,9 @@ var getCosTempToken = async () => {
|
|
|
192200
192211
|
const errorText = await res.text();
|
|
192201
192212
|
throw new Error(`API request failed (${res.status}): ${errorText}`);
|
|
192202
192213
|
}
|
|
192203
|
-
|
|
192214
|
+
const tokenResponse = await res.json();
|
|
192215
|
+
tokenCache.token = tokenResponse;
|
|
192216
|
+
return tokenResponse;
|
|
192204
192217
|
};
|
|
192205
192218
|
var getOrCreateProject = async () => {
|
|
192206
192219
|
if (getProjectName()) {
|
|
@@ -192355,31 +192368,24 @@ var createPagesDeployment = async (opts) => {
|
|
|
192355
192368
|
}
|
|
192356
192369
|
return data;
|
|
192357
192370
|
};
|
|
192358
|
-
var
|
|
192359
|
-
|
|
192360
|
-
|
|
192361
|
-
|
|
192362
|
-
|
|
192363
|
-
|
|
192364
|
-
|
|
192365
|
-
|
|
192366
|
-
|
|
192367
|
-
|
|
192368
|
-
|
|
192369
|
-
|
|
192370
|
-
|
|
192371
|
-
|
|
192372
|
-
|
|
192373
|
-
|
|
192374
|
-
|
|
192375
|
-
|
|
192376
|
-
});
|
|
192377
|
-
} catch (error3) {
|
|
192378
|
-
errorLog("Error getting COS temp token: " + error3);
|
|
192379
|
-
callback({});
|
|
192380
|
-
}
|
|
192381
|
-
}
|
|
192382
|
-
});
|
|
192371
|
+
var getCosInstance = async () => {
|
|
192372
|
+
if (tokenCache.cos) {
|
|
192373
|
+
return tokenCache.cos;
|
|
192374
|
+
}
|
|
192375
|
+
const result = await getCosTempToken();
|
|
192376
|
+
if (result.Code !== 0 || !result.Data || !result.Data.Response || !result.Data.Response.Credentials) {
|
|
192377
|
+
throw new Error("Failed to get COS temp token");
|
|
192378
|
+
}
|
|
192379
|
+
const response = result.Data.Response;
|
|
192380
|
+
const credentials = response.Credentials;
|
|
192381
|
+
const cos = new import_cos_nodejs_sdk_v5.default({
|
|
192382
|
+
SecretId: credentials.TmpSecretId,
|
|
192383
|
+
SecretKey: credentials.TmpSecretKey,
|
|
192384
|
+
SecurityToken: credentials.Token
|
|
192385
|
+
});
|
|
192386
|
+
tokenCache.cos = cos;
|
|
192387
|
+
return cos;
|
|
192388
|
+
};
|
|
192383
192389
|
var fastListFolder = async (rootPath) => {
|
|
192384
192390
|
const list = [];
|
|
192385
192391
|
const deep = async (dirPath) => {
|
|
@@ -192430,6 +192436,7 @@ var getFiles = (list, localFolder, bucket, region, targetPath) => {
|
|
|
192430
192436
|
});
|
|
192431
192437
|
};
|
|
192432
192438
|
var uploadFiles = async (files) => {
|
|
192439
|
+
const cos = await getCosInstance();
|
|
192433
192440
|
return new Promise((resolve6, reject) => {
|
|
192434
192441
|
cos.uploadFiles(
|
|
192435
192442
|
{
|
|
@@ -192446,7 +192453,7 @@ var uploadFiles = async (files) => {
|
|
|
192446
192453
|
);
|
|
192447
192454
|
});
|
|
192448
192455
|
};
|
|
192449
|
-
var
|
|
192456
|
+
var uploadToEdgeOneCOS = async (localPath) => {
|
|
192450
192457
|
var _a6;
|
|
192451
192458
|
try {
|
|
192452
192459
|
const tokenResult = await getCosTempToken();
|
|
@@ -192466,11 +192473,12 @@ var uploadDirectoryToCOS = async (localPath) => {
|
|
|
192466
192473
|
}
|
|
192467
192474
|
const isZip = isZipFile(localPath);
|
|
192468
192475
|
if (isZip) {
|
|
192469
|
-
progressLog(`[
|
|
192476
|
+
progressLog(`[uploadToEdgeOneCOS] Uploading zip file to COS with targetPath: ${targetPath}...`);
|
|
192470
192477
|
const fileName = path7.basename(localPath);
|
|
192471
192478
|
const key2 = `${targetPath}/${fileName}`;
|
|
192472
192479
|
const fileBuffer = await fs7.readFile(localPath);
|
|
192473
192480
|
const fileStats = await fs7.stat(localPath);
|
|
192481
|
+
const cos = await getCosInstance();
|
|
192474
192482
|
return new Promise((resolve6, reject) => {
|
|
192475
192483
|
cos.putObject(
|
|
192476
192484
|
{
|
|
@@ -192485,7 +192493,7 @@ var uploadDirectoryToCOS = async (localPath) => {
|
|
|
192485
192493
|
errorLog("Error uploading zip file to COS: " + err2);
|
|
192486
192494
|
reject(err2);
|
|
192487
192495
|
} else {
|
|
192488
|
-
progressLog(`[
|
|
192496
|
+
progressLog(`[uploadToEdgeOneCOS] Upload successful.`);
|
|
192489
192497
|
resolve6({
|
|
192490
192498
|
success: true,
|
|
192491
192499
|
targetPath: key2
|
|
@@ -192498,10 +192506,10 @@ var uploadDirectoryToCOS = async (localPath) => {
|
|
|
192498
192506
|
const folderList = await fastListFolder(localPath);
|
|
192499
192507
|
const files = getFiles(folderList, localPath, bucket, region, targetPath);
|
|
192500
192508
|
progressLog(
|
|
192501
|
-
`[
|
|
192509
|
+
`[uploadToEdgeOneCOS] Uploading ${files.length} files to COS with targetPath: ${targetPath}...`
|
|
192502
192510
|
);
|
|
192503
192511
|
await uploadFiles(files);
|
|
192504
|
-
progressLog(`[
|
|
192512
|
+
progressLog(`[uploadToEdgeOneCOS] Upload successful.`);
|
|
192505
192513
|
return {
|
|
192506
192514
|
success: true,
|
|
192507
192515
|
targetPath
|
|
@@ -192527,7 +192535,7 @@ var pollProjectStatus = async (projectId, deploymentId) => {
|
|
|
192527
192535
|
if (deployment.Status !== "Process") {
|
|
192528
192536
|
isProcessing = false;
|
|
192529
192537
|
} else {
|
|
192530
|
-
await sleep(
|
|
192538
|
+
await sleep(5e3);
|
|
192531
192539
|
}
|
|
192532
192540
|
}
|
|
192533
192541
|
return deployment;
|
|
@@ -192590,9 +192598,10 @@ var getDeploymentStructuredResult = async (deploymentResult, projectId, env3 = "
|
|
|
192590
192598
|
};
|
|
192591
192599
|
var deployFolderOrZipToEdgeOne = async (localPath, env3 = "Production") => {
|
|
192592
192600
|
var _a6, _b2, _c2, _d2;
|
|
192601
|
+
resetTokenCache();
|
|
192593
192602
|
const isZip = await validateFolder(localPath);
|
|
192594
192603
|
await checkAndSetBaseUrl();
|
|
192595
|
-
const uploadResult = await
|
|
192604
|
+
const uploadResult = await uploadToEdgeOneCOS(localPath);
|
|
192596
192605
|
if (!uploadResult.targetPath) {
|
|
192597
192606
|
throw new Error("COS upload succeeded but targetPath is missing.");
|
|
192598
192607
|
}
|