@cloudbase/lowcode-builder 1.2.0 → 1.2.1-alpha.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.
@@ -16,3 +16,11 @@ export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-sha
16
16
  * miniprogram_npm存放目录。IDE插件builder用到
17
17
  */
18
18
  export declare const miniprogramDir: string;
19
+ export interface ICDN_ENDPOINTS_COFIG {
20
+ common?: string;
21
+ cloudbase?: string;
22
+ cdngo?: string;
23
+ aegis?: string;
24
+ }
25
+ export declare const CDN_ENDPONTS_CONFIG: ICDN_ENDPOINTS_COFIG;
26
+ export declare function generateCdnEndpoints(endpoints?: ICDN_ENDPOINTS_COFIG): ICDN_ENDPOINTS_COFIG;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
29
+ exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const os_1 = __importDefault(require("os"));
32
32
  var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
@@ -54,3 +54,18 @@ exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqclou
54
54
  * miniprogram_npm存放目录。IDE插件builder用到
55
55
  */
56
56
  exports.miniprogramDir = path.join(os_1.default.homedir(), exports.sharedMaterialsDir, 'miniprogram_npm');
57
+ exports.CDN_ENDPONTS_CONFIG = {
58
+ common: '',
59
+ cloudbase: '//static.cloudbase.net',
60
+ cdngo: 'https://qbase.cdn-go.cn',
61
+ aegis: 'https://cdn-go.cn',
62
+ };
63
+ function generateCdnEndpoints(endpoints = exports.CDN_ENDPONTS_CONFIG) {
64
+ for (const key in exports.CDN_ENDPONTS_CONFIG) {
65
+ if (!Object.prototype.hasOwnProperty.call(endpoints, key)) {
66
+ endpoints[key] = endpoints.common ? endpoints.common : exports.CDN_ENDPONTS_CONFIG[key];
67
+ }
68
+ }
69
+ return endpoints;
70
+ }
71
+ exports.generateCdnEndpoints = generateCdnEndpoints;
@@ -2,7 +2,8 @@ import { IMaterialItem, IWeAppData, IPlugin, IExtraData } from '@cloudbase/lowco
2
2
  import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from '../types/common';
3
3
  import { DEPLOY_MODE, RUNTIME } from '../../types';
4
4
  import { IPlatformApp } from '@cloudbase/cals';
