@cloudbase/lowcode-builder 1.1.4 → 1.1.5-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,6 +2,7 @@ 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
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
5
6
  export interface IBaseAppProps {
6
7
  appKey: string;
7
8
  dependencies?: IMaterialItem[];
@@ -35,11 +36,39 @@ export interface IBuildWedaApp extends IBaseAppProps {
35
36
  path?: string;
36
37
  };
37
38
  isBrowserMpBuilder?: boolean;
39
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
38
40
  }
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>;
41
+ export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
40
42
  export declare function cleanComponentDir(): Promise<void>;
41
43
  export declare const version: any;
42
44
  export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
43
45
  export { downloadZip } from '../util/net';
44
46
  export { getCompileDirs } from '../util';
45
47
  export default buildWedaApp;
48
+ interface INormalizeInput {
49
+ appId?: string;
50
+ appKey?: string;
51
+ dependencies?: IBuildWedaApp['dependencies'];
52
+ buildTypeList: IBuildWedaApp['buildTypeList'];
53
+ mainAppSerializeData?: IBuildWedaApp['cals'];
54
+ cals?: IBuildWedaApp['cals'];
55
+ subAppSerializeDataList?: IBuildWedaApp['subAppCalsList'];
56
+ subAppCalsList?: IBuildWedaApp['subAppCalsList'];
57
+ deployOptions: IBuildWedaApp['deployOptions'];
58
+ mpAppId?: string;
59
+ extraData?: {
60
+ isComposite: boolean;
61
+ compProps: {};
62
+ };
63
+ [key: string]: any;
64
+ }
65
+ interface InormalizeOutput extends INormalizeInput {
66
+ dependencies: Required<INormalizeInput['dependencies']>;
67
+ }
68
+ export declare function normalizeInputs(inputs: INormalizeInput, { envId, getWebRootPath, }: {
69
+ envId: string;
70
+ getWebRootPath?: ({ appId, deployOptions }: {
71
+ appId: any;
72
+ deployOptions: any;
73
+ }) => string;
74
+ }): 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, }, cb) {
24
24
  var _a, _b;
25
25
  if (!cals) {
26
26
  console.error('无效的应用配置');
@@ -48,15 +48,15 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
48
48
  weapps: apps,
49
49
  projDir: appBuildDir,
50
50
  appId: appKey,
51
- domain: domain,
51
+ domain,
52
52
  materials: dependencies,
53
53
  plugins,
54
54
  isProduction: mode === common_1.WebpackModeType.PRODUCTION,
55
55
  deployMode,
56
- extraData,
57
56
  isMixMode,
58
57
  options: {
59
58
  isCrossAccount: resourceAppId !== deployOptions.targetMpAppId,
59
+ mpAppId: deployOptions.mpAppId || '',
60
60
  resourceAppId,
61
61
  },
62
62
  buildTypeList,
@@ -86,11 +86,11 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
86
86
  // 模板需要占位保证 mp 文件夹存在
87
87
  fs_extra_1.default.removeSync(path_1.default.resolve(outDir, 'miniprogram_npm'));
88
88
  }
89
- cb === null || cb === void 0 ? void 0 : cb(null, {
89
+ await (cb === null || cb === void 0 ? void 0 : cb(null, {
90
90
  ...result,
91
91
  outDir,
92
92
  timeElapsed: Date.now() - startTime,
93
- });
93
+ }));
94
94
  return outDir;
95
95
  }
96
96
  else {
@@ -108,17 +108,36 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
108
108
  deployMode,
109
109
  ignoreInstall,
110
110
  domain,
111
+ cdnEndpoints,
111
112
  });
112
- cb === null || cb === void 0 ? void 0 : cb(null, {
113
+ await (cb === null || cb === void 0 ? void 0 : cb(null, {
113
114
  outDir: h5BuildDir,
114
115
  timeElapsed: Date.now() - startTime,
115
- });
116
+ }));
116
117
  return h5BuildDir;
