@cloudbase/lowcode-builder 0.1.1 → 0.1.5-mp-beta

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 (47) hide show
  1. package/lib/builder/config/index.d.ts +14 -0
  2. package/lib/builder/config/index.js +16 -1
  3. package/lib/builder/core/index.d.ts +4 -1
  4. package/lib/builder/core/index.js +15 -3
  5. package/lib/builder/h5/copy.js +17 -3
  6. package/lib/builder/mp/BuildContext.d.ts +1 -0
  7. package/lib/builder/mp/index.d.ts +2 -1
  8. package/lib/builder/mp/index.js +65 -53
  9. package/lib/builder/mp/materials.js +12 -14
  10. package/lib/builder/mp/mp_config.js +1 -1
  11. package/lib/builder/mp/wxml.js +5 -1
  12. package/lib/builder/service/webpack.js +10 -10
  13. package/lib/builder/util/common.js +5 -4
  14. package/lib/builder/util/generateFiles.d.ts +33 -0
  15. package/lib/builder/util/generateFiles.js +120 -1
  16. package/lib/builder/util/net.d.ts +20 -1
  17. package/lib/builder/util/net.js +72 -3
  18. package/lib/types.d.ts +1 -0
  19. package/lib/types.js +3 -1
  20. package/package.json +21 -7
  21. package/template/html/index.html.ejs +6 -9
  22. package/template/mp/app/weapps-api.js +17 -45
  23. package/template/mp/app.js +66 -66
  24. package/template/mp/common/weapp-page.js +3 -1
  25. package/template/mp/component/index.js +6 -2
  26. package/template/mp/datasources/config.js.tpl +1 -1
  27. package/template/mp/datasources/datasource-profiles.js.tpl +1 -1
  28. package/template/mp/datasources/index.js +13 -4
  29. package/template/mp/package.json +12 -11
  30. package/template/mp/page/index.js +6 -2
  31. package/template/package.json +4 -2
  32. package/template/src/app/global-api.js +6 -83
  33. package/template/src/app/material-actions.js +15 -13
  34. package/template/src/datasources/index.js +15 -2
  35. package/template/src/index.jsx +1 -1
  36. package/template/webpack/web.prod.js +62 -41
  37. package/lib/generate.d.ts +0 -1
  38. package/lib/generate.js +0 -60
  39. package/lib/tests/build.d.ts +0 -1
  40. package/lib/tests/build.js +0 -19
  41. package/lib/tests/build.test.d.ts +0 -1
  42. package/lib/tests/build.test.js +0 -22
  43. package/lib/tests/data.d.ts +0 -18
  44. package/lib/tests/data.js +0 -94216
  45. package/lib/utils/postProcess copy.d.ts +0 -2
  46. package/lib/utils/postProcess copy.js +0 -27
  47. package/template/src/pages/composite.tpl +0 -151
@@ -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;
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  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;
25
+ 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
26
  const path = __importStar(require("path"));
27
27
  const os_1 = __importDefault(require("os"));
28
28
  var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