5
- export interface IBaseAppProps {
5
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
6
+ interface IBaseAppProps {
6
7
  appKey: string;
7
8
  dependencies?: IMaterialItem[];
8
9
  publicPath?: string;
@@ -35,11 +36,41 @@ export interface IBuildWedaApp extends IBaseAppProps {
35
36
  path?: string;
36
37
  };
37
38
  isBrowserMpBuilder?: boolean;
39
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
40
+ isPrivateMode?: boolean;
41
+ endpointType?: 'tcb-api' | 'wechat-service';
38
42
  }
39
- 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>;
43
+ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, isPrivateMode, endpointType, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
40
44
  export declare function cleanComponentDir(): Promise<void>;
41
45
  export declare const version: any;
42
46
  export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
43
47
  export { downloadZip } from '../util/net';
44
48
  export { getCompileDirs } from '../util';
45
49
  export default buildWedaApp;
50
+ interface INormalizeInput {
51
+ appId?: string;
52
+ appKey?: string;
53
+ dependencies?: IBuildWedaApp['dependencies'];
54
+ buildTypeList: IBuildWedaApp['buildTypeList'];
55
+ mainAppSerializeData?: IBuildWedaApp['cals'];
56
+ cals?: IBuildWedaApp['cals'];
57
+ subAppSerializeDataList?: IBuildWedaApp['subAppCalsList'];
58
+ subAppCalsList?: IBuildWedaApp['subAppCalsList'];
59
+ deployOptions: IBuildWedaApp['deployOptions'];
60
+ mpAppId?: string;
61
+ extraData?: {
62
+ isComposite: boolean;
63
+ compProps: {};
64
+ };
65
+ [key: string]: any;
66
+ }
67
+ interface InormalizeOutput extends INormalizeInput {
68
+ dependencies: Required<INormalizeInput['dependencies']>;
69
+ }
70
+ export declare function normalizeInputs(inputs: INormalizeInput, { envId, getWebRootPath, }: {
71
+ envId: string;
72
+ getWebRootPath?: ({ appId, deployOptions }: {
73
+ appId: any;
74
+ deployOptions: any;
75
+ }) => string;
76
+ }): InormalizeOutput;
@@ -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.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = void 0;
6
+ exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -20,7 +20,7 @@ const pkg = require('../../../package.json');
20
20
  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 = {
21
21
  isComposite: false,
22
22
  compProps: {},
23
- }, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, }, cb) {
23
+ }, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, cdnEndpoints, isPrivateMode = false, endpointType = undefined, }, cb) {
24
24
  var _a, _b;
25
25
  if (!cals) {
26
26
  console.error('无效的应用配置');
@@ -28,6 +28,18 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
28
28
  }
29
29
  const { mode: deployMode = types_1.DEPLOY_MODE.PREVIEW } = deployOptions;
30
30
  let appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || (runtime === types_1.RUNTIME.CI ? (_a = (0, util_1.getCompileDirs)('app')) === null || _a === void 0 ? void 0 : _a.appBuildDir : (_b = (0, util_1.getCompileDirs)(appKey)) === null || _b === void 0 ? void 0 : _b.appBuildDir);
31
+ const buildContext = {
32
+ projDir: appBuildDir,
33
+ appId: appKey,
34
+ isProduction: mode === common_1.WebpackModeType.PRODUCTION,
35
+ materialLibs: dependencies,
36
+ debugMode: mode !== common_1.WebpackModeType.PRODUCTION && !!process.env.WEAPPS_DEBUG,
37
+ isMixMode: generateMpType === common_1.GenerateMpType.SUBPACKAGE,
38
+ domain,
39
+ isBrowserMpBuilder,
40
+ isPrivateMode,
41
+ endpointType,
42
+ };
31
43
  console.log('domain', domain);
32
44
  console.log('应用名', appKey);
33
45
  console.log('生成模式', generateMpType);
@@ -37,28 +49,25 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
37
49
  if (buildTypeList.includes(common_1.BuildType.MP)) {
38
50
  const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
39
51
  const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
40
- appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp');
41
- const isMixMode = generateMpType === common_1.GenerateMpType.SUBPACKAGE;
42
52
  const apps = [mainAppSerializeData, ...subAppSerializeDataList];
43
53
  if (isBrowserMpBuilder) {
44
54
  // 尽早下载物料
45
55
  await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
46
56
  }
57
+ const mpBuildContext = {
58
+ ...buildContext,
59
+ projDir: (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp'),
60
+ mainAppData: mainAppSerializeData,
61
+ };
47
62
  const result = await (0, index_1.generateWxMp)({
48
63
  weapps: apps,
49
- projDir: appBuildDir,
50
- appId: appKey,
51
- domain: domain,
52
- materials: dependencies,
64
+ buildContext: mpBuildContext,
53
65
  plugins,
54
- isProduction: mode === common_1.WebpackModeType.PRODUCTION,
55
66
  deployMode,
56
- extraData,
57
- isMixMode,
58
67
  options: {
59
68
  isCrossAccount: resourceAppId !== deployOptions.targetMpAppId,
69
+ mpAppId: deployOptions.mpAppId || '',
60
70
  resourceAppId,
61
- mpAppId: deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mpAppId,
62
71
  },
63
72
  buildTypeList,
64
73
  isBrowserMpBuilder,
@@ -66,17 +75,17 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
66
75
  });
67
76
  // 如果是混合模式,则将特定的目录复制到工程下
68
77
  // 针对 app.json / package.json 则采用 merge 的操作
69
- if (isMixMode) {
70
- console.log(chalk_1.default.green('【混合模式】'), appBuildDir);
78
+ if (buildContext.isMixMode) {
79
+ console.log(chalk_1.default.green('【混合模式】'), mpBuildContext.projDir);
71
80
  await (0, mixMode_1.handleMixMode)({
81
+ buildContext: mpBuildContext,
72
82
  apps,
73
- generateMpPath: appBuildDir,
74
83
  miniprogramRoot: result.miniprogramRoot,
75
84
  plugins,
76
85
  ignoreInstall,
77
86
  });
78
87
  }
79
- const outDir = appBuildDir;
88
+ const outDir = mpBuildContext.projDir;
80
89
  let projectJsonPath = path_1.default.resolve(outDir, 'project.config.json');
81
90
  await (0, postProcess_1.postprocessProjectConfig)(projectJsonPath, {
82
91
  appid: deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mpAppId,
@@ -89,18 +98,16 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
89
98
  // 模板需要占位保证 mp 文件夹存在
90
99
  fs_extra_1.default.removeSync(path_1.default.resolve(outDir, 'miniprogram_npm'));
91
100
  }
92
- cb === null || cb === void 0 ? void 0 : cb(null, {
101
+ await (cb === null || cb === void 0 ? void 0 : cb(null, {
93
102
  ...result,
94
103
  outDir,
95
104
  timeElapsed: Date.now() - startTime,
96
- });
105
+ }));
97
106
  return outDir;
98
107
  }
99
108
  else {
100
109
  const h5BuildDir = await (0, index_2.buildH5App)({
101
- appKey,
102
- buildDir: appBuildDir,
103
- dependencies,
110
+ buildContext: { ...buildContext, isMixMode: false },
104
111
  cals,
105
112
  subAppCalsList,
106
113
  extraData,
@@ -110,18 +117,36 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
110
117
  runtime,
111
118
  deployMode,
112
119
  ignoreInstall,
113
- domain,
120
+ cdnEndpoints,
114
121
  });
115
- cb === null || cb === void 0 ? void 0 : cb(null, {
122
+ await (cb === null || cb === void 0 ? void 0 : cb(null, {
116
123
  outDir: h5BuildDir,
117
124
  timeElapsed: Date.now() - startTime,
118
- });
125
+ }));
119
126
  return h5BuildDir;
120
127
  }
121
128
  }
122
- catch (e) {
123
- cb === null || cb === void 0 ? void 0 : cb(e);
124
- throw e;
129
+ catch (err) {
130
+ if (err.length) {
131
+ let messageList = (err[0] || '').split('\n');
132
+ let lineIndex = 0;
133
+ let reg = /node_modules\/@babel/;
134
+ messageList.find((str, index) => {
135
+ if (reg.test(str)) {
136
+ lineIndex = index;
137
+ return true;
138
+ }
139
+ else {
140
+ return false;
141
+ }
142
+ });
143
+ if (lineIndex) {
144
+ messageList = messageList.slice(0, lineIndex);
145
+ }
146
+ err = new Error(messageList.join('\n'));
147
+ }
148
+ cb === null || cb === void 0 ? void 0 : cb(err);
149
+ throw err;
125
150
  }
126
151
  }
127
152
  exports.buildWedaApp = buildWedaApp;
@@ -139,3 +164,98 @@ Object.defineProperty(exports, "downloadZip", { enumerable: true, get: function
139
164
  var util_2 = require("../util");
140
165
  Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
141
166
  exports.default = buildWedaApp;
167
+ function normalizeInputs(inputs, { envId, getWebRootPath, }) {
168
+ const { extraData = { isComposite: false, compProps: {} } } = inputs;
169
+ /**
170
+ * 过滤处理 dependencies
171
+ */
172
+ let map = {};
173
+ inputs.dependencies = (inputs.dependencies || []).reduce((list, item) => {
174
+ if (!map[`${item.name}@${item.version}`]) {
175
+ map[`${item.name}@${item.version}`] = true;
176
+ list.push(item);
177
+ }
178
+ return list;
179
+ }, []);
180
+ const normalizeCalsOptions = {
181
+ buildTypeList: inputs.buildTypeList,
182
+ envId,
183
+ deployOptions: inputs.deployOptions,
184
+ appId: inputs.appId || inputs.appKey,
185
+ getWebRootPath: getWebRootPath || _getWebRootPath,
186
+ };
187
+ if (inputs.mainAppSerializeData) {
188
+ inputs.mainAppSerializeData = normalizeCals(inputs.mainAppSerializeData, normalizeCalsOptions);
189
+ if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
190
+ inputs.subAppSerializeDataList = [];
191
+ }
192
+ }
193
+ if (inputs.cals) {
194
+ inputs.cals = normalizeCals(inputs.cals, normalizeCalsOptions);
195
+ if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
196
+ inputs.subAppCalsList = [];
197
+ }
198
+ }
199
+ if (!(0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
200
+ // 小程序构建
201
+ const { mpAppId, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW } } = inputs;
202
+ inputs.deployOptions = {
203
+ ...deployOptions,
204
+ mpAppId: deployOptions.mpAppId || mpAppId,
205
+ };
206
+ if (!inputs.deployOptions.targetMpAppId) {
207
+ inputs.deployOptions.targetMpAppId = inputs.deployOptions.mpAppId;
208
+ }
209
+ }
210
+ if (extraData.isComposite) {
211
+ Object.keys(extraData.compProps.events).forEach((eName) => {
212
+ extraData.compProps.events[eName] = `$$EVENT_${eName}$$`;
213
+ });
214
+ }
215
+ return inputs;
216
+ }
217
+ exports.normalizeInputs = normalizeInputs;
218
+ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWebRootPath }) {
219
+ var _a, _b;
220
+ if (!cals.extra) {
221
+ cals.extra = {};
222
+ }
223
+ if (!cals.mpPkgUrl) {
224
+ if (buildTypeList.includes(common_1.BuildType.APP) ||
225
+ buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
226
+ buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
227
+ cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
228
+ }
229
+ }
230
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.envId)) {
231
+ cals.extra.envId = envId;
232
+ }
233
+ if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
234
+ // web 构建不处理小程序插件
235
+ if (cals.extra.miniprogramPlugins) {
236
+ cals.extra.miniprogramPlugins = [];
237
+ }
238
+ let { appConfig = {} } = cals.extra;
239
+ let { window = {} } = appConfig;
240
+ let path = getWebRootPath({ appId, deployOptions });
241
+ cals.extra.appConfig = {
242
+ ...appConfig,
243
+ window: {
244
+ ...window,
245
+ // Todo: 处理自定义域名逻辑
246
+ publicPath: (0, common_1.buildAsXPageByBuildType)(buildTypeList)
247
+ ? (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.publicPath) || `https://${(_b = cals.extra) === null || _b === void 0 ? void 0 : _b.domain}${path}`
248
+ : path,
249
+ basename: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList)
250
+ ? `app/${appId}${(deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) !== types_1.DEPLOY_MODE.UPLOAD ? '-preview' : ''}`
251
+ : (0, common_1.buildAsXPageByBuildType)(buildTypeList)
252
+ ? '/'
253
+ : path,
254
+ },
255
+ };
256
+ }
257
+ return cals;
258
+ }
259
+ function _getWebRootPath({ appId, deployOptions }) {
260
+ return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.PREVIEW ? `/${appId}/preview/` : `/${appId}/production/`;
261
+ }
@@ -1,11 +1,12 @@
1
1
  import { BuildAppProps } from '@cloudbase/lowcode-generator';