117
118
  }
118
119
  }
119
- catch (e) {
120
- cb === null || cb === void 0 ? void 0 : cb(e);
121
- throw e;
120
+ catch (err) {
121
+ if (err.length) {
122
+ let messageList = (err[0] || '').split('\n');
123
+ let lineIndex = 0;
124
+ let reg = /node_modules\/@babel/;
125
+ messageList.find((str, index) => {
126
+ if (reg.test(str)) {
127
+ lineIndex = index;
128
+ return true;
129
+ }
130
+ else {
131
+ return false;
132
+ }
133
+ });
134
+ if (lineIndex) {
135
+ messageList = messageList.slice(0, lineIndex);
136
+ }
137
+ err = new Error(messageList.join('\n'));
138
+ }
139
+ cb === null || cb === void 0 ? void 0 : cb(err);
140
+ throw err;
122
141
  }
123
142
  }
124
143
  exports.buildWedaApp = buildWedaApp;
@@ -136,3 +155,98 @@ Object.defineProperty(exports, "downloadZip", { enumerable: true, get: function
136
155
  var util_2 = require("../util");
137
156
  Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
138
157
  exports.default = buildWedaApp;
158
+ function normalizeInputs(inputs, { envId, getWebRootPath, }) {
159
+ const { extraData = { isComposite: false, compProps: {} } } = inputs;
160
+ /**
161
+ * 过滤处理 dependencies
162
+ */
163
+ let map = {};
164
+ inputs.dependencies = (inputs.dependencies || []).reduce((list, item) => {
165
+ if (!map[`${item.name}@${item.version}`]) {
166
+ map[`${item.name}@${item.version}`] = true;
167
+ list.push(item);
168
+ }
169
+ return list;
170
+ }, []);
171
+ const normalizeCalsOptions = {
172
+ buildTypeList: inputs.buildTypeList,
173
+ envId,
174
+ deployOptions: inputs.deployOptions,
175
+ appId: inputs.appId || inputs.appKey,
176
+ getWebRootPath: getWebRootPath || _getWebRootPath,
177
+ };
178
+ if (inputs.mainAppSerializeData) {
179
+ inputs.mainAppSerializeData = normalizeCals(inputs.mainAppSerializeData, normalizeCalsOptions);
180
+ if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
181
+ inputs.subAppSerializeDataList = [];
182
+ }
183
+ }
184
+ if (inputs.cals) {
185
+ inputs.cals = normalizeCals(inputs.cals, normalizeCalsOptions);
186
+ if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
187
+ inputs.subAppCalsList = [];
188
+ }
189
+ }
190
+ if (!(0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
191
+ // 小程序构建
192
+ const { mpAppId, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW } } = inputs;
193
+ inputs.deployOptions = {
194
+ ...deployOptions,
195
+ mpAppId: deployOptions.mpAppId || mpAppId,
196
+ };
197
+ if (inputs.deployOptions.targetMpAppId === undefined) {
198
+ inputs.deployOptions.targetMpAppId = inputs.deployOptions.mpAppId;
199
+ }
200
+ }
201
+ if (extraData.isComposite) {
202
+ Object.keys(extraData.compProps.events).forEach((eName) => {
203
+ extraData.compProps.events[eName] = `$$EVENT_${eName}$$`;
204
+ });
205
+ }
206
+ return inputs;
207
+ }
208
+ exports.normalizeInputs = normalizeInputs;
209
+ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWebRootPath }) {
210
+ var _a, _b;
211
+ if (!cals.extra) {
212
+ cals.extra = {};
213
+ }
214
+ if (!cals.mpPkgUrl) {
215
+ if (buildTypeList.includes(common_1.BuildType.APP) ||
216
+ buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
217
+ buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
218
+ cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
219
+ }
220
+ }
221
+ if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.envId)) {
222
+ cals.extra.envId = envId;
223
+ }
224
+ if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
225
+ // web 构建不处理小程序插件
226
+ if (cals.extra.miniprogramPlugins) {
227
+ cals.extra.miniprogramPlugins = [];
228
+ }
229
+ let { appConfig = {} } = cals.extra;
230
+ let { window = {} } = appConfig;
231
+ let path = getWebRootPath({ appId, deployOptions });
232
+ cals.extra.appConfig = {
233
+ ...appConfig,
234
+ window: {
235
+ ...window,
236
+ // Todo: 处理自定义域名逻辑
237
+ publicPath: (0, common_1.buildAsXPageByBuildType)(buildTypeList)
238
+ ? (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.publicPath) || `https://${(_b = cals.extra) === null || _b === void 0 ? void 0 : _b.domain}${path}`
239
+ : path,
240
+ basename: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList)
241
+ ? `app/${appId}${(deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) !== types_1.DEPLOY_MODE.UPLOAD ? '-preview' : ''}`
242
+ : (0, common_1.buildAsXPageByBuildType)(buildTypeList)
243
+ ? '/'
244
+ : path,
245
+ },
246
+ };
247
+ }
248
+ return cals;
249
+ }
250
+ function _getWebRootPath({ appId, deployOptions }) {
251
+ return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.PREVIEW ? `/${appId}/preview/` : `/${appId}/production/`;
252
+ }
@@ -1,10 +1,11 @@
1
1
  import { BuildAppProps } from '@cloudbase/lowcode-generator';