@@ -35,3 +35,18 @@ Object.defineProperty(exports, "rpxConfig", { enumerable: true, get: function ()
35
35
  exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
36
36
  exports.appTemplateDir = path.resolve(__dirname, '../../../template');
37
37
  exports.materialsDirName = 'materials'; // materials diretory of current project
38
+ /**
39
+ * src/template的代码,在IDE编辑器插件中构建builder
40
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
41
+ */
42
+ exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template.zip';
43
+ /**
44
+ * miniprogram的代码,IDE插件后续会提供端功能
45
+ * 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488&region=ap-shanghai&path=%252Flcap-builder%252F
46
+ */
47
+ // export const miniprogramURL = 'https://cos-1252394733.cos.ap-nanjing.myqcloud.com/miniprogram_npm.zip';
48
+ exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm.zip';
49
+ /**
50
+ * miniprogram_npm存放目录。IDE插件builder用到
51
+ */
52
+ 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;
@@ -55,7 +55,7 @@ exports.runCopy = runCopy;
55
55
  async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDir) {
56
56
  const localPkg = (0, common_1.getCurrentPackageJson)();
57
57
  await Promise.all(dependencies.map(async (componentLib) => {
58
- var _a;
58
+ var _a, _b, _c, _d, _e;
59
59
  const { name, version } = componentLib;
60
60
  const materialNameVersion = `${name}@${version}`;
61
61
  const materialDir = path.join(materialsDir, materialNameVersion);
@@ -86,6 +86,9 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
86
86
  // 副作用修改了dependence定义,trycatch 不阻塞主流程
87
87
  try {
88
88
  const meta = (0, common_1.readComponentLibMata)(librariesDir);
89
+ if (meta === null || meta === void 0 ? void 0 : meta.schemaVersion) {
90
+ componentLib['schemaVersion'] = meta === null || meta === void 0 ? void 0 : meta.schemaVersion;
91
+ }
89
92
  let [major] = ((_a = meta === null || meta === void 0 ? void 0 : meta.schemaVersion) === null || _a === void 0 ? void 0 : _a.split('.')) || [];
90
93
  if (Number(major) >= 3) {
91
94
  componentLib['isPlainProps'] = true;
@@ -94,8 +97,19 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
94
97
  catch (e) { }
95
98
  try {
96
99
  const packageJson = fs_extra_1.default.readJsonSync(path.join(materialDir, 'package.json'));
97
- if (packageJson.lowcode) {
98
- componentLib['entry'] = path.posix.relative(srcDir, packageJson.lowcode);
100
+ if ((_c = (_b = packageJson.weda) === null || _b === void 0 ? void 0 : _b.platform) === null || _c === void 0 ? void 0 : _c.web) {
101
+ const entries = (_e = (_d = packageJson.weda) === null || _d === void 0 ? void 0 : _d.platform) === null || _e === void 0 ? void 0 : _e.web;
102
+ componentLib['entries'] = {
103
+ entry: path.posix.relative(srcDir, entries.entry),
104
+ components: path.posix.relative(srcDir, entries.components),
105
+ actions: path.posix.relative(srcDir, entries.actions),
106
+ };
107
+ }
108
+ else if (packageJson.lowcode) {
109
+ const entry = path.posix.relative(srcDir, packageJson.lowcode);
110
+ componentLib['entries'] = {
111
+ entry,
112
+ };
99
113
  }
100
114
  }
101
115
  catch (e) { }
@@ -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
  }>;
@@ -51,7 +51,7 @@ const net_1 = require("../util/net");
51
51
  const templateDir = config_1.appTemplateDir + '/mp/';
52
52
  const em = chalk_1.default.blue.bold;
53
53
  const error = chalk_1.default.redBright;
54
- async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, }) {
54
+ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
55
55
  const operationLabel = em('Wexin MiniProgram Generated');
56
56
  console.time(operationLabel);
57
57
  console.log('Generating ' + em('Wexin MiniProgram') + ' to ' + projDir);
@@ -66,6 +66,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
66
66
  isMixMode,
67
67
  mainAppData,
68
68
  domain,
69
+ isBrowserMpBuilder,
69
70
  };
70
71
  const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
71
72
  const { appUsedComps, allAppUsedComps } = handleUsedComponents({
@@ -93,31 +94,42 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
93
94
  const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
94
95
  await generateFramework(mainAppData, miniprogramRoot, buildContext);
95
96
  // #3 生成主包根路径文件
96
- let appFileData = {
97
- 'common/style.js': {},
98
- 'common/utils.wxs': {
99
- domain: domain,
100
- },
101
- 'common/util.js': {
102
- isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
103
- },
104
- 'common/widget.js': {},
105
- 'common/url.js': {},
106
- 'common/weapp-sdk.js': {},
107
- 'common/weapp-page.js': {
108
- dataPropNames: wxmlDataPrefix,
109
- debug: buildContext.debugMode,
110
- },
111
- 'common/weapp-component.js': {},
112
- 'common/merge-renderer.js': {
113
- dataPropNames: wxmlDataPrefix,
114
- debug: buildContext.debugMode,
115
- },
116
- 'common/process.js': {},
117
- 'common/data-patch.js': {},
118
- 'common/event-emitter.js': {},
119
- 'common/watch.js': {},
120
- };
97
+ let appFileData = {};
98
+ if (weapps.find((item) => !item.mpPkgUrl)) {
99
+ await generateFramework(mainAppData, miniprogramRoot, buildContext);
100
+ // 有了 framework app 之后,并且是源码的方式,追加 app 引用
101
+ if (mainAppData.mpPkgUrl) {
102
+ let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
103
+ let appJsContent = await fs.readFile(appJsPath);
104
+ await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
105
+ }
106
+ appFileData = {
107
+ ...appFileData,
108
+ 'common/style.js': {},
109
+ 'common/utils.wxs': {
110
+ domain: domain,
111
+ },
112
+ 'common/util.js': {
113
+ isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
114
+ },
115
+ 'common/widget.js': {},
116
+ 'common/url.js': {},
117
+ 'common/weapp-sdk.js': {},
118
+ 'common/weapp-page.js': {
119
+ dataPropNames: wxmlDataPrefix,
120
+ debug: buildContext.debugMode,
121
+ },
122
+ 'common/weapp-component.js': {},
123
+ 'common/merge-renderer.js': {
124
+ dataPropNames: wxmlDataPrefix,
125
+ debug: buildContext.debugMode,
126
+ },
127
+ 'common/process.js': {},
128
+ 'common/data-patch.js': {},
129
+ 'common/event-emitter.js': {},
130
+ 'common/watch.js': {},
131
+ };
132
+ }
121
133
  if (mainAppData.mpPkgUrl) {
122
134
  // 合并 project 和 app json
123
135
  if (!projectConfigJson.setting) {
@@ -142,9 +154,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
142
154
  }
143
155
  appJson.subpackages = subpackages;
144
156
  await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
145
- let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
146
- let appJsContent = await fs.readFile(appJsPath);
147
- await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
148
157
  }
149
158
  else {
150
159
  appFileData = {
@@ -178,26 +187,28 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
178
187
  await fs.move(path_1.default.join(projDir, config_1.materialsDirName), path_1.default.join(miniprogramRoot, config_1.materialsDirName));
179
188
  }
180
189
  // 生成数据源
181
- const datasourceFileData = {
182
- 'datasources/index.js': {},
183
- 'datasources/config.js.tpl': {
184
- envID: mainAppData.envId,
185
- appID: appId,
186
- resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
187
- isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
188
- },
189
- 'datasources/datasource-profiles.js.tpl': {
190
- datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
191
- datasources.push(...(app.datasources || []));
192
- return datasources;
193
- }, [])), { EOL: true }),
194
- },
195
- 'datasources/dataset-profiles.js.tpl': {
196
- datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
197
- },
198
- };
199
- console.log('Generating ' + em('datasources') + ' files');
200
- await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot, buildContext);
190
+ if (weapps.find((item) => !item.mpPkgUrl)) {
191
+ const datasourceFileData = {
192
+ 'datasources/index.js': {},
193
+ 'datasources/config.js.tpl': {
194
+ envID: mainAppData.envId,
195
+ appID: appId,
196
+ resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
197
+ isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
198
+ },
199
+ 'datasources/datasource-profiles.js.tpl': {
200
+ datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
201
+ datasources.push(...(app.datasources || []));
202
+ return datasources;
203
+ }, [])), { EOL: false }),
204
+ },
205
+ 'datasources/dataset-profiles.js.tpl': {
206
+ datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
207
+ },
208
+ };
209
+ console.log('Generating ' + em('datasources') + ' files');
210
+ await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot, buildContext);
211
+ }
201
212
  // 生成子包
