@cloudbase/lowcode-builder 0.1.4 → 0.1.5-mpbeta.1

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.
Files changed (37) hide show
  1. package/README.md +59 -0
  2. package/lib/builder/config/index.d.ts +14 -0
  3. package/lib/builder/config/index.js +21 -2
  4. package/lib/builder/core/index.d.ts +4 -1
  5. package/lib/builder/core/index.js +15 -3
  6. package/lib/builder/h5/copy.js +5 -1
  7. package/lib/builder/h5/material.js +5 -1
  8. package/lib/builder/mp/BuildContext.d.ts +1 -0
  9. package/lib/builder/mp/index.d.ts +2 -1
  10. package/lib/builder/mp/index.js +12 -6
  11. package/lib/builder/mp/materials.d.ts +7 -0
  12. package/lib/builder/mp/materials.js +30 -14
  13. package/lib/builder/mp/mixMode.js +5 -1
  14. package/lib/builder/mp/mp_config.js +8 -4
  15. package/lib/builder/mp/plugin.js +5 -1
  16. package/lib/builder/mp/util.js +14 -1
  17. package/lib/builder/mp/wxml.js +4 -0
  18. package/lib/builder/service/webpack.js +10 -10
  19. package/lib/builder/util/common.js +5 -4
  20. package/lib/builder/util/generateFiles.d.ts +35 -0
  21. package/lib/builder/util/generateFiles.js +128 -2
  22. package/lib/builder/util/index.js +5 -1
  23. package/lib/builder/util/junk.js +4 -1
  24. package/lib/builder/util/mp.js +5 -1
  25. package/lib/builder/util/net.d.ts +20 -1
  26. package/lib/builder/util/net.js +77 -4
  27. package/lib/builder.web.js +94 -0
  28. package/lib/index.js +5 -1
  29. package/lib/types.d.ts +1 -0
  30. package/lib/types.js +3 -1
  31. package/package.json +21 -7
  32. package/template/mp/common/util.js +2 -2
  33. package/template/mp/common/weapp-component.js +3 -3
  34. package/template/mp/common/weapp-page.js +4 -3
  35. package/template/mp/common/widget.js +10 -10
  36. package/template/mp/component/index.js +10 -4
  37. package/template/mp/page/index.js +11 -4
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ ## 本包说明
2
+ - @cloudbase/lowcode-builder是微搭用于将DSL构建为小程序和web的构建包。
3
+ - 例子在__tests__/build.ts下
4
+ - 主要是在node环境下运行。由于微信IDE的背景,提供了web构建出小程序版本的功能。两种方式如何使用见以下示例
5
+
6
+ ## node端使用
7
+ 使用示例:
8
+ ```javascript
9
+ import { buildWedaApp } from '@cloudbase/lowcode-builder';
10
+ import { simpleData as data, options } from './data';
11
+ import path from 'path';
12
+ import fs from 'fs-extra';
13
+
14
+ const outPath = path.resolve(__dirname, '.temp');
15
+ fs.emptyDirSync(outPath);
16
+ buildWedaApp({
17
+ ...data,
18
+ ...options,
19
+ buildTypeList: ['web' as any],
20
+ output: { path: outPath },
21
+ }).then((dir) => {
22
+ console.log(dir);
23
+ });
24
+ ```
25
+
26
+ ## web端使用
27
+ 使用示例:
28
+ ```javascript
29
+ export async function builderToZip(builderData: any, selectedPageId: string, outputPath: string) {
30
+ return import('@cloudbase/lowcode-builder/lib/builder.web').then(async (result) => {
31
+ try {
32
+ console.log('rose builderToZip import result ', result);
33
+ const { buildWedaApp, getFiles, fileToZip, strToBuf } = result;
34
+
35
+ // 1、构建到指定路径,返回构建文件存放路径
36
+ const buildPath = await buildWedaApp(builderData);
37
+
38
+ // 2、从指定路径获取文件
39
+ const files = await getFiles(buildPath, {}, `${outputPath}/`);
40
+
41
+ // 3、修改app.json入口地址
42
+ const finalFiles = setEntryPage(files, selectedPageId, strToBuf);
43
+
44
+ // 4、得到zip包,返回主进程,传给微信hybrid
45
+ const zipFiles = await fileToZip(finalFiles, 'arraybuffer'); // blob or arraybuffer
46
+
47
+ return {
48
+ zipFiles,
49
+ strFiles: '', // TODO暂时保留,用于返回zip包内容
50
+ };
51
+ } catch (err) {
52
+ error('builder.worker.js->builderToZip->catch:', err);
53
+ throw err;
54
+ }
55
+ });
56
+ }
57
+ ```
58
+
59
+
@@ -2,3 +2,17 @@ export { REPLACE_SIGN, MP_CONFIG_MODULE_NAME, KBONE_PAGE_KEYS, npmRegistry, remC
2
2
  export declare const sharedMaterialsDir: string;
3
3
  export declare const appTemplateDir: string;
4
4
  export declare const materialsDirName = "materials";
5
+ /**
6
+ * src/template的代码,在IDE编辑器插件中构建builder
7
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
8
+ */
9
+ export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.zip";
10
+ /**
11
+ * miniprogram的代码,IDE插件后续会提供端功能
12
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
13
+ */
14
+ export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm.zip";
15
+ /**
16
+ * miniprogram_npm存放目录。IDE插件builder用到
17
+ */
18
+ export declare const miniprogramDir: string;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -22,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
29
+ exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
26
30
  const path = __importStar(require("path"));
27
31
  const os_1 = __importDefault(require("os"));
28
32
  var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
@@ -35,3 +39,18 @@ Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function ()
35
39
  exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
36
40
  exports.appTemplateDir = path.resolve(__dirname, '../../../template');
37
41
  exports.materialsDirName = 'materials'; // materials diretory of current project
42
+ /**
43
+ * src/template的代码,在IDE编辑器插件中构建builder
44
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
45
+ */
46
+ exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.zip';
47
+ /**
48
+ * miniprogram的代码,IDE插件后续会提供端功能
49
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
50
+ */
51
+ // export const miniprogramURL = 'https://cos-1252394733.cos.ap-nanjing.myqcloud.com/miniprogram_npm.zip';
52
+ exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm.zip';
53
+ /**
54
+ * miniprogram_npm存放目录。IDE插件builder用到
55
+ */
56
+ exports.miniprogramDir = path.join(os_1.default.homedir(), exports.sharedMaterialsDir, 'miniprogram_npm');
@@ -36,9 +36,12 @@ export interface IBuildWedaApp extends IBaseAppProps {
36
36
  output?: {
37
37
  path?: string;
38
38
  };
39
+ isBrowserMpBuilder?: boolean;
39
40
  }
40
- export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
41
+ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
41
42
  export declare function cleanComponentDir(): Promise<void>;
42
43
  export declare function installDep(dir: any, opts?: IInstallOpts): Promise<void>;
43
44
  export declare const version: any;
45
+ export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
46
+ export { downloadZip } from '../util/net';
44
47
  export default buildWedaApp;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.version = exports.installDep = exports.cleanComponentDir = exports.buildWedaApp = exports.getCompileDirs = void 0;
6
+ exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.installDep = exports.cleanComponentDir = exports.buildWedaApp = exports.getCompileDirs = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const webpack_1 = require("../service/webpack");
9
9
  const util_1 = require("../util");
@@ -18,11 +18,12 @@ const index_2 = require("../h5/index");
18
18
  const chalk_1 = __importDefault(require("chalk"));
19
19
  const common_2 = require("../../utils/common");
20
20
  const postProcess_1 = require("../../utils/postProcess");
21
+ const net_1 = require("../util/net");
21
22
  const pkg = require('../../../package.json');
22
23
  async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appKey = 'test', runtime = types_1.RUNTIME.NONE, ignoreInstall = false, buildTypeList = [common_1.BuildType.WEB], mode = common_1.WebpackModeType.PRODUCTION, devTool = 'webpack', deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, generateMpType = common_1.GenerateMpType.APP, plugins = [], extraData = {
23
24
  isComposite: false,
24
25
  compProps: {},
25
- }, resourceAppId = undefined, domain = '', output, }, cb) {
26
+ }, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, }, cb) {
26
27
  var _a, _b;
27
28
  if (!cals) {
28
29
  console.error('无效的应用配置');
@@ -44,6 +45,10 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
44
45
  appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp');
45
46
  const isMixMode = generateMpType === common_1.GenerateMpType.SUBPACKAGE;
46
47
  const apps = [mainAppSerializeData, ...subAppSerializeDataList];
48
+ if (isBrowserMpBuilder) {
49
+ // 尽早下载物料
50
+ await (0, net_1.downloadBrowserMaterial)(output && output.path);
51
+ }
47
52
  try {
48
53
  const result = await (0, index_1.generateWxMp)({
49
54
  weapps: apps,
@@ -61,6 +66,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
61
66
  resourceAppId,
62
67
  },
63
68
  buildTypeList,
69
+ isBrowserMpBuilder,
64
70
  });
65
71
  // 如果是混合模式,则将特定的目录复制到工程下
66
72
  // 针对 app.json / package.json 则采用 merge 的操作
@@ -81,7 +87,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
81
87
  });
