@cloudbase/lowcode-builder 1.3.12-alpha.3 → 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.js +1 -1
- package/lib/builder/core/index.d.ts +8 -0
- package/lib/builder/core/index.js +78 -8
- 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/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
|
@@ -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"));
|
|
@@ -17,7 +17,47 @@ const common_2 = require("../../utils/common");
|
|
|
17
17
|
const postProcess_1 = require("../../utils/postProcess");
|
|
18
18
|
const cals_1 = require("@cloudbase/cals");
|
|
19
19
|
const net_1 = require("../util/net");
|
|
20
|
+
const config_1 = require("../config");
|
|
20
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;
|
|
21
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 = {
|
|
22
62
|
isComposite: false,
|
|
23
63
|
compProps: {},
|
|
@@ -27,7 +67,9 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
27
67
|
console.error('无效的应用配置');
|
|
28
68
|
return;
|
|
29
69
|
}
|
|
30
|
-
|
|
70
|
+
if (!deployOptions.mode) {
|
|
71
|
+
deployOptions.mode = types_1.DEPLOY_MODE.PREVIEW;
|
|
72
|
+
}
|
|
31
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);
|
|
32
74
|
const buildContext = {
|
|
33
75
|
projDir: appBuildDir,
|
|
@@ -47,30 +89,58 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
47
89
|
console.log('生成路径', appBuildDir);
|
|
48
90
|
try {
|
|
49
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
|
+
}
|
|
50
118
|
if (buildTypeList.includes(common_1.BuildType.MP)) {
|
|
51
|
-
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
52
|
-
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))) || [];
|
|
53
121
|
const apps = [mainAppSerializeData, ...subAppSerializeDataList];
|
|
54
122
|
if (isBrowserMpBuilder) {
|
|
55
123
|
// 尽早下载物料
|
|
56
124
|
await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
|
|
57
125
|
}
|
|
126
|
+
const { enablePageRoot } = (0, cals_1.parseVersion)(cals === null || cals === void 0 ? void 0 : cals.schemaVersion, dependencies);
|
|
58
127
|
const mpBuildContext = {
|
|
59
128
|
...buildContext,
|
|
60
129
|
projDir: (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp'),
|
|
61
130
|
mainAppData: mainAppSerializeData,
|
|
62
131
|
processCssUnit: ([cals, ...subAppCalsList].find((cals) => {
|
|
63
|
-
const FEATURE_MAP = (0, cals_1.parseVersion)(cals.schemaVersion);
|
|
132
|
+
const FEATURE_MAP = (0, cals_1.parseVersion)(cals.schemaVersion, dependencies);
|
|
64
133
|
return !FEATURE_MAP.defaultDynamicCssUnit;
|
|
65
134
|
})
|
|
66
135
|
? 'px'
|
|
67
136
|
: 'rpx'),
|
|
137
|
+
enablePageRoot,
|
|
68
138
|
};
|
|
69
139
|
const result = await (0, index_1.generateWxMp)({
|
|
70
140
|
weapps: apps,
|
|
71
141
|
buildContext: mpBuildContext,
|
|
72
142
|
plugins,
|
|
73
|
-
|
|
143
|
+
deployOptions,
|
|
74
144
|
options: {
|
|
75
145
|
isCrossAccount: resourceAppId !== deployOptions.targetMpAppId,
|
|
76
146
|
mpAppId: deployOptions.mpAppId || '',
|
|
@@ -121,7 +191,7 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
121
191
|
mode,
|
|
122
192
|
devTool,
|
|
123
193
|
runtime,
|
|
124
|
-
|
|
194
|
+
deployOptions,
|
|
125
195
|
ignoreInstall,
|
|
126
196
|
cdnEndpoints,
|
|
127
197
|
});
|
|
@@ -263,5 +333,5 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
|
|
|
263
333
|
return cals;
|
|
264
334
|
}
|
|
265
335
|
function _getWebRootPath({ appId, deployOptions }) {
|
|
266
|
-
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/`;
|
|
267
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 里的实现进行整合
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -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.handleUsedComponents = exports.writeLowCodeFiles = exports.generateWxMp = void 0;
|
|
29
|
+
exports.handleUsedComponents = exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
|
|
30
30
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const util_1 = require("util");
|
|
@@ -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({ buildContext, weapps, plugins,
|
|
57
|
+
async function generateWxMp({ buildContext, weapps, plugins, deployOptions, options, buildTypeList, ignoreInstall = false, }) {
|
|
58
58
|
var _a;
|
|
59
59
|
const { appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = buildContext;
|
|
60
60
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
@@ -76,30 +76,33 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
76
76
|
'project.config.json': { content: projConfig },
|
|
77
77
|
};
|
|
78
78
|
console.log(`Generating ${em('project')} files`);
|
|
79
|
-
await (0, generateFiles_1.default)(
|
|
79
|
+
await (0, generateFiles_1.default)(projectFileData, templateDir, projDir);
|
|
80
80
|
}
|
|
81
81
|
// #2 生成主包
|
|
82
82
|
await generatePkg({ ...buildContext, rootPath: mainAppData.rootPath }, mainAppData, path_1.default.join(projDir, '/'), pageConfigs[0]);
|
|
83
83
|
const projectConfigJsonPath = path_1.default.join(projDir, mainAppData.rootPath || '', 'project.config.json');
|
|
84
84
|
let projectConfigJson = await fs.readJSON(projectConfigJsonPath);
|
|
85
85
|
const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
|
|
86
|
-
await generateFramework(buildContext, mainAppData, miniprogramRoot);
|
|
86
|
+
await generateFramework(buildContext, mainAppData, miniprogramRoot, { deployOptions });
|
|
87
87
|
// #3 生成主包根路径文件
|
|
88
88
|
let appFileData = {};
|
|
89
89
|
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
90
|
-
await generateFramework(buildContext, mainAppData, miniprogramRoot);
|
|
90
|
+
await generateFramework(buildContext, mainAppData, miniprogramRoot, { deployOptions });
|
|
91
91
|
// 有了 framework app 之后,并且是源码的方式,追加 app 引用
|
|
92
92
|
if (mainAppData.mpPkgUrl) {
|
|
93
93
|
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
94
94
|
let appJsContent = await fs.readFile(appJsPath);
|
|
95
95
|
await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
|
|
96
96
|
}
|
|
97
|
+
await generateConfig({
|
|
98
|
+
domain,
|
|
99
|
+
isPrivateMode,
|
|
100
|
+
endpointType,
|
|
101
|
+
}, miniprogramRoot);
|
|
97
102
|
appFileData = {
|
|
98
103
|
...appFileData,
|
|
99
104
|
'common/style.js': {},
|
|
100
|
-
'common/utils.wxs': {
|
|
101
|
-
domain,
|
|
102
|
-
},
|
|
105
|
+
'common/utils.wxs': {},
|
|
103
106
|
'common/util.js': {
|
|
104
107
|
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
105
108
|
},
|
|
@@ -164,7 +167,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
164
167
|
};
|
|
165
168
|
}
|
|
166
169
|
console.log(`Generating ${em('miniprogramRoot')} files`);
|
|
167
|
-
await (0, generateFiles_1.default)(
|
|
170
|
+
await (0, generateFiles_1.default)(appFileData, templateDir, miniprogramRoot);
|
|
168
171
|
// 若项目目录与小程序根目录不同,则拷贝素材到小程序根目录
|
|
169
172
|
if (miniprogramRoot !== path_1.default.join(projDir, '/') && fs.existsSync(path_1.default.join(projDir, config_1.materialsDirName))) {
|
|
170
173
|
console.log(`Move ${em(config_1.materialsDirName)} from` + `${projDir} to ${miniprogramRoot}`);
|
|
@@ -178,25 +181,18 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
178
181
|
envID: mainAppData.envId,
|
|
179
182
|
appID: appId,
|
|
180
183
|
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
181
|
-
isProd:
|
|
184
|
+
isProd: (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD,
|
|
182
185
|
clientID: (_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.clientId,
|
|
183
|
-
isPrivateMode,
|
|
184
|
-
endpointType,
|
|
185
|
-
tcbApiOrigin: endpointType === 'tcb-api' && isPrivateMode && domain ? `https://${domain}` : '',
|
|
186
186
|
},
|
|
187
187
|
'datasources/datasource-profiles.js.tpl': {
|
|
188
|
-
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)(
|
|
189
|
-
/**
|
|
190
|
-
* 精简文件生成,新 cloud-sdk 不依赖 profile 了
|
|
191
|
-
*/
|
|
192
|
-
[]), { EOL: false }),
|
|
188
|
+
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)([], { EOL: false }),
|
|
193
189
|
},
|
|
194
190
|
'datasources/dataset-profiles.js.tpl': {
|
|
195
191
|
datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
|
|
196
192
|
},
|
|
197
193
|
};
|
|
198
194
|
console.log(`Generating ${em('datasources')} files`);
|
|
199
|
-
await (0, generateFiles_1.default)(
|
|
195
|
+
await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot);
|
|
200
196
|
}
|
|
201
197
|
// 生成子包
|
|
202
198
|
await Promise.all(weapps.map(async (app, index) => {
|
|
@@ -210,11 +206,11 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
210
206
|
rootPath: app.rootPath,
|
|
211
207
|
};
|
|
212
208
|
await generatePkg(subpackageBuildCtx, app, subpackageRootPath, pageConfigs[index]);
|
|
213
|
-
await generateFramework(subpackageBuildCtx, app, subpackageRootPath);
|
|
209
|
+
await generateFramework(subpackageBuildCtx, app, subpackageRootPath, { deployOptions });
|
|
214
210
|
// 生成package.json
|
|
215
211
|
let packageJsonPath = path_1.default.join(subpackageRootPath, 'package.json');
|
|
216
212
|
if (!fs.existsSync(packageJsonPath)) {
|
|
217
|
-
await (0, generateFiles_1.default)(
|
|
213
|
+
await (0, generateFiles_1.default)({
|
|
218
214
|
'package.json': {
|
|
219
215
|
appId,
|
|
220
216
|
importJSSDK: endpointType === 'tcb-api',
|
|
@@ -283,6 +279,20 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
283
279
|
}
|
|
284
280
|
}
|
|
285
281
|
exports.generateWxMp = generateWxMp;
|
|
282
|
+
async function generateConfig(data, root) {
|
|
283
|
+
const { domain = '', isPrivateMode = false, endpointType = '' } = data;
|
|
284
|
+
await (0, generateFiles_1.default)({
|
|
285
|
+
'common/config.js': {
|
|
286
|
+
domain,
|
|
287
|
+
isPrivateMode,
|
|
288
|
+
endpointType,
|
|
289
|
+
},
|
|
290
|
+
'common/config.wxs': {
|
|
291
|
+
domain,
|
|
292
|
+
},
|
|
293
|
+
}, templateDir, root);
|
|
294
|
+
}
|
|
295
|
+
exports.generateConfig = generateConfig;
|
|
286
296
|
async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
287
297
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!ctx.isProduction);
|
|
288
298
|
console.log(`Generating ${em(weapp.rootPath ? 'subApp' : 'app')} to ${appRoot}`);
|
|
@@ -301,7 +311,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
301
311
|
console.log(`Generating ${em('page')} files`);
|
|
302
312
|
(0, generateFiles_1.cleanDir)(path_1.default.join(appRoot, 'pages'), []);
|
|
303
313
|
await Promise.all(weapp.pageInstanceList.map(async (page) => {
|
|
304
|
-
var _a, _b;
|
|
314
|
+
var _a, _b, _c, _d, _e, _f;
|
|
305
315
|
// # Generating page
|
|
306
316
|
const rootPath = weapp.rootPath || '';
|
|
307
317
|
const usingComponents = {};
|
|
@@ -318,11 +328,12 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
318
328
|
widgetProps: (0, util_2.createWidgetProps)(ctx, componentInstances),
|
|
319
329
|
pageUUID: rootPath ? `${rootPath}/${page.id}` : page.id,
|
|
320
330
|
pageName: page.id,
|
|
331
|
+
pageTitle: ((_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.navigationBarTitleText) === null || _b === void 0 ? void 0 : _b.value) || ((_d = (_c = page === null || page === void 0 ? void 0 : page.data) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.value),
|
|
321
332
|
pageSource: page.data.src || '',
|
|
322
333
|
eventHanlders: (0, util_2.createEventHanlders)(ctx, componentInstances, 'this', page),
|
|
323
334
|
dataBinds: (0, util_2.createDataBinds)(ctx, componentInstances),
|
|
324
335
|
pageAttributes: {
|
|
325
|
-
...(((
|
|
336
|
+
...(((_e = page.data) === null || _e === void 0 ? void 0 : _e.appShareMessage) ? { appShareMessage: page.data.appShareMessage.value } : {}),
|
|
326
337
|
},
|
|
327
338
|
debug: ctx.debugMode,
|
|
328
339
|
stringifyObj: util_1.inspect,
|
|
@@ -338,7 +349,7 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
338
349
|
content: wxml,
|
|
339
350
|
},
|
|
340
351
|
[`index.wxss|${pageFileName}.wxss`]: {
|
|
341
|
-
subWxss: rootPath && !((
|
|
352
|
+
subWxss: rootPath && !((_f = ctx.mainAppData) === null || _f === void 0 ? void 0 : _f.mpPkgUrl)
|
|
342
353
|
? `@import "${path_1.default.posix.relative(`/${rootPath}/pages/${page.id}`, '/lowcode')}/style.wxss";`
|
|
343
354
|
: '',
|
|
344
355
|
content: (0, weapps_core_1.toCssText)((0, cals_1.processCommonStyle2CSSProperties)(page.commonStyle, {
|
|
@@ -348,13 +359,14 @@ async function generatePkg(ctx, weapp, appRoot, pageConfigs) {
|
|
|
348
359
|
},
|
|
349
360
|
};
|
|
350
361
|
// Generating file by template and data
|
|
351
|
-
await (0, generateFiles_1.default)(
|
|
362
|
+
await (0, generateFiles_1.default)(pageFileData, `${templateDir}/page`, path_1.default.join(appRoot, 'pages', page.id));
|
|
352
363
|
}));
|
|
353
364
|
// #3 writing lowcode files
|
|
354
365
|
await writeLowCodeFiles(ctx, weapp, appRoot);
|
|
355
366
|
}
|
|
356
367
|
}
|
|
357
|
-
async function generateFramework(ctx, appData, outDir) {
|
|
368
|
+
async function generateFramework(ctx, appData, outDir, options) {
|
|
369
|
+
var _a;
|
|
358
370
|
let fileData = {};
|
|
359
371
|
if (appData.mpPkgUrl) {
|
|
360
372
|
if (!appData.rootPath) {
|
|
@@ -366,7 +378,6 @@ async function generateFramework(ctx, appData, outDir) {
|
|
|
366
378
|
subLevelPath: '',
|
|
367
379
|
subPackageName: '',
|
|
368
380
|
importor: (0, util_3.generateLowcodeImportor)([]),
|
|
369
|
-
domain: ctx.domain || '',
|
|
370
381
|
appConfig: JSON.stringify({}),
|
|
371
382
|
},
|
|
372
383
|
};
|
|
@@ -391,15 +402,14 @@ async function generateFramework(ctx, appData, outDir) {
|
|
|
391
402
|
...fileData,
|
|
392
403
|
'app/app-global.js': {},
|
|
393
404
|
'app/weapps-api.js': {
|
|
394
|
-
appId: ctx.appId,
|
|
395
|
-
domain: ctx.domain || '',
|
|
396
405
|
subLevelPath: appData.rootPath ? `${path_1.default.posix.relative(`${appData.rootPath}`, '')}/` : '',
|
|
397
406
|
subPackageName: appData.rootPath || '',
|
|
398
407
|
importor,
|
|
399
408
|
appConfig: (0, util_3.JsonToStringWithVariableName)({
|
|
400
409
|
id: ctx.appId,
|
|
410
|
+
label: (appData === null || appData === void 0 ? void 0 : appData.label) || '',
|
|
411
|
+
version: (_a = options === null || options === void 0 ? void 0 : options.deployOptions) === null || _a === void 0 ? void 0 : _a.version,
|
|
401
412
|
envId: appData.envId,
|
|
402
|
-
staticResourceDomain: ctx.domain || '',
|
|
403
413
|
envVersion: (ctx === null || ctx === void 0 ? void 0 : ctx.isProduction) ? 'production' : 'preview',
|
|
404
414
|
pages: appData.pageInstanceList
|
|
405
415
|
.sort((item) => (item.isHome ? -1 : 1))
|
|
@@ -411,7 +421,7 @@ async function generateFramework(ctx, appData, outDir) {
|
|
|
411
421
|
},
|
|
412
422
|
'app/common.js': {
|
|
413
423
|
mods: appData.lowCodes
|
|
414
|
-
.filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE && m.name !==
|
|
424
|
+
.filter((m) => m.type === cals_1.ECodeType.NORMAL_MODULE && m.name !== cals_1.ECodeName.PLACEHOLDER)
|
|
415
425
|
.map((m) => m.name)
|
|
416
426
|
.sort(),
|
|
417
427
|
},
|
|
@@ -419,7 +429,7 @@ async function generateFramework(ctx, appData, outDir) {
|
|
|
419
429
|
}
|
|
420
430
|
}
|
|
421
431
|
console.log('Generate app framework');
|
|
422
|
-
await (0, generateFiles_1.default)(
|
|
432
|
+
await (0, generateFiles_1.default)(fileData, templateDir, outDir);
|
|
423
433
|
}
|
|
424
434
|
async function writeLowCodeFiles(ctx, appData, outDir) {
|
|
425
435
|
console.log(`Writing ${em('lowcode')} files:`);
|