@@ -14,13 +14,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1414Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
1515const path_1 = __importDefault ( require ( "path" ) ) ;
1616const inquirer_1 = __importDefault ( require ( "inquirer" ) ) ;
17- const utils_1 = require ( "../../utils" ) ;
1817const error_1 = require ( "../../error" ) ;
1918const function_1 = require ( "../../function" ) ;
19+ const gateway_1 = require ( "../../gateway" ) ;
20+ const utils_1 = require ( "../../utils" ) ;
21+ const constant_1 = require ( "../../constant" ) ;
2022function printSuccessTips ( envId ) {
2123 const link = utils_1 . genClickableLink ( `https://console.cloud.tencent.com/tcb/scf?envId=${ envId } ` ) ;
2224 console . log ( `\n控制台查看函数详情:${ link } ` ) ;
23- console . log ( `\n使用 ${ utils_1 . highlightCommand ( 'cloudbase functions:list' ) } 命令查看已部署云函数` ) ;
25+ console . log ( `\n使用 ${ utils_1 . highlightCommand ( 'cloudbase functions:list' ) } 命令查看已部署云函数\n` ) ;
26+ }
27+ function genApiGateway ( envId , name ) {
28+ var _a , _b , _c , _d ;
29+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
30+ const loading = utils_1 . loadingFactory ( ) ;
31+ loading . start ( '生成云函数 HTTP Service 中...' ) ;
32+ const res = yield gateway_1 . queryGateway ( {
33+ name,
34+ envId
35+ } ) ;
36+ if ( ( ( _a = res ) === null || _a === void 0 ? void 0 : _a . EnableService ) === false )
37+ return ;
38+ let path ;
39+ if ( ( ( _c = ( _b = res ) === null || _b === void 0 ? void 0 : _b . APISet ) === null || _c === void 0 ? void 0 : _c . length ) > 0 ) {
40+ path = ( _d = res . APISet [ 0 ] ) === null || _d === void 0 ? void 0 : _d . Path ;
41+ }
42+ else {
43+ path = `/${ utils_1 . random ( 12 ) } ` ;
44+ yield gateway_1 . createGateway ( {
45+ envId,
46+ name,
47+ path
48+ } ) ;
49+ }
50+ loading . stop ( ) ;
51+ const link = utils_1 . genClickableLink ( `https://${ envId } .service.tcloudbase.com${ path } ` ) ;
52+ console . log ( `\n云函数 HTTP Service 链接:${ link } ` ) ;
53+ } ) ;
2454}
2555function deploy ( ctx , name ) {
2656 return __awaiter ( this , void 0 , void 0 , function * ( ) {
@@ -68,23 +98,14 @@ function deploy(ctx, name) {
6898 newFunction = functions . find ( item => item . name === name ) ;
6999 }
70100 if ( ! newFunction || ! newFunction . name ) {
71- const { useDefaultFunctionDeployOptions } = yield inquirer_1 . default . prompt ( {
101+ const { useDefaultConfig } = yield inquirer_1 . default . prompt ( {
72102 type : 'confirm' ,
73- name : 'useDefaultFunctionDeployOptions ' ,
74- message : '未找到函数发布配置,使用默认配置 (仅适用于 Node.js 云函数)' ,
103+ name : 'useDefaultConfig ' ,
104+ message : '未找到函数发布配置,是否使用默认配置 (仅适用于 Node.js 云函数)' ,
75105 default : false
76106 } ) ;
77- if ( useDefaultFunctionDeployOptions ) {
78- newFunction = {
79- name,
80- config : {
81- timeout : 5 ,
82- runtime : 'Nodejs8.9' ,
83- installDependency : true
84- } ,
85- handler : 'index.main' ,
86- ignore : [ 'node_modules' , 'node_modules/**/*' , '.git' ]
87- } ;
107+ if ( useDefaultConfig ) {
108+ newFunction = Object . assign ( { name } , constant_1 . DefaultFunctionDeployConfig ) ;
88109 }
89110 else {
90111 throw new error_1 . CloudBaseError ( `函数 ${ name } 配置不存在` ) ;
@@ -101,6 +122,7 @@ function deploy(ctx, name) {
101122 functionRootPath
102123 } ) ;
103124 loading . succeed ( `[${ newFunction . name } ] 云函数部署成功!` ) ;
125+ yield genApiGateway ( envId , name ) ;
104126 printSuccessTips ( envId ) ;
105127 }
106128 catch ( e ) {
@@ -123,6 +145,7 @@ function deploy(ctx, name) {
123145 functionRootPath
124146 } ) ;
125147 loading . succeed ( `[${ newFunction . name } ] 云函数部署成功!` ) ;
148+ yield genApiGateway ( envId , name ) ;
126149 printSuccessTips ( envId ) ;
127150 }
128151 catch ( e ) {
0 commit comments