@cloudbase/lowcode-builder 0.1.3 → 0.1.5-mpbeta.0

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 (39) hide show
  1. package/lib/builder/config/index.d.ts +14 -0
  2. package/lib/builder/config/index.js +21 -2
  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 +5 -1
  6. package/lib/builder/h5/material.js +5 -1
  7. package/lib/builder/mp/BuildContext.d.ts +1 -0
  8. package/lib/builder/mp/index.d.ts +2 -1
  9. package/lib/builder/mp/index.js +70 -54
  10. package/lib/builder/mp/materials.d.ts +7 -0
  11. package/lib/builder/mp/materials.js +30 -14
  12. package/lib/builder/mp/mixMode.js +5 -1
  13. package/lib/builder/mp/mp_config.js +8 -4
  14. package/lib/builder/mp/plugin.js +5 -1
  15. package/lib/builder/service/webpack.js +10 -10
  16. package/lib/builder/util/common.js +5 -4
  17. package/lib/builder/util/generateFiles.d.ts +35 -0
  18. package/lib/builder/util/generateFiles.js +128 -2
  19. package/lib/builder/util/index.js +5 -1
  20. package/lib/builder/util/junk.js +4 -1
  21. package/lib/builder/util/mp.js +5 -1
  22. package/lib/builder/util/net.d.ts +20 -1
  23. package/lib/builder/util/net.js +77 -4
  24. package/lib/index.js +5 -1
  25. package/lib/types.d.ts +1 -0
  26. package/lib/types.js +3 -1
  27. package/package.json +21 -7
  28. package/template/mp/component/index.js +6 -2
  29. package/template/mp/page/index.js +6 -2
  30. package/lib/generate.d.ts +0 -1
  31. package/lib/generate.js +0 -60
  32. package/lib/tests/build.d.ts +0 -1
  33. package/lib/tests/build.js +0 -19
  34. package/lib/tests/build.test.d.ts +0 -1
  35. package/lib/tests/build.test.js +0 -22
  36. package/lib/tests/data.d.ts +0 -18
  37. package/lib/tests/data.js +0 -94216
  38. package/lib/utils/postProcess copy.d.ts +0 -2
  39. package/lib/utils/postProcess copy.js +0 -27
@@ -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({
@@ -93,31 +98,42 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
93
98
  const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
94
99
  await generateFramework(mainAppData, miniprogramRoot, buildContext);
95
100
  // #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
- };
101
+ let appFileData = {};
102
+ if (weapps.find((item) => !item.mpPkgUrl)) {
103
+ await generateFramework(mainAppData, miniprogramRoot, buildContext);
104
+ // 有了 framework app 之后,并且是源码的方式,追加 app 引用
105
+ if (mainAppData.mpPkgUrl) {
106
+ let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
107
+ let appJsContent = await fs.readFile(appJsPath);
108
+ await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
109
+ }
110
+ appFileData = {
111
+ ...appFileData,
112
+ 'common/style.js': {},
113
+ 'common/utils.wxs': {
114
+ domain: domain,
115
+ },
116
+ 'common/util.js': {
117
+ isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
118
+ },
119
+ 'common/widget.js': {},
120
+ 'common/url.js': {},
121
+ 'common/weapp-sdk.js': {},
122
+ 'common/weapp-page.js': {
123
+ dataPropNames: wxmlDataPrefix,
124
+ debug: buildContext.debugMode,
125
+ },
126
+ 'common/weapp-component.js': {},
127
+ 'common/merge-renderer.js': {
128
+ dataPropNames: wxmlDataPrefix,
129
+ debug: buildContext.debugMode,
130
+ },
131
+ 'common/process.js': {},
132
+ 'common/data-patch.js': {},
133
+ 'common/event-emitter.js': {},
134
+ 'common/watch.js': {},
135
+ };
136
+ }
121
137
  if (mainAppData.mpPkgUrl) {
122
138
  // 合并 project 和 app json
123
139
  if (!projectConfigJson.setting) {
@@ -142,9 +158,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
142
158
  }
143
159
  appJson.subpackages = subpackages;
144
160
  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
161
  }
149
162
  else {
150
163
  appFileData = {
@@ -178,26 +191,28 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
178
191
  await fs.move(path_1.default.join(projDir, config_1.materialsDirName), path_1.default.join(miniprogramRoot, config_1.materialsDirName));
179
192
  }
180
193
  // 生成数据源
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);
194
+ if (weapps.find((item) => !item.mpPkgUrl)) {
195
+ const datasourceFileData = {
196
+ 'datasources/index.js': {},
197
+ 'datasources/config.js.tpl': {
198
+ envID: mainAppData.envId,
199
+ appID: appId,
200
+ resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
201
+ isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
202
+ },
203
+ 'datasources/datasource-profiles.js.tpl': {
204
+ datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
205
+ datasources.push(...(app.datasources || []));
206
+ return datasources;
207
+ }, [])), { EOL: false }),
208
+ },
209
+ 'datasources/dataset-profiles.js.tpl': {
210
+ datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
211
+ },
212
+ };
213
+ console.log('Generating ' + em('datasources') + ' files');
214
+ await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot, buildContext);
215
+ }
201
216
  // 生成子包
202
217
  await Promise.all(weapps.map(async (app, index) => {
203
218
  if (index == 0) {
@@ -223,13 +238,14 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
223
238
  }
224
239
  }
225
240
  }));
226
- if (fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
241
+ if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
227
242
  await (0, webpack_1.installDependencies)(miniprogramRoot);
228
243
  }
229
244
  await handleMpPlugins();
230
245
  console.timeEnd(operationLabel);
231
- cleanProj(weapps, miniprogramRoot);
232
- 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);
233
249
  return { miniprogramRoot };
234
250
  function resolveNpmDeps() {
235
251
  var _a;
@@ -285,7 +301,7 @@ async function generatePkg(weapp, appRoot, ctx, pageConfigs) {
285
301
  // 清空历史文件,使用zip覆盖
286
302
  console.log(`Removing ${appRoot}`);
287
303
  await (0, generateFiles_1.cleanDir)(appRoot, ['materials']);
288
- await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot);
304
+ await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot, ctx.isBrowserMpBuilder);
289
305
  if (fs.existsSync(path_1.default.join(appRoot, '__MACOSX'))) {
290
306
  await fs.remove(path_1.default.join(appRoot, '__MACOSX'));
291
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];
@@ -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;