@cloudbase/cli 2.7.2 → 2.7.4
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/.yarn/install-state.gz +0 -0
- package/lib/commands/cloudrun/base.js +11 -7
- package/lib/commands/functions/code-download.js +1 -2
- package/lib/commands/functions/layer/download.js +1 -2
- package/lib/function/code.js +3 -27
- package/lib/function/layer/download.js +3 -22
- package/lib/utils/tools/common.js +69 -0
- package/package.json +1 -1
- package/types/function/code.d.ts +0 -1
- package/types/function/layer/download.d.ts +0 -1
- package/types/utils/tools/common.d.ts +1 -0
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -704,6 +704,10 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
704
704
|
示例:--extendedContext '{"a":1,"b":2}'
|
|
705
705
|
环境变量:EXTENDED_CONTEXT
|
|
706
706
|
`
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
flags: '--open-debug-panel <openDebugPanel>',
|
|
710
|
+
desc: `是否打开调试面板,默认为 'true'`
|
|
707
711
|
}
|
|
708
712
|
],
|
|
709
713
|
requiredEnvId: false,
|
|
@@ -713,7 +717,7 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
713
717
|
execute(envId, logger, ctx, options) {
|
|
714
718
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715
719
|
debugger;
|
|
716
|
-
let { runMode = 'normal', agentId } = options;
|
|
720
|
+
let { runMode = 'normal', agentId, openDebugPanel = true } = options;
|
|
717
721
|
const type = runMode;
|
|
718
722
|
console.log(chalk_1.default.green(`当前运行模式: ${type}`));
|
|
719
723
|
if (!process.argv.some((arg) => arg.includes('--dotEnvFilePath='))) {
|
|
@@ -738,7 +742,7 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
738
742
|
{
|
|
739
743
|
type: 'input',
|
|
740
744
|
name: 'agentId',
|
|
741
|
-
message: `请输入 Agent ID
|
|
745
|
+
message: `请输入 Agent ID(如没有请填写任意值):`,
|
|
742
746
|
validate: (val) => {
|
|
743
747
|
return val.trim() ? true : 'Agent ID 不能为空';
|
|
744
748
|
}
|
|
@@ -788,7 +792,7 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
788
792
|
logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
|
|
789
793
|
if (!nodemonInstance._firstStartDone) {
|
|
790
794
|
nodemonInstance._firstStartDone = true;
|
|
791
|
-
this.openDebugApp(type, port, envId, agentId);
|
|
795
|
+
this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
|
|
792
796
|
}
|
|
793
797
|
}))
|
|
794
798
|
.on('quit', (e) => {
|
|
@@ -812,13 +816,13 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
812
816
|
}
|
|
813
817
|
else {
|
|
814
818
|
(0, functions_framework_1.runCLI)();
|
|
815
|
-
if (!process.env.FROM_NODEMON) {
|
|
816
|
-
this.openDebugApp(type, port, envId, agentId);
|
|
819
|
+
if (!process.env.FROM_NODEMON && openDebugPanel) {
|
|
820
|
+
this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
|
|
817
821
|
}
|
|
818
822
|
}
|
|
819
823
|
});
|
|
820
824
|
}
|
|
821
|
-
openDebugApp(type, port, envId, agentId) {
|
|
825
|
+
openDebugApp(type, port, envId, agentId, isOpen = true) {
|
|
822
826
|
setTimeout(() => {
|
|
823
827
|
let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
|
|
824
828
|
if (type === 'agent') {
|
|
@@ -828,7 +832,7 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
|
|
|
828
832
|
else {
|
|
829
833
|
console.log(chalk_1.default.green(`点击 [${url}] 可以打开函数调试面板`));
|
|
830
834
|
}
|
|
831
|
-
(0, open_1.default)(url, { wait: false });
|
|
835
|
+
isOpen && (0, open_1.default)(url, { wait: false });
|
|
832
836
|
}, 3000);
|
|
833
837
|
}
|
|
834
838
|
};
|
|
@@ -102,8 +102,7 @@ let CodeDownload = class CodeDownload extends common_1.Command {
|
|
|
102
102
|
envId,
|
|
103
103
|
functionName: name,
|
|
104
104
|
destPath: destPath,
|
|
105
|
-
codeSecret: codeSecret
|
|
106
|
-
unzip: true
|
|
105
|
+
codeSecret: codeSecret
|
|
107
106
|
});
|
|
108
107
|
loading.succeed(`[${name}] 云函数代码下载成功!`);
|
|
109
108
|
});
|
package/lib/function/code.js
CHANGED
|
@@ -8,45 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.downloadFunctionCode = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const unzipper_1 = __importDefault(require("unzipper"));
|
|
19
13
|
const utils_1 = require("../utils");
|
|
14
|
+
const common_1 = require("../utils/tools/common");
|
|
20
15
|
const scfService = utils_1.CloudApiService.getInstance('scf');
|
|
21
16
|
function downloadFunctionCode(options) {
|
|
22
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const { destPath, envId, functionName, codeSecret
|
|
18
|
+
const { destPath, envId, functionName, codeSecret } = options;
|
|
24
19
|
(0, utils_1.checkFullAccess)(destPath, true);
|
|
25
20
|
const { Url } = yield scfService.request('GetFunctionAddress', {
|
|
26
21
|
FunctionName: functionName,
|
|
27
22
|
Namespace: envId,
|
|
28
23
|
CodeSecret: codeSecret
|
|
29
24
|
});
|
|
30
|
-
|
|
31
|
-
const zipPath = path_1.default.join(destPath, `${functionName}.zip`);
|
|
32
|
-
const dest = fs_1.default.createWriteStream(zipPath);
|
|
33
|
-
res.body.pipe(dest);
|
|
34
|
-
return new Promise(resolve => {
|
|
35
|
-
dest.on('close', () => {
|
|
36
|
-
if (!unzip) {
|
|
37
|
-
resolve();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const unzipStream = unzipper_1.default.Extract({
|
|
41
|
-
path: destPath
|
|
42
|
-
});
|
|
43
|
-
fs_1.default.createReadStream(zipPath).pipe(unzipStream);
|
|
44
|
-
unzipStream.on('close', () => {
|
|
45
|
-
(0, utils_1.delSync)([zipPath]);
|
|
46
|
-
resolve();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|
|
25
|
+
return (0, common_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
50
26
|
});
|
|
51
27
|
}
|
|
52
28
|
exports.downloadFunctionCode = downloadFunctionCode;
|
|
@@ -13,15 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.downloadLayer = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
16
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const unzipper_1 = __importDefault(require("unzipper"));
|
|
19
17
|
const utils_1 = require("../../utils");
|
|
20
18
|
const error_1 = require("../../error");
|
|
19
|
+
const common_1 = require("../../utils/tools/common");
|
|
21
20
|
const scfService = new utils_1.CloudApiService('scf');
|
|
22
21
|
function downloadLayer(options) {
|
|
23
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const { name, version, destPath
|
|
23
|
+
const { name, version, destPath } = options;
|
|
25
24
|
const res = yield scfService.request('GetLayerVersion', {
|
|
26
25
|
LayerName: name,
|
|
27
26
|
LayerVersion: version
|
|
@@ -31,25 +30,7 @@ function downloadLayer(options) {
|
|
|
31
30
|
if ((0, utils_1.checkFullAccess)(zipPath)) {
|
|
32
31
|
throw new error_1.CloudBaseError(`文件已存在:${zipPath}`);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
const dest = fs_1.default.createWriteStream(zipPath);
|
|
36
|
-
streamRes.body.pipe(dest);
|
|
37
|
-
return new Promise(resolve => {
|
|
38
|
-
dest.on('close', () => {
|
|
39
|
-
if (!unzip) {
|
|
40
|
-
resolve();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const unzipStream = unzipper_1.default.Extract({
|
|
44
|
-
path: destPath
|
|
45
|
-
});
|
|
46
|
-
fs_1.default.createReadStream(zipPath).pipe(unzipStream);
|
|
47
|
-
unzipStream.on('close', () => {
|
|
48
|
-
(0, utils_1.delSync)([zipPath]);
|
|
49
|
-
resolve();
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
33
|
+
return (0, common_1.downloadAndExtractRemoteZip)(url, destPath);
|
|
53
34
|
});
|
|
54
35
|
}
|
|
55
36
|
exports.downloadLayer = downloadLayer;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.downloadAndExtractRemoteZip = void 0;
|
|
16
|
+
const toolbox_1 = require("@cloudbase/toolbox");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
+
const unzipper_1 = __importDefault(require("unzipper"));
|
|
20
|
+
function downloadAndExtractRemoteZip(downloadUrl, targetPath) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const downloadResponse = yield (0, toolbox_1.fetchStream)(downloadUrl);
|
|
23
|
+
if (!downloadResponse.ok) {
|
|
24
|
+
throw new Error(`下载失败,状态码: ${downloadResponse.status}`);
|
|
25
|
+
}
|
|
26
|
+
if (!downloadResponse.body) {
|
|
27
|
+
throw new Error('下载响应中没有数据流');
|
|
28
|
+
}
|
|
29
|
+
const dirPath = path_1.default.resolve(targetPath);
|
|
30
|
+
yield fs_extra_1.default.ensureDir(dirPath);
|
|
31
|
+
yield new Promise((resolve, reject) => {
|
|
32
|
+
let fileCount = 0;
|
|
33
|
+
let extractedCount = 0;
|
|
34
|
+
downloadResponse
|
|
35
|
+
.body.pipe(unzipper_1.default.Parse())
|
|
36
|
+
.on('error', reject)
|
|
37
|
+
.on('entry', (entry) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const filePath = path_1.default.join(dirPath, entry.path);
|
|
39
|
+
try {
|
|
40
|
+
yield fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
|
|
41
|
+
if (entry.type === 'Directory') {
|
|
42
|
+
yield fs_extra_1.default.ensureDir(filePath);
|
|
43
|
+
extractedCount++;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
fileCount++;
|
|
47
|
+
entry
|
|
48
|
+
.pipe(fs_extra_1.default.createWriteStream(filePath))
|
|
49
|
+
.on('error', reject)
|
|
50
|
+
.on('finish', () => {
|
|
51
|
+
extractedCount++;
|
|
52
|
+
checkCompletion();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
reject(err);
|
|
58
|
+
}
|
|
59
|
+
}))
|
|
60
|
+
.on('close', checkCompletion);
|
|
61
|
+
function checkCompletion() {
|
|
62
|
+
if (fileCount > 0 && fileCount === extractedCount) {
|
|
63
|
+
resolve('');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.downloadAndExtractRemoteZip = downloadAndExtractRemoteZip;
|
package/package.json
CHANGED
package/types/function/code.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function downloadAndExtractRemoteZip(downloadUrl: string, targetPath: string): Promise<void>;
|