@cloudbase/lowcode-builder 1.8.35 → 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.
@@ -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: ([cals, ...subAppCalsList].find((cals) => {
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: {
@@ -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
- async function generateWxMp({ buildContext, weapps, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, }) {
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
- * 修改 buildContext 进行 miniprogramPlugins 精简
66
- * 应该提前处理,不应该修改 buildContext
76
+ * 此函数具有副作用,用于补充修正小程序特殊的buildContext
77
+ * 注意一定在入口进行处理,应当尽可能提前,后续逻辑不应该更新buildContext
67
78
  */
68
- buildContext.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
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/`;
@@ -57,7 +61,8 @@ async function installMaterials(ctx, projDir, usedComps, weapps) {
57
61
  }
58
62
  else {
59
63
  materialsSrcDir = path.join(config_1.sharedMaterialsDir, `${name}-mp@${version}`);
60
- await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder);
64
+ const noCache = mpPkgUrl.indexOf('127.0.0.1') >= 0;
65
+ await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder, noCache);
61
66
  }
62
67
  function libUpdated(libDir, version) {
63
68
  const meta = (0, util_2.readComponentLibMata)(libDir);
@@ -229,10 +234,10 @@ function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, output
229
234
  return usedComps;
230
235
  }
231
236
  exports.extractUsedCompsRecursively = extractUsedCompsRecursively;
232
- async function downloadMaterial(zipUrl, dstFolder, isBrowser = false) {
233
- if (fs.existsSync(path.join(dstFolder, 'meta.json')))
237
+ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false, noCache = false) {
238
+ if (!noCache && fs.existsSync(path.join(dstFolder, 'meta.json')))
234
239
  return;
235
- await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser);
240
+ await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser, noCache);
236
241
  }
237
242
  async function generateCompositeComponent(ctx, compositedComp, compLibCommonResource) {
238
243
  const compositeCtx = {
@@ -352,6 +357,7 @@ async function generateCompositeComponent(ctx, compositedComp, compLibCommonReso
352
357
  * }
353
358
  * }
354
359
  */
360
+ const NAME_MANAGER = new name_mangler_1.default({ blackList: mp_1.builtinMpTags });
355
361
  function getWxmlTag(ctx, cmp, nameMangler) {
356
362
  var _a, _b, _c, _d, _e, _f;
357
363
  const { moduleName, name } = cmp;
@@ -382,7 +388,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
382
388
  ? compPath
383
389
  : path.posix.join(
384
390
  /* ctx.isMixMode ? '/' + rootPath : */ '', `/${config_1.materialsDirName}/${cmp.moduleName}`, compPath);
385
- tagName = `${moduleName}-${name}`;
391
+ tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
386
392
  if (nameMangler) {
387
393
  tagName = nameMangler.mangle(tagName);
388
394
  }
@@ -390,7 +396,7 @@ function getWxmlTag(ctx, cmp, nameMangler) {
390
396
  }
391
397
  else {
392
398
  compPath = `plugin://${miniprogramPlugin === null || miniprogramPlugin === void 0 ? void 0 : miniprogramPlugin.name}/${name}`;
393
- tagName = `${moduleName}-${name}`;
399
+ tagName = `${/^\$/.test(moduleName) ? NAME_MANAGER.mangle(moduleName) : moduleName}-${name}`;
394
400
  if (nameMangler) {
395
401
  tagName = nameMangler.mangle(tagName);
396
402
  }
@@ -4,7 +4,7 @@ export declare function downloadFile(url: string, filePath: string): Promise<voi
4
4
  * @param url
5
5
  * @param dstDir folder to hold the extract zip content
6
6
  */
7
- export declare function downloadZip(url: string, dstDir: string, isBrowser?: boolean): Promise<void>;
7
+ export declare function downloadZip(url: string, dstDir: string, isBrowser?: boolean, noCache?: boolean): Promise<void>;
8
8
  /**
9
9
  * node中下载和保存zip文件
10
10
  * @param url 下载的url
@@ -17,7 +17,7 @@ export declare function downloadZipInNode(url: string, dstDir: string): Promise<
17
17
  * @param dstDir 存放文件夹
18
18
  * @returns
19
19
  */
20
- export declare function downloadZipInBrowser(url: string, dstDir: string): Promise<void>;
20
+ export declare function downloadZipInBrowser(url: string, dstDir: string, noCache: boolean): Promise<void>;
21
21
  /**
22
22
  * 微信IDE builder需要下载template文件和miniprogram_npm
23
23
  * miniprogram_npm待微信提供端能力
@@ -46,10 +46,10 @@ exports.downloadFile = downloadFile;
46
46
  * @param url
47
47
  * @param dstDir folder to hold the extract zip content
48
48
  */
49
- async function downloadZip(url, dstDir, isBrowser = false) {
49
+ async function downloadZip(url, dstDir, isBrowser = false, noCache = false) {
50
50
  // TODO 待加上平台判断
51
51
  if (isBrowser) {
52
- await downloadZipInBrowser(url, dstDir);
52
+ await downloadZipInBrowser(url, dstDir, noCache);
53
53
  return;
54
54
  }
55
55
  await downloadZipInNode(url, dstDir);
@@ -72,9 +72,9 @@ exports.downloadZipInNode = downloadZipInNode;
72
72
  * @param dstDir 存放文件夹
73
73
  * @returns
74
74
  */
75
- async function downloadZipInBrowser(url, dstDir) {
75
+ async function downloadZipInBrowser(url, dstDir, noCache) {
76
76
  // IMPORTANT 防止保存的时候保存
77
- if (fs_extra_1.default.existsSync(dstDir)) {
77
+ if (!noCache && fs_extra_1.default.existsSync(dstDir)) {
78
78
  return;
79
79
  }
80
80
  fs_extra_1.default.ensureDirSync(dstDir);
@@ -96,9 +96,11 @@ async function saveFiles(files, dstDir) {
96
96
  continue;
97
97
  }
98
98
  if (files[fileName].dir) { // 如果该文件为目录需先创建文件夹
99
- fs_extra_1.default.mkdirSync(dest, {
100
- recursive: true
101
- });
99
+ if (!fs_extra_1.default.pathExistsSync(dest)) {
100
+ fs_extra_1.default.mkdirSync(dest, {
101
+ recursive: true
102
+ });
103
+ }
102
104
  }
103
105
  else {
104
106
  const ret = await files[fileName].async('nodebuffer'); // 由于这里有await,不能用forEach
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.8.35",
3
+ "version": "1.8.37",
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",
@@ -29,9 +29,9 @@
29
29
  "develop": "tsc -w",
30
30
  "clean": "rm -rf lib && rm -rf dist",
31
31
  "build": "tsc",
32
- "test": "jest",
33
32
  "test:build": "ts-node ./__tests__/build.ts",
34
- "dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
33
+ "dev:web:serve": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/web.config.js",
34
+ "dev:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=development webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js",
35
35
  "build:web": "rm -rf dist && node ./webpack/scripts/web.pre.js && cross-env NODE_ENV=production webpack --config ./webpack/web.config.js && node ./webpack/scripts/web.post.js",
36
36
  "build:template": "./scripts/buildTemplate.sh"
37
37
  },
@@ -41,8 +41,8 @@
41
41
  "dependencies": {
42
42
  "@babel/core": "7.12.3",
43
43
  "@babel/preset-env": "7.12.1",
44
- "@cloudbase/cals": "^1.0.23",
45
- "@cloudbase/lowcode-generator": "^1.8.12",
44
+ "@cloudbase/cals": "^1.0.25",
45
+ "@cloudbase/lowcode-generator": "^1.8.13",
46
46
  "axios": "^0.21.0",
47
47
  "browserfs": "^1.4.3",
48
48
  "browserify-zlib": "^0.2.0",
@@ -540,7 +540,7 @@
540
540
  crossorigin
541
541
  src="<%=
542
542
  cdnEndpoints.cdngo
543
- %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.1a8d700051f7a14000ad.bundle.js"
543
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.6f7cc6eededb826a73c7.bundle.js"
544
544
  ></script>
545
545
  </body>
546
546
  </html>
@@ -296,11 +296,11 @@ export function createPage({
296
296
  const params = Array.isArray(_params)
297
297
  ? _params.reduce((map, meta) => {
298
298
  let { key, value } = meta;
299
- if (key.startsWith('$page.')) {
299
+ if (key?.startsWith?.('$page.')) {
300
300
  key = key.replace(/^\$page\./, '');
301
301
  }
302
302
  if(key?.trim?.()){
303
- map[key] = value;
303
+ map[key?.trim?.()] = value;
304
304
  }
305
305
  return map;
306
306
  }, {})
@@ -6,7 +6,7 @@
6
6
  "@cloudbase/js-sdk": "2.5.6-beta.1",<%
7
7
  } %>
8
8
  "@cloudbase/oauth": "0.1.1-alpha.5",
9
- "@cloudbase/weda-client": "1.0.7",
9
+ "@cloudbase/weda-client": "1.0.8",
10
10
  "@cloudbase/weda-cloud-sdk": "1.0.45",
11
11
  "mobx": "^5.15.4",
12
12
  "lodash.get": "^4.4.2",