@cloudbase/lowcode-builder 1.8.26 → 1.8.28
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/lib/builder/config/index.d.ts +1 -1
- package/lib/builder/config/index.js +1 -1
- package/lib/builder/mp/index.d.ts +1 -0
- package/lib/builder/mp/index.js +17 -2
- package/package.json +2 -2
- package/template/html/index.html.ejs +1 -1
- package/template/mp/app/handlers.js +5 -5
- package/template/mp/app/weapps-api.js +2 -1
- package/template/mp/app.js +78 -52
- package/template/mp/page/index.js +1 -1
|
@@ -6,7 +6,7 @@ export declare const materialsDirName = "materials";
|
|
|
6
6
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
7
7
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
8
8
|
*/
|
|
9
|
-
export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.
|
|
9
|
+
export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.27.zip";
|
|
10
10
|
/**
|
|
11
11
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
12
12
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
@@ -45,7 +45,7 @@ exports.materialsDirName = 'materials'; // materials diretory of current project
|
|
|
45
45
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
46
46
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
47
47
|
*/
|
|
48
|
-
exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.
|
|
48
|
+
exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.1.8.27.zip';
|
|
49
49
|
/**
|
|
50
50
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
51
51
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
@@ -22,6 +22,7 @@ export declare function generateConfig(data: {
|
|
|
22
22
|
isPrivateMode?: boolean;
|
|
23
23
|
endpointType?: IBuildContext['endpointType'] | '';
|
|
24
24
|
}, root: string): Promise<void>;
|
|
25
|
+
export declare function normalizePageId(pageId: any): string;
|
|
25
26
|
export declare function writeLowCodeFiles(ctx: IBuildContext, appData: IWeAppData, outDir: string): Promise<void>;
|
|
26
27
|
/**
|
|
27
28
|
* TODO: 与 cals 里的实现进行整合
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.handleUsedComponents = exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
|
|
29
|
+
exports.handleUsedComponents = exports.writeLowCodeFiles = exports.normalizePageId = exports.generateConfig = exports.generateWxMp = void 0;
|
|
30
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const util_1 = require("util");
|
|
@@ -288,6 +288,20 @@ async function generateConfig(data, root) {
|
|
|
288
288
|
}, templateDir, root);
|
|
289
289
|
}
|
|
290
290
|
exports.generateConfig = generateConfig;
|
|
291
|
+
/**
|
|
292
|
+
* pageId 名称管理器
|
|
293
|
+
* 因为 pageId 命名为非法
|
|
294
|
+
*/
|
|
295
|
+
const _MANAGER_PAGE_ID_LIST = [];
|
|
296
|
+
const _MANAGER_PAGE_ID_MAP = {};
|
|
297
|
+
function normalizePageId(pageId) {
|
|
298
|
+
if (!_MANAGER_PAGE_ID_MAP[pageId]) {
|
|
299
|
+
_MANAGER_PAGE_ID_MAP[pageId] = `$${_MANAGER_PAGE_ID_LIST.length}`;
|
|
300
|
+
_MANAGER_PAGE_ID_LIST.push(pageId);
|
|
301
|
+
}
|
|
302
|
+
return _MANAGER_PAGE_ID_MAP[pageId];
|
|
303
|
+
}
|
|
304
|
+
exports.normalizePageId = normalizePageId;
|
|
291
305
|
async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
292
306
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
|
|
293
307
|
console.log(`Generating ${em(weapp.rootPath ? 'subApp' : 'app')} to ${appRoot}`);
|
|
@@ -335,7 +349,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
335
349
|
stringifyObj: util_1.inspect,
|
|
336
350
|
},
|
|
337
351
|
[`index.js|${pageFileName}.js`]: {
|
|
338
|
-
|
|
352
|
+
pageNameVar: normalizePageId(page.id),
|
|
339
353
|
pageName: page.id,
|
|
340
354
|
pageSource: page.data.src || '',
|
|
341
355
|
eventHandlers: (0, util_2.createEventHandlers)(ctx, componentInstances, 'this', page),
|
|
@@ -405,6 +419,7 @@ async function generateFramework(ctx, appData, outDir, options) {
|
|
|
405
419
|
(0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList || [], (p) => {
|
|
406
420
|
allCodeModules.push({
|
|
407
421
|
id: p.id,
|
|
422
|
+
pageNameVar: normalizePageId(p.id),
|
|
408
423
|
lowCodes: p.lowCodes || [],
|
|
409
424
|
});
|
|
410
425
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.28",
|
|
4
4
|
"description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
|
|
5
5
|
"author": "yhsunshining@gmail.com",
|
|
6
6
|
"homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/core": "7.12.3",
|
|
43
43
|
"@babel/preset-env": "7.12.1",
|
|
44
|
-
"@cloudbase/cals": "^1.0.
|
|
44
|
+
"@cloudbase/cals": "^1.0.18",
|
|
45
45
|
"@cloudbase/lowcode-generator": "^1.8.10",
|
|
46
46
|
"axios": "^0.21.0",
|
|
47
47
|
"browserfs": "^1.4.3",
|
|
@@ -551,7 +551,7 @@
|
|
|
551
551
|
crossorigin
|
|
552
552
|
src="<%=
|
|
553
553
|
cdnEndpoints.cdngo
|
|
554
|
-
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.
|
|
554
|
+
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.5ec891fedc6dc37d6d57.bundle.js"
|
|
555
555
|
></script>
|
|
556
556
|
</body>
|
|
557
557
|
</html>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<% pageModules.forEach(({id: pageId, lowCodes}
|
|
1
|
+
<% pageModules.forEach(({id: pageId, pageNameVar, lowCodes}) => { %>
|
|
2
2
|
<% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
|
|
3
|
-
import
|
|
3
|
+
import <%= pageNameVar%>_<%= mod.name%> from '../lowcode/<%= pageId%>/handler/<%= mod.name%>'
|
|
4
4
|
<% }) %>
|
|
5
5
|
<% }) %>
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<% pageModules.forEach(({id: pageId, lowCodes, pageNameVar}) => { %>
|
|
10
10
|
// <%= pageId %>
|
|
11
|
-
export const
|
|
11
|
+
export const <%=pageNameVar %> = {
|
|
12
12
|
<% lowCodes.filter(mod => mod.type === 'handler-fn' && mod.name !== '____index____').forEach(mod => {%>
|
|
13
|
-
['<%= mod.name%>']:
|
|
13
|
+
['<%= mod.name%>']: <%= pageNameVar%>_<%= mod.name%>,
|
|
14
14
|
<% }) %>
|
|
15
15
|
}
|
|
16
16
|
<% }) %>
|
|
@@ -111,8 +111,9 @@ function createGlboalApi() {
|
|
|
111
111
|
|
|
112
112
|
let dataset = createDataset('$global')
|
|
113
113
|
dataset.query = generateDatasetQuery({<% Object.entries(appQuery).map(([id, item])=>{%>
|
|
114
|
-
<%= id %>: { <% const { dataBinds, eventHandlers, ...rest } = item %>
|
|
114
|
+
<%= id %>: { <% const { dataBinds, eventHandlers, handler, ...rest } = item %>
|
|
115
115
|
...(<%= stringifyObj(rest, {depth: null}) %>),
|
|
116
|
+
handler: <%= handler %>,
|
|
116
117
|
dataBinds: {<%= printBoundData(dataBinds) %>},
|
|
117
118
|
eventHandlers: {<% printEventHandler(eventHandlers) %>}
|
|
118
119
|
},<%}) %>
|
package/template/mp/app.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
<%= importor.lifecycle? "import lifeCycle from './lowcode/lifecycle'" : "const lifeCycle = {}" %>
|
|
2
|
-
import { app, $app } from './app/weapps-api'
|
|
2
|
+
import { app, $app } from './app/weapps-api';
|
|
3
3
|
// 引入数据源管理器并进行初始化
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
setConfig,
|
|
6
|
+
getAccessToken,
|
|
7
|
+
EXTRA_API,
|
|
8
|
+
createStateDataSourceVar,
|
|
9
|
+
generateParamsParser,
|
|
10
|
+
} from './datasources/index';
|
|
11
|
+
import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util';
|
|
6
12
|
|
|
7
13
|
// 防止报类型不匹配warning
|
|
8
14
|
const originWarn = console.warn;
|
|
9
15
|
const warningSkipRegexp = /(type-uncompatible)|(slot "[\w-]*?" is not found)/;
|
|
10
16
|
console.warn = (...args) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
+
// 只看第一条
|
|
18
|
+
const shouldSkip = args.length > 0 && args[0][0] === '[' && args[0][1] === 'C' && warningSkipRegexp.test(args[0]);
|
|
19
|
+
if (!shouldSkip) {
|
|
20
|
+
originWarn(...args);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
17
23
|
|
|
18
24
|
// 设置数据源请求的 loading 及 toast 处理
|
|
19
25
|
setConfig({
|
|
20
26
|
beforeDSRequest: (cfg) => {
|
|
21
|
-
if (!cfg.options || !cfg.options.showLoading) return
|
|
22
|
-
app.showLoading()
|
|
27
|
+
if (!cfg.options || !cfg.options.showLoading) return;
|
|
28
|
+
app.showLoading();
|
|
23
29
|
},
|
|
24
30
|
beforeCallFunction: async (params) => {
|
|
25
31
|
try {
|
|
@@ -46,7 +52,7 @@ setConfig({
|
|
|
46
52
|
params.data.accessToken = accessToken;
|
|
47
53
|
}
|
|
48
54
|
} catch (e) {
|
|
49
|
-
if (app?.cloud?.currentUser?.userType ===
|
|
55
|
+
if (app?.cloud?.currentUser?.userType === 'externalUser' && e?.error === 'unauthenticated') {
|
|
50
56
|
app.showToast({
|
|
51
57
|
title: '登录态失效',
|
|
52
58
|
icon: 'error',
|
|
@@ -57,25 +63,45 @@ setConfig({
|
|
|
57
63
|
return params;
|
|
58
64
|
},
|
|
59
65
|
afterDSRequest: (cfg, error, result) => {
|
|
60
|
-
if (!cfg.options) return
|
|
61
|
-
if (cfg.options.showLoading) app.hideLoading()
|
|
62
|
-
if (!cfg.options.showToast) return
|
|
63
|
-
const isSuccess = !error && result && !result.code
|
|
64
|
-
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
66
|
+
if (!cfg.options) return;
|
|
67
|
+
if (cfg.options.showLoading) app.hideLoading();
|
|
68
|
+
if (!cfg.options.showToast) return;
|
|
69
|
+
const isSuccess = !error && result && !result.code;
|
|
70
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' });
|
|
65
71
|
},
|
|
66
72
|
async afterCallFunction(params, error, res) {
|
|
67
|
-
|
|
73
|
+
const oauthError =
|
|
74
|
+
error?.message?.includes?.('PERMISSION_DENIED') ||
|
|
75
|
+
error?.code === 'unauthenticated' ||
|
|
76
|
+
error?.error === 'unauthenticated' ||
|
|
77
|
+
error?.code === 'invalid_grant' ||
|
|
78
|
+
error?.error === 'invalid_grant' ||
|
|
79
|
+
error?.code === 'INVALID_ACCESS_TOKEN' ||
|
|
80
|
+
(error?.code === 'OPERATION_FAIL' && /^\[INVALID_ACCESS_TOKEN\]/.test(error?.message || ''));
|
|
81
|
+
|
|
82
|
+
if (
|
|
83
|
+
params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' &&
|
|
84
|
+
(['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code) ||
|
|
85
|
+
oauthError)
|
|
86
|
+
) {
|
|
68
87
|
const loginPage = findLoginPage();
|
|
69
88
|
if (loginPage) {
|
|
70
89
|
const authConfig = await getAuthConfig();
|
|
71
|
-
if (authConfig.RejectStrategy
|
|
90
|
+
if (authConfig.RejectStrategy === 'to_login') {
|
|
72
91
|
if (['InnerError.AuthFailure'].includes(res?.result?.code)) {
|
|
73
92
|
const isAnonymous = await checkAnonymous();
|
|
74
93
|
if (!isAnonymous) return;
|
|
75
94
|
// 匿名用户越权去登录
|
|
76
95
|
}
|
|
77
96
|
redirectToLogin();
|
|
78
|
-
} else if (authConfig.RejectStrategy
|
|
97
|
+
} else if (authConfig.RejectStrategy === 'show_warning') {
|
|
98
|
+
if (oauthError) {
|
|
99
|
+
const isAnonymous = await checkAnonymous();
|
|
100
|
+
if (!isAnonymous) {
|
|
101
|
+
redirectToLogin(generateLoginUrl);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
79
105
|
app.showToast({
|
|
80
106
|
title: '接口无访问权限',
|
|
81
107
|
icon: 'error',
|
|
@@ -83,27 +109,27 @@ setConfig({
|
|
|
83
109
|
}
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
|
-
}
|
|
87
|
-
})
|
|
112
|
+
},
|
|
113
|
+
});
|
|
88
114
|
|
|
89
115
|
App({
|
|
90
116
|
_query: {},
|
|
91
117
|
globaldata: {
|
|
92
|
-
_beforeCustomLaunchPromise: null
|
|
118
|
+
_beforeCustomLaunchPromise: null,
|
|
93
119
|
},
|
|
94
120
|
async beforeCustomLaunch(query) {
|
|
95
|
-
if(!this.globaldata?._beforeCustomLaunchPromise){
|
|
96
|
-
if(!this.globaldata) {
|
|
97
|
-
this.globaldata = {}
|
|
121
|
+
if (!this.globaldata?._beforeCustomLaunchPromise) {
|
|
122
|
+
if (!this.globaldata) {
|
|
123
|
+
this.globaldata = {};
|
|
98
124
|
}
|
|
99
|
-
this.globaldata._beforeCustomLaunchPromise = new Promise(async (resolve)=>{
|
|
125
|
+
this.globaldata._beforeCustomLaunchPromise = new Promise(async (resolve) => {
|
|
100
126
|
try {
|
|
101
|
-
EXTRA_API.setParams('$global', query || {})
|
|
127
|
+
EXTRA_API.setParams('$global', query || {});
|
|
102
128
|
await createStateDataSourceVar('$global', generateParamsParser({ app, $page: {}, $w: app.__internal__?.$w }));
|
|
103
129
|
} catch (e) {
|
|
104
130
|
throw e;
|
|
105
131
|
} finally {
|
|
106
|
-
for (const queryId in app.dataset?.query||{}) {
|
|
132
|
+
for (const queryId in app.dataset?.query || {}) {
|
|
107
133
|
if (app.dataset.query[queryId]?._schema?.trigger === 'auto') {
|
|
108
134
|
try {
|
|
109
135
|
app.dataset?.query?.[queryId]?.trigger?.();
|
|
@@ -112,44 +138,44 @@ App({
|
|
|
112
138
|
}
|
|
113
139
|
}
|
|
114
140
|
}
|
|
115
|
-
resolve()
|
|
141
|
+
resolve();
|
|
116
142
|
}
|
|
117
|
-
})
|
|
143
|
+
});
|
|
118
144
|
}
|
|
119
|
-
return this.globaldata._beforeCustomLaunchPromise
|
|
145
|
+
return this.globaldata._beforeCustomLaunchPromise;
|
|
120
146
|
},
|
|
121
147
|
async onLaunch(options) {
|
|
122
|
-
this.app = app
|
|
123
|
-
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
124
|
-
let { query = {} } = options
|
|
125
|
-
this._query = query
|
|
148
|
+
this.app = app;
|
|
149
|
+
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch;
|
|
150
|
+
let { query = {} } = options;
|
|
151
|
+
this._query = query;
|
|
126
152
|
|
|
127
|
-
await this.beforeCustomLaunch(query)
|
|
128
|
-
onLaunch && onLaunch.call(this, options)
|
|
153
|
+
await this.beforeCustomLaunch(query);
|
|
154
|
+
onLaunch && onLaunch.call(this, options);
|
|
129
155
|
// 初始私有全局数据
|
|
130
156
|
this.$$global = {
|
|
131
|
-
homePageId: '<%= appConfig.homePageId %>'
|
|
132
|
-
}
|
|
157
|
+
homePageId: '<%= appConfig.homePageId %>',
|
|
158
|
+
};
|
|
133
159
|
},
|
|
134
160
|
async onShow(options) {
|
|
135
|
-
await this.beforeCustomLaunch(this._query)
|
|
136
|
-
const fn = lifeCycle.onShow || lifeCycle.onAppShow
|
|
137
|
-
fn && fn.call(this, options)
|
|
161
|
+
await this.beforeCustomLaunch(this._query);
|
|
162
|
+
const fn = lifeCycle.onShow || lifeCycle.onAppShow;
|
|
163
|
+
fn && fn.call(this, options);
|
|
138
164
|
},
|
|
139
165
|
onHide() {
|
|
140
|
-
const fn = lifeCycle.onHide || lifeCycle.onAppHide
|
|
141
|
-
fn && fn.call(this)
|
|
166
|
+
const fn = lifeCycle.onHide || lifeCycle.onAppHide;
|
|
167
|
+
fn && fn.call(this);
|
|
142
168
|
},
|
|
143
169
|
onError(msg) {
|
|
144
|
-
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
145
|
-
fn && fn.call(this, msg)
|
|
170
|
+
const fn = lifeCycle.onError || lifeCycle.onAppError;
|
|
171
|
+
fn && fn.call(this, msg);
|
|
146
172
|
},
|
|
147
173
|
onPageNotFound() {
|
|
148
|
-
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
|
|
149
|
-
fn && fn.call(this)
|
|
174
|
+
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound;
|
|
175
|
+
fn && fn.call(this);
|
|
150
176
|
},
|
|
151
177
|
onUnhandledRejection() {
|
|
152
|
-
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
|
|
153
|
-
fn && fn.call(this)
|
|
178
|
+
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection;
|
|
179
|
+
fn && fn.call(this);
|
|
154
180
|
},
|
|
155
|
-
})
|
|
181
|
+
});
|
|
@@ -2,7 +2,7 @@ import { observable } from 'mobx';
|
|
|
2
2
|
import { createPage } from '<%= subLevelPath %>../../common/weapp-page'
|
|
3
3
|
import { concatClassList, px2rpx } from '<%= subLevelPath %>../../common/style'
|
|
4
4
|
import { app, $app } from '<%= subLevelPath %>../../app/weapps-api'
|
|
5
|
-
import {
|
|
5
|
+
import { <%= pageNameVar %> as handlers } from '../../app/handlers'
|
|
6
6
|
<%= importor.lifecycle? `import lifecycle from '../../lowcode/${pageName}/lifecycle'` : "const lifecycle = {}" %>
|
|
7
7
|
<%= importor.state? `import state from '../../lowcode/${pageName}/state'` : "const state = {}" %>
|
|
8
8
|
<%= importor.computed? `import computed from '../../lowcode/${pageName}/computed'` : "const computed = {}" %>
|