@cloudbase/lowcode-builder 1.8.36 → 1.8.37
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/dist/builder.web.js +11 -11
- package/lib/builder/core/index.js +3 -1
- package/lib/builder/mp/index.d.ts +3 -1
- package/lib/builder/mp/index.js +60 -48
- package/lib/builder/mp/materials.d.ts +0 -7
- package/lib/builder/mp/materials.js +7 -2
- package/lib/builder/types/common.d.ts +1 -1
- package/lib/builder/util/common.d.ts +1 -1
- package/lib/builder.web.js +11 -11
- package/package.json +4 -5
- package/template/html/index.html.ejs +1 -1
- package/template/mp/package.json +1 -1
|
@@ -122,6 +122,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
122
122
|
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(processRepeaterDisplay(cals), dependencies);
|
|
123
123
|
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(processRepeaterDisplay(item), dependencies))) || [];
|
|
124
124
|
const apps = [mainAppSerializeData, ...subAppSerializeDataList];
|
|
125
|
+
const calses = [cals, ...subAppCalsList];
|
|
125
126
|
if (isBrowserMpBuilder) {
|
|
126
127
|
// 尽早下载物料
|
|
127
128
|
await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
|
|
@@ -131,7 +132,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
131
132
|
...buildContext,
|
|
132
133
|
projDir: (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp'),
|
|
133
134
|
mainAppData: mainAppSerializeData,
|
|
134
|
-
processCssUnit: (
|
|
135
|
+
processCssUnit: (calses.find((cals) => {
|
|
135
136
|
const FEATURE_MAP = (0, cals_1.parseVersion)(cals.schemaVersion, dependencies);
|
|
136
137
|
return !FEATURE_MAP.defaultDynamicCssUnit;
|
|
137
138
|
})
|
|
@@ -142,6 +143,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
142
143
|
};
|
|
143
144
|
const result = await (0, index_1.generateWxMp)({
|
|
144
145
|
weapps: apps,
|
|
146
|
+
calses,
|
|
145
147
|
buildContext: mpBuildContext,
|
|
146
148
|
plugins,
|
|
147
149
|
deployOptions,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
3
|
import { BuildType, IAppUsedComp, IUsedComps } from '../types/common';
|
|
4
|
+
import { IPlatformApp } from '@cloudbase/cals';
|
|
4
5
|
import { IBuildWedaApp } from '../core';
|
|
5
|
-
export declare function generateWxMp({ buildContext, weapps, plugins, deployOptions, options, buildTypeList, ignoreInstall, }: {
|
|
6
|
+
export declare function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall, }: {
|
|
6
7
|
buildContext: IBuildContext;
|
|
7
8
|
weapps: IWeAppData[];
|
|
9
|
+
calses: IPlatformApp[];
|
|
8
10
|
plugins: IPlugin[];
|
|
9
11
|
deployOptions: Required<IBuildWedaApp>['deployOptions'];
|
|
10
12
|
options: {
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -54,18 +54,30 @@ const cals_1 = require("@cloudbase/cals");
|
|
|
54
54
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
55
55
|
const em = chalk_1.default.blue.bold;
|
|
56
56
|
const error = chalk_1.default.redBright;
|
|
57
|
-
|
|
57
|
+
function patchBuildContext(ctx, calses, weapps) {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const { mainAppData } = ctx;
|
|
60
|
+
if ((_b = (_a = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _a === void 0 ? void 0 : _a.templates) === null || _b === void 0 ? void 0 : _b.length) {
|
|
61
|
+
ctx.materialLibs = [...ctx.materialLibs, (0, cals_1.processTemplatesToDependiencies)((_c = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _c === void 0 ? void 0 : _c.templates)];
|
|
62
|
+
}
|
|
63
|
+
const { allAppUsedComps } = handleUsedComponents({ buildContext: ctx, weapps });
|
|
64
|
+
/**
|
|
65
|
+
* 修改 buildContext 进行 miniprogramPlugins 精简
|
|
66
|
+
*/
|
|
67
|
+
ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
|
|
68
|
+
return { allAppUsedComps };
|
|
69
|
+
}
|
|
70
|
+
async function generateWxMp({ buildContext, weapps, calses, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, }) {
|
|
58
71
|
var _a;
|
|
59
|
-
const { appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = buildContext;
|
|
60
72
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
61
73
|
console.time(operationLabel);
|
|
62
|
-
console.log(`Generating ${em('Wexin MiniProgram')} to ${projDir}`);
|
|
63
|
-
const { allAppUsedComps } = handleUsedComponents({ buildContext, weapps });
|
|
74
|
+
console.log(`Generating ${em('Wexin MiniProgram')} to ${buildContext.projDir}`);
|
|
64
75
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
76
|
+
* 此函数具有副作用,用于补充修正小程序特殊的buildContext
|
|
77
|
+
* 注意一定在入口进行处理,应当尽可能提前,后续逻辑不应该更新buildContext
|
|
67
78
|
*/
|
|
68
|
-
|
|
79
|
+
const { allAppUsedComps } = patchBuildContext(buildContext, calses, weapps);
|
|
80
|
+
const { appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = buildContext;
|
|
69
81
|
// 安装依赖库,生成 materials 目录
|
|
70
82
|
await (0, materials_1.installMaterials)(buildContext, projDir, allAppUsedComps, weapps);
|
|
71
83
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
|
|
@@ -164,7 +176,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
|
|
|
164
176
|
'package.json': {
|
|
165
177
|
appId,
|
|
166
178
|
importJSSDK: endpointType === 'tcb-api',
|
|
167
|
-
extraDeps: resolveNpmDeps(),
|
|
179
|
+
extraDeps: resolveNpmDeps(weapps, materials),
|
|
168
180
|
},
|
|
169
181
|
};
|
|
170
182
|
}
|
|
@@ -216,7 +228,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
|
|
|
216
228
|
'package.json': {
|
|
217
229
|
appId,
|
|
218
230
|
importJSSDK: endpointType === 'tcb-api',
|
|
219
|
-
extraDeps: resolveNpmDeps(),
|
|
231
|
+
extraDeps: resolveNpmDeps(weapps, materials),
|
|
220
232
|
},
|
|
221
233
|
}, templateDir, subpackageRootPath);
|
|
222
234
|
}
|
|
@@ -234,45 +246,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
|
|
|
234
246
|
!isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
|
|
235
247
|
!isBrowserMpBuilder && cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
|
|
236
248
|
return { miniprogramRoot };
|
|
237
|
-
function resolveNpmDeps(extra = {}) {
|
|
238
|
-
var _a;
|
|
239
|
-
const deps = [
|
|
240
|
-
{
|
|
241
|
-
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) || {},
|
|
242
|
-
name: '主包',
|
|
243
|
-
},
|
|
244
|
-
];
|
|
245
|
-
deps.push(...weapps
|
|
246
|
-
.filter((app) => !!app.rootPath)
|
|
247
|
-
.map((app) => ({
|
|
248
|
-
deps: app.npmDependencies,
|
|
249
|
-
name: `子包:${app.rootPath}`,
|
|
250
|
-
})));
|
|
251
|
-
deps.push(...materials
|
|
252
|
-
.filter((lib) => lib.isComposite && lib.compLibCommonResource)
|
|
253
|
-
.map((lib) => {
|
|
254
|
-
var _a;
|
|
255
|
-
return ({
|
|
256
|
-
deps: ((_a = lib.compLibCommonResource) === null || _a === void 0 ? void 0 : _a.npm) || {},
|
|
257
|
-
name: `组件库级别${lib.name}`,
|
|
258
|
-
});
|
|
259
|
-
}));
|
|
260
|
-
deps.push(...materials.map((lib) => ({
|
|
261
|
-
deps: lib.dependencies || {},
|
|
262
|
-
name: `组件库${lib.name}`,
|
|
263
|
-
})));
|
|
264
|
-
return deps.reduce((result, cur) => {
|
|
265
|
-
Object.keys(cur.deps || {}).map((npmPkgName) => {
|
|
266
|
-
if (!result[npmPkgName]) {
|
|
267
|
-
result[npmPkgName] = cur.deps[npmPkgName];
|
|
268
|
-
}
|
|
269
|
-
else if (result[npmPkgName] != cur.deps[npmPkgName]) {
|
|
270
|
-
console.error(error(`${cur.name}的Npm依赖${npmPkgName}已在其他地方定义,将被忽略`));
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
return result;
|
|
274
|
-
}, extra);
|
|
275
|
-
}
|
|
276
249
|
// SDK 插件
|
|
277
250
|
async function handleMpPlugins() {
|
|
278
251
|
// 编译后置原生小程序类的安装
|
|
@@ -281,6 +254,45 @@ async function generateWxMp({ buildContext, weapps, plugins, deployOptions, opti
|
|
|
281
254
|
}
|
|
282
255
|
}
|
|
283
256
|
exports.generateWxMp = generateWxMp;
|
|
257
|
+
function resolveNpmDeps(weapps, materials, extra = {}) {
|
|
258
|
+
var _a;
|
|
259
|
+
const deps = [
|
|
260
|
+
{
|
|
261
|
+
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) || {},
|
|
262
|
+
name: '主包',
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
deps.push(...weapps
|
|
266
|
+
.filter((app) => !!app.rootPath)
|
|
267
|
+
.map((app) => ({
|
|
268
|
+
deps: app.npmDependencies,
|
|
269
|
+
name: `子包:${app.rootPath}`,
|
|
270
|
+
})));
|
|
271
|
+
deps.push(...materials
|
|
272
|
+
.filter((lib) => lib.isComposite && lib.compLibCommonResource)
|
|
273
|
+
.map((lib) => {
|
|
274
|
+
var _a;
|
|
275
|
+
return ({
|
|
276
|
+
deps: ((_a = lib.compLibCommonResource) === null || _a === void 0 ? void 0 : _a.npm) || {},
|
|
277
|
+
name: `组件库级别${lib.name}`,
|
|
278
|
+
});
|
|
279
|
+
}));
|
|
280
|
+
deps.push(...materials.map((lib) => ({
|
|
281
|
+
deps: lib.dependencies || {},
|
|
282
|
+
name: `组件库${lib.name}`,
|
|
283
|
+
})));
|
|
284
|
+
return deps.reduce((result, cur) => {
|
|
285
|
+
Object.keys(cur.deps || {}).map((npmPkgName) => {
|
|
286
|
+
if (!result[npmPkgName]) {
|
|
287
|
+
result[npmPkgName] = cur.deps[npmPkgName];
|
|
288
|
+
}
|
|
289
|
+
else if (result[npmPkgName] != cur.deps[npmPkgName]) {
|
|
290
|
+
console.error(error(`${cur.name}的Npm依赖${npmPkgName}已在其他地方定义,将被忽略`));
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
return result;
|
|
294
|
+
}, extra);
|
|
295
|
+
}
|
|
284
296
|
async function generateConfig(data, root) {
|
|
285
297
|
const { domain = '', isPrivateMode = false, endpointType = '' } = data;
|
|
286
298
|
await (0, generateFiles_1.default)({
|
|
@@ -11,13 +11,6 @@ export declare function installMaterials(ctx: IBuildContext, projDir: string, us
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function filterMaterial(src: any, dest: any): boolean;
|
|
13
13
|
export declare function extractUsedCompsRecursively(comps: IUsedComps, checkedComps: ICompositedComponent[], compositedLibs: IMaterialItem[], outputComps?: IUsedComps): IUsedComps;
|
|
14
|
-
/**
|
|
15
|
-
* {
|
|
16
|
-
* gsd: {
|
|
17
|
-
* input: 'input'
|
|
18
|
-
* }
|
|
19
|
-
* }
|
|
20
|
-
*/
|
|
21
14
|
export declare function getWxmlTag(ctx: IBuildContext, cmp: Required<IWeAppComponentInstance>['xComponent'], nameMangler?: NameMangler): {
|
|
22
15
|
tagName: string;
|
|
23
16
|
path?: undefined;
|
|
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.filterMaterial = exports.installMaterials = void 0;
|
|
27
30
|
const path = __importStar(require("path"));
|
|
@@ -36,6 +39,7 @@ const wxml_1 = require("./wxml");
|
|
|
36
39
|
const generateFiles_1 = __importStar(require("../util/generateFiles"));
|
|
37
40
|
const lowcode_1 = require("./lowcode");
|
|
38
41
|
const net_1 = require("../util/net");
|
|
42
|
+
const name_mangler_1 = __importDefault(require("@cloudbase/lowcode-generator/lib/generator/util/name-mangler"));
|
|
39
43
|
const junk = __importStar(require("../util/junk"));
|
|
40
44
|
const cals_1 = require("@cloudbase/cals");
|
|
41
45
|
const templateDir = `${config_1.appTemplateDir}/mp/`;
|
|
@@ -353,6 +357,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
|
|
|
353
357
|
* }
|
|
354
358
|
* }
|
|
355
359
|
*/
|
|
360
|
+
const NAME_MANAGER = new name_mangler_1.default({ blackList: mp_1.builtinMpTags });
|
|
356
361
|
function getWxmlTag(ctx, cmp, nameMangler) {
|
|
357
362
|
var _a, _b, _c, _d, _e, _f;
|
|
358
363
|
const { moduleName, name } = cmp;
|
|
@@ -383,7 +388,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
383
388
|
? compPath
|
|
384
389
|
: path.posix.join(
|
|
385
390
|
/* ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
|
|
386
|
-
tagName = `${moduleName}-${name}`;
|
|
391
|
+
tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
|
|
387
392
|
if (nameMangler) {
|
|
388
393
|
tagName = nameMangler.mangle(tagName);
|
|
389
394
|
}
|
|
@@ -391,7 +396,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
|
|
|
391
396
|
}
|
|
392
397
|
else {
|
|
393
398
|
compPath = `plugin://${miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.name}/${name}`;
|
|
394
|
-
tagName = `${moduleName}-${name}`;
|
|
399
|
+
tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
|
|
395
400
|
if (nameMangler) {
|
|
396
401
|
tagName = nameMangler.mangle(tagName);
|
|
397
402
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { BuildType, GenerateMpType, WebpackModeType, WebpackBuildCallBack, IPackageJson, buildAsWebByBuildType, buildAsAdminPortalByBuildType, buildAsXPageByBuildType, IAppUsedComp, IUsedComps, ISyncProp, IComponentInputProps, IFileCodeMap, } from '@cloudbase/lowcode-generator/lib/generator/types/common';
|
|
2
2
|
import { IComponentMeta, ICompositedComponent } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
3
|
-
export type IComponentsInfoMap = {
|
|
3
|
+
export declare type IComponentsInfoMap = {
|
|
4
4
|
[componentSourceKey: string]: ({
|
|
5
5
|
meta: IComponentMeta;
|
|
6
6
|
} & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IComponentInputProps, IComponentsInfoMap, IPackageJson } from '../types/common';
|
|
2
2
|
import { IMaterialItem, IWeAppComponentInstance, IWeAppCode } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
3
3
|
export { getMetaInfoBySourceKey, isArray, isPlainObject, deepDeal, simpleDeepClone, deepDealSchema, getFileNameByUrl, } from '@cloudbase/lowcode-generator/lib/generator/util/common';
|
|
4
|
-
type PromiseResult<T> = Promise<[null, T] | [Error, null]>;
|
|
4
|
+
declare type PromiseResult<T> = Promise<[null, T] | [Error, null]>;
|
|
5
5
|
export declare function promiseWrapper<T>(p: Promise<T>): PromiseResult<T>;
|
|
6
6
|
export declare function getCurrentPackageJson(): {
|
|
7
7
|
name: any;
|