2
2
  import { IPlatformApp } from '@cloudbase/cals';
3
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
3
4
  import { BuildType } from '../types/common';
4
5
  /**
5
6
  * 该函数从 @govcloud/generate 取到需要的模版文件
6
7
  */
7
8
  export declare function generateProjectFiles(buildData: BuildAppProps): Promise<void>;
8
- export declare function generateHTML({ appId, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, }: {
9
+ export declare function generateHTML({ appId, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
9
10
  appId: string;
10
11
  externalResources: Required<IPlatformApp>['externalResources'];
11
12
  appBuildDir: string;
@@ -13,6 +14,7 @@ export declare function generateHTML({ appId, appBuildDir, externalResources, mo
13
14
  devTool: string;
14
15
  isBuildApp: boolean;
15
16
  buildTypeList: BuildType[];
17
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
16
18
  }): Promise<void>;
17
19
  export declare function handleAssets({ appBuildDir, buildTypeList, assets, }: {
18
20
  appBuildDir: string;
@@ -25,7 +25,7 @@ async function generateProjectFiles(buildData) {
25
25
  }));
26
26
  }
27
27
  exports.generateProjectFiles = generateProjectFiles;
28
- async function generateHTML({ appId, appBuildDir, externalResources = [], mode, devTool, isBuildApp, buildTypeList, }) {
28
+ async function generateHTML({ appId, appBuildDir, externalResources = [], mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }) {
29
29
  const templatePath = path_1.default.join(config_1.appTemplateDir, 'html', 'index.html.ejs');
30
30
  const dstFilePath = path_1.default.join(appBuildDir, 'index.html');
31
31
  const packageTpl = await fs_extra_1.default.readFile(templatePath, { encoding: 'utf8' });
@@ -53,6 +53,7 @@ async function generateHTML({ appId, appBuildDir, externalResources = [], mode,
53
53
  mode,
54
54
  isBuildApp,
55
55
  isAdminPortal: (0, common_2.buildAsAdminPortalByBuildType)(buildTypeList),
56
+ cdnEndpoints: (0, config_1.generateCdnEndpoints)(cdnEndpoints),
56
57
  }));
57
58
  }
58
59
  exports.generateHTML = generateHTML;
@@ -1,13 +1,13 @@
1
- import { IMaterialItem, II18nConfig, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { II18nConfig, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { BuildType, WebpackModeType } from '../types/common';
3
3
  import { DEPLOY_MODE, RUNTIME } from '../../types';
4
4
  import { IPlatformApp } from '@cloudbase/cals';
5
- export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployMode, ignoreInstall, domain, }: {
6
- appKey: string;
7
- buildDir: string;
5
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
6
+ import { IBuildContext } from '../mp/BuildContext';
7
+ export declare function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployMode, ignoreInstall, cdnEndpoints, }: {
8
+ buildContext: Omit<IBuildContext, 'mainAppData'>;
8
9
  cals: IPlatformApp;
9
10
  subAppCalsList: IPlatformApp[];
10
- dependencies: IMaterialItem[];
11
11
  i18nConfig?: II18nConfig;
12
12
  buildTypeList: BuildType[];
13
13
  extraData: IExtraData;
@@ -16,5 +16,5 @@ export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig,
16
16
  runtime?: RUNTIME;
17
17
  deployMode?: DEPLOY_MODE;
18
18
  ignoreInstall?: boolean;
19
- domain: string;
19
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
20
20
  }): Promise<string>;
@@ -19,31 +19,31 @@ const types_1 = require("../../types");
19
19
  const mp_1 = require("../mp");
20
20
  const common_2 = require("../../utils/common");
21
21
  const config_1 = require("../config");
22
- async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployMode = types_1.DEPLOY_MODE.PREVIEW, ignoreInstall = false, domain = '', }) {
23
- var _a, _b;
22
+ const fs_extra_1 = __importDefault(require("fs-extra"));
23
+ async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployMode = types_1.DEPLOY_MODE.PREVIEW, ignoreInstall = false, cdnEndpoints, }) {
24
+ var _a, _b, _c;
25
+ const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode } = buildContext;
24
26
  try {
25
27
  const { materialsDir } = runtime === types_1.RUNTIME.CI ? (0, util_1.getCompileDirs)(appKey) : (0, util_1.getCompileDirs)('app');
26
28
  const h5BuildDir = path_1.default.join(buildDir, 'h5');
29
+ if (buildTypeList.includes(common_1.BuildType.APP) ||
30
+ buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
31
+ buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
32
+ if (!cals.extra) {
33
+ cals.extra = {};
34
+ }
35
+ cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
36
+ }
27
37
  const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
28
38
  const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
29
- const buildContext = {
30
- projDir: buildDir,
31
- appId: appKey,
32
- isProduction: mode === common_1.WebpackModeType.PRODUCTION,
33
- materialLibs: dependencies,
34
- isMixMode: false,
35
- mainAppData: mainAppSerializeData,
36
- domain,
37
- };
38
39
  const { allAppUsedComps } = (0, mp_1.handleUsedComponents)({
39
- buildContext,
40
+ buildContext: { ...buildContext, mainAppData: mainAppSerializeData },
40
41
  weapps: [mainAppSerializeData, ...subAppSerializeDataList],
41
- materials: dependencies,
42
42
  });
43
43
  // 处理应用数据
44
44
  const mainAppData = (0, weapps_core_1.deserialize)(mainAppSerializeData);
45
45
  if (!mainAppData.extra) {
46
- mainAppData.extra = { domain: domain };
46
+ mainAppData.extra = { domain };
47
47
  }
48
48
  if (!((_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.domain)) {
49
49
  mainAppData.extra.domain = domain;
@@ -88,6 +88,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
88
88
  runtime,
89
89
  deployMode,
90
90
  _indexPage,
91
+ isPrivateMode,
91
92
  });
92
93
  console.timeEnd(runGenerateTag);
93
94
  // // 构建 NPM 包
@@ -117,6 +118,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
117
118
  devTool,
118
119
  publicPath,
119
120
  domain,
121
+ cdnEndpoints,
120
122
  });