2
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
2
3
  import { BuildType } from '../types/common';
3
4
  /**
4
5
  * 该函数从 @govcloud/generate 取到需要的模版文件
5
6
  */
6
7
  export declare function generateProjectFiles(buildData: BuildAppProps): Promise<void>;
7
- export declare function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuildApp, buildTypeList, }: {
8
+ export declare function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
8
9
  appId: string;
9
10
  jsApis: string[];
10
11
  appBuildDir: string;
@@ -12,6 +13,7 @@ export declare function generateHTML({ appId, appBuildDir, jsApis, mode, devTool
12
13
  devTool: string;
13
14
  isBuildApp: boolean;
14
15
  buildTypeList: BuildType[];
16
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
15
17
  }): Promise<void>;
16
18
  export declare function handleAssets({ appBuildDir, buildTypeList, assets, }: {
17
19
  appBuildDir: string;
@@ -24,7 +24,7 @@ async function generateProjectFiles(buildData) {
24
24
  }));
25
25
  }
26
26
  exports.generateProjectFiles = generateProjectFiles;
27
- async function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuildApp, buildTypeList, }) {
27
+ async function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }) {
28
28
  const templatePath = path_1.default.join(config_1.appTemplateDir, 'html', 'index.html.ejs');
29
29
  const dstFilePath = path_1.default.join(appBuildDir, 'index.html');
30
30
  const packageTpl = await fs_extra_1.default.readFile(templatePath, { encoding: 'utf8' });
@@ -37,6 +37,7 @@ async function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuild
37
37
  mode,
38
38
  isBuildApp,
39
39
  isAdminPortal: (0, common_2.buildAsAdminPortalByBuildType)(buildTypeList),
40
+ cdnEndpoints: (0, config_1.generateCdnEndpoints)(cdnEndpoints),
40
41
  }));
41
42
  }
42
43
  exports.generateHTML = generateHTML;
@@ -2,7 +2,8 @@ import { IMaterialItem, II18nConfig, IExtraData } from '@cloudbase/lowcode-gener
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, }: {
5
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
6
+ export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployMode, ignoreInstall, domain, cdnEndpoints, }: {
6
7
  appKey: string;
7
8
  buildDir: string;
8
9
  cals: IPlatformApp;
@@ -17,4 +18,5 @@ export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig,
17
18
  deployMode?: DEPLOY_MODE;
18
19
  ignoreInstall?: boolean;
19
20
  domain: string;
21
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
20
22
  }): Promise<string>;