82
88
  // 如果是代开发的模式,则写入ext.json
83
89
  await (0, postProcess_1.postprocessDeployExtraJson)(outDir, deployOptions);
84
- if (generateMpType === common_1.GenerateMpType.APP) {
90
+ if (!isBrowserMpBuilder && generateMpType === common_1.GenerateMpType.APP) {
85
91
  // 模板拷入的 miniprogram_npm 有问题,直接删除使用重新构建的版本
86
92
  // 模板需要占位保证 mp 文件夹存在
87
93
  fs_extra_1.default.removeSync(path_1.default.resolve(outDir, 'miniprogram_npm'));
@@ -133,4 +139,10 @@ function installDep(dir, opts = {}) {
133
139
  }
134
140
  exports.installDep = installDep;
135
141
  exports.version = pkg.version;
142
+ var generateFiles_1 = require("../util/generateFiles");
143
+ Object.defineProperty(exports, "getFiles", { enumerable: true, get: function () { return generateFiles_1.getFiles; } });
144
+ Object.defineProperty(exports, "fileToZip", { enumerable: true, get: function () { return generateFiles_1.fileToZip; } });
145
+ Object.defineProperty(exports, "strToBuf", { enumerable: true, get: function () { return generateFiles_1.strToBuf; } });
146
+ var net_2 = require("../util/net");
147
+ Object.defineProperty(exports, "downloadZip", { enumerable: true, get: function () { return net_2.downloadZip; } });
136
148
  exports.default = buildWedaApp;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -13,4 +13,5 @@ export interface IBuildContext {
13
13
  rootPath?: string;
14
14
  miniprogramPlugins?: IMiniprogramPlugin[];
15
15
  debugMode?: boolean;
16
+ isBrowserMpBuilder?: boolean;
16
17
  }
@@ -2,7 +2,7 @@ import { IMaterialItem, IWeAppData, IPlugin } from '@cloudbase/lowcode-generator
2
2
  import { IBuildContext } from './BuildContext';
3
3
  import { DEPLOY_MODE } from '../../types';
4
4
  import { BuildType, IAppUsedComp, IUsedComps } from '../types/common';
5
- export declare function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, }: {
5
+ export declare function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder, }: {
6
6
  weapps: IWeAppData[];
7
7
  projDir: string;
8
8
  appId: string;
@@ -18,6 +18,7 @@ export declare function generateWxMp({ weapps, projDir, appId, domain, materials
18
18
  isCrossAccount: boolean;
19
19
  };
20
20
  buildTypeList: BuildType[];
21
+ isBrowserMpBuilder: boolean;
21
22
  }): Promise<{
22
23
  miniprogramRoot: string;
23
24
  }>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -51,7 +55,7 @@ const net_1 = require("../util/net");
51
55
  const templateDir = config_1.appTemplateDir + '/mp/';
52
56
  const em = chalk_1.default.blue.bold;
53
57
  const error = chalk_1.default.redBright;
54
- async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, }) {
58
+ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
55
59
  const operationLabel = em('Wexin MiniProgram Generated');
56
60
  console.time(operationLabel);
57
61
  console.log('Generating ' + em('Wexin MiniProgram') + ' to ' + projDir);
@@ -66,6 +70,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
66
70
  isMixMode,
67
71
  mainAppData,
68
72
  domain,
73
+ isBrowserMpBuilder,
69
74
  };