202
213
  await Promise.all(weapps.map(async (app, index) => {
203
214
  if (index == 0) {
@@ -223,13 +234,14 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
223
234
  }
224
235
  }
225
236
  }));
226
- if (fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
237
+ if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
227
238
  await (0, webpack_1.installDependencies)(miniprogramRoot);
228
239
  }
229
240
  await handleMpPlugins();
230
241
  console.timeEnd(operationLabel);
231
- cleanProj(weapps, miniprogramRoot);
232
- cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
242
+ // web端的builder不需要清除
243
+ !isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
244
+ !isBrowserMpBuilder && cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
233
245
  return { miniprogramRoot };
234
246
  function resolveNpmDeps() {
235
247
  var _a;
@@ -285,7 +297,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
285
297
  // 清空历史文件,使用zip覆盖
286
298
  console.log(`Removing ${appRoot}`);
287
299
  await (0, generateFiles_1.cleanDir)(appRoot, ['materials']);
288
- await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot);
300
+ await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot, ctx.isBrowserMpBuilder);
289
301
  if (fs.existsSync(path_1.default.join(appRoot, '__MACOSX'))) {
290
302
  await fs.remove(path_1.default.join(appRoot, '__MACOSX'));
291
303
  }
@@ -18,9 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
22
  exports.getWxmlTag = exports.extractUsedCompsRecursively = exports.installMaterials = void 0;
