@cloudbase/lowcode-builder 1.1.7 → 1.1.8
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 +8 -0
- package/lib/builder/config/index.js +16 -1
- package/lib/builder/core/index.d.ts +32 -2
- package/lib/builder/core/index.js +146 -27
- package/lib/builder/h5/generate.d.ts +3 -1
- package/lib/builder/h5/generate.js +2 -1
- package/lib/builder/h5/index.d.ts +6 -6
- package/lib/builder/h5/index.js +20 -14
- package/lib/builder/h5/webpack.d.ts +3 -1
- package/lib/builder/h5/webpack.js +2 -1
- package/lib/builder/mp/BuildContext.d.ts +4 -0
- package/lib/builder/mp/index.d.ts +5 -12
- package/lib/builder/mp/index.js +18 -28
- package/lib/builder/mp/materials.js +6 -0
- package/lib/builder/mp/mixMode.d.ts +3 -2
- package/lib/builder/mp/mixMode.js +5 -2
- package/lib/builder/mp/mp_config.d.ts +1 -1
- package/lib/builder/mp/mp_config.js +4 -1
- package/lib/builder/service/webpack.d.ts +7 -0
- package/lib/builder/service/webpack.js +34 -23
- package/lib/builder/util/generateFiles.js +3 -11
- package/package.json +2 -2
- package/template/html/index.html.ejs +1 -1
|
@@ -16,3 +16,11 @@ export declare const miniprogramURL = "https://comp-public-1303824488.cos.ap-sha
|
|
|
16
16
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
17
17
|
*/
|
|
18
18
|
export declare const miniprogramDir: string;
|
|
19
|
+
export interface ICDN_ENDPOINTS_COFIG {
|
|
20
|
+
common?: string;
|
|
21
|
+
cloudbase?: string;
|
|
22
|
+
cdngo?: string;
|
|
23
|
+
aegis?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const CDN_ENDPONTS_CONFIG: ICDN_ENDPOINTS_COFIG;
|
|
26
|
+
export declare function generateCdnEndpoints(endpoints?: ICDN_ENDPOINTS_COFIG): ICDN_ENDPOINTS_COFIG;
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
|
|
29
|
+
exports.generateCdnEndpoints = exports.CDN_ENDPONTS_CONFIG = exports.miniprogramDir = exports.miniprogramURL = exports.builderTemplateURL = exports.materialsDirName = exports.appTemplateDir = exports.sharedMaterialsDir = exports.OFFICIAL_LIB_KEY = exports.rpxConfig = exports.remConfig = exports.npmRegistry = exports.KBONE_PAGE_KEYS = exports.MP_CONFIG_MODULE_NAME = exports.REPLACE_SIGN = void 0;
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const os_1 = __importDefault(require("os"));
|
|
32
32
|
var index_1 = require("@cloudbase/lowcode-generator/lib/generator/config/index");
|
|
@@ -54,3 +54,18 @@ exports.miniprogramURL = 'https://comp-public-1303824488.cos.ap-shanghai.myqclou
|
|
|
54
54
|
* miniprogram_npm存放目录。IDE插件builder用到
|
|
55
55
|
*/
|
|
56
56
|
exports.miniprogramDir = path.join(os_1.default.homedir(), exports.sharedMaterialsDir, 'miniprogram_npm');
|
|
57
|
+
exports.CDN_ENDPONTS_CONFIG = {
|
|
58
|
+
common: '',
|
|
59
|
+
cloudbase: '//static.cloudbase.net',
|
|
60
|
+
cdngo: 'https://qbase.cdn-go.cn',
|
|
61
|
+
aegis: 'https://cdn-go.cn',
|
|
62
|
+
};
|
|
63
|
+
function generateCdnEndpoints(endpoints = exports.CDN_ENDPONTS_CONFIG) {
|
|
64
|
+
for (const key in exports.CDN_ENDPONTS_CONFIG) {
|
|
65
|
+
if (!Object.prototype.hasOwnProperty.call(endpoints, key)) {
|
|
66
|
+
endpoints[key] = endpoints.common ? endpoints.common : exports.CDN_ENDPONTS_CONFIG[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return endpoints;
|
|
70
|
+
}
|
|
71
|
+
exports.generateCdnEndpoints = generateCdnEndpoints;
|
|
@@ -2,7 +2,8 @@ import { IMaterialItem, IWeAppData, IPlugin, IExtraData } from '@cloudbase/lowco
|
|
|
2
2
|
import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from '../types/common';
|
|
3
3
|
import { DEPLOY_MODE, RUNTIME } from '../../types';
|
|
4
4
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
5
|
-
|
|
5
|
+
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
|
+
interface IBaseAppProps {
|
|
6
7
|
appKey: string;
|
|
7
8
|
dependencies?: IMaterialItem[];
|
|
8
9
|
publicPath?: string;
|
|
@@ -35,11 +36,40 @@ export interface IBuildWedaApp extends IBaseAppProps {
|
|
|
35
36
|
path?: string;
|
|
36
37
|
};
|
|
37
38
|
isBrowserMpBuilder?: boolean;
|
|
39
|
+
cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
|
|
40
|
+
isPrivateMode?: boolean;
|
|
38
41
|
}
|
|
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>;
|
|
42
|
+
export declare function buildWedaApp({ cals, subAppCalsList, dependencies, appKey, runtime, ignoreInstall, buildTypeList, mode, devTool, deployOptions, generateMpType, plugins, extraData, resourceAppId, domain, output, isBrowserMpBuilder, cdnEndpoints, isPrivateMode, }: IBuildWedaApp, cb?: WebpackBuildCallBack): Promise<string | undefined>;
|
|
40
43
|
export declare function cleanComponentDir(): Promise<void>;
|
|
41
44
|
export declare const version: any;
|
|
42
45
|
export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
|
|
43
46
|
export { downloadZip } from '../util/net';
|
|
44
47
|
export { getCompileDirs } from '../util';
|
|
45
48
|
export default buildWedaApp;
|
|
49
|
+
interface INormalizeInput {
|
|
50
|
+
appId?: string;
|
|
51
|
+
appKey?: string;
|
|
52
|
+
dependencies?: IBuildWedaApp['dependencies'];
|
|
53
|
+
buildTypeList: IBuildWedaApp['buildTypeList'];
|
|
54
|
+
mainAppSerializeData?: IBuildWedaApp['cals'];
|
|
55
|
+
cals?: IBuildWedaApp['cals'];
|
|
56
|
+
subAppSerializeDataList?: IBuildWedaApp['subAppCalsList'];
|
|
57
|
+
subAppCalsList?: IBuildWedaApp['subAppCalsList'];
|
|
58
|
+
deployOptions: IBuildWedaApp['deployOptions'];
|
|
59
|
+
mpAppId?: string;
|
|
60
|
+
extraData?: {
|
|
61
|
+
isComposite: boolean;
|
|
62
|
+
compProps: {};
|
|
63
|
+
};
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
}
|
|
66
|
+
interface InormalizeOutput extends INormalizeInput {
|
|
67
|
+
dependencies: Required<INormalizeInput['dependencies']>;
|
|
68
|
+
}
|
|
69
|
+
export declare function normalizeInputs(inputs: INormalizeInput, { envId, getWebRootPath, }: {
|
|
70
|
+
envId: string;
|
|
71
|
+
getWebRootPath?: ({ appId, deployOptions }: {
|
|
72
|
+
appId: any;
|
|
73
|
+
deployOptions: any;
|
|
74
|
+
}) => string;
|
|
75
|
+
}): InormalizeOutput;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = void 0;
|
|
6
|
+
exports.normalizeInputs = exports.getCompileDirs = exports.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.cleanComponentDir = exports.buildWedaApp = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -20,7 +20,7 @@ const pkg = require('../../../package.json');
|
|
|
20
20
|
async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appKey = 'test', runtime = types_1.RUNTIME.NONE, ignoreInstall = false, buildTypeList = [common_1.BuildType.WEB], mode = common_1.WebpackModeType.PRODUCTION, devTool = 'webpack', deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW }, generateMpType = common_1.GenerateMpType.APP, plugins = [], extraData = {
|
|
21
21
|
isComposite: false,
|
|
22
22
|
compProps: {},
|
|
23
|
-
}, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, }, cb) {
|
|
23
|
+
}, resourceAppId = undefined, domain = '', output, isBrowserMpBuilder = false, cdnEndpoints, isPrivateMode = false, }, cb) {
|
|
24
24
|
var _a, _b;
|
|
25
25
|
if (!cals) {
|
|
26
26
|
console.error('无效的应用配置');
|
|
@@ -28,6 +28,17 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
28
28
|
}
|
|
29
29
|
const { mode: deployMode = types_1.DEPLOY_MODE.PREVIEW } = deployOptions;
|
|
30
30
|
let appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || (runtime === types_1.RUNTIME.CI ? (_a = (0, util_1.getCompileDirs)('app')) === null || _a === void 0 ? void 0 : _a.appBuildDir : (_b = (0, util_1.getCompileDirs)(appKey)) === null || _b === void 0 ? void 0 : _b.appBuildDir);
|
|
31
|
+
const buildContext = {
|
|
32
|
+
projDir: appBuildDir,
|
|
33
|
+
appId: appKey,
|
|
34
|
+
isProduction: mode === common_1.WebpackModeType.PRODUCTION,
|
|
35
|
+
materialLibs: dependencies,
|
|
36
|
+
debugMode: mode !== common_1.WebpackModeType.PRODUCTION && !!process.env.WEAPPS_DEBUG,
|
|
37
|
+
isMixMode: generateMpType === common_1.GenerateMpType.SUBPACKAGE,
|
|
38
|
+
domain,
|
|
39
|
+
isBrowserMpBuilder,
|
|
40
|
+
isPrivateMode,
|
|
41
|
+
};
|
|
31
42
|
console.log('domain', domain);
|
|
32
43
|
console.log('应用名', appKey);
|
|
33
44
|
console.log('生成模式', generateMpType);
|
|
@@ -37,28 +48,25 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
37
48
|
if (buildTypeList.includes(common_1.BuildType.MP)) {
|
|
38
49
|
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
39
50
|
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
|
|
40
|
-
appBuildDir = (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp');
|
|
41
|
-
const isMixMode = generateMpType === common_1.GenerateMpType.SUBPACKAGE;
|
|
42
51
|
const apps = [mainAppSerializeData, ...subAppSerializeDataList];
|
|
43
52
|
if (isBrowserMpBuilder) {
|
|
44
53
|
// 尽早下载物料
|
|
45
54
|
await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
|
|
46
55
|
}
|
|
56
|
+
const mpBuildContext = {
|
|
57
|
+
...buildContext,
|
|
58
|
+
projDir: (output === null || output === void 0 ? void 0 : output.path) || path_1.default.join(appBuildDir, 'mp'),
|
|
59
|
+
mainAppData: mainAppSerializeData,
|
|
60
|
+
};
|
|
47
61
|
const result = await (0, index_1.generateWxMp)({
|
|
48
62
|
weapps: apps,
|
|
49
|
-
|
|
50
|
-
appId: appKey,
|
|
51
|
-
domain: domain,
|
|
52
|
-
materials: dependencies,
|
|
63
|
+
buildContext: mpBuildContext,
|
|
53
64
|
plugins,
|
|
54
|
-
isProduction: mode === common_1.WebpackModeType.PRODUCTION,
|
|
55
65
|
deployMode,
|
|
56
|
-
extraData,
|
|
57
|
-
isMixMode,
|
|
58
66
|
options: {
|
|
59
67
|
isCrossAccount: resourceAppId !== deployOptions.targetMpAppId,
|
|
68
|
+
mpAppId: deployOptions.mpAppId || '',
|
|
60
69
|
resourceAppId,
|
|
61
|
-
mpAppId: deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mpAppId,
|
|
62
70
|
},
|
|
63
71
|
buildTypeList,
|
|
64
72
|
isBrowserMpBuilder,
|
|
@@ -66,16 +74,16 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
66
74
|
});
|
|
67
75
|
// 如果是混合模式,则将特定的目录复制到工程下
|
|
68
76
|
// 针对 app.json / package.json 则采用 merge 的操作
|
|
69
|
-
if (isMixMode) {
|
|
70
|
-
console.log(chalk_1.default.green('【混合模式】'),
|
|
77
|
+
if (buildContext.isMixMode) {
|
|
78
|
+
console.log(chalk_1.default.green('【混合模式】'), mpBuildContext.projDir);
|
|
71
79
|
await (0, mixMode_1.handleMixMode)({
|
|
80
|
+
buildContext: mpBuildContext,
|
|
72
81
|
apps,
|
|
73
|
-
generateMpPath: appBuildDir,
|
|
74
82
|
miniprogramRoot: result.miniprogramRoot,
|
|
75
83
|
plugins,
|
|
76
84
|
});
|
|
77
85
|
}
|
|
78
|
-
const outDir =
|
|
86
|
+
const outDir = mpBuildContext.projDir;
|
|
79
87
|
let projectJsonPath = path_1.default.resolve(outDir, 'project.config.json');
|
|
80
88
|
await (0, postProcess_1.postprocessProjectConfig)(projectJsonPath, {
|
|
81
89
|
appid: deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mpAppId,
|
|
@@ -88,18 +96,16 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
88
96
|
// 模板需要占位保证 mp 文件夹存在
|
|
89
97
|
fs_extra_1.default.removeSync(path_1.default.resolve(outDir, 'miniprogram_npm'));
|
|
90
98
|
}
|
|
91
|
-
cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
99
|
+
await (cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
92
100
|
...result,
|
|
93
101
|
outDir,
|
|
94
102
|
timeElapsed: Date.now() - startTime,
|
|
95
|
-
});
|
|
103
|
+
}));
|
|
96
104
|
return outDir;
|
|
97
105
|
}
|
|
98
106
|
else {
|
|
99
107
|
const h5BuildDir = await (0, index_2.buildH5App)({
|
|
100
|
-
|
|
101
|
-
buildDir: appBuildDir,
|
|
102
|
-
dependencies,
|
|
108
|
+
buildContext: { ...buildContext, isMixMode: false },
|
|
103
109
|
cals,
|
|
104
110
|
subAppCalsList,
|
|
105
111
|
extraData,
|
|
@@ -109,18 +115,36 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
109
115
|
runtime,
|
|
110
116
|
deployMode,
|
|
111
117
|
ignoreInstall,
|
|
112
|
-
|
|
118
|
+
cdnEndpoints,
|
|
113
119
|
});
|
|
114
|
-
cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
120
|
+
await (cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
115
121
|
outDir: h5BuildDir,
|
|
116
122
|
timeElapsed: Date.now() - startTime,
|
|
117
|
-
});
|
|
123
|
+
}));
|
|
118
124
|
return h5BuildDir;
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
|
-
catch (
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (err.length) {
|
|
129
|
+
let messageList = (err[0] || '').split('\n');
|
|
130
|
+
let lineIndex = 0;
|
|
131
|
+
let reg = /node_modules\/@babel/;
|
|
132
|
+
messageList.find((str, index) => {
|
|
133
|
+
if (reg.test(str)) {
|
|
134
|
+
lineIndex = index;
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (lineIndex) {
|
|
142
|
+
messageList = messageList.slice(0, lineIndex);
|
|
143
|
+
}
|
|
144
|
+
err = new Error(messageList.join('\n'));
|
|
145
|
+
}
|
|
146
|
+
cb === null || cb === void 0 ? void 0 : cb(err);
|
|
147
|
+
throw err;
|
|
124
148
|
}
|
|
125
149
|
}
|
|
126
150
|
exports.buildWedaApp = buildWedaApp;
|
|
@@ -138,3 +162,98 @@ Object.defineProperty(exports, "downloadZip", { enumerable: true, get: function
|
|
|
138
162
|
var util_2 = require("../util");
|
|
139
163
|
Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
|
|
140
164
|
exports.default = buildWedaApp;
|
|
165
|
+
function normalizeInputs(inputs, { envId, getWebRootPath, }) {
|
|
166
|
+
const { extraData = { isComposite: false, compProps: {} } } = inputs;
|
|
167
|
+
/**
|
|
168
|
+
* 过滤处理 dependencies
|
|
169
|
+
*/
|
|
170
|
+
let map = {};
|
|
171
|
+
inputs.dependencies = (inputs.dependencies || []).reduce((list, item) => {
|
|
172
|
+
if (!map[`${item.name}@${item.version}`]) {
|
|
173
|
+
map[`${item.name}@${item.version}`] = true;
|
|
174
|
+
list.push(item);
|
|
175
|
+
}
|
|
176
|
+
return list;
|
|
177
|
+
}, []);
|
|
178
|
+
const normalizeCalsOptions = {
|
|
179
|
+
buildTypeList: inputs.buildTypeList,
|
|
180
|
+
envId,
|
|
181
|
+
deployOptions: inputs.deployOptions,
|
|
182
|
+
appId: inputs.appId || inputs.appKey,
|
|
183
|
+
getWebRootPath: getWebRootPath || _getWebRootPath,
|
|
184
|
+
};
|
|
185
|
+
if (inputs.mainAppSerializeData) {
|
|
186
|
+
inputs.mainAppSerializeData = normalizeCals(inputs.mainAppSerializeData, normalizeCalsOptions);
|
|
187
|
+
if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
188
|
+
inputs.subAppSerializeDataList = [];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (inputs.cals) {
|
|
192
|
+
inputs.cals = normalizeCals(inputs.cals, normalizeCalsOptions);
|
|
193
|
+
if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
194
|
+
inputs.subAppCalsList = [];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (!(0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
198
|
+
// 小程序构建
|
|
199
|
+
const { mpAppId, deployOptions = { mode: types_1.DEPLOY_MODE.PREVIEW } } = inputs;
|
|
200
|
+
inputs.deployOptions = {
|
|
201
|
+
...deployOptions,
|
|
202
|
+
mpAppId: deployOptions.mpAppId || mpAppId,
|
|
203
|
+
};
|
|
204
|
+
if (!inputs.deployOptions.targetMpAppId) {
|
|
205
|
+
inputs.deployOptions.targetMpAppId = inputs.deployOptions.mpAppId;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (extraData.isComposite) {
|
|
209
|
+
Object.keys(extraData.compProps.events).forEach((eName) => {
|
|
210
|
+
extraData.compProps.events[eName] = `$$EVENT_${eName}$$`;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return inputs;
|
|
214
|
+
}
|
|
215
|
+
exports.normalizeInputs = normalizeInputs;
|
|
216
|
+
function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWebRootPath }) {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
if (!cals.extra) {
|
|
219
|
+
cals.extra = {};
|
|
220
|
+
}
|
|
221
|
+
if (!cals.mpPkgUrl) {
|
|
222
|
+
if (buildTypeList.includes(common_1.BuildType.APP) ||
|
|
223
|
+
buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
|
|
224
|
+
buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
|
|
225
|
+
cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (!((_a = cals === null || cals === void 0 ? void 0 : cals.extra) === null || _a === void 0 ? void 0 : _a.envId)) {
|
|
229
|
+
cals.extra.envId = envId;
|
|
230
|
+
}
|
|
231
|
+
if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
|
|
232
|
+
// web 构建不处理小程序插件
|
|
233
|
+
if (cals.extra.miniprogramPlugins) {
|
|
234
|
+
cals.extra.miniprogramPlugins = [];
|
|
235
|
+
}
|
|
236
|
+
let { appConfig = {} } = cals.extra;
|
|
237
|
+
let { window = {} } = appConfig;
|
|
238
|
+
let path = getWebRootPath({ appId, deployOptions });
|
|
239
|
+
cals.extra.appConfig = {
|
|
240
|
+
...appConfig,
|
|
241
|
+
window: {
|
|
242
|
+
...window,
|
|
243
|
+
// Todo: 处理自定义域名逻辑
|
|
244
|
+
publicPath: (0, common_1.buildAsXPageByBuildType)(buildTypeList)
|
|
245
|
+
? (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.publicPath) || `https://${(_b = cals.extra) === null || _b === void 0 ? void 0 : _b.domain}${path}`
|
|
246
|
+
: path,
|
|
247
|
+
basename: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList)
|
|
248
|
+
? `app/${appId}${(deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) !== types_1.DEPLOY_MODE.UPLOAD ? '-preview' : ''}`
|
|
249
|
+
: (0, common_1.buildAsXPageByBuildType)(buildTypeList)
|
|
250
|
+
? '/'
|
|
251
|
+
: path,
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return cals;
|
|
256
|
+
}
|
|
257
|
+
function _getWebRootPath({ appId, deployOptions }) {
|
|
258
|
+
return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.PREVIEW ? `/${appId}/preview/` : `/${appId}/production/`;
|
|
259
|
+
}
|
|
@@ -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;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { II18nConfig, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { BuildType, WebpackModeType } from '../types/common';
|
|
3
3
|
import { DEPLOY_MODE, RUNTIME } from '../../types';
|
|
4
4
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
|
+
import { IBuildContext } from '../mp/BuildContext';
|
|
7
|
+
export declare function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployMode, ignoreInstall, cdnEndpoints, }: {
|
|
8
|
+
buildContext: Omit<IBuildContext, 'mainAppData'>;
|
|
8
9
|
cals: IPlatformApp;
|
|
9
10
|
subAppCalsList: IPlatformApp[];
|
|
10
|
-
dependencies: IMaterialItem[];
|
|
11
11
|
i18nConfig?: II18nConfig;
|
|
12
12
|
buildTypeList: BuildType[];
|
|
13
13
|
extraData: IExtraData;
|
|
@@ -16,5 +16,5 @@ export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig,
|
|
|
16
16
|
runtime?: RUNTIME;
|
|
17
17
|
deployMode?: DEPLOY_MODE;
|
|
18
18
|
ignoreInstall?: boolean;
|
|
19
|
-
|
|
19
|
+
cdnEndpoints?: ICDN_ENDPOINTS_COFIG;
|
|
20
20
|
}): Promise<string>;
|
package/lib/builder/h5/index.js
CHANGED
|
@@ -19,31 +19,31 @@ const types_1 = require("../../types");
|
|
|
19
19
|
const mp_1 = require("../mp");
|
|
20
20
|
const common_2 = require("../../utils/common");
|
|
21
21
|
const config_1 = require("../config");
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
23
|
+
async function buildH5App({ buildContext, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployMode = types_1.DEPLOY_MODE.PREVIEW, ignoreInstall = false, cdnEndpoints, }) {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
const { projDir: buildDir, domain, materialLibs: dependencies, appId: appKey, isPrivateMode } = buildContext;
|
|
24
26
|
try {
|
|
25
27
|
const { materialsDir } = runtime === types_1.RUNTIME.CI ? (0, util_1.getCompileDirs)(appKey) : (0, util_1.getCompileDirs)('app');
|
|
26
28
|
const h5BuildDir = path_1.default.join(buildDir, 'h5');
|
|
29
|
+
if (buildTypeList.includes(common_1.BuildType.APP) ||
|
|
30
|
+
buildTypeList.includes(common_1.BuildType.XPAGE_PC) ||
|
|
31
|
+
buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL)) {
|
|
32
|
+
if (!cals.extra) {
|
|
33
|
+
cals.extra = {};
|
|
34
|
+
}
|
|
35
|
+
cals.extra.historyType = types_1.HISTORY_TYPE.HASH;
|
|
36
|
+
}
|
|
27
37
|
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
28
38
|
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
|
|
29
|
-
const buildContext = {
|
|
30
|
-
projDir: buildDir,
|
|
31
|
-
appId: appKey,
|
|
32
|
-
isProduction: mode === common_1.WebpackModeType.PRODUCTION,
|
|
33
|
-
materialLibs: dependencies,
|
|
34
|
-
isMixMode: false,
|
|
35
|
-
mainAppData: mainAppSerializeData,
|
|
36
|
-
domain,
|
|
37
|
-
};
|
|
38
39
|
const { allAppUsedComps } = (0, mp_1.handleUsedComponents)({
|
|
39
|
-
buildContext,
|
|
40
|
+
buildContext: { ...buildContext, mainAppData: mainAppSerializeData },
|
|
40
41
|
weapps: [mainAppSerializeData, ...subAppSerializeDataList],
|
|
41
|
-
materials: dependencies,
|
|
42
42
|
});
|
|
43
43
|
// 处理应用数据
|
|
44
44
|
const mainAppData = (0, weapps_core_1.deserialize)(mainAppSerializeData);
|
|
45
45
|
if (!mainAppData.extra) {
|
|
46
|
-
mainAppData.extra = { domain
|
|
46
|
+
mainAppData.extra = { domain };
|
|
47
47
|
}
|
|
48
48
|
if (!((_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.domain)) {
|
|
49
49
|
mainAppData.extra.domain = domain;
|
|
@@ -88,6 +88,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
88
88
|
runtime,
|
|
89
89
|
deployMode,
|
|
90
90
|
_indexPage,
|
|
91
|
+
isPrivateMode,
|
|
91
92
|
});
|
|
92
93
|
console.timeEnd(runGenerateTag);
|
|
93
94
|
// // 构建 NPM 包
|
|
@@ -116,6 +117,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
116
117
|
devTool,
|
|
117
118
|
publicPath,
|
|
118
119
|
domain,
|
|
120
|
+
cdnEndpoints,
|
|
119
121
|
});
|
|
120
122
|
await new Promise((resolve, reject) => {
|
|
121
123
|
// 开始编译前清理一下 lowcode 内容
|
|
@@ -133,6 +135,10 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
133
135
|
}
|
|
134
136
|
});
|
|
135
137
|
});
|
|
138
|
+
// 普通 web 模式,且非hash模式,根据页面生成多份入口
|
|
139
|
+
if (!((_c = cals.extra) === null || _c === void 0 ? void 0 : _c.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
|
|
140
|
+
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'))));
|
|
141
|
+
}
|
|
136
142
|
return h5BuildDir;
|
|
137
143
|
}
|
|
138
144
|
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) {
|
|
@@ -3,6 +3,9 @@ import { IMaterialItem, IWeAppData, IMiniprogramPlugin } from '@cloudbase/lowcod
|
|
|
3
3
|
* All build parameters and intermediate data to be share across processes
|
|
4
4
|
*/
|
|
5
5
|
export interface IBuildContext {
|
|
6
|
+
/**
|
|
7
|
+
* 应用id
|
|
8
|
+
*/
|
|
6
9
|
appId: string;
|
|
7
10
|
domain: string;
|
|
8
11
|
projDir: string;
|
|
@@ -14,4 +17,5 @@ export interface IBuildContext {
|
|
|
14
17
|
miniprogramPlugins?: IMiniprogramPlugin[];
|
|
15
18
|
debugMode?: boolean;
|
|
16
19
|
isBrowserMpBuilder?: boolean;
|
|
20
|
+
isPrivateMode?: boolean;
|
|
17
21
|
}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IBuildContext } from './BuildContext';
|
|
3
3
|
import { DEPLOY_MODE } from '../../types';
|
|
4
4
|
import { BuildType, IAppUsedComp, IUsedComps } from '../types/common';
|
|
5
|
-
export declare function generateWxMp({
|
|
5
|
+
export declare function generateWxMp({ buildContext, weapps, plugins, deployMode, options, buildTypeList, isBrowserMpBuilder, ignoreInstall, }: {
|
|
6
|
+
buildContext: IBuildContext;
|
|
6
7
|
weapps: IWeAppData[];
|
|
7
|
-
projDir: string;
|
|
8
|
-
appId: string;
|
|
9
|
-
domain: string;
|
|
10
|
-
materials: IMaterialItem[];
|
|
11
8
|
plugins: IPlugin[];
|
|
12
|
-
isProduction: boolean;
|
|
13
9
|
deployMode: DEPLOY_MODE;
|
|
14
|
-
extraData: any;
|
|
15
|
-
isMixMode: boolean;
|
|
16
10
|
options: {
|
|
11
|
+
mpAppId: string;
|
|
17
12
|
resourceAppId?: string;
|
|
18
|
-
mpAppId?: string;
|
|
19
13
|
isCrossAccount: boolean;
|
|
20
14
|
};
|
|
21
15
|
buildTypeList: BuildType[];
|
|
@@ -29,10 +23,9 @@ export declare function writeLowCodeFiles(appData: IWeAppData, outDir: string, c
|
|
|
29
23
|
* TODO: 与 cals 里的实现进行整合
|
|
30
24
|
* 关键点在于 appUsedComps 分组, 与 generic componen 的实现
|
|
31
25
|
*/
|
|
32
|
-
export declare function handleUsedComponents({ buildContext, weapps
|
|
26
|
+
export declare function handleUsedComponents({ buildContext, weapps }: {
|
|
33
27
|
buildContext: IBuildContext;
|
|
34
28
|
weapps: IWeAppData[];
|
|
35
|
-
materials: IMaterialItem[];
|
|
36
29
|
}): {
|
|
37
30
|
appUsedComps: IAppUsedComp[];
|
|
38
31
|
allAppUsedComps: IUsedComps;
|
package/lib/builder/mp/index.js
CHANGED
|
@@ -54,35 +54,18 @@ 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({
|
|
57
|
+
async function generateWxMp({ buildContext, weapps, plugins, deployMode, options, buildTypeList, isBrowserMpBuilder = false, ignoreInstall = false, }) {
|
|
58
58
|
var _a;
|
|
59
|
+
const { appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isPrivateMode = false, } = buildContext;
|
|
59
60
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
60
61
|
console.time(operationLabel);
|
|
61
62
|
console.log(`Generating ${em('Wexin MiniProgram')} to ${projDir}`);
|
|
62
|
-
|
|
63
|
-
let mainAppData = weapps[0];
|
|
64
|
-
const buildContext = {
|
|
65
|
-
projDir,
|
|
66
|
-
appId,
|
|
67
|
-
isProduction,
|
|
68
|
-
materialLibs: materials,
|
|
69
|
-
debugMode: !isProduction && !!process.env.WEAPPS_DEBUG,
|
|
70
|
-
isMixMode,
|
|
71
|
-
mainAppData,
|
|
72
|
-
domain,
|
|
73
|
-
isBrowserMpBuilder,
|
|
74
|
-
};
|
|
75
|
-
const yyptConfig = await (0, util_3.getYyptConfigInfo)(extraData);
|
|
76
|
-
const { allAppUsedComps } = handleUsedComponents({
|
|
77
|
-
buildContext,
|
|
78
|
-
weapps,
|
|
79
|
-
materials,
|
|
80
|
-
});
|
|
63
|
+
const { allAppUsedComps } = handleUsedComponents({ buildContext, weapps });
|
|
81
64
|
buildContext.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
|
|
82
65
|
// 安装依赖库,生成 materials 目录
|
|
83
66
|
await (0, materials_1.installMaterials)(projDir, allAppUsedComps, weapps, buildContext);
|
|
84
67
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
|
|
85
|
-
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext, { mpAppId: options
|
|
68
|
+
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext, { mpAppId: options.mpAppId });
|
|
86
69
|
// #1 generate project files
|
|
87
70
|
if (!mainAppData.mpPkgUrl) {
|
|
88
71
|
const projectFileData = {
|
|
@@ -135,7 +118,8 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
135
118
|
};
|
|
136
119
|
}
|
|
137
120
|
if (mainAppData.mpPkgUrl) {
|
|
138
|
-
// 合并 project 和 app json
|
|
121
|
+
// 合并 project 和 app json,复写 appId
|
|
122
|
+
projectConfigJson.appId = projConfig.appId;
|
|
139
123
|
if (!projectConfigJson.setting) {
|
|
140
124
|
projectConfigJson.setting = {};
|
|
141
125
|
}
|
|
@@ -153,7 +137,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
153
137
|
const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
|
|
154
138
|
appFileData = {
|
|
155
139
|
...appFileData,
|
|
156
|
-
'common/wx_yypt_report_v2.js': {},
|
|
157
140
|
'app.js': { appConfig, importor },
|
|
158
141
|
'app.json': { content: appConfig },
|
|
159
142
|
'app.wxss': {
|
|
@@ -166,6 +149,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
166
149
|
},
|
|
167
150
|
'package.json': {
|
|
168
151
|
appId,
|
|
152
|
+
isPrivateMode,
|
|
169
153
|
extraDeps: resolveNpmDeps(),
|
|
170
154
|
},
|
|
171
155
|
};
|
|
@@ -187,6 +171,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
187
171
|
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
188
172
|
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
189
173
|
clientID: (_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.clientId,
|
|
174
|
+
isPrivateMode,
|
|
190
175
|
},
|
|
191
176
|
'datasources/datasource-profiles.js.tpl': {
|
|
192
177
|
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(
|
|
@@ -221,6 +206,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
221
206
|
await (0, generateFiles_1.default)({
|
|
222
207
|
'package.json': {
|
|
223
208
|
appId,
|
|
209
|
+
isPrivateMode,
|
|
224
210
|
extraDeps: resolveNpmDeps(),
|
|
225
211
|
},
|
|
226
212
|
}, templateDir, subpackageRootPath, buildContext);
|
|
@@ -228,7 +214,10 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
228
214
|
}
|
|
229
215
|
}));
|
|
230
216
|
if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
|
|
231
|
-
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
217
|
+
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
218
|
+
ignoreInstall,
|
|
219
|
+
fixNodeModulesMap: { '@cloudbase/js-sdk': !isPrivateMode, mobx: true },
|
|
220
|
+
});
|
|
232
221
|
}
|
|
233
222
|
await handleMpPlugins();
|
|
234
223
|
console.timeEnd(operationLabel);
|
|
@@ -240,7 +229,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
240
229
|
var _a;
|
|
241
230
|
const deps = [
|
|
242
231
|
{
|
|
243
|
-
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) ||
|
|
232
|
+
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) || {},
|
|
244
233
|
name: '主包',
|
|
245
234
|
},
|
|
246
235
|
];
|
|
@@ -427,7 +416,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
427
416
|
// 混合模式,子包不生成顶级(应用级)的 lowcodes
|
|
428
417
|
if (!(ctx.isMixMode && appData.rootPath)) {
|
|
429
418
|
await Promise.all(lowCodes
|
|
430
|
-
.filter((mod) => mod.type !==
|
|
419
|
+
.filter((mod) => mod.type !== cals_1.ECodeType.RENDERER)
|
|
431
420
|
.map((m) => {
|
|
432
421
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
|
|
433
422
|
}));
|
|
@@ -435,7 +424,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
435
424
|
await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
|
|
436
425
|
const codes = (0, cals_1.processRuntimeCodeResources)({ id: page.id }, page.lowCodes || page.codeModules, 'page');
|
|
437
426
|
await codes
|
|
438
|
-
.filter((mod) => mod.type !==
|
|
427
|
+
.filter((mod) => mod.type !== cals_1.ECodeType.RENDERER)
|
|
439
428
|
.forEach((m) => {
|
|
440
429
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
|
|
441
430
|
});
|
|
@@ -463,7 +452,8 @@ function getAppendableJson(json) {
|
|
|
463
452
|
* TODO: 与 cals 里的实现进行整合
|
|
464
453
|
* 关键点在于 appUsedComps 分组, 与 generic componen 的实现
|
|
465
454
|
*/
|
|
466
|
-
function handleUsedComponents({ buildContext, weapps
|
|
455
|
+
function handleUsedComponents({ buildContext, weapps }) {
|
|
456
|
+
const { materialLibs: materials } = buildContext;
|
|
467
457
|
const appUsedComps = weapps.map((app) => {
|
|
468
458
|
var _a;
|
|
469
459
|
const usedComps = {};
|
|
@@ -327,6 +327,12 @@ async function generateCompositeComponent(compositedComp, ctx, compLibCommonReso
|
|
|
327
327
|
${compLibCommonResource.theme.class || ''}
|
|
328
328
|
`;
|
|
329
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* 低码没有开放 index 类别,直接去掉
|
|
332
|
+
*/
|
|
333
|
+
if (mod.name === 'index') {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
330
336
|
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, ctx);
|
|
331
337
|
});
|
|
332
338
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { IWeAppData, IPlugin, IMaterialItem } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IAppUsedComp } from '../types/common';
|
|
3
|
-
|
|
3
|
+
import { IBuildContext } from '../mp/BuildContext';
|
|
4
|
+
export declare function handleMixMode({ buildContext, apps, miniprogramRoot, plugins, }: {
|
|
5
|
+
buildContext: IBuildContext;
|
|
4
6
|
apps: IWeAppData[];
|
|
5
|
-
generateMpPath: string;
|
|
6
7
|
miniprogramRoot: string;
|
|
7
8
|
plugins: IPlugin[];
|
|
8
9
|
}): Promise<void>;
|
|
@@ -36,13 +36,16 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
36
36
|
const generateFiles_1 = require("../util/generateFiles");
|
|
37
37
|
const webpack_1 = require("../service/webpack");
|
|
38
38
|
// 将 BUILD 目录往混合模式移动
|
|
39
|
-
async function handleMixMode({ apps = [],
|
|
39
|
+
async function handleMixMode({ buildContext, apps = [], miniprogramRoot, plugins = [], }) {
|
|
40
|
+
const { projDir: generateMpPath, isPrivateMode } = buildContext;
|
|
40
41
|
// await handleMainApp()
|
|
41
42
|
// await handleAppPages()
|
|
42
43
|
await handleSubApps();
|
|
43
44
|
// await handleAppJson()
|
|
44
45
|
// await handlePkgJson()
|
|
45
|
-
await (0, webpack_1.installDependencies)(miniprogramRoot
|
|
46
|
+
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
47
|
+
fixNodeModulesMap: { mobx: true, '@cloudbase/js-sdk': !isPrivateMode },
|
|
48
|
+
});
|
|
46
49
|
await handlePlugins();
|
|
47
50
|
// 复制框架公用内容
|
|
48
51
|
async function handleMainApp() {
|
|
@@ -6,7 +6,7 @@ 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, options
|
|
9
|
+
export declare function generateMpConfig(weapps: IWeAppData[], ctx: IBuildContext, options: {
|
|
10
10
|
mpAppId?: string;
|
|
11
11
|
}): {
|
|
12
12
|
appConfig: any;
|
|
@@ -117,6 +117,9 @@ function generateMpConfig(weapps, ctx, options) {
|
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
+
if (options.mpAppId) {
|
|
121
|
+
projConfig.appId = options.mpAppId;
|
|
122
|
+
}
|
|
120
123
|
// merge(pageConfigs, extractAllPagesConfig())
|
|
121
124
|
return { appConfig, projConfig, pageConfigs };
|
|
122
125
|
}
|
|
@@ -165,7 +168,7 @@ function transformDynamicData(originData) {
|
|
|
165
168
|
const temp = {};
|
|
166
169
|
for (const key in originData) {
|
|
167
170
|
const target = originData[key];
|
|
168
|
-
if (target
|
|
171
|
+
if (target === null || target === void 0 ? void 0 : target.value) {
|
|
169
172
|
temp[key] = target.value;
|
|
170
173
|
}
|
|
171
174
|
}
|
|
@@ -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;
|
|
@@ -74,11 +75,17 @@ export interface IInstallOpts {
|
|
|
74
75
|
version: string;
|
|
75
76
|
downloadUrl: string;
|
|
76
77
|
};
|
|
78
|
+
fixNodeModulesMap?: IFixNodeModulesMap;
|
|
77
79
|
}
|
|
78
80
|
export declare function installDependencies(targetDir: string, options?: IInstallOpts): Promise<void>;
|
|
81
|
+
interface IFixNodeModulesMap {
|
|
82
|
+
mobx?: boolean;
|
|
83
|
+
'@cloudbase/js-sdk'?: boolean;
|
|
84
|
+
}
|
|
79
85
|
export declare function getMaterialNodeModulesPathList(dependencies: IMaterialItem[] | undefined, materialsDir: string, base?: string): string[];
|
|
80
86
|
export declare function generateWebpackWebDevServerFile({ appBuildDir, buildTypeList }: {
|
|
81
87
|
appBuildDir: any;
|
|
82
88
|
buildTypeList: any;
|
|
83
89
|
}): Promise<void>;
|
|
84
90
|
export declare function downloadAssets(targetDir: string, assetUrl: string): Promise<unknown>;
|
|
91
|
+
export {};
|
|
@@ -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,
|
|
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)
|
|
@@ -456,13 +455,10 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
456
455
|
}
|
|
457
456
|
}
|
|
458
457
|
catch (e) { }
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
*/
|
|
464
|
-
const cacheMeta = generateFiles_1.generatedFileContents[packageJsonPath];
|
|
465
|
-
const isPkgModify = !cacheMeta || cacheMeta.once ? false : generateFiles_1.generatedFileContents[path_1.default.resolve(targetDir, 'package.json')].modify;
|
|
458
|
+
// 如果generatedFileContents[path.resolve(targetDir, 'package.json')]不存在,说明是不存在缓存文件,isPkgModify必须是true,才不会忽略install
|
|
459
|
+
const isPkgModify = !generateFiles_1.generatedFileContents[path_1.default.resolve(targetDir, 'package.json')]
|
|
460
|
+
? true
|
|
461
|
+
: generateFiles_1.generatedFileContents[path_1.default.resolve(targetDir, 'package.json')].modify;
|
|
466
462
|
if ((options === null || options === void 0 ? void 0 : options.ignoreInstall) && fs_extra_1.default.existsSync(path_1.default.join(targetDir, 'node_modules')) && !isPkgModify) {
|
|
467
463
|
console.log(`ignore install dependencies in ${targetDir}`);
|
|
468
464
|
return;
|
|
@@ -488,20 +484,25 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
488
484
|
};
|
|
489
485
|
}
|
|
490
486
|
}
|
|
491
|
-
let installProcess;
|
|
492
487
|
// 云端构建, 选用 npm
|
|
493
|
-
const
|
|
488
|
+
const installProcessOptions = {
|
|
494
489
|
cwd: targetDir,
|
|
495
490
|
// NODE_ENV="production"时,devDependencies里的包不会下载,兼容h5在线编译
|
|
496
491
|
env: { ...process.env, NODE_ENV: '' },
|
|
497
492
|
stdio: 'inherit',
|
|
498
493
|
};
|
|
494
|
+
let installprocess;
|
|
495
|
+
// TODO: install 失败 应该终止进程
|
|
499
496
|
if (yarnExists && (options === null || options === void 0 ? void 0 : options.runtime) !== types_1.RUNTIME.CI) {
|
|
500
497
|
const addPackage = packageName ? ['add', packageName] : [];
|
|
501
|
-
|
|
498
|
+
installprocess = cross_spawn_1.default.sync('yarn', [...addPackage, registry], installProcessOptions);
|
|
502
499
|
}
|
|
503
500
|
else {
|
|
504
|
-
|
|
501
|
+
installprocess = cross_spawn_1.default.sync('npm', ['install', packageName, ...npmOptions], installProcessOptions);
|
|
502
|
+
}
|
|
503
|
+
// TODO: 确认 process.status 语义来判断是否标识进程正常退出
|
|
504
|
+
if (installprocess.status) {
|
|
505
|
+
throw new Error(`安装依赖失败 ${installprocess.error || ''}`);
|
|
505
506
|
}
|
|
506
507
|
fixNodeModules(targetDir);
|
|
507
508
|
try {
|
|
@@ -512,14 +513,24 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
512
513
|
console.timeEnd(operationTag);
|
|
513
514
|
}
|
|
514
515
|
exports.installDependencies = installDependencies;
|
|
515
|
-
function fixNodeModules(projDir) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const
|
|
520
|
-
if (fs_extra_1.default.existsSync(
|
|
521
|
-
mobxPackageFileContent
|
|
522
|
-
fs_extra_1.default.
|
|
516
|
+
function fixNodeModules(projDir, options = { mobx: false, '@cloudbase/js-sdk': false }) {
|
|
517
|
+
const { mobx = false, ['@cloudbase/js-sdk']: jsSDK = false } = options;
|
|
518
|
+
if (mobx) {
|
|
519
|
+
// # fix mobx/package.json: "main": "lib/index.js" -> "main": "lib/index.js"
|
|
520
|
+
const mobxPackageFile = path_1.default.join(projDir, 'node_modules', 'mobx/package.json');
|
|
521
|
+
if (fs_extra_1.default.existsSync(mobxPackageFile)) {
|
|
522
|
+
const mobxPackageFileContent = fs_extra_1.default.readJSONSync(mobxPackageFile);
|
|
523
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(projDir, 'node_modules', 'mobx/lib/mobx.min.js'))) {
|
|
524
|
+
mobxPackageFileContent.main = 'lib/mobx.min.js';
|
|
525
|
+
fs_extra_1.default.writeJSONSync(mobxPackageFile, mobxPackageFileContent);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (jsSDK) {
|
|
530
|
+
const scriptPath = path_1.default.resolve(projDir, 'node_modules', '@cloudbase/weda-cloud-sdk/scripts/fix-wx-none-private');
|
|
531
|
+
if (fs_extra_1.default.existsSync(scriptPath)) {
|
|
532
|
+
const fix = require(scriptPath);
|
|
533
|
+
fix();
|
|
523
534
|
}
|
|
524
535
|
}
|
|
525
536
|
}
|
|
@@ -67,16 +67,8 @@ async function generateFiles(appFileData, srcDir, dstDir, ctx) {
|
|
|
67
67
|
}
|
|
68
68
|
exports.default = generateFiles;
|
|
69
69
|
async function writeFile(outFile, content) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
once: true,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
exports.generatedFileContents[outFile].once = false;
|
|
77
|
-
}
|
|
78
|
-
const meta = exports.generatedFileContents[outFile];
|
|
79
|
-
const generated = meta.content;
|
|
70
|
+
var _a;
|
|
71
|
+
const generated = (_a = exports.generatedFileContents[outFile]) === null || _a === void 0 ? void 0 : _a.content;
|
|
80
72
|
if (generated === content && fs_extra_1.default.existsSync(outFile)) {
|
|
81
73
|
exports.generatedFileContents[outFile].modify = false;
|
|
82
74
|
return false;
|
|
@@ -84,7 +76,7 @@ async function writeFile(outFile, content) {
|
|
|
84
76
|
// console.log(outFile);
|
|
85
77
|
await fs_extra_1.default.ensureFile(outFile);
|
|
86
78
|
await fs_extra_1.default.writeFile(outFile, content);
|
|
87
|
-
exports.generatedFileContents[outFile] = {
|
|
79
|
+
exports.generatedFileContents[outFile] = { content, modify: true };
|
|
88
80
|
return true;
|
|
89
81
|
}
|
|
90
82
|
exports.writeFile = writeFile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
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.11",
|
|
42
|
-
"@cloudbase/lowcode-generator": "^1.1.
|
|
42
|
+
"@cloudbase/lowcode-generator": "^1.1.4",
|
|
43
43
|
"axios": "^0.21.0",
|
|
44
44
|
"browserfs": "^1.4.3",
|
|
45
45
|
"browserify-zlib": "^0.2.0",
|
|
@@ -461,7 +461,7 @@
|
|
|
461
461
|
></script>
|
|
462
462
|
<script
|
|
463
463
|
crossorigin
|
|
464
|
-
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.
|
|
464
|
+
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.59a4c563eb076206c8bd.bundle.js"
|
|
465
465
|
></script>
|
|
466
466
|
</body>
|
|
467
467
|
</html>
|