@@ -19,11 +19,20 @@ 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({ 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 = '', cdnEndpoints, }) {
24
+ var _a, _b, _c;
24
25
  try {
25
26
  const { materialsDir } = runtime === types_1.RUNTIME.CI ? (0, util_1.getCompileDirs)(appKey) : (0, util_1.getCompileDirs)('app');
26
27
  const h5BuildDir = path_1.default.join(buildDir, 'h5');
28
+ if (buildTypeList.includes(common_1.BuildType.APP) ||
29
+ buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
30
+ buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
31
+ if (!cals.extra) {
32
+ cals.extra = {};
33
+ }
34
+ cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
35
+ }
27
36
  const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
28
37
  const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
29
38
  const buildContext = {
@@ -43,7 +52,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
43
52
  // 处理应用数据
44
53
  const mainAppData = (0, weapps_core_1.deserialize)(mainAppSerializeData);
45
54
  if (!mainAppData.extra) {
46
- mainAppData.extra = { domain: domain };
55
+ mainAppData.extra = { domain };
47
56
  }
48
57
  if (!((_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.domain)) {
49
58
  mainAppData.extra.domain = domain;
@@ -116,6 +125,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
116
125
  devTool,
117
126
  publicPath,
118
127
  domain,
128
+ cdnEndpoints,
119
129
  });
120
130
  await new Promise((resolve, reject) => {
121
131
  // 开始编译前清理一下 lowcode 内容
@@ -133,6 +143,10 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
133
143
  }
134
144
  });
135
145
  });
146
+ // 普通 web 模式,且非hash模式,根据页面生成多份入口
147
+ if (!((_c = cals.extra) === null || _c === void 0 ? void 0 : _c.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
148
+ 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'))));
149
+ }
136
150
  return h5BuildDir;
137
151
  }
