@cloudbase/lowcode-builder 1.3.12-alpha.1 → 1.3.12-alpha.4
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.
- package/lib/builder/config/index.d.ts +2 -2
- package/lib/builder/config/index.js +3 -3
- package/lib/builder/core/index.d.ts +8 -0
- package/lib/builder/core/index.js +96 -25
- package/lib/builder/h5/generate.d.ts +2 -1
- package/lib/builder/h5/generate.js +14 -3
- package/lib/builder/h5/index.d.ts +4 -3
- package/lib/builder/h5/index.js +54 -3
- package/lib/builder/h5/webpack.js +1 -0
- package/lib/builder/mp/BuildContext.d.ts +9 -0
- package/lib/builder/mp/index.d.ts +8 -3
- package/lib/builder/mp/index.js +42 -32
- package/lib/builder/mp/materials.js +12 -10
- package/lib/builder/mp/util.js +29 -5
- package/lib/builder/mp/wxml.js +32 -4
- package/lib/builder/util/common.d.ts +1 -1
- package/lib/builder/util/common.js +0 -4
- package/lib/builder/util/generateFiles.d.ts +1 -2
- package/lib/builder/util/generateFiles.js +1 -13
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -2
- package/package.json +3 -3
- package/template/html/index.html.ejs +72 -4
- package/template/mp/app/weapps-api.js +8 -5
- package/template/mp/app.js +27 -4
- package/template/mp/app.wxss +2 -1
- package/template/mp/common/config.js +9 -0
- package/template/mp/common/config.wxs +3 -0
- package/template/mp/common/util.js +16 -9
- package/template/mp/common/utils.wxs +3 -1
- package/template/mp/common/weapp-page.js +57 -18
- package/template/mp/common/widget.js +42 -13
- package/template/mp/component/index.js +1 -0
- package/template/mp/datasources/config.js.tpl +4 -3
- package/template/mp/package.json +1 -1
- package/template/mp/page/api.js +5 -2
- package/template/mp/page/index.js +2 -1
- package/dist/builder.web.js +0 -71
- package/lib/.turbo/turbo-build.log +0 -0
- package/lib/.turbo/turbo-develop.log +0 -0
- package/lib/builder.web.js +0 -71
- package/lib/test.d.ts +0 -11
- package/lib/test.js +0 -717
- package/template/assets.zip +0 -0
|
@@ -6,12 +6,12 @@ export declare const materialsDirName = "materials";
|
|
|
6
6
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
7
7
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
8
8
|
*/
|
|
9
|
-
export declare const builderTemplateURL = "
|
|
9
|
+
export declare const builderTemplateURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template_20230213.zip";
|
|
10
10
|
/**
|
|
11
11
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
12
12
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
13
13
|
*/
|
|
14
|
-
export declare const miniprogramURL = "
|
|
14
|
+
export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm_20230213.zip";
|
|
15
15
|
/**
|
|
16
16
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
17
17
|
*/
|
|
@@ -45,12 +45,12 @@ exports.materialsDirName = 'materials'; // materials diretory of current project
|
|
|
45
45
|
* src/template的代码,在IDE编辑器插件中构建builder
|
|
46
46
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
47
47
|
*/
|
|
48
|
-
exports.builderTemplateURL = '
|
|
48
|
+
exports.builderTemplateURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/template_20230213.zip';
|
|
49
49
|
/**
|
|
50
50
|
* miniprogram的代码,IDE插件后续会提供端功能
|
|
51
51
|
* 存放在大账号:100015939275。访问地址:https://console.cloud.tencent.com/cos/bucket?bucket=comp-public-1303824488®ion=ap-shanghai&path=%252Flcap-builder%252F
|
|
52
52
|
*/
|
|
53
|
-
exports.miniprogramURL = '
|
|
53
|
+
exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqcloud.com/lcap-builder/miniprogram_npm_20230213.zip';
|
|
54
54
|
/**
|
|
55
55
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
56
56
|
*/
|
|
@@ -59,7 +59,7 @@ exports.CDN_ENDPONTS_CONFIG = {
|
|
|
59
59
|
common: '',
|
|
60
60
|
cloudbase: '//static.cloudbase.net',
|
|
61
61
|
cdngo: 'https://qbase.cdn-go.cn',
|
|
62
|
-
aegis: 'https://cdn-go.cn',
|
|
62
|
+
aegis: 'https://tam.cdn-go.cn',
|
|
63
63
|
};
|
|
64
64
|
function generateCdnEndpoints(endpoints = exports.CDN_ENDPONTS_CONFIG) {
|
|
65
65
|
for (const key in exports.CDN_ENDPONTS_CONFIG) {
|
|
@@ -28,6 +28,7 @@ export interface IBuildWedaApp extends IBaseAppProps {
|
|
|
28
28
|
mode: DEPLOY_MODE;
|
|
29
29
|
mpAppId?: string;
|
|
30
30
|
targetMpAppId?: string;
|
|
31
|
+
version?: string;
|
|
31
32
|
};
|
|
32
33
|
runtime?: RUNTIME;
|
|
33
34
|
ignoreInstall?: boolean;
|
|
@@ -40,6 +41,13 @@ export interface IBuildWedaApp extends IBaseAppProps {
|
|
|
40
41
|
isPrivateMode?: boolean;
|
|
41
42
|
endpointType?: 'tcb-api' | 'wechat-service';
|
|
42
43
|
}
|
|
44
|
+
export declare function buildWedaConfig({ output, domain, isPrivateMode, endpointType, buildTypeList, }: {
|
|
45
|
+
output: Required<IBuildWedaApp['output']>;
|
|
46
|
+
domain?: string;
|
|
47
|
+
isPrivateMode?: boolean;
|
|
48
|
+
endpointType?: IBuildWedaApp['endpointType'];
|
|
49
|
+
buildTypeList?: IBuildWedaApp['buildTypeList'];
|
|
50
|
+
}): Promise<void>;
|
|
43
51
|
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>;
|
|
44
52
|
export declare function cleanComponentDir(): Promise<void>;
|
|
45
53
|
export declare const version: any;
|
|
@@ -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.normalizeInputs = 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 = exports.buildWedaConfig = 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"));
|
|
@@ -12,11 +12,52 @@ const common_1 = require("../types/common");
|
|
|
12
12
|
const index_1 = require("../mp/index");
|
|
13
13
|
const types_1 = require("../../types");
|
|
14
14
|
const mixMode_1 = require("../mp/mixMode");
|
|
15
|
+
const index_2 = require("../h5/index");
|
|
15
16
|
const common_2 = require("../../utils/common");
|
|
16
17
|
const postProcess_1 = require("../../utils/postProcess");
|
|
17
18
|
const cals_1 = require("@cloudbase/cals");
|
|
18
19
|
const net_1 = require("../util/net");
|
|
20
|
+
const config_1 = require("../config");
|
|
19
21
|
const pkg = require('../../../package.json');
|
|
22
|
+
async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
|
|
23
|
+
if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
|
|
24
|
+
throw new Error('构建类型仅支持 MP');
|
|
25
|
+
}
|
|
26
|
+
let outDir = output === null || output === void 0 ? void 0 : output.path;
|
|
27
|
+
if (!outDir) {
|
|
28
|
+
throw new Error('无效的项目输出路径');
|
|
29
|
+
}
|
|
30
|
+
let miniprogramRoot = outDir;
|
|
31
|
+
let projectJsonPath = path_1.default.resolve(outDir, 'project.config.json');
|
|
32
|
+
if (fs_extra_1.default.existsSync(projectJsonPath)) {
|
|
33
|
+
const projectConfigJson = await fs_extra_1.default.readJson(projectJsonPath);
|
|
34
|
+
miniprogramRoot = path_1.default.join(outDir, projectConfigJson.miniprogramRoot || '/');
|
|
35
|
+
}
|
|
36
|
+
const configPath = path_1.default.resolve(miniprogramRoot, 'common/config.js');
|
|
37
|
+
let data = { domain, isPrivateMode, endpointType };
|
|
38
|
+
if (fs_extra_1.default.existsSync(configPath)) {
|
|
39
|
+
try {
|
|
40
|
+
let config = require(configPath);
|
|
41
|
+
let current = {};
|
|
42
|
+
if (config.__esModule) {
|
|
43
|
+
current = config.default || {};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
current = config || {};
|
|
47
|
+
}
|
|
48
|
+
for (const key in data) {
|
|
49
|
+
if (data[key] === undefined) {
|
|
50
|
+
data[key] = current[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error('parse current file error, overwrite current config', e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
await (0, index_1.generateConfig)(data, outDir);
|
|
59
|
+
}
|
|
60
|
+
exports.buildWedaConfig = buildWedaConfig;
|
|
20
61
|
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
62
|
isComposite: false,
|
|
22
63
|
compProps: {},
|
|
@@ -26,7 +67,9 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
26
67
|
console.error('无效的应用配置');
|
|
27
68
|
return;
|
|
28
69
|
}
|
|
29
|
-
|
|
70
|
+
if (!deployOptions.mode) {
|
|
71
|
+
deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
|
|
72
|
+
}
|
|
30
73
|
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
74
|
const buildContext = {
|
|
32
75
|
projDir: appBuildDir,
|
|
@@ -46,30 +89,58 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
46
89
|
console.log('生成路径', appBuildDir);
|
|
47
90
|
try {
|
|
48
91
|
const startTime = Date.now();
|
|
92
|
+
function processRepeaterDisplay(cals) {
|
|
93
|
+
cals.items = (cals.items || []).map((page) => {
|
|
94
|
+
return JSON.parse(JSON.stringify(page, (key, value) => {
|
|
95
|
+
if (value === null || value === void 0 ? void 0 : value.component) {
|
|
96
|
+
const component = value;
|
|
97
|
+
if ((value === null || value === void 0 ? void 0 : value.component) &&
|
|
98
|
+
`${component.module}:${component.component}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
|
|
99
|
+
// 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
|
|
100
|
+
const { items = [] } = component;
|
|
101
|
+
component.items = items.map((item) => {
|
|
102
|
+
if (component.directives[':display'] !== undefined && component.directives[':display'] !== 'true') {
|
|
103
|
+
if (!item.directives) {
|
|
104
|
+
item.directives = {};
|
|
105
|
+
}
|
|
106
|
+
const current = item.directives[':display'] || 'true';
|
|
107
|
+
item.directives[':display'] = `(\n${component.directives[':display']}\n) && (\n${current}\n)`;
|
|
108
|
+
}
|
|
109
|
+
return item;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return value;
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
116
|
+
return cals;
|
|
117
|
+
}
|
|
49
118
|
if (buildTypeList.includes(common_1.BuildType.MP)) {
|
|
50
|
-
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
51
|
-
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
|
|
119
|
+
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(processRepeaterDisplay(cals), dependencies);
|
|
120
|
+
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(processRepeaterDisplay(item), dependencies))) || [];
|
|
52
121
|
const apps = [mainAppSerializeData, ...subAppSerializeDataList];
|
|
53
122
|
if (isBrowserMpBuilder) {
|
|
54
123
|
// 尽早下载物料
|
|
55
124
|
await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
|
|
56
125
|
}
|
|
126
|
+
const { enablePageRoot } = (0, cals_1.parseVersion)(cals === null || cals === void 0 ? void 0 : cals.schemaVersion, dependencies);
|
|
57
127
|
const mpBuildContext = {
|
|
58
128
|
...buildContext,
|
|
59
129
|
projDir: (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp'),
|
|
60
130
|
mainAppData: mainAppSerializeData,
|
|
61
131
|
processCssUnit: ([cals, ...subAppCalsList].find((cals) => {
|
|
62
|
-
const FEATURE_MAP = (0, cals_1.parseVersion)(cals.schemaVersion);
|
|
132
|
+
const FEATURE_MAP = (0, cals_1.parseVersion)(cals.schemaVersion, dependencies);
|
|
63
133
|
return !FEATURE_MAP.defaultDynamicCssUnit;
|
|
64
134
|
})
|
|
65
135
|
? 'px'
|
|
66
136
|
: 'rpx'),
|
|
137
|
+
enablePageRoot,
|
|
67
138
|
};
|
|
68
139
|
const result = await (0, index_1.generateWxMp)({
|
|
69
140
|
weapps: apps,
|
|
70
141
|
buildContext: mpBuildContext,
|
|
71
142
|
plugins,
|
|
72
|
-
|
|
143
|
+
deployOptions,
|
|
73
144
|
options: {
|
|
74
145
|
isCrossAccount: resourceAppId !== deployOptions.targetMpAppId,
|
|
75
146
|
mpAppId: deployOptions.mpAppId || '',
|
|
@@ -111,24 +182,24 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
111
182
|
return outDir;
|
|
112
183
|
}
|
|
113
184
|
else {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
185
|
+
const h5BuildDir = await (0, index_2.buildH5App)({
|
|
186
|
+
buildContext: { ...buildContext, isMixMode: false },
|
|
187
|
+
cals,
|
|
188
|
+
subAppCalsList,
|
|
189
|
+
extraData,
|
|
190
|
+
buildTypeList,
|
|
191
|
+
mode,
|
|
192
|
+
devTool,
|
|
193
|
+
runtime,
|
|
194
|
+
deployOptions,
|
|
195
|
+
ignoreInstall,
|
|
196
|
+
cdnEndpoints,
|
|
197
|
+
});
|
|
198
|
+
await (cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
199
|
+
outDir: h5BuildDir,
|
|
200
|
+
timeElapsed: Date.now() - startTime,
|
|
201
|
+
}));
|
|
202
|
+
return h5BuildDir;
|
|
132
203
|
}
|
|
133
204
|
}
|
|
134
205
|
catch (err) {
|
|
@@ -262,5 +333,5 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
|
|
|
262
333
|
return cals;
|
|
263
334
|
}
|
|
264
335
|
function _getWebRootPath({ appId, deployOptions }) {
|
|
265
|
-
return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.
|
|
336
|
+
return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD ? `/${appId}/production/` : `/${appId}/preview/`;
|
|
266
337
|
}
|
|
@@ -6,8 +6,9 @@ import { BuildType } from '../types/common';
|
|
|
6
6
|
* 该函数从 @govcloud/generate 取到需要的模版文件
|
|
7
7
|
*/
|
|
8
8
|
export declare function generateProjectFiles(buildData: BuildAppProps): Promise<void>;
|
|
9
|
-
export declare function generateHTML({ appId, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
|
|
9
|
+
export declare function generateHTML({ appId, envId, appBuildDir, externalResources, mode, devTool, isBuildApp, buildTypeList, cdnEndpoints, }: {
|
|
10
10
|
appId: string;
|
|
11
|
+
envId: string;
|
|
11
12
|
externalResources: Required<IPlatformApp>['externalResources'];
|
|
12
13
|
appBuildDir: string;
|
|
13
14
|
mode: 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, cdnEndpoints, }) {
|
|
28
|
+
async function generateHTML({ appId, envId, 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' });
|
|
@@ -54,6 +54,16 @@ async function generateHTML({ appId, appBuildDir, externalResources = [], mode,
|
|
|
54
54
|
isBuildApp,
|
|
55
55
|
isAdminPortal: (0, common_2.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
56
56
|
cdnEndpoints: (0, config_1.generateCdnEndpoints)(cdnEndpoints),
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated
|
|
59
|
+
* 临时先这么添加白名单
|
|
60
|
+
*/
|
|
61
|
+
enableStaticLoading: [
|
|
62
|
+
'lowcode-4gzdsu5k66946492',
|
|
63
|
+
'lowcode-2gay8jgh25c7b1cf',
|
|
64
|
+
'lowcode-4g9b78bx94404d85',
|
|
65
|
+
'lowcode-8gmx7bat3135e2de',
|
|
66
|
+
].includes(envId) && !(0, common_2.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
57
67
|
}));
|
|
58
68
|
}
|
|
59
69
|
exports.generateHTML = generateHTML;
|
|
@@ -74,14 +84,15 @@ async function handleAssets({ appBuildDir, buildTypeList, assets, }) {
|
|
|
74
84
|
if (assetsArr && assetsArr.length > 0) {
|
|
75
85
|
if (buildTypeList.includes('app')) {
|
|
76
86
|
const targetDir = path_1.default.resolve(appBuildDir, './assets');
|
|
77
|
-
assetsArr.
|
|
87
|
+
await Promise.all(assetsArr.map(async (assetUrl) => {
|
|
78
88
|
console.log('============>>>>>> getWebpackWebBuildParams assetUrl', assetUrl);
|
|
79
89
|
if (assetUrl) {
|
|
80
90
|
const fileName = (0, common_1.getFileNameByUrl)(assetUrl);
|
|
81
91
|
jsApis.push(`./${fileName}`);
|
|
82
92
|
await (0, webpack_1.downloadAssets)(targetDir, assetUrl);
|
|
93
|
+
return `./${fileName}`;
|
|
83
94
|
}
|
|
84
|
-
});
|
|
95
|
+
}));
|
|
85
96
|
}
|
|
86
97
|
else {
|
|
87
98
|
jsApis = jsApis.concat(assetsArr);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { II18nConfig, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { BuildType, WebpackModeType } from '../types/common';
|
|
3
|
-
import {
|
|
3
|
+
import { RUNTIME } from '../../types';
|
|
4
4
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
5
5
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
6
|
import { IBuildContext } from '../mp/BuildContext';
|
|
7
|
-
|
|
7
|
+
import { IBuildWedaApp } from '../core';
|
|
8
|
+
export declare function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployOptions, ignoreInstall, cdnEndpoints, }: {
|
|
8
9
|
buildContext: Omit<IBuildContext, 'mainAppData'>;
|
|
9
10
|
cals: IPlatformApp;
|
|
10
11
|
subAppCalsList: IPlatformApp[];
|
|
@@ -14,7 +15,7 @@ export declare function buildH5App({ buildContext, i18nConfig, extraData, cals,
|
|
|
14
15
|
mode: WebpackModeType;
|
|
15
16
|
devTool: string;
|
|
16
17
|
runtime?: RUNTIME;
|
|
17
|
-
|
|
18
|
+
deployOptions?: IBuildWedaApp['deployOptions'];
|
|
18
19
|
ignoreInstall?: boolean;
|
|
19
20
|
cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
|
|
20
21
|
}): Promise<string>;
|
package/lib/builder/h5/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = 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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -20,9 +43,14 @@ const mp_1 = require("../mp");
|
|
|
20
43
|
const common_2 = require("../../utils/common");
|
|
21
44
|
const config_1 = require("../config");
|
|
22
45
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
23
|
-
|
|
46
|
+
const junk = __importStar(require("../util/junk"));
|
|
47
|
+
const url_1 = require("url");
|
|
48
|
+
async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, ignoreInstall = false, cdnEndpoints, }) {
|
|
24
49
|
var _a, _b, _c;
|
|
25
50
|
const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode } = buildContext;
|
|
51
|
+
if (!deployOptions.mode) {
|
|
52
|
+
deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
|
|
53
|
+
}
|
|
26
54
|
try {
|
|
27
55
|
const { materialsDir } = runtime === types_1.RUNTIME.CI ? (0, util_1.getCompileDirs)(appKey) : (0, util_1.getCompileDirs)('app');
|
|
28
56
|
const h5BuildDir = path_1.default.join(buildDir, 'h5');
|
|
@@ -86,7 +114,7 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildType
|
|
|
86
114
|
buildTypeList,
|
|
87
115
|
isSandbox: false,
|
|
88
116
|
runtime,
|
|
89
|
-
|
|
117
|
+
deployOptions,
|
|
90
118
|
_indexPage,
|
|
91
119
|
isPrivateMode,
|
|
92
120
|
});
|
|
@@ -136,10 +164,33 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildType
|
|
|
136
164
|
}
|
|
137
165
|
});
|
|
138
166
|
});
|
|
167
|
+
const MAINIFAST_FILENAME = 'weda-manifest.json';
|
|
168
|
+
const preHeatUrls = fs_extra_1.default
|
|
169
|
+
.readdirSync(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR))
|
|
170
|
+
.filter((file) => junk.not(file) && file !== MAINIFAST_FILENAME)
|
|
171
|
+
.map((file) => {
|
|
172
|
+
if (/LICENSE\.txt$/.test(file) || /\.map$/.test(file)) {
|
|
173
|
+
return '';
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const url = new url_1.URL(publicPath);
|
|
177
|
+
return `${url.origin}${path_1.default.posix.join(url.pathname, file)}`;
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
return path_1.default.posix.join(publicPath, file);
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
.filter((item) => !!item);
|
|
139
184
|
// 普通 web 模式,且非hash模式,根据页面生成多份入口
|
|
140
185
|
if (!((_c = cals.extra) === null || _c === void 0 ? void 0 : _c.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
|
|
141
|
-
|
|
186
|
+
preHeatUrls.push(path_1.default.posix.join(basename));
|
|
187
|
+
await Promise.all((cals.items || []).map((page) => {
|
|
188
|
+
preHeatUrls.push(path_1.default.posix.join(basename, page.id));
|
|
189
|
+
preHeatUrls.push(path_1.default.posix.join(basename, page.id, '/'));
|
|
190
|
+
return 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'));
|
|
191
|
+
}));
|
|
142
192
|
}
|
|
193
|
+
await fs_extra_1.default.writeFile(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'weda-manifest.json'), JSON.stringify({ preHeatUrls }, undefined, 2));
|
|
143
194
|
return h5BuildDir;
|
|
144
195
|
}
|
|
145
196
|
catch (e) {
|
|
@@ -28,6 +28,7 @@ async function runWebpackCore({ cals, mainAppData, subAppDataList, appBuildDir,
|
|
|
28
28
|
console.timeEnd('generateMpJsonConfigFile');
|
|
29
29
|
await (0, generate_1.generateHTML)({
|
|
30
30
|
appId: mainAppData.id || appKey,
|
|
31
|
+
envId: mainAppData.envId || '',
|
|
31
32
|
appBuildDir,
|
|
32
33
|
externalResources: (cals.externalResources || []).concat(assets.map((url) => ({
|
|
33
34
|
type: cals_1.EExternalResourceType.CSSUrl,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
|
-
import { DEPLOY_MODE } from '../../types';
|
|
4
3
|
import { BuildType, IAppUsedComp, IUsedComps } from '../types/common';
|
|
5
|
-
|
|
4
|
+
import { IBuildWedaApp } from '../core';
|
|
5
|
+
export declare function generateWxMp({ buildContext, weapps, plugins, deployOptions, options, buildTypeList, ignoreInstall, }: {
|
|
6
6
|
buildContext: IBuildContext;
|
|
7
7
|
weapps: IWeAppData[];
|
|
8
8
|
plugins: IPlugin[];
|
|
9
|
-
|
|
9
|
+
deployOptions: Required<IBuildWedaApp>['deployOptions'];
|
|
10
10
|
options: {
|
|
11
11
|
mpAppId: string;
|
|
12
12
|
resourceAppId?: string;
|
|
@@ -17,6 +17,11 @@ export declare function generateWxMp({ buildContext, weapps, plugins, deployMode
|
|
|
17
17
|
}): Promise<{
|
|
18
18
|
miniprogramRoot: string;
|
|
19
19
|
}>;
|
|
20
|
+
export declare function generateConfig(data: {
|
|
21
|
+
domain?: string;
|
|
22
|
+
isPrivateMode?: boolean;
|
|
23
|
+
endpointType?: IBuildContext['endpointType'] | '';
|
|
24
|
+
}, root: string): Promise<void>;
|
|
20
25
|
export declare function writeLowCodeFiles(ctx: IBuildContext, appData: IWeAppData, outDir: string): Promise<void>;
|
|
21
26
|
/**
|
|
22
27
|
* TODO: 与 cals 里的实现进行整合
|