121
123
  await new Promise((resolve, reject) => {
122
124
  // 开始编译前清理一下 lowcode 内容
@@ -134,6 +136,10 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
134
136
  }
135
137
  });
136
138
  });
139
+ // 普通 web 模式,且非hash模式,根据页面生成多份入口
140
+ if (!((_c = cals.extra) === null || _c === void 0 ? void 0 : _c.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
141
+ await Promise.all((cals.items || []).map((page) => fs_extra_1.default.copy(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'index.html'), path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, page.id, 'index.html'))));
142
+ }
137
143
  return h5BuildDir;
138
144
  }
139
145
  catch (e) {
@@ -1,6 +1,7 @@
1
1
  import { IWebRuntimeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { BuildAppProps } from '../core/index';
3
3
  import { IPlatformApp } from '@cloudbase/cals';
4
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
4
5
  interface IWebpackCoreProps extends BuildAppProps {
5
6
  cals: IPlatformApp;
6
7
  appBuildDir: string;
@@ -8,6 +9,7 @@ interface IWebpackCoreProps extends BuildAppProps {
8
9
  mainAppData: IWebRuntimeAppData;
9
10
  subAppDataList: IWebRuntimeAppData[];
10
11
  assets: string[];
12
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
11
13
  }
12
- export declare function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, mpConfig, assets, devTool, generateMpType, }: IWebpackCoreProps): Promise<string>;
14
+ export declare function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, mpConfig, assets, devTool, generateMpType, cdnEndpoints, }: IWebpackCoreProps): Promise<string>;
13
15
  export {};