70
75
  const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
71
76
  const { appUsedComps, allAppUsedComps } = handleUsedComponents({
@@ -233,13 +238,14 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
233
238
  }
234
239
  }
235
240
  }));
236
- if (fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
241
+ if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
237
242
  await (0, webpack_1.installDependencies)(miniprogramRoot);
238
243
  }
239
244
  await handleMpPlugins();
240
245
  console.timeEnd(operationLabel);
241
- cleanProj(weapps, miniprogramRoot);
242
- cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
246
+ // web端的builder不需要清除
247
+ !isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
248
+ !isBrowserMpBuilder && cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
243
249
  return { miniprogramRoot };
244
250
  function resolveNpmDeps() {
245
251
  var _a;
@@ -295,7 +301,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
295
301
  // 清空历史文件,使用zip覆盖
296
302
  console.log(`Removing ${appRoot}`);
297
303
  await (0, generateFiles_1.cleanDir)(appRoot, ['materials']);
298
- await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot);
304
+ await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot, ctx.isBrowserMpBuilder);
299
305
  if (fs.existsSync(path_1.default.join(appRoot, '__MACOSX'))) {
300
306
  await fs.remove(path_1.default.join(appRoot, '__MACOSX'));
301
307
  }
@@ -3,6 +3,13 @@ import { IBuildContext } from './BuildContext';
3
3
  import NameMangler from '@cloudbase/lowcode-generator/lib/generator/util/name-mangler';