26
23
  const path = __importStar(require("path"));
@@ -32,14 +29,14 @@ const mp_1 = require("@cloudbase/lowcode-generator/lib/generator/config/mp");
32
29
  const util_2 = require("../util");
33
30
  const util_3 = require("./util");
34
31
  const wxml_1 = require("./wxml");
35
- const generateFiles_1 = __importDefault(require("../util/generateFiles"));
32
+ const generateFiles_1 = __importStar(require("../util/generateFiles"));
36
33
  const lowcode_1 = require("./lowcode");
37
34
  const net_1 = require("../util/net");
38
35
  const util_4 = require("../util");
39
36
  const junk = __importStar(require("../util/junk"));
40
37
  const templateDir = config_1.appTemplateDir + '/mp/';
41
38
  async function installMaterials(projDir, usedComps, weapps, ctx) {
42
- let { materialLibs } = ctx;
39
+ let { materialLibs, isBrowserMpBuilder } = ctx;
43
40
  const weappsList = ctx.isMixMode
44
41
  ? weapps
45
42
  : weapps.filter((item) => !item.rootPath);
@@ -58,7 +55,7 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
58
55
  }
59
56
  else {
60
57
  materialsSrcDir = path.join(config_1.sharedMaterialsDir, `${name}-mp@${version}`);
61
- await downloadMaterial(mpPkgUrl, materialsSrcDir);
58
+ await downloadMaterial(mpPkgUrl, materialsSrcDir, ctx.isBrowserMpBuilder);
62
59
  }