@@ -5,7 +5,7 @@ const common_1 = require("../types/common");
5
5
  const webpack_1 = require("../service/webpack");
6
6
  const generate_1 = require("./generate");
7
7
  const cals_1 = require("@cloudbase/cals");
8
- async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], mpConfig, assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, }) {
8
+ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], mpConfig, assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, }) {
9
9
  console.time('runWebpackCore');
10
10
  console.time('webpackGenerate');
11
11
  const allAppDataList = subAppDataList.concat(mainAppData);
@@ -37,6 +37,7 @@ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir,
37
37
  devTool,
38
38
  isBuildApp: buildTypeList.includes(common_1.BuildType.APP),
39
39
  buildTypeList,
40
+ cdnEndpoints,
40
41
  });
41
42
  if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
42
43
  if (mode !== common_1.WebpackModeType.PRODUCTION) {
@@ -3,6 +3,9 @@ import { IMaterialItem, IWeAppData, IMiniprogramPlugin } from '@cloudbase/lowcod
3
3
  * All build parameters and intermediate data to be share across processes
4
4
  */
5
5
  export interface IBuildContext {
6
+ /**
7
+ * 应用id
8
+ */
6
9
  appId: string;
7
10
  domain: string;
8
11
  projDir: string;
@@ -14,4 +17,12 @@ export interface IBuildContext {
14
17
  miniprogramPlugins?: IMiniprogramPlugin[];
15
18
  debugMode?: boolean;
16
19
  isBrowserMpBuilder?: boolean;
20
+ /**
21
+ * 是否是私有化的环境
22
+ */
23
+ isPrivateMode?: boolean;
24
+ /**
25
+ * 云开发sdk请求,js-sdk or wx.cloud
26
+ */
27
+ endpointType?: 'tcb-api' | 'wechat-service';
17
28
  }
@@ -1,21 +1,15 @@
1
- import { IMaterialItem, IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
1
+ import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
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, isBrowserMpBuilder, ignoreInstall, }: {
5
+ export declare function generateWxMp({ buildContext, weapps, plugins, deployMode, options, buildTypeList, isBrowserMpBuilder, ignoreInstall, }: {
6
+ buildContext: IBuildContext;
6
7
  weapps: IWeAppData[];
7
- projDir: string;
8
- appId: string;
9
- domain: string;
10
- materials: IMaterialItem[];
11
8
  plugins: IPlugin[];
12
- isProduction: boolean;
13
9
  deployMode: DEPLOY_MODE;
14
- extraData: any;
15
- isMixMode: boolean;
16
10
  options: {
11
+ mpAppId: string;
17
12
  resourceAppId?: string;
18
- mpAppId?: string;
19
13
  isCrossAccount: boolean;
20
14
  };
21
15
  buildTypeList: BuildType[];
@@ -29,10 +23,9 @@ export declare function writeLowCodeFiles(appData: IWeAppData, outDir: string, c
29
23
  * TODO: 与 cals 里的实现进行整合
30
24
  * 关键点在于 appUsedComps 分组, 与 generic componen 的实现
31
25
  */
32
- export declare function handleUsedComponents({ buildContext, weapps, materials, }: {
26
+ export declare function handleUsedComponents({ buildContext, weapps }: {
33
27
  buildContext: IBuildContext;
34
28
  weapps: IWeAppData[];
35
- materials: IMaterialItem[];
36
29
  }): {
37
30
  appUsedComps: IAppUsedComp[];
38
31
  allAppUsedComps: IUsedComps;