@cloudbase/lowcode-builder 1.8.85 → 1.8.87
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/mp/index.js +3 -3
- package/lib/builder/mp/mp_config.d.ts +2 -2
- package/lib/builder/mp/mp_config.js +32 -24
- package/lib/builder/util/net.js +5 -2
- package/lib/builder.web.js +3 -3
- package/package.json +2 -2
- package/template/html/index.html.ejs +14 -12
- package/template/mp/common/query.js +83 -66
- package/template/mp/common/util.js +27 -14
- package/template/mp/common/weapp-page.js +5 -3
package/lib/builder/mp/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function patchBuildContext(ctx, calses) {
|
|
|
71
71
|
return { used: used };
|
|
72
72
|
}
|
|
73
73
|
async function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
|
|
74
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
74
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
75
75
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
76
76
|
console.time(operationLabel);
|
|
77
77
|
console.log(`Generating ${em('Wexin MiniProgram')} to ${_buildContext.projDir}`);
|
|
@@ -84,7 +84,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
84
84
|
* 依据所有应用的低码配置生成默认项目json
|
|
85
85
|
* 次高优先级,生成整个小程序的配置信息
|
|
86
86
|
*/
|
|
87
|
-
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(_buildContext, weapps, calses, {
|
|
87
|
+
const { projConfig, appConfig, pageConfigs } = await (0, mp_config_1.generateMpConfig)(_buildContext, weapps, calses, {
|
|
88
88
|
mpAppId: options.mpAppId,
|
|
89
89
|
mpConfig,
|
|
90
90
|
});
|
|
@@ -293,7 +293,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
293
293
|
}
|
|
294
294
|
let appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
|
|
295
295
|
let appJson = await fs.readJson(appJsonPath);
|
|
296
|
-
appJson.subpackages = (0, mp_config_1.mergeSubPackages)(appJson.subpackages, appConfig.subpackages);
|
|
296
|
+
appJson.subpackages = (0, mp_config_1.mergeSubPackages)(((_s = (_r = appJson.subpackages) === null || _r === void 0 ? void 0 : _r.filter) === null || _s === void 0 ? void 0 : _s.call(_r, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], appConfig.subpackages);
|
|
297
297
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
298
298
|
}
|
|
299
299
|
else {
|
|
@@ -11,11 +11,11 @@ import { IPlatformApp } from '@cloudbase/cals';
|
|
|
11
11
|
export declare function generateMpConfig(ctx: Omit<IBuildContext, 'wedaRoot'>, weapps: IWeAppData[], calses: IPlatformApp[], options: {
|
|
12
12
|
mpAppId?: string;
|
|
13
13
|
mpConfig?: IBuildWedaApp['mpConfig'];
|
|
14
|
-
}): {
|
|
14
|
+
}): Promise<{
|
|
15
15
|
appConfig: any;
|
|
16
16
|
projConfig: any;
|
|
17
17
|
pageConfigs: {}[];
|
|
18
|
-
}
|
|
18
|
+
}>;
|
|
19
19
|
interface ISubpackage {
|
|
20
20
|
root: string;
|
|
21
21
|
pages?: string[];
|
|
@@ -41,8 +41,8 @@ const util_1 = require("../util");
|
|
|
41
41
|
* @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
|
|
42
42
|
* @param appConfigs app config from prop edit panel
|
|
43
43
|
*/
|
|
44
|
-
function generateMpConfig(ctx, weapps, calses, options) {
|
|
45
|
-
var _a, _b, _c, _d, _e;
|
|
44
|
+
async function generateMpConfig(ctx, weapps, calses, options) {
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
46
46
|
const appConfig = {
|
|
47
47
|
useExtendedLib: { weui: true },
|
|
48
48
|
};
|
|
@@ -84,10 +84,6 @@ function generateMpConfig(ctx, weapps, calses, options) {
|
|
|
84
84
|
const { projectConfigJson = {}, appJson = {} } = config;
|
|
85
85
|
// # project.config.json, https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html
|
|
86
86
|
(0, lodash_1.merge)(projConfig, projectConfigJson);
|
|
87
|
-
// # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
|
|
88
|
-
if (appJson.tabBar) {
|
|
89
|
-
parseTabConfig(appJson.tabBar, ctx.projDir);
|
|
90
|
-
}
|
|
91
87
|
(0, lodash_1.merge)(appConfig, appJson);
|
|
92
88
|
}
|
|
93
89
|
});
|
|
@@ -95,6 +91,10 @@ function generateMpConfig(ctx, weapps, calses, options) {
|
|
|
95
91
|
if (projConfig.wedaRoot) {
|
|
96
92
|
projConfig.wedaRoot = (0, util_1.normalizeWedaRoot)(projConfig.wedaRoot);
|
|
97
93
|
}
|
|
94
|
+
// # app.json, https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html
|
|
95
|
+
if (appConfig.tabBar) {
|
|
96
|
+
await parseTabConfig(appConfig.tabBar, path.posix.join(ctx.projDir, projConfig.miniprogramRoot || ''), path.posix.join('./', projConfig.wedaRoot || ''));
|
|
97
|
+
}
|
|
98
98
|
/**
|
|
99
99
|
* 基础配置合并完成
|
|
100
100
|
* 开启特殊合并合并/覆盖逻辑
|
|
@@ -113,11 +113,11 @@ function generateMpConfig(ctx, weapps, calses, options) {
|
|
|
113
113
|
*/
|
|
114
114
|
const { subpackages, pages = [] } = extractPages(weapps, pageConfigs, { wedaRoot: projConfig.wedaRoot });
|
|
115
115
|
appConfig.pages = Array.from(new Set([...(appConfig.pages || []), ...pages]));
|
|
116
|
-
appConfig.subpackages = mergeSubPackages(appConfig.subpackages, [
|
|
116
|
+
appConfig.subpackages = mergeSubPackages(((_e = (_d = appConfig.subpackages) === null || _d === void 0 ? void 0 : _d.filter) === null || _e === void 0 ? void 0 : _e.call(_d, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], [
|
|
117
117
|
{
|
|
118
118
|
root: path.posix.join(projConfig.wedaRoot || '', 'packages/$wd_system'),
|
|
119
119
|
name: 'wd-sys-module',
|
|
120
|
-
pages: ((
|
|
120
|
+
pages: ((_g = (_f = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _f === void 0 ? void 0 : _f.extra) === null || _g === void 0 ? void 0 : _g.loginConfigVersion) ? ['pages/login/index'] : [],
|
|
121
121
|
},
|
|
122
122
|
]
|
|
123
123
|
.concat(ctx.enableAsyncMaterials
|
|
@@ -171,9 +171,9 @@ function generateMpConfig(ctx, weapps, calses, options) {
|
|
|
171
171
|
if (!projConfig.setting.packNpmRelationList) {
|
|
172
172
|
projConfig.setting.packNpmRelationList = [];
|
|
173
173
|
}
|
|
174
|
-
projConfig.setting.packNpmRelationList = mergePackNpmRelationList(generateSystemPackNpmRelationList(path.posix.join('./', projConfig.miniprogramRoot || '/', projConfig.wedaRoot || '')), projConfig.setting.packNpmRelationList.filter((item) => {
|
|
174
|
+
projConfig.setting.packNpmRelationList = mergePackNpmRelationList(generateSystemPackNpmRelationList(path.posix.join('./', projConfig.miniprogramRoot || '/', projConfig.wedaRoot || '')), ((_j = (_h = projConfig.setting.packNpmRelationList) === null || _h === void 0 ? void 0 : _h.filter) === null || _j === void 0 ? void 0 : _j.call(_h, (item) => {
|
|
175
175
|
return !/\/packages\/\$wd_system\/package.json/.test(item.packageJsonPath);
|
|
176
|
-
}));
|
|
176
|
+
})) || []);
|
|
177
177
|
if (process.env.IS_WEB_WORKER) {
|
|
178
178
|
projConfig.setting.ignoreUploadUnusedFiles = true;
|
|
179
179
|
}
|
|
@@ -214,7 +214,7 @@ function extractPages(weapps, pageConfigs, options) {
|
|
|
214
214
|
}
|
|
215
215
|
return { pages, subpackages };
|
|
216
216
|
}
|
|
217
|
-
function getAppPagesConfig(pages) {
|
|
217
|
+
function getAppPagesConfig(pages = []) {
|
|
218
218
|
const pagesConfig = {};
|
|
219
219
|
pages.map((page) => {
|
|
220
220
|
const pageConfig = transformDynamicData(page.data);
|
|
@@ -233,27 +233,35 @@ function transformDynamicData(originData) {
|
|
|
233
233
|
}
|
|
234
234
|
return temp;
|
|
235
235
|
}
|
|
236
|
-
function parseTabConfig(tabBar,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (iconPath) {
|
|
240
|
-
tab.iconPath = parseTabIcon(iconPath, index, 'icon');
|
|
241
|
-
}
|
|
242
|
-
if (selectedIconPath) {
|
|
243
|
-
tab.selectedIconPath = parseTabIcon(selectedIconPath, index, 'selectedIcon');
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
function parseTabIcon(iconUrl, index, filename) {
|
|
236
|
+
function parseTabConfig(tabBar, miniprogramRoot, wedaRoot) {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
async function parseTabIcon(iconUrl, index, filename) {
|
|
247
239
|
if (typeof iconUrl !== 'string') {
|
|
248
240
|
console.error(chalk_1.default.red('App.json invalid tabbar icon path'), iconUrl);
|
|
249
241
|
return;
|
|
250
242
|
}
|
|
251
|
-
const iconPath = `assets/tab${index}/${filename}${path.extname(iconUrl)}
|
|
252
|
-
(0, net_1.downloadFile)(iconUrl, `${
|
|
243
|
+
const iconPath = path.posix.join('./', wedaRoot || '/', `assets/tab${index}/${filename}${path.extname(iconUrl)}`);
|
|
244
|
+
await (0, net_1.downloadFile)(iconUrl, `${miniprogramRoot}/${iconPath}`).catch((e) => {
|
|
253
245
|
console.error(chalk_1.default.red(`Fail to download tabBar icon from ${iconUrl}`), e);
|
|
246
|
+
throw e;
|
|
254
247
|
});
|
|
255
248
|
return iconPath;
|
|
256
249
|
}
|
|
250
|
+
return Promise.all(((_b = (_a = tabBar.list) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, async (tab, index) => {
|
|
251
|
+
const { iconPath, selectedIconPath } = tab;
|
|
252
|
+
if (iconPath && /^http(s):\/\//.test(iconPath)) {
|
|
253
|
+
try {
|
|
254
|
+
tab.iconPath = await parseTabIcon(iconPath, index, 'icon');
|
|
255
|
+
}
|
|
256
|
+
catch (e) { }
|
|
257
|
+
}
|
|
258
|
+
if (selectedIconPath && /^http(s):\/\//.test(selectedIconPath)) {
|
|
259
|
+
try {
|
|
260
|
+
tab.selectedIconPath = await parseTabIcon(selectedIconPath, index, 'selectedIcon');
|
|
261
|
+
}
|
|
262
|
+
catch (e) { }
|
|
263
|
+
}
|
|
264
|
+
})) || []);
|
|
257
265
|
}
|
|
258
266
|
function mergeSubPackages(base = [], extra = []) {
|
|
259
267
|
const baseMap = base.reduce((map, item) => {
|
package/lib/builder/util/net.js
CHANGED
|
@@ -36,9 +36,12 @@ const config_1 = require("../config");
|
|
|
36
36
|
const generateFiles_1 = require("../util/generateFiles");
|
|
37
37
|
const junk_1 = require("../util/junk");
|
|
38
38
|
async function downloadFile(url, filePath) {
|
|
39
|
+
if (fs_extra_1.default.existsSync(filePath)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
39
42
|
await fs_extra_1.default.ensureDir(path.dirname(filePath));
|
|
40
|
-
const res = await axios_1.default.get(url, { responseType: '
|
|
41
|
-
|
|
43
|
+
const res = await axios_1.default.get(url, { responseType: 'arraybuffer' });
|
|
44
|
+
fs_extra_1.default.writeFileSync(filePath, res.data);
|
|
42
45
|
}
|
|
43
46
|
exports.downloadFile = downloadFile;
|
|
44
47
|
/**
|