63
60
  function libUpdated(libDir, version) {
64
61
  const meta = (0, util_4.readComponentLibMata)(libDir);
@@ -86,29 +83,30 @@ async function installMaterials(projDir, usedComps, weapps, ctx) {
86
83
  if (libUpdated(targetDir, version)) {
87
84
  const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
88
85
  if (fs.existsSync(materialsSrcDirPath)) {
89
- console.log(`Copying material ${materialId} from ${materialsSrcDir}/src to ${targetDir}`);
86
+ console.log(`Copying material ${materialId} from ${isBrowserMpBuilder ? materialsSrcDirPath : materialsSrcDir}/src to ${targetDir}`);
90
87
  // #2 从根目录 copy meta 文件
91
88
  const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
92
89
  if (fs.existsSync(metaJosnPath)) {
93
- await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json'));
90
+ !isBrowserMpBuilder ? await fs.copy(metaJosnPath, path.join(targetDir, 'meta.json')) : (0, generateFiles_1.copyRecursiveSync)(metaJosnPath, path.join(targetDir, 'meta.json'));
91
+ ;
94
92
  }
95
93
  // #3 copy 组件库代码文件到项目目录
96
- await fs.copy(materialsSrcDirPath, targetDir, {
94
+ !isBrowserMpBuilder ? await fs.copy(materialsSrcDirPath, targetDir, {
97
95
  filter: function (src, dest) {
98
96
  const path = src.split('/');
99
97
  return !junk.is(path[path.length - 1]);
100
98
  },
101
- });
99
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDirPath, targetDir);
102
100
  }
103
101
  else {
104
102
  console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
105
103
  // #2 link material to current project
106
- await fs.copy(materialsSrcDir, targetDir, {
104
+ !isBrowserMpBuilder ? await fs.copy(materialsSrcDir, targetDir, {
107
105
  filter: function (src, dest) {
108
106
  const path = src.split('/');
109
107
  return !junk.is(path[path.length - 1]);
110
108
  },
111
- });
109
+ }) : (0, generateFiles_1.copyRecursiveSync)(materialsSrcDir, targetDir);
112
110
  }
113
111
  }
114
112
  const libMeta = (0, util_4.readComponentLibMata)(targetDir);
@@ -206,10 +204,10 @@ function extractUsedCompsRecursively(comps, checkedComps, compositedLibs, output
206
204
  return usedComps;
207
205
  }
208
206
  exports.extractUsedCompsRecursively = extractUsedCompsRecursively;
209
- async function downloadMaterial(zipUrl, dstFolder) {
207
+ async function downloadMaterial(zipUrl, dstFolder, isBrowser = false) {
210
208
  if (fs.existsSync(path.join(dstFolder, 'meta.json')))
211
209
  return;
212
- await (0, net_1.downloadZip)(zipUrl, dstFolder);
210
+ await (0, net_1.downloadZip)(zipUrl, dstFolder, isBrowser);
213
211
  }
214
212
  async function generateCompositeComponent(compositedComp, ctx, compLibCommonResource) {
215
213
  const { materialName } = compositedComp;
@@ -43,7 +43,7 @@ function generateMpConfig(weapps, ctx) {
43
43
  };
44
44
  const { miniprogramPlugins = [] } = ctx;
45
45
  const projConfig = (0, lodash_1.merge)({}, mp_1.defaultProjConfig, {
46
- projectname: 'WeDa-' + ctx.appId,
46
+ projectname: (ctx.mainAppData && ctx.mainAppData.label) || ('WeDa-' + ctx.appId),
47
47
  });
48
48
  const pageConfigs = weapps.map((app) => {
49
49
  var _a;
@@ -105,7 +105,11 @@ function generateWxml(widgets, docTag, wxmlDataPrefix, ctx, usingComponents, com
105
105
  elements.push({
106
106
  type: 'element',
107
107
  name: tagName,
108
- attributes: { name: data0.name.value },
108
+ attributes: {
109
+ name: data0.name.type && data0.name.type !== 'static'
110
+ ? `{{${id}.name}}`
111
+ : data0.name.value,
112
+ },
109
113
  elements: [],
110
114
  _order: xIndex || 0,
111
115
  _parent: null,
@@ -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,34 @@ 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: any, target: any): void;
25
+ /**
26
+ * 根据源文件目录,输出目录,递归复制文件
27
+ * @param {string} src 源文件目录
28
+ * @param {string} dest 输出目录
29
+ */
30
+ export declare const copyRecursiveSync: (src: any, dest: any) => void;
31
+ /**
32
+ * 返回指定目录的文件列表内容,返回map格式
33
+ * @param dir 指定目录
34
+ * @param files_ 文件列表
35
+ * @param replacePath 去掉前面路径
36
+ * @returns
37
+ */
38
+ export declare function getFiles(dir: string, files_: any, replacePath?: string): any;
39
+ /**
40
+ * 将文件压缩为zip包
41
+ * 参考JSZip例子:https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
42
+ * @param files
43
+ * @param type
44
+ * @returns
45
+ */
46
+ export declare function fileToZip(files: {
47
+ [key: string]: Uint8Array;
48
+ }, type: OutputType): Promise<string | Buffer | Uint8Array | number[] | ArrayBuffer | Blob>;
49
+ export declare function strToBuf(str: any): Buffer;