@cloudbase/lowcode-builder 1.8.94 → 1.8.96
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/core/index.d.ts +9 -0
- package/lib/builder/core/index.js +118 -7
- package/lib/builder/h5/generate.d.ts +1 -1
- package/lib/builder/h5/index.d.ts +2 -2
- package/lib/builder/h5/index.js +24 -6
- package/lib/builder/h5/webpack.d.ts +2 -2
- package/lib/builder/mp/BuildContext.d.ts +18 -14
- package/lib/builder/mp/index.d.ts +11 -1
- package/lib/builder/mp/index.js +98 -85
- package/lib/builder/mp/lowcode.d.ts +5 -3
- package/lib/builder/mp/lowcode.js +14 -5
- package/lib/builder/mp/materials.d.ts +10 -5
- package/lib/builder/mp/materials.js +139 -135
- package/lib/builder/mp/util.d.ts +15 -12
- package/lib/builder/mp/util.js +50 -22
- package/lib/builder/mp/wxml.d.ts +5 -3
- package/lib/builder/mp/wxml.js +29 -27
- package/lib/builder/service/webpack.js +0 -1
- package/lib/builder/util/common.d.ts +1 -2
- package/lib/builder/util/common.js +1 -45
- package/lib/builder/util/generateFiles.d.ts +1 -1
- package/lib/builder/util/generateFiles.js +5 -1
- package/lib/builder.web.js +8 -55
- package/package.json +2 -2
- package/template/html/index.html.ejs +7 -3
- package/template/mp/app/weapps-api.js +1 -1
- package/template/mp/app.js +4 -2
- package/template/mp/common/cloud-sdk.js +28 -0
- package/template/mp/common/data-patch.js +18 -3
- package/template/mp/common/util.js +6 -2
- package/template/mp/common/watch.js +1 -1
- package/template/mp/common/weapp-component.js +5 -5
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +51 -38
- package/template/mp/component/index.js +7 -6
- package/template/mp/datasources/index.js.tpl +2 -30
- package/template/mp/package.json +3 -3
- package/template/webpack/web.prod.js +1 -1
|
@@ -3,6 +3,7 @@ import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from
|
|
|
3
3
|
import { DEPLOY_MODE, RUNTIME } from '../../types';
|
|
4
4
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
5
5
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
|
+
import { ICommonBuildContext } from '../mp/BuildContext';
|
|
6
7
|
interface IBaseAppProps {
|
|
7
8
|
appKey: string;
|
|
8
9
|
dependencies?: IMaterialItem[];
|
|
@@ -94,3 +95,11 @@ export declare function normalizeInputs(inputs: INormalizeInput, { envId, getWeb
|
|
|
94
95
|
deployOptions: any;
|
|
95
96
|
}) => string;
|
|
96
97
|
}): InormalizeOutput;
|
|
98
|
+
export declare function buildComposite({ dependencies, output, isBrowserMpBuilder, }: {
|
|
99
|
+
dependencies: IMaterialItem[];
|
|
100
|
+
rpxCalcRoot?: string;
|
|
101
|
+
output: {
|
|
102
|
+
path: string;
|
|
103
|
+
};
|
|
104
|
+
isBrowserMpBuilder?: ICommonBuildContext['isBrowserMpBuilder'];
|
|
105
|
+
}): Promise<void>;
|
|
@@ -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 = exports.buildWedaConfig = void 0;
|
|
6
|
+
exports.buildComposite = 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 path_1 = __importDefault(require("path"));
|
|
9
9
|
const util_1 = require("../util");
|
|
@@ -16,6 +16,7 @@ const cals_1 = require("@cloudbase/cals");
|
|
|
16
16
|
const net_1 = require("../util/net");
|
|
17
17
|
const config_1 = require("../config");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const materials_1 = require("../mp/materials");
|
|
19
20
|
const pkg = require('../../../package.json');
|
|
20
21
|
async function buildWedaConfig({ output, domain = undefined, isPrivateMode = undefined, endpointType = undefined, buildTypeList = [common_1.BuildType.WEB], }) {
|
|
21
22
|
if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
|
|
@@ -131,6 +132,10 @@ async function buildWedaApp({ cals, subAppCalsList: _subAppCalsList = [], depend
|
|
|
131
132
|
}
|
|
132
133
|
if (value === null || value === void 0 ? void 0 : value.component) {
|
|
133
134
|
const component = value;
|
|
135
|
+
/**
|
|
136
|
+
* TODO: 判断需要根据 componentType 来
|
|
137
|
+
* 但是此刻还没有具体的 componentInfo 信息
|
|
138
|
+
*/
|
|
134
139
|
if ((value === null || value === void 0 ? void 0 : value.component) &&
|
|
135
140
|
`${component.module}:${component.component}` === `${config_1.REPEATER.MODULE_NAME}:${config_1.REPEATER.REPEATER_NAME}`) {
|
|
136
141
|
// 给 Repeater 组件加一层虚拟项组件,在虚拟项组件上挂 for 循环
|
|
@@ -295,15 +300,9 @@ function normalizeInputs(inputs, { envId, getWebRootPath, }) {
|
|
|
295
300
|
};
|
|
296
301
|
if (inputs.mainAppSerializeData) {
|
|
297
302
|
inputs.mainAppSerializeData = normalizeCals(inputs.mainAppSerializeData, normalizeCalsOptions);
|
|
298
|
-
if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
299
|
-
inputs.subAppSerializeDataList = [];
|
|
300
|
-
}
|
|
301
303
|
}
|
|
302
304
|
if (inputs.cals) {
|
|
303
305
|
inputs.cals = normalizeCals(inputs.cals, normalizeCalsOptions);
|
|
304
|
-
if ((0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
305
|
-
inputs.subAppCalsList = [];
|
|
306
|
-
}
|
|
307
306
|
}
|
|
308
307
|
if (!(0, common_1.buildAsWebByBuildType)(inputs.buildTypeList)) {
|
|
309
308
|
// 小程序构建
|
|
@@ -368,3 +367,115 @@ function normalizeCals(cals, { buildTypeList, envId, deployOptions, appId, getWe
|
|
|
368
367
|
function _getWebRootPath({ appId, deployOptions }) {
|
|
369
368
|
return (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD ? `/${appId}/production/` : `/${appId}/preview/`;
|
|
370
369
|
}
|
|
370
|
+
async function buildComposite({ dependencies, output, isBrowserMpBuilder, }) {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
const packageMiniprogramEntry = 'dist';
|
|
373
|
+
const localWedaRoot = path_1.default.join(output.path, packageMiniprogramEntry);
|
|
374
|
+
const buildContext = {
|
|
375
|
+
materialLibs: dependencies.map((lib) => {
|
|
376
|
+
(0, materials_1.normalizeCompositeDependienciesForBuild)(lib);
|
|
377
|
+
return lib;
|
|
378
|
+
}),
|
|
379
|
+
isProduction: true,
|
|
380
|
+
/**
|
|
381
|
+
* 新版本不再默认转换
|
|
382
|
+
* 则此处构建都以px为准
|
|
383
|
+
*/
|
|
384
|
+
processCssUnit: 'px',
|
|
385
|
+
isBrowserMpBuilder,
|
|
386
|
+
};
|
|
387
|
+
await (0, index_1.generateWedaRootCommonFile)({
|
|
388
|
+
buildContext,
|
|
389
|
+
buildTypeList: [common_1.BuildType.MP],
|
|
390
|
+
localWedaRoot,
|
|
391
|
+
nativeMode: true,
|
|
392
|
+
// 组件无需生成,节省空间
|
|
393
|
+
filter: (src) => {
|
|
394
|
+
return !/common\/weapp-page/.test(src);
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
let usedComps;
|
|
398
|
+
const composite = dependencies.find((lib) => lib.isComposite);
|
|
399
|
+
if (composite) {
|
|
400
|
+
let id = 0;
|
|
401
|
+
const cals = {
|
|
402
|
+
items: [
|
|
403
|
+
{
|
|
404
|
+
id: '$page',
|
|
405
|
+
type: 'PAGE',
|
|
406
|
+
items: ((_b = (_a = composite.components) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (component) => {
|
|
407
|
+
id += 1;
|
|
408
|
+
return {
|
|
409
|
+
id: `id${id}`,
|
|
410
|
+
module: composite.name,
|
|
411
|
+
component: component.name,
|
|
412
|
+
attributes: {},
|
|
413
|
+
};
|
|
414
|
+
})) || [],
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
};
|
|
418
|
+
usedComps = (0, cals_1.getUsedComps)([cals], dependencies, { streamline: true, withAction: true });
|
|
419
|
+
}
|
|
420
|
+
await (0, materials_1.installMaterials)(buildContext, localWedaRoot, usedComps, 'lib');
|
|
421
|
+
await Promise.all(buildContext.materialLibs.map((lib) => {
|
|
422
|
+
return fs_extra_1.default.remove(path_1.default.join(localWedaRoot, config_1.materialsDirName, lib.name, 'meta.json'));
|
|
423
|
+
}));
|
|
424
|
+
await patchMpComponentNPM({
|
|
425
|
+
packageDir: output.path,
|
|
426
|
+
name: composite === null || composite === void 0 ? void 0 : composite.name,
|
|
427
|
+
version: composite === null || composite === void 0 ? void 0 : composite.version,
|
|
428
|
+
packageMiniprogramEntry,
|
|
429
|
+
});
|
|
430
|
+
// await generateCompLibs(dependencies, rpxCalcRoot);
|
|
431
|
+
}
|
|
432
|
+
exports.buildComposite = buildComposite;
|
|
433
|
+
async function patchMpComponentNPM({ packageDir, name, version, packageMiniprogramEntry = '', }) {
|
|
434
|
+
await fs_extra_1.default.mkdirSync(path_1.default.join(packageDir, 'scripts'));
|
|
435
|
+
const packageJsonPath = path_1.default.join(packageDir, 'package.json');
|
|
436
|
+
let packageJSON = {};
|
|
437
|
+
if (fs_extra_1.default.existsSync(packageJsonPath)) {
|
|
438
|
+
packageJSON = await fs_extra_1.default.readJSON(packageJsonPath);
|
|
439
|
+
}
|
|
440
|
+
const BASE_DEPS = {
|
|
441
|
+
mobx: '^5.15.4',
|
|
442
|
+
'lodash.get': '^4.4.2',
|
|
443
|
+
'lodash.set': '^4.3.2',
|
|
444
|
+
'miniprogram-gesture': '^1.0.6',
|
|
445
|
+
'miniprogram-api-promise': '^1.0.4',
|
|
446
|
+
'@cloudbase/oauth': '^0.1.1-alpha.5',
|
|
447
|
+
'@cloudbase/weda-client': '^1.0.31',
|
|
448
|
+
'@cloudbase/weda-cloud-sdk': '^1.0.59',
|
|
449
|
+
};
|
|
450
|
+
if (packageJSON.dependencies) {
|
|
451
|
+
for (const key in BASE_DEPS) {
|
|
452
|
+
delete packageJSON.dependencies[key];
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
packageJSON = {
|
|
456
|
+
...packageJSON,
|
|
457
|
+
name: `@tcwd/weda-component-${name || 'lib'}`,
|
|
458
|
+
version: version || packageJSON.version || '0.0.1',
|
|
459
|
+
miniprogram: `./${packageMiniprogramEntry}`,
|
|
460
|
+
scripts: {
|
|
461
|
+
...packageJSON.scripts,
|
|
462
|
+
postinstall: 'node scripts/fixCloudSdk.js',
|
|
463
|
+
},
|
|
464
|
+
peerDependencies: {
|
|
465
|
+
...packageJSON.peerDependencies,
|
|
466
|
+
...BASE_DEPS,
|
|
467
|
+
},
|
|
468
|
+
};
|
|
469
|
+
await Promise.all([
|
|
470
|
+
fs_extra_1.default.writeFile(path_1.default.join(packageDir, 'scripts', 'fixCloudSdk.js'), `try {
|
|
471
|
+
const cloudIndex = require.resolve('@cloudbase/weda-cloud-sdk') || '';
|
|
472
|
+
const cloudFixPath = cloudIndex.replace(/@cloudbase\\/weda-cloud-sdk\\/.*$/, '@cloudbase/weda-cloud-sdk/scripts/fix-wx-none-private.js');
|
|
473
|
+
const fix = require(cloudFixPath);
|
|
474
|
+
fix()
|
|
475
|
+
} catch(e) {
|
|
476
|
+
console.log('run scripts error', e)
|
|
477
|
+
}
|
|
478
|
+
`),
|
|
479
|
+
fs_extra_1.default.writeFile(packageJsonPath, JSON.stringify(packageJSON, undefined, 2)),
|
|
480
|
+
]);
|
|
481
|
+
}
|
|
@@ -13,7 +13,7 @@ export declare function generateHTML({ buildContext, appId, envId, description,
|
|
|
13
13
|
* 默认值为 undefined 否则应为 false
|
|
14
14
|
*/
|
|
15
15
|
enableLoading, publicPath, }: {
|
|
16
|
-
buildContext:
|
|
16
|
+
buildContext: Pick<ICommonBuildContext, 'materialLibs' | 'uin'>;
|
|
17
17
|
appId: string;
|
|
18
18
|
envId: string;
|
|
19
19
|
description?: string;
|
|
@@ -3,10 +3,10 @@ import { BuildType, WebpackModeType } from '../types/common';
|
|
|
3
3
|
import { RUNTIME } from '../../types';
|
|
4
4
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
5
5
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
6
|
-
import {
|
|
6
|
+
import { IAppCommonBuildContext } from '../mp/BuildContext';
|
|
7
7
|
import { IBuildWedaApp } from '../core';
|
|
8
8
|
export declare function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployOptions, ignoreInstall, cdnEndpoints, }: {
|
|
9
|
-
buildContext: Omit<
|
|
9
|
+
buildContext: Omit<IAppCommonBuildContext, 'mainAppData'>;
|
|
10
10
|
cals: IPlatformApp;
|
|
11
11
|
subAppCalsList: IPlatformApp[];
|
|
12
12
|
i18nConfig?: II18nConfig;
|
package/lib/builder/h5/index.js
CHANGED
|
@@ -113,8 +113,8 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
|
|
|
113
113
|
await (0, generate_1.generateProjectFiles)({
|
|
114
114
|
dependencies: processedDependencies,
|
|
115
115
|
cals,
|
|
116
|
+
sub_cals: subAppCalsList,
|
|
116
117
|
mainAppData,
|
|
117
|
-
subAppDataList,
|
|
118
118
|
appKey,
|
|
119
119
|
publicPath,
|
|
120
120
|
i18nConfig,
|
|
@@ -128,6 +128,7 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
|
|
|
128
128
|
_indexPage,
|
|
129
129
|
isPrivateMode,
|
|
130
130
|
expirationStartTimesnap: enableExpiredTag ? Date.now() : undefined,
|
|
131
|
+
usedComps: used,
|
|
131
132
|
});
|
|
132
133
|
console.timeEnd(runGenerateTag);
|
|
133
134
|
// // 构建 NPM 包
|
|
@@ -195,11 +196,28 @@ async function buildH5App({ buildContext, i18nConfig, extraData, cals: _cals, bu
|
|
|
195
196
|
// 普通 web 模式,且非hash模式,根据页面生成多份入口
|
|
196
197
|
if (!((_f = cals.extra) === null || _f === void 0 ? void 0 : _f.historyType) || cals.extra.historyType === types_1.HISTORY_TYPE.BROWSER) {
|
|
197
198
|
preHeatUrls.push(path_1.default.posix.join(basename || ''));
|
|
198
|
-
await Promise.all(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
await Promise.all([
|
|
200
|
+
...(cals.items || []).map((page) => {
|
|
201
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', page.id));
|
|
202
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', page.id, '/'));
|
|
203
|
+
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'));
|
|
204
|
+
}),
|
|
205
|
+
...(subAppCalsList || []).reduce((list, cals) => {
|
|
206
|
+
const { rootPath } = cals.extra || {};
|
|
207
|
+
const packageName = (0, util_1.normalizePackageName)(rootPath);
|
|
208
|
+
if (packageName) {
|
|
209
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', packageName));
|
|
210
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, '/'));
|
|
211
|
+
list.push(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, packageName, 'index.html')));
|
|
212
|
+
(cals.items || []).forEach((page) => {
|
|
213
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id));
|
|
214
|
+
preHeatUrls.push(path_1.default.posix.join(basename || '', packageName, page.id, '/'));
|
|
215
|
+
list.push(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, packageName, page.id, 'index.html')));
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return list;
|
|
219
|
+
}, []),
|
|
220
|
+
]);
|
|
203
221
|
}
|
|
204
222
|
await fs_extra_1.default.writeFile(path_1.default.resolve(h5BuildDir, webpack_2.OUTPUT_DIR, 'weda-manifest.json'), JSON.stringify({ preHeatUrls }, undefined, 2));
|
|
205
223
|
return h5BuildDir;
|
|
@@ -2,9 +2,9 @@ import { IWebRuntimeAppData } from '@cloudbase/lowcode-generator/lib/weapps-core
|
|
|
2
2
|
import { BuildAppProps } from '../core/index';
|
|
3
3
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
4
4
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
5
|
-
import {
|
|
5
|
+
import { IAppCommonBuildContext } from '../mp/BuildContext';
|
|
6
6
|
interface IWebpackCoreProps extends BuildAppProps {
|
|
7
|
-
buildContext: Omit<
|
|
7
|
+
buildContext: Omit<IAppCommonBuildContext, 'mainAppData'>;
|
|
8
8
|
cals: IPlatformApp;
|
|
9
9
|
appBuildDir: string;
|
|
10
10
|
mainAppData: IWebRuntimeAppData;
|
|
@@ -7,18 +7,9 @@ export interface ICommonBuildContext {
|
|
|
7
7
|
* 账号信息
|
|
8
8
|
*/
|
|
9
9
|
uin?: string;
|
|
10
|
-
/**
|
|
11
|
-
* 应用id
|
|
12
|
-
*/
|
|
13
|
-
appId: string;
|
|
14
|
-
projDir: string;
|
|
15
|
-
domain: string;
|
|
16
10
|
materialLibs: IMaterialItem[];
|
|
17
11
|
isProduction: boolean;
|
|
18
|
-
mainAppData: IWeAppData;
|
|
19
|
-
isMixMode: boolean;
|
|
20
12
|
rootPath?: string;
|
|
21
|
-
miniprogramPlugins?: IMiniprogramPlugin[];
|
|
22
13
|
debugMode?: boolean;
|
|
23
14
|
isBrowserMpBuilder?: boolean;
|
|
24
15
|
processCssUnit?: 'px' | 'rem' | 'rpx';
|
|
@@ -26,6 +17,16 @@ export interface ICommonBuildContext {
|
|
|
26
17
|
* 是否是私有化的环境
|
|
27
18
|
*/
|
|
28
19
|
isPrivateMode?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface IAppCommonBuildContext extends ICommonBuildContext {
|
|
22
|
+
/**
|
|
23
|
+
* 应用id
|
|
24
|
+
*/
|
|
25
|
+
appId: string;
|
|
26
|
+
projDir: string;
|
|
27
|
+
domain: string;
|
|
28
|
+
mainAppData: IWeAppData;
|
|
29
|
+
isMixMode: boolean;
|
|
29
30
|
/**
|
|
30
31
|
* 云开发sdk请求,js-sdk or wx.cloud
|
|
31
32
|
*/
|
|
@@ -59,16 +60,19 @@ export interface ICommonBuildContext {
|
|
|
59
60
|
*/
|
|
60
61
|
statusPageId?: string;
|
|
61
62
|
}
|
|
62
|
-
export interface
|
|
63
|
+
export interface IMpCommonBuildContext extends ICommonBuildContext {
|
|
64
|
+
/**
|
|
65
|
+
* 组件库目录独立子包
|
|
66
|
+
*/
|
|
67
|
+
enableAsyncMaterials?: boolean;
|
|
68
|
+
miniprogramPlugins?: IMiniprogramPlugin[];
|
|
69
|
+
}
|
|
70
|
+
export interface IBuildContext extends IAppCommonBuildContext, IMpCommonBuildContext {
|
|
63
71
|
/**
|
|
64
72
|
* 是否在页面层面添加节点
|
|
65
73
|
* 并设置 #page-root-id
|
|
66
74
|
*/
|
|
67
75
|
enablePageRoot?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* 组件库目录独立子包
|
|
70
|
-
*/
|
|
71
|
-
enableAsyncMaterials?: boolean;
|
|
72
76
|
/**
|
|
73
77
|
* weda 默认自身root
|
|
74
78
|
*/
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { IWeAppData, IPlugin } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { ICDN_ENDPOINTS_COFIG } from '../config';
|
|
3
|
-
import { IBuildContext } from './BuildContext';
|
|
3
|
+
import { IBuildContext, IMpCommonBuildContext } from './BuildContext';
|
|
4
4
|
import { BuildType } from '../types/common';
|
|
5
5
|
import { IPlatformApp } from '@cloudbase/cals';
|
|
6
6
|
import { IBuildWedaApp } from '../core';
|
|
7
|
+
export declare function generateWedaRootCommonFile({ buildContext, buildTypeList, localWedaRoot, loginConfigVersion, cssVarConfig, appId, nativeMode, filter, }: {
|
|
8
|
+
buildContext: IMpCommonBuildContext & Partial<Pick<IBuildContext, 'enableExpiredTag' | 'domain' | 'runtimeDynamicConfig'>>;
|
|
9
|
+
buildTypeList: BuildType[];
|
|
10
|
+
localWedaRoot: string;
|
|
11
|
+
appId?: string;
|
|
12
|
+
loginConfigVersion?: string;
|
|
13
|
+
cssVarConfig?: Object;
|
|
14
|
+
nativeMode?: boolean;
|
|
15
|
+
filter?: (src: string) => boolean;
|
|
16
|
+
}): Promise<void>;
|
|
7
17
|
export declare function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall, cdnEndpoints, mpConfig, }: {
|
|
8
18
|
buildContext: Omit<IBuildContext, 'wedaRoot'>;
|
|
9
19
|
weapps: IWeAppData[];
|
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.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = void 0;
|
|
29
|
+
exports.writeLowCodeFiles = exports.generateConfig = exports.generateWxMp = exports.generateWedaRootCommonFile = 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");
|
|
@@ -64,10 +64,87 @@ function patchBuildContext(ctx, calses) {
|
|
|
64
64
|
* 修改 buildContext 进行 miniprogramPlugins 精简
|
|
65
65
|
*/
|
|
66
66
|
ctx.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => used.component[plugin.name] || used.action[plugin.name]);
|
|
67
|
-
return { used
|
|
67
|
+
return { used };
|
|
68
68
|
}
|
|
69
|
+
async function generateWedaRootCommonFile({ buildContext, buildTypeList, localWedaRoot, loginConfigVersion, cssVarConfig, appId, nativeMode, filter = () => true, }) {
|
|
70
|
+
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!buildContext.isProduction);
|
|
71
|
+
const expirationStartTimesnap = buildContext.enableExpiredTag ? Date.now() : 0;
|
|
72
|
+
const cssVarMap = Object.entries((0, theme_1.mergeCssVarConfig)(cssVarConfig, 'MP'))
|
|
73
|
+
.map(([key, _value]) => {
|
|
74
|
+
const value = _value || '';
|
|
75
|
+
return [key, value.replace(/;$/, '')];
|
|
76
|
+
})
|
|
77
|
+
.reduce((map, [key, value]) => {
|
|
78
|
+
map[key] = value;
|
|
79
|
+
return map;
|
|
80
|
+
}, {}) || {};
|
|
81
|
+
let customLoginConfig;
|
|
82
|
+
let loginConfigPathname = loginConfigVersion
|
|
83
|
+
? (0, cals_1.generateCustomLoginConfigPathname)({ appId: appId || '', version: loginConfigVersion })
|
|
84
|
+
: '';
|
|
85
|
+
if (loginConfigPathname && buildContext.domain) {
|
|
86
|
+
const url = `https://${buildContext.domain}${loginConfigPathname}`;
|
|
87
|
+
try {
|
|
88
|
+
const { data } = await axios_1.default.get(url, { responseType: 'json' });
|
|
89
|
+
if (data) {
|
|
90
|
+
customLoginConfig = data;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
console.error('预置获取登录配置失败:', url, e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const wedaRootFileData = {
|
|
98
|
+
'common/style.js': {},
|
|
99
|
+
'common/util.js': {
|
|
100
|
+
skipCheckAuth: process.env.SKIP_CHECK_AUTH,
|
|
101
|
+
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
102
|
+
expirationStartTimesnap,
|
|
103
|
+
runtimeDynamicConfig: buildContext.runtimeDynamicConfig || {},
|
|
104
|
+
RUNTIME_CONFIG_URL: index_1.RUNTIME_CONFIG_URL,
|
|
105
|
+
loginConfigPathname,
|
|
106
|
+
customLoginConfig: customLoginConfig ? JSON.stringify(customLoginConfig, undefined, 2) : 'null',
|
|
107
|
+
},
|
|
108
|
+
'common/cloud-sdk.js': {},
|
|
109
|
+
'common/widget.js': {},
|
|
110
|
+
'common/weapp-page.js': {
|
|
111
|
+
expirationStartTimesnap,
|
|
112
|
+
pageStyle: JSON.stringify(cssVarMap || {}, undefined, 2),
|
|
113
|
+
},
|
|
114
|
+
'common/weapp-component.js': {
|
|
115
|
+
nativeMode,
|
|
116
|
+
},
|
|
117
|
+
'common/merge-renderer.js': {
|
|
118
|
+
dataPropNames: wxmlDataPrefix,
|
|
119
|
+
debug: buildContext.debugMode,
|
|
120
|
+
},
|
|
121
|
+
'common/data-patch.js': {},
|
|
122
|
+
'common/event-emitter.js': {},
|
|
123
|
+
'common/watch.js': {},
|
|
124
|
+
'common/constant.js': {
|
|
125
|
+
REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
|
|
126
|
+
},
|
|
127
|
+
'common/query.js': {},
|
|
128
|
+
'common/flow.js': {},
|
|
129
|
+
'common/info': {},
|
|
130
|
+
'common/placeholder': {},
|
|
131
|
+
/**
|
|
132
|
+
* 使用微信的 modal
|
|
133
|
+
* 暂时保留内部实现待之后使用
|
|
134
|
+
*/
|
|
135
|
+
// 'common/privacyModal': {},
|
|
136
|
+
// 'common/modal': {},
|
|
137
|
+
/**
|
|
138
|
+
* 调试用
|
|
139
|
+
*/
|
|
140
|
+
// 'common/behaviors.js': {},
|
|
141
|
+
};
|
|
142
|
+
console.log(`Generating ${em('weda root')} files`);
|
|
143
|
+
await (0, generateFiles_1.default)(wedaRootFileData, templateDir, localWedaRoot, filter);
|
|
144
|
+
}
|
|
145
|
+
exports.generateWedaRootCommonFile = generateWedaRootCommonFile;
|
|
69
146
|
async function generateWxMp({ buildContext: _buildContext, weapps, calses, deployOptions, options, buildTypeList, ignoreInstall = false, cdnEndpoints = {}, mpConfig = {}, }) {
|
|
70
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
147
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
71
148
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
72
149
|
console.time(operationLabel);
|
|
73
150
|
console.log(`Generating ${em('Wexin MiniProgram')} to ${_buildContext.projDir}`);
|
|
@@ -104,8 +181,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
104
181
|
const templateLib = (0, cals_1.processTemplatesToDependiencies)((_b = calses === null || calses === void 0 ? void 0 : calses[0]) === null || _b === void 0 ? void 0 : _b.templates);
|
|
105
182
|
_buildContext.materialLibs = [..._buildContext.materialLibs, templateLib];
|
|
106
183
|
}
|
|
107
|
-
const { uin = '', appId, projDir, materialLibs: materials,
|
|
108
|
-
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
|
|
184
|
+
const { uin = '', appId, projDir, materialLibs: materials, mainAppData, domain, isPrivateMode = false, endpointType = '', isBrowserMpBuilder = false, } = _buildContext;
|
|
109
185
|
const hasLowcodePkg = weapps.find((item) => !item.mpPkgUrl);
|
|
110
186
|
// #1 generate project files
|
|
111
187
|
if (!mainAppData.mpPkgUrl) {
|
|
@@ -131,7 +207,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
131
207
|
};
|
|
132
208
|
// #1.5 安装依赖库,生成 materials 目录副作用修改了buildContext 因此需要早于页面生成
|
|
133
209
|
if (hasLowcodePkg) {
|
|
134
|
-
await (0, materials_1.installMaterials)(buildContext, localWedaRoot, used
|
|
210
|
+
await (0, materials_1.installMaterials)(buildContext, localWedaRoot, used);
|
|
135
211
|
}
|
|
136
212
|
// #2 生成主包, 若主包为代码包上游已经处理过,不再处理
|
|
137
213
|
if (mainAppData.mpPkgUrl) {
|
|
@@ -147,84 +223,21 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
147
223
|
isPrivateMode,
|
|
148
224
|
endpointType,
|
|
149
225
|
}, localWedaRoot);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}, {}) || {};
|
|
160
|
-
let customLoginConfig;
|
|
161
|
-
let loginConfigPathname = ((_f = (_e = calses[0]) === null || _e === void 0 ? void 0 : _e.extra) === null || _f === void 0 ? void 0 : _f.loginConfigVersion)
|
|
162
|
-
? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_h = (_g = calses[0]) === null || _g === void 0 ? void 0 : _g.extra) === null || _h === void 0 ? void 0 : _h.loginConfigVersion })
|
|
163
|
-
: '';
|
|
164
|
-
if (loginConfigPathname) {
|
|
165
|
-
const url = `https://${domain}${loginConfigPathname}`;
|
|
166
|
-
try {
|
|
167
|
-
const { data } = await axios_1.default.get(url, { responseType: 'json' });
|
|
168
|
-
if (data) {
|
|
169
|
-
customLoginConfig = data;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
console.error('预置获取登录配置失败:', url, e);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const wedaRootFileData = {
|
|
177
|
-
'common/style.js': {},
|
|
178
|
-
'common/util.js': {
|
|
179
|
-
skipCheckAuth: process.env.SKIP_CHECK_AUTH,
|
|
180
|
-
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
181
|
-
expirationStartTimesnap,
|
|
182
|
-
runtimeDynamicConfig: buildContext.runtimeDynamicConfig,
|
|
183
|
-
RUNTIME_CONFIG_URL: index_1.RUNTIME_CONFIG_URL,
|
|
184
|
-
loginConfigPathname: ((_k = (_j = calses[0]) === null || _j === void 0 ? void 0 : _j.extra) === null || _k === void 0 ? void 0 : _k.loginConfigVersion)
|
|
185
|
-
? (0, cals_1.generateCustomLoginConfigPathname)({ appId, version: (_m = (_l = calses[0]) === null || _l === void 0 ? void 0 : _l.extra) === null || _m === void 0 ? void 0 : _m.loginConfigVersion })
|
|
186
|
-
: '',
|
|
187
|
-
customLoginConfig: customLoginConfig ? JSON.stringify(customLoginConfig, undefined, 2) : 'null',
|
|
188
|
-
},
|
|
189
|
-
'common/widget.js': {},
|
|
190
|
-
'common/weapp-page.js': {
|
|
191
|
-
expirationStartTimesnap,
|
|
192
|
-
pageStyle: JSON.stringify(cssVarMap || {}, undefined, 2),
|
|
193
|
-
},
|
|
194
|
-
'common/weapp-component.js': {},
|
|
195
|
-
'common/merge-renderer.js': {
|
|
196
|
-
dataPropNames: wxmlDataPrefix,
|
|
197
|
-
debug: buildContext.debugMode,
|
|
198
|
-
},
|
|
199
|
-
'common/data-patch.js': {},
|
|
200
|
-
'common/event-emitter.js': {},
|
|
201
|
-
'common/watch.js': {},
|
|
202
|
-
'common/constant.js': {
|
|
203
|
-
REPEATER: JSON.stringify(config_1.REPEATER, undefined, 2),
|
|
204
|
-
},
|
|
205
|
-
'common/query.js': {},
|
|
206
|
-
'common/flow.js': {},
|
|
207
|
-
'common/info': {},
|
|
208
|
-
'common/placeholder': {},
|
|
209
|
-
/**
|
|
210
|
-
* 使用微信的 modal
|
|
211
|
-
* 暂时保留内部实现待之后使用
|
|
212
|
-
*/
|
|
213
|
-
// 'common/privacyModal': {},
|
|
214
|
-
// 'common/modal': {},
|
|
215
|
-
/**
|
|
216
|
-
* 调试用
|
|
217
|
-
*/
|
|
218
|
-
// 'common/behaviors.js': {},
|
|
226
|
+
await generateWedaRootCommonFile({
|
|
227
|
+
buildContext,
|
|
228
|
+
buildTypeList,
|
|
229
|
+
localWedaRoot,
|
|
230
|
+
appId,
|
|
231
|
+
loginConfigVersion: (_d = (_c = calses[0]) === null || _c === void 0 ? void 0 : _c.extra) === null || _d === void 0 ? void 0 : _d.loginConfigVersion,
|
|
232
|
+
cssVarConfig: (_f = (_e = calses[0]) === null || _e === void 0 ? void 0 : _e.theme) === null || _f === void 0 ? void 0 : _f.cssVarConfig,
|
|
233
|
+
});
|
|
234
|
+
await (0, generateFiles_1.default)({
|
|
219
235
|
'package.json': {
|
|
220
236
|
appId,
|
|
221
237
|
importJSSDK: endpointType === 'tcb-api',
|
|
222
238
|
extraDeps: resolveNpmDeps(weapps, materials),
|
|
223
|
-
cdnEndpoints,
|
|
224
239
|
},
|
|
225
|
-
};
|
|
226
|
-
console.log(`Generating ${em('weda root')} files`);
|
|
227
|
-
await (0, generateFiles_1.default)(wedaRootFileData, templateDir, localWedaRoot);
|
|
240
|
+
}, templateDir, localWedaRoot);
|
|
228
241
|
// 生成数据源
|
|
229
242
|
const officialLib = materials.find((item) => item.name === cals_1.OFFICIAL_LIB_KEY);
|
|
230
243
|
const datasourceFileData = {
|
|
@@ -236,9 +249,9 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
236
249
|
appID: appId,
|
|
237
250
|
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
238
251
|
isProd: (deployOptions === null || deployOptions === void 0 ? void 0 : deployOptions.mode) === types_1.DEPLOY_MODE.UPLOAD,
|
|
239
|
-
clientID: ((
|
|
252
|
+
clientID: ((_g = mainAppData.extra) === null || _g === void 0 ? void 0 : _g.enableLoginStatusShare)
|
|
240
253
|
? mainAppData.envId
|
|
241
|
-
: (
|
|
254
|
+
: (_h = mainAppData.extra) === null || _h === void 0 ? void 0 : _h.clientId,
|
|
242
255
|
cdnEndpoints,
|
|
243
256
|
builderVersion: core_1.version || '',
|
|
244
257
|
officialLibVersion: (officialLib === null || officialLib === void 0 ? void 0 : officialLib.version) || '',
|
|
@@ -288,8 +301,8 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
288
301
|
projectConfigJson.setting = {
|
|
289
302
|
...projectConfigJson.setting,
|
|
290
303
|
...projConfig.setting,
|
|
291
|
-
packNpmRelationList: ((
|
|
292
|
-
? (0, mp_config_1.mergePackNpmRelationList)(projConfig.setting.packNpmRelationList, (
|
|
304
|
+
packNpmRelationList: ((_j = projConfig.setting) === null || _j === void 0 ? void 0 : _j.packNpmRelationList) || ((_k = projectConfigJson.setting) === null || _k === void 0 ? void 0 : _k.packNpmRelationList)
|
|
305
|
+
? (0, mp_config_1.mergePackNpmRelationList)(projConfig.setting.packNpmRelationList, (_l = projectConfigJson.setting) === null || _l === void 0 ? void 0 : _l.packNpmRelationList)
|
|
293
306
|
: undefined,
|
|
294
307
|
};
|
|
295
308
|
const wedaRoot = path_1.default.posix.join('./', projectConfigJson.miniprogramRoot || '/', projectConfigJson.wedaRoot || '');
|
|
@@ -309,7 +322,7 @@ async function generateWxMp({ buildContext: _buildContext, weapps, calses, deplo
|
|
|
309
322
|
}
|
|
310
323
|
const appJsonPath = path_1.default.join(miniprogramRoot, 'app.json');
|
|
311
324
|
const appJson = await fs.readJson(appJsonPath);
|
|
312
|
-
appJson.subpackages = (0, mp_config_1.mergeSubPackages)(((
|
|
325
|
+
appJson.subpackages = (0, mp_config_1.mergeSubPackages)(((_o = (_m = appJson.subpackages) === null || _m === void 0 ? void 0 : _m.filter) === null || _o === void 0 ? void 0 : _o.call(_m, (item) => item.name !== 'wd-sys-module' && item.name !== 'wd-sys-materials')) || [], appConfig.subpackages);
|
|
313
326
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
314
327
|
}
|
|
315
328
|
else {
|
|
@@ -473,7 +486,7 @@ async function generatePkg(ctx, { cals, weapp }, appRoot, pageConfigs) {
|
|
|
473
486
|
if (weapp.mpPkgUrl) {
|
|
474
487
|
// 清空历史文件,使用zip覆盖
|
|
475
488
|
console.log(`Removing ${appRoot}`);
|
|
476
|
-
await (0, generateFiles_1.cleanDir)(appRoot, [
|
|
489
|
+
await (0, generateFiles_1.cleanDir)(appRoot, [config_1.materialsDirName]);
|
|
477
490
|
await (0, net_1.downloadZip)(weapp.mpPkgUrl, appRoot, ctx.isBrowserMpBuilder);
|
|
478
491
|
if (fs.existsSync(path_1.default.join(appRoot, '__MACOSX'))) {
|
|
479
492
|
await fs.remove(path_1.default.join(appRoot, '__MACOSX'));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IWeAppCode, ICompositedComponent } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
|
-
import { IBuildContext } from './BuildContext';
|
|
3
|
-
export declare function writeCode2file(ctx: IBuildContext
|
|
2
|
+
import { IBuildContext, IMpCommonBuildContext } from './BuildContext';
|
|
3
|
+
export declare function writeCode2file(ctx: IBuildContext | (IMpCommonBuildContext & {
|
|
4
|
+
isMixMode?: undefined;
|
|
5
|
+
}), mod: IWeAppCode, lowcodeRootDir: string, opts?: {
|
|
4
6
|
pageId?: string;
|
|
5
7
|
appDir?: string;
|
|
6
8
|
comp?: ICompositedComponent;
|
|
7
|
-
}, themeCode?: ''): Promise<void>;
|
|
9
|
+
}, themeCode?: '', externalAPIImport?: boolean): Promise<void>;
|
|
8
10
|
export declare function handle$page(code: string): string;
|
|
9
11
|
export declare function handle$comp(code: string): string;
|