4
4
  import { IUsedComps } from '../types/common';
5
5
  export declare function installMaterials(projDir: string, usedComps: IUsedComps, weapps: IWeAppData[], ctx: IBuildContext): Promise<void>;
6
+ /**
7
+ * 过滤组件库文件
8
+ * @param src 源文件
9
+ * @param dest 目标文件
10
+ * @returns boolean
11
+ */
12
+ export declare function filterMaterial(src: any, dest: any): boolean;
6
13
  export declare function extractUsedCompsRecursively(comps: IUsedComps, checkedComps: ICompositedComponent[], compositedLibs: IMaterialItem[], outputComps?: IUsedComps): IUsedComps;
7
14
  /**
8
15
  * {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,11 +22,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
25
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.installMaterials = void 0;
26
+ exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.filterMaterial = exports.installMaterials = void 0;
26
27
  const path = __importStar(require("path"));
27
28
  const util_1 = require("util");
28
29
  const fs = __importStar(require("fs-extra"));
@@ -32,14 +33,14 @@ const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
32
33
  const util_2 = require("../util");
33
34
  const util_3 = require("./util");
34
35
  const wxml_1 = require("./wxml");
35
- const generateFiles_1 = __importDefault(require("../util/generateFiles"));
36
+ const generateFiles_1 = __importStar(require("../util/generateFiles"));
36
37
  const lowcode_1 = require("./lowcode");
37
38
  const net_1 = require("../util/net");
38
39
  const util_4 = require("../util");
39
40
  const junk = __importStar(require("../util/junk"));
40
41
  const templateDir = config_1.appTemplateDir + '/mp/';
41
42
  async function installMaterials(projDir, usedComps, weapps, ctx) {
42
- let { materialLibs } = ctx;
43
+ let { materialLibs, isBrowserMpBuilder } = ctx;
43
44
  const weappsList = ctx.isMixMode
44
45
  ? weapps
45
46
  : weapps.filter((item) => !item.rootPath);
@@ -58,7 +59,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
58
59
  }
59
60
  else {
60
61
  materialsSrcDir = path.join(config_1.sharedMaterialsDir, `${name}-mp@${version}`);
61
- await downloadMaterial(mpPkgUrl, materialsSrcDir);
62
+ await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder);
62
63
  }
63
64
  function libUpdated(libDir, version) {
64
65
  const meta = (0, util_4.readComponentLibMata)(libDir);
@@ -86,28 +87,32 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
86
87
  if (libUpdated(targetDir, version)) {
87
88
  const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
88
89
  if (fs.existsSync(materialsSrcDirPath)) {
89
- console.log(`Copying material ${materialId} from ${materialsSrcDir}/src to ${targetDir}`);
90
+ console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
90
91
  // #2 从根目录 copy meta 文件
91
92
  const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
92
93
  if (fs.existsSync(metaJosnPath)) {
93
- await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'));
94
+ !isBrowserMpBuilder ? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json')) : (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
94
95
  }
95
96
  // #3 copy 组件库代码文件到项目目录
96
- await fs.copy(materialsSrcDirPath, targetDir, {
97
+ !isBrowserMpBuilder ? await fs.copy(materialsSrcDirPath, targetDir, {
97
98
  filter: function (src, dest) {
98
99
  const path = src.split('/');
99
100
  return !junk.is(path[path.length - 1]);
100
101
  },
102
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir, {
103
+ filter: filterMaterial,
101
104
  });
102
105
  }
103
106
  else {
104
107
  console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
105
108
  // #2 link material to current project
106
- await fs.copy(materialsSrcDir, targetDir, {
109
+ !isBrowserMpBuilder ? await fs.copy(materialsSrcDir, targetDir, {
107
110
  filter: function (src, dest) {
108
111
  const path = src.split('/');
109
112
  return !junk.is(path[path.length - 1]);
110
113
  },
114
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir, {
115
+ filter: filterMaterial,
111
116
  });
112
117
  }
113
118
  }
@@ -172,6 +177,17 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
172
177
  }));
173
178
  }
174
179
  exports.installMaterials = installMaterials;
180
+ /**
181
+ * 过滤组件库文件
182
+ * @param src 源文件
183
+ * @param dest 目标文件
184
+ * @returns boolean
185
+ */
186
+ function filterMaterial(src, dest) {
187
+ const srcPath = src.split('/');
188
+ return !junk.is(srcPath[srcPath.length - 1]);
189
+ }
190
+ exports.filterMaterial = filterMaterial;
175
191
  // 递归查询复合组件所使用的组件