138
152
  catch (e) {
@@ -1,11 +1,13 @@
1
1
  import { IWebRuntimeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core';
2
2
  import { BuildAppProps } from '../core/index';
3
+ import { ICDN_ENDPOINTS_COFIG } from '../config';
3
4
  interface IWebpackCoreProps extends BuildAppProps {
4
5
  appBuildDir: string;
5
6
  mpConfig: any;
6
7
  mainAppData: IWebRuntimeAppData;
7
8
  subAppDataList: IWebRuntimeAppData[];
8
9
  assets: string[];
10
+ cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
9
11
  }
10
- export declare function runWebpackCore({ mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, mpConfig, assets, devTool, generateMpType, }: IWebpackCoreProps): Promise<string>;
12
+ export declare function runWebpackCore({ mainAppData, subAppDataList, appBuildDir, publicPath, mode, appKey, buildTypeList, mpConfig, assets, devTool, generateMpType, cdnEndpoints, }: IWebpackCoreProps): Promise<string>;
11
13
  export {};
@@ -4,7 +4,7 @@ exports.runWebpackCore = void 0;
4
4
  const common_1 = require("../types/common");
5
5
  const webpack_1 = require("../service/webpack");
6
6
  const generate_1 = require("./generate");
7
- async function runWebpackCore({ mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], mpConfig, assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, }) {
7
+ async function runWebpackCore({ 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, }) {
8
8
  console.time('runWebpackCore');
9
9
  console.time('webpackGenerate');
10
10
  const allAppDataList = subAppDataList.concat(mainAppData);
@@ -33,6 +33,7 @@ async function runWebpackCore({ mainAppData, subAppDataList, appBuildDir, public
33
33
  devTool,
34
34
  isBuildApp: buildTypeList.includes(common_1.BuildType.APP),
35
35
  buildTypeList,
36
+ cdnEndpoints,
36
37
  });
37
38
  if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
38
39
  if (mode !== common_1.WebpackModeType.PRODUCTION) {
@@ -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, isBrowserMpBuilder, }: {
5
+ export declare function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, isMixMode, options, buildTypeList, isBrowserMpBuilder, }: {
6
6
  weapps: IWeAppData[];
7
7
  projDir: string;
8
8
  appId: string;
@@ -11,9 +11,9 @@ export declare function generateWxMp({ weapps, projDir, appId, domain, materials
11
11
  plugins: IPlugin[];
12
12
  isProduction: boolean;
13
13
  deployMode: DEPLOY_MODE;
14
- extraData: any;
15
14
  isMixMode: boolean;
16
15
  options: {
16
+ mpAppId: string;
17
17
  resourceAppId?: string;
18
18
  isCrossAccount: boolean;
19
19
  };
@@ -54,7 +54,7 @@ const cals_1 = require("@cloudbase/cals");
54
54
  const templateDir = `${config_1.appTemplateDir}/mp/`;
55
55
  const em = chalk_1.default.blue.bold;
56
56
  const error = chalk_1.default.redBright;
57
- async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
57
+ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, }) {
58
58
  var _a;
59
59
  const operationLabel = em('Wexin MiniProgram Generated');
60
60
  console.time(operationLabel);
@@ -72,7 +72,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
72
72
  domain,
73
73
  isBrowserMpBuilder,
74
74
  };
75
- const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
76
75
  const { allAppUsedComps } = handleUsedComponents({
77
76
  buildContext,
78
77
  weapps,
@@ -82,7 +81,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
82
81
  // 安装依赖库,生成 materials 目录
83
82
  await (0, materials_1.installMaterials)(projDir, allAppUsedComps, weapps, buildContext);
84
83
  const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
85
- const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext);
84
+ const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext, { mpAppId: options.mpAppId });
86
85
  // #1 generate project files
87
86
  if (!mainAppData.mpPkgUrl) {
88
87
  const projectFileData = {
@@ -135,7 +134,8 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
135
134
  };
136
135
  }
137
136
  if (mainAppData.mpPkgUrl) {
138
- // 合并 project 和 app json
137
+ // 合并 project 和 app json,复写 appId
138
+ projectConfigJson.appId = projConfig.appId;
139
139
  if (!projectConfigJson.setting) {
140
140
  projectConfigJson.setting = {};
141
141
  }
@@ -6,7 +6,9 @@ import { IBuildContext } from './BuildContext';
6
6
  * @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
7
7
  * @param appConfigs app config from prop edit panel
8
8
  */
9
- export declare function generateMpConfig(weapps: IWeAppData[], ctx: IBuildContext): {
9
+ export declare function generateMpConfig(weapps: IWeAppData[], ctx: IBuildContext, options: {
10
+ mpAppId?: string;
11
+ }): {
10
12
  appConfig: any;
11
13
  projConfig: any;
12
14
  pageConfigs: {}[];
@@ -40,7 +40,7 @@ const chalk_1 = __importDefault(require("chalk"));
40
40
  * @param kboneConfig https://wechat-miniprogram.github.io/kbone/docs/config/
41
41
  * @param appConfigs app config from prop edit panel
42
42
  */
43
- function generateMpConfig(weapps, ctx) {
43
+ function generateMpConfig(weapps, ctx, options) {
44
44
  var _a;
45
45
  const appConfig = {
46
46
  useExtendedLib: { weui: true },
@@ -116,6 +116,9 @@ function generateMpConfig(weapps, ctx) {
116
116
  });
117
117
  }
118
118
  });
119
+ if (options.mpAppId) {
120
+ projConfig.appId = options.mpAppId;
121
+ }
119
122
  // merge(pageConfigs, extractAllPagesConfig())
120
123
  return { appConfig, projConfig, pageConfigs };
121
124
  }
@@ -67,7 +67,7 @@ function generateDataBindMeta(bind) {
67
67
  imports += (0, lowcode_generator_1.generateExpressionAlias)(value);
68
68
  }
69
69
  catch (e) {
70
- console.error('parse expression error', value, e);
70
+ console.error('parse expression error', value);
71
71
  }
72
72
  expr = value;
73
73
  }
@@ -2,6 +2,7 @@ import { IMaterialItem, IWebRuntimeAppData } from '@cloudbase/lowcode-generator/
2
2
  import { BuildType, WebpackModeType } from '../types/common';
3
3
  import { RUNTIME } from '../../types';
4
4
  export declare const PERSISTENT_DEPENDIENCES_MAP: {};
5
+ export declare const OUTPUT_DIR = "preview";
5
6
  export interface IMpConfig {
6
7
  origin: string;
7
8
  entry: string;
@@ -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.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 = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
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 = exports.OUTPUT_DIR = exports.PERSISTENT_DEPENDIENCES_MAP = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const lodash_1 = require("lodash");
@@ -18,6 +18,7 @@ const common_2 = require("../util/common");
18
18
  const types_1 = require("../../types");
19
19
  const generateFiles_1 = require("../util/generateFiles");
20
20
  exports.PERSISTENT_DEPENDIENCES_MAP = {};
21
+ exports.OUTPUT_DIR = 'preview';
21
22
  async function fixAppJson(appBuildDir) {
22
23
  const appJsonPath = path_1.default.resolve(appBuildDir, 'dist/mp/app.json');
23
24
  if (!fs_extra_1.default.existsSync(appJsonPath)) {
@@ -273,7 +274,7 @@ function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = c
273
274
  watch: false,
274
275
  entry: path_1.default.resolve(appBuildDir, 'src/index.jsx'),
275
276
  output: {
276
- path: path_1.default.resolve(appBuildDir, './preview'),
277
+ path: path_1.default.resolve(appBuildDir, exports.OUTPUT_DIR),
277
278
  filename: '[name].[contenthash].bundle.js',
278
279
  chunkFilename: '[name].[contenthash].chunk.js',
279
280
  publicPath: buildTypeList.includes(common_1.BuildType.APP) || buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL) ? '' : publicPath,
@@ -294,8 +295,6 @@ function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = c
294
295
  resolveModules: [path_1.default.resolve(appBuildDir), 'node_modules'],
295
296
  definePlugin: {
296
297
  'process.env.buildType': `"${buildTypeList[0]}"`,
297
- 'process.env.isApp': buildTypeList.includes(common_1.BuildType.APP),
298
- 'process.env.isAdminPortal': (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
299
298
  ...extraDefine,
300
299
  },
301
300
  devtool: ['app-nvzcvt10', 'app-msa2ihs9'].includes(appId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/lowcode-builder",
3
- "version": "1.1.4",
3
+ "version": "1.1.5-alpha.1",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@cloudbase/cals": "^0.4.10",
42
- "@cloudbase/lowcode-generator": "^1.1.1",
42
+ "@cloudbase/lowcode-generator": "^1.1.2-alpha.0",
43
43
  "axios": "^0.21.0",
44
44
  "browserfs": "^1.4.3",
45
45
  "browserify-zlib": "^0.2.0",
@@ -12,9 +12,12 @@
12
12
  <meta name="description" content="<%= desc %>" />
13
13
  <link
14
14
  rel="stylesheet"
15
- href="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.ba91c21b0d605c84ac7f.css"
15
+ href="<%=
16
+ cdnEndpoints.cdngo
17
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.ba91c21b0d605c84ac7f.css"
16
18
  />
17
- <script crossorigin="anonymous" src="https://cdn-go.cn/aegis/aegis-sdk/latest/aegis.min.js?v=1"></script>
19
+ <% if(cdnEndpoints.aegis){ %>
20
+ <script crossorigin="anonymous" src="<%= cdnEndpoints.aegis %>/aegis/aegis-sdk/latest/aegis.min.js?v=1"></script>
18
21
  <script>
19
22
  <% if(!isAdminPortal){ %>
20
23
  const _aegis = new Aegis({
@@ -36,6 +39,7 @@
36
39
  window._aegis = _aegis;
37
40
  window._aegis_inited = Date.now()
38
41
  </script>
42
+ <% }%>
39
43
  <title><%= title %></title>
40
44
  <% if(mode !== 'production'){ %>
41
45
  <!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
@@ -387,10 +391,10 @@
387
391
  <script type="module" src="/src/index.jsx"></script>
388
392
  <% } %> <% if(!isAdminPortal){ %>
389
393
  <script src="/weda-config/weda-private.js"></script>
390
- <script src="//static.cloudbase.net/cloudbase-js-sdk/2.4.7-beta.0/cloudbase.full.js?v=1"></script>
394
+ <script src="<%= cdnEndpoints.cloudbase %>/cloudbase-js-sdk/2.4.7-beta.0/cloudbase.full.js?v=1"></script>
391
395
  <% }%>
392
396
  <script>
393
- if (window.cloudbase) {
397
+ if (window.cloudbase && window._aegis) {
394
398
  const _callFunction = window.cloudbase.__proto__.callFunction;
395
399
  window.cloudbase.__proto__.callFunction = function (args) {
396
400
  let promise = _callFunction.call(window.cloudbase, ...arguments);
@@ -431,19 +435,23 @@
431
435
  </script>
432
436
  <script
433
437
  crossorigin
434
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/react@16.14.0/umd/react.production.min.js"
438
+ src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/release/_npm/react@16.14.0/umd/react.production.min.js"
435
439
  ></script>
436
440
  <script
437
441
  crossorigin
438
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/react-dom@16.14.0/umd/react-dom.production.min.js"
442
+ src="<%=
443
+ cdnEndpoints.cdngo
444
+ %>/lcap/lcap-resource-cdngo/-/release/_npm/react-dom@16.14.0/umd/react-dom.production.min.js"
439
445
  ></script>
440
446
  <script
441
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js"
447
+ src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js"
442
448
  crossorigin="anonymous"
443
449
  ></script>
444
450
  <script
445
451
  crossorigin="anonymous"
446
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.19/dist/h5.browser.js"
452
+ src="<%=
453
+ cdnEndpoints.cdngo
454
+ %>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.19/dist/h5.browser.js"
447
455
  ></script>
448
456
  <script>
449
457
  // zxing polifill
@@ -453,15 +461,19 @@
453
461
  </script>
454
462
  <script
455
463
  crossorigin="anonymous"
456
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"
464
+ src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"
457
465
  ></script>
458
466
  <script
459
467
  crossorigin
460
- src="https://qbase.cdn-go.cn//lcap/lcap-resource-cdngo/-/release/_url/qcloud/lowcode/static/ide/assets/js/babel.min.js"
468
+ src="<%=
469
+ cdnEndpoints.cdngo
470
+ %>/lcap/lcap-resource-cdngo/-/release/_url/qcloud/lowcode/static/ide/assets/js/babel.min.js"
461
471
  ></script>
462
472
  <script
463
473
  crossorigin
464
- src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.90a1845eb61a012b3d66.bundle.js"
474
+ src="<%=
475
+ cdnEndpoints.cdngo
476
+ %>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.90a1845eb61a012b3d66.bundle.js"
465
477
  ></script>
466
478
  </body>
467
479
  </html>
@@ -7,7 +7,7 @@
7
7
  "dependencies": {
8
8
  "@cloudbase/js-sdk": "2.4.0-beta.0",
9
9
  "@tcwd/weapps-core": "2.2.6",
10
- "@tcwd/weapps-sdk": "1.2.10",
10
+ "@tcwd/weapps-sdk": "1.2.12",
11
11
  "@zxing/library": "^0.18.6",
12
12
  "@cloudbase/weda-client": "^0.2.4",
13
13
  "lodash": "^4.17.19",