176
192
  function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, outputComps) {
177
193
  let usedComps = (outputComps || comps);
@@ -206,10 +222,10 @@ function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, output
206
222
  return usedComps;
207
223
  }
208
224
  exports.extractUsedCompsRecursively = extractUsedCompsRecursively;
209
- async function downloadMaterial(zipUrl, dstFolder) {
225
+ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false) {
210
226
  if (fs.existsSync(path.join(dstFolder, 'meta.json')))
211
227
  return;
212
- await (0, net_1.downloadZip)(zipUrl, dstFolder);
228
+ await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser);
213
229
  }
214
230
  async function generateCompositeComponent(compositedComp, ctx, compLibCommonResource) {
215
231
  const { materialName } = compositedComp;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -43,7 +47,7 @@ function generateMpConfig(weapps, ctx) {
43
47
  };
44
48
  const { miniprogramPlugins = [] } = ctx;
45
49
  const projConfig = (0, lodash_1.merge)({}, mp_1.defaultProjConfig, {
46
- projectname: 'WeDa-' + ctx.appId,
50
+ projectname: (ctx.mainAppData && ctx.mainAppData.label) || ('WeDa-' + ctx.appId),
47
51
  });
48
52
  const pageConfigs = weapps.map((app) => {
49
53
  var _a;
@@ -102,8 +106,8 @@ function generateMpConfig(weapps, ctx) {
102
106
  appConfig.plugins = plugins;
103
107
  }
104
108
  miniprogramPlugins.forEach((plugin) => {
105
- var _a, _b;
106
- if (!((_b = (_a = appConfig) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b[plugin.name])) {
109
+ var _a;
110
+ if (!((_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.plugins) === null || _a === void 0 ? void 0 : _a[plugin.name])) {
107
111
  (0, lodash_1.set)(appConfig, `plugins.${plugin.name}`, {
108
112
  version: plugin.version,
109
113
  provider: plugin.pluginAppId,
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -111,7 +111,7 @@ exports.createWidgetProps = createWidgetProps;
111
111
  function createEventHanlders(widgets, componentApi, ctx) {
112
112
  const eventHanlders = {};
113
113
  (0, weapp_1.walkThroughWidgets)(widgets, (id, widget, parentId) => {
114
- var _a, _b;
114
+ var _a, _b, _c;
115
115
  const { xComponent } = widget;
116
116
  const xProps = widget.xProps || {};
117
117
  if (!xComponent) {
@@ -175,6 +175,19 @@ function createEventHanlders(widgets, componentApi, ctx) {
175
175
  type: l.type,
176
176
  });
177
177
  });
178
+ // 如果是数据容器,则生成一个onDataChange事件处理
179
+ if ((_c = compProto === null || compProto === void 0 ? void 0 : compProto.compConfig) === null || _c === void 0 ? void 0 : _c.isDataContainer) {
180
+ const customName = (0, wxml_1.getMpEventHanlderName)(id, 'onDataChange', {});
181
+ eventHanlders[customName] = [{
182
+ key: '',
183
+ handler: `({event})=>{
184
+ app.utils.set(context, '${id}.data', event?.detail?.data);
185
+ }`,
186
+ handlerModule: weapps_core_1.ActionType.Platform,
187
+ data: {},
188
+ boundData: {},
189
+ }];
190
+ }
178
191
  });
179
192
  return eventHanlders;
180
193
  }
@@ -205,6 +205,10 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
205
205
  });
206
206
  // 扩展组件配置
207
207
  const compConfig = componentProto.compConfig;
208
+ // 如果是数据容器,则增加一个onDataChange事件 bind:onDataChange="onid1$onDataChange"
209
+ if (compConfig === null || compConfig === void 0 ? void 0 : compConfig.isDataContainer) {
210
+ node.attributes['bind:onDataChange'] = getMpEventHanlderName(id, 'onDataChange');
211
+ }
208
212
  if (compConfig && compConfig.pluginConfig) {
209
213
  if (compConfig.pluginConfig.attributes) {
210
214
  Object.assign(node.attributes, compConfig.pluginConfig.attributes);
@@ -2,7 +2,6 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- var _a;
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.downloadAssets = exports.generateWebpackWebDevServerFile = exports.getMaterialNodeModulesPathList = exports.installDependencies = exports.downloadDependencies = exports.downloadAndInstallDependencies = exports.getAllPageMpEntryPath = exports.getWebpackMpBuildParams = exports.getWebpackWebBuildParams = exports.getMpAllRouterConfig = exports.getPageName = exports.getHomePageInstance = exports.getMainAppDataByList = exports.generateMpJsonConfigFile = exports.generateKboneAppConfig = exports.generateKbonePageConfig = exports.downloadAndWriteTabBarIcon = exports.generateKboneTabBarConfig = exports.generateAppConfig = exports.generateWebpackWebBuildParamsFile = exports.fixAppJson = void 0;
8
7
  const path_1 = __importDefault(require("path"));
@@ -20,15 +19,6 @@ const config_2 = require("../config");
20
19
  const common_2 = require("../util/common");
21
20
  const types_1 = require("../../types");
22
21
  const generateFiles_1 = require("../util/generateFiles");
23
- let yarnExists = false;
24
- try {
25
- let { stdout } = cross_spawn_1.default.sync('yarn', ['-v']);
26
- let str = stdout.toString();
27
- if (Number((_a = str.split('.')) === null || _a === void 0 ? void 0 : _a[0]) <= 1) {
28
- yarnExists = true;
29
- }
30
- }
31
- catch (e) { }
32
22
  async function fixAppJson(appBuildDir) {
33
23
  const appJsonPath = path_1.default.resolve(appBuildDir, 'dist/mp/app.json');
34
24
  if (!fs_extra_1.default.existsSync(appJsonPath)) {
@@ -407,6 +397,16 @@ async function downloadDependencies(targetDir, srcZipUrl) {
407
397
  exports.downloadDependencies = downloadDependencies;
408
398
  // TODO use yarn if installed
409
399
  async function installDependencies(targetDir, options = {}) {
400
+ var _a;
401
+ let yarnExists = false;
402
+ try {
403
+ let { stdout } = cross_spawn_1.default.sync('yarn', ['-v']);
404
+ let str = stdout.toString();
405
+ if (Number((_a = str.split('.')) === null || _a === void 0 ? void 0 : _a[0]) <= 1) {
406
+ yarnExists = true;
407
+ }
408
+ }
409
+ catch (e) { }
410
410
  if ((options === null || options === void 0 ? void 0 : options.ignoreInstall) &&
411
411
  fs_extra_1.default.existsSync(path_1.default.join(targetDir, 'node_modules'))) {
412
412
  console.log('ignore install dependencies in ' + targetDir);
@@ -57,11 +57,12 @@ function getSelfPackageJson() {
57
57
  exports.getSelfPackageJson = getSelfPackageJson;
58
58
  function JsonToStringWithVariableName(copyJson, options = {}) {
59
59
  let variable = JSON.stringify(copyJson, null, 2).replace(/"%%%(.*?)%%%"/g, function (match, expression) {
60
- return expression.replace(/\\'/g, "'").replace(/\\"/g, '"');
60
+ return expression
61
+ .replace(/\\"/g, '"')
62
+ .replace(/\\'/g, "'")
63
+ .replace(/\\r/g, '\r')
64
+ .replace(/\\n/g, '\n');
61
65
  });
62
- if (options.EOL) {
63
- variable = variable.replace(/\\n/g, '\n').replace(/\\r/g, '\r');
64
- }
65
66
  return variable;
66
67
  }
67
68
  exports.JsonToStringWithVariableName = JsonToStringWithVariableName;
@@ -1,4 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import { IBuildContext } from '../mp/BuildContext';
3
+ import { OutputType } from 'jszip';
2
4
  export default function generateFiles(appFileData: any, srcDir: string, dstDir: string, ctx: IBuildContext): Promise<string[]>;
3
5
  export declare function writeFile(outFile: string, content: string): Promise<boolean>;
4
6
  export declare function removeFile(file: string): void;
@@ -14,3 +16,36 @@ export declare function cleanDir(dir: string, allowedFiles: string[]): void;
14
16
  */
15
17
  export declare function copyFiles(copyFiles: string[], srcDir: string, dstDir: string): Promise<void[]>;
16
18
  export declare function copy(src: string, dest: string): Promise<void>;
19
+ /**
20
+ * 复制文件
21
+ * @param source 源文件
22
+ * @param target 目标文件
23
+ */
24
+ export declare function copyFileSync(source: string, target: string): void;
25
+ /**
26
+ * 根据源文件目录,输出目录,递归复制文件
27
+ * @param {string} src 源文件目录
28
+ * @param {string} dest 输出目录
29
+ */
30
+ export declare const copyRecursiveSync: (src: string, dest: string, options?: {
31
+ filter: (src: string, dest: string) => boolean;
32
+ } | undefined) => void;
33
+ /**
34
+ * 返回指定目录的文件列表内容,返回map格式
35
+ * @param dir 指定目录
36
+ * @param files_ 文件列表
37
+ * @param replacePath 去掉前面路径
38
+ * @returns
39
+ */
40
+ export declare function getFiles(dir: string, files_: any, replacePath?: string): any;
41
+ /**
42
+ * 将文件压缩为zip包
43
+ * 参考JSZip例子:https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
44
+ * @param files
45
+ * @param type
46
+ * @returns
47
+ */
48
+ export declare function fileToZip(files: {
49
+ [key: string]: Uint8Array;
50
+ }, type: OutputType): Promise<string | Buffer | Uint8Array | number[] | ArrayBuffer | Blob>;
51
+ export declare function strToBuf(str: any): Buffer;