@cloudbase/lowcode-builder 0.1.26 → 1.0.0
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 +1 -3
- package/lib/builder/core/index.js +42 -52
- package/lib/builder/h5/compile.d.ts +1 -1
- package/lib/builder/h5/compile.js +59 -20
- package/lib/builder/h5/copy.js +2 -4
- package/lib/builder/h5/generate.js +3 -3
- package/lib/builder/h5/index.d.ts +5 -4
- package/lib/builder/h5/index.js +25 -14
- package/lib/builder/h5/material.js +6 -11
- package/lib/builder/h5/npm.js +6 -5
- package/lib/builder/mp/index.js +38 -49
- package/lib/builder/mp/materials.js +25 -18
- package/lib/builder/mp/mixMode.js +7 -10
- package/lib/builder/mp/mp_config.js +2 -3
- package/lib/builder/mp/wxml.js +1 -1
- package/lib/builder/service/webpack.d.ts +7 -1
- package/lib/builder/service/webpack.js +97 -24
- package/lib/builder/types/common.d.ts +1 -1
- package/lib/builder/types/common.js +2 -1
- package/lib/builder/util/common.js +1 -4
- package/lib/builder/util/generateFiles.js +12 -10
- package/lib/builder/util/mp.js +2 -8
- package/lib/builder.web.js +71 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +6 -0
- package/lib/types.d.ts +1 -0
- package/lib/types.js +11 -0
- package/package.json +3 -8
- package/template/html/index.html.ejs +59 -29
- package/template/mp/common/weapp-page.js +23 -1
- package/template/mp/package.json +1 -1
- package/template/mp/page/index.js +2 -1
- package/template/package.json +5 -2
- package/template/webpack/getCSSModuleLocalIdent.js +28 -0
- package/template/webpack/web.prod.js +112 -103
- package/template/src/app/common.js +0 -13
- package/template/src/app/global-api.js +0 -99
- package/template/src/app/handlers.js +0 -13
- package/template/src/app/material-actions.js +0 -16
- package/template/src/app/mountAppApis.js +0 -25
- package/template/src/app/mountMpApis.js +0 -4
- package/template/src/datasources/config.js.tpl +0 -23
- package/template/src/datasources/dataset-profiles.js.tpl +0 -5
- package/template/src/datasources/datasource-profiles.js.tpl +0 -4
- package/template/src/datasources/index.js +0 -31
- package/template/src/handlers/FieldMiddleware/renderer.jsx +0 -331
- package/template/src/handlers/HotAreas.js +0 -36
- package/template/src/handlers/PositionHandler.jsx +0 -8
- package/template/src/handlers/actionHandler/utils.js +0 -149
- package/template/src/handlers/componentEventActionEmitter.js +0 -29
- package/template/src/handlers/componentNodeMap.js +0 -24
- package/template/src/handlers/controller.js +0 -5
- package/template/src/handlers/emitComponentEvent.js +0 -8
- package/template/src/handlers/eventListener/componentEventListener.js +0 -15
- package/template/src/handlers/eventListener/hotAreaEventListener.js +0 -32
- package/template/src/handlers/eventListener/index.js +0 -29
- package/template/src/handlers/eventListener/pageEventListener.js +0 -11
- package/template/src/handlers/eventListener/types.js +0 -32
- package/template/src/handlers/hooks/index.js +0 -14
- package/template/src/handlers/initWebEnv.js +0 -4
- package/template/src/handlers/injectStyle.js +0 -14
- package/template/src/handlers/instanceMap.js +0 -39
- package/template/src/handlers/lifecycle.js +0 -232
- package/template/src/handlers/render.jsx +0 -131
- package/template/src/handlers/utils/common.js +0 -151
- package/template/src/handlers/utils/eventProxy.js +0 -64
- package/template/src/handlers/utils/events.js +0 -8
- package/template/src/handlers/utils/index.js +0 -4
- package/template/src/handlers/utils/widgets.js +0 -320
- package/template/src/index.jsx +0 -142
- package/template/src/index.less +0 -119
- package/template/src/libraries/default-lib/wx_yypt_report_v2.js +0 -441
- package/template/src/pages/app.tpl +0 -124
- package/template/src/router/index.tpl +0 -28
- package/template/src/store/computed.js +0 -11
- package/template/src/store/index.js +0 -40
- package/template/src/utils/ScanCodeComponent.js +0 -396
- package/template/src/utils/date.js +0 -324
- package/template/src/utils/history.js +0 -72
- package/template/src/utils/index.js +0 -67
- package/template/src/utils/kbone.js +0 -18
- package/template/src/utils/monitor-jssdk.min.js +0 -763
- package/template/src/utils/request.js +0 -5
- package/template/src/utils/scan-code-action.js +0 -27
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { IInstallOpts } from '../service/webpack';
|
|
2
|
-
export { getCompileDirs } from '../util';
|
|
3
1
|
import { IMaterialItem, IWeAppData, IPlugin, IExtraData } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
4
2
|
import { BuildType, GenerateMpType, WebpackBuildCallBack, WebpackModeType } from '../types/common';
|
|
5
3
|
import { DEPLOY_MODE, RUNTIME } from '../../types';
|
|
@@ -40,8 +38,8 @@ export interface IBuildWedaApp extends IBaseAppProps {
|
|
|
40
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
40
|
export declare function cleanComponentDir(): Promise<void>;
|
|
43
|
-
export declare function installDep(dir: any, opts?: IInstallOpts): Promise<void>;
|
|
44
41
|
export declare const version: any;
|
|
45
42
|
export { getFiles, fileToZip, strToBuf } from '../util/generateFiles';
|
|
46
43
|
export { downloadZip } from '../util/net';
|
|
44
|
+
export { getCompileDirs } from '../util';
|
|
47
45
|
export default buildWedaApp;
|
|
@@ -3,19 +3,16 @@ 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.downloadZip = exports.strToBuf = exports.fileToZip = exports.getFiles = exports.version = exports.
|
|
6
|
+
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
|
-
const
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const util_1 = require("../util");
|
|
10
|
-
var util_2 = require("../util");
|
|
11
|
-
Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
|
|
12
11
|
const common_1 = require("../types/common");
|
|
13
12
|
const index_1 = require("../mp/index");
|
|
14
|
-
const path_1 = __importDefault(require("path"));
|
|
15
13
|
const types_1 = require("../../types");
|
|
16
14
|
const mixMode_1 = require("../mp/mixMode");
|
|
17
15
|
const index_2 = require("../h5/index");
|
|
18
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
19
16
|
const common_2 = require("../../utils/common");
|
|
20
17
|
const postProcess_1 = require("../../utils/postProcess");
|
|
21
18
|
const net_1 = require("../util/net");
|
|
@@ -29,27 +26,24 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
29
26
|
console.error('无效的应用配置');
|
|
30
27
|
return;
|
|
31
28
|
}
|
|
32
|
-
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
33
|
-
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) ||
|
|
34
|
-
[];
|
|
35
29
|
const { mode: deployMode = types_1.DEPLOY_MODE.PREVIEW } = deployOptions;
|
|
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);
|
|
36
31
|
console.log('domain', domain);
|
|
37
32
|
console.log('应用名', appKey);
|
|
38
33
|
console.log('生成模式', generateMpType);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
try {
|
|
34
|
+
console.log('生成路径', appBuildDir);
|
|
35
|
+
try {
|
|
36
|
+
const startTime = Date.now();
|
|
37
|
+
if (buildTypeList.includes(common_1.BuildType.MP)) {
|
|
38
|
+
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
39
|
+
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
|
+
const apps = [mainAppSerializeData, ...subAppSerializeDataList];
|
|
43
|
+
if (isBrowserMpBuilder) {
|
|
44
|
+
// 尽早下载物料
|
|
45
|
+
await (0, net_1.downloadBrowserMaterial)(output === null || output === void 0 ? void 0 : output.path);
|
|
46
|
+
}
|
|
53
47
|
const result = await (0, index_1.generateWxMp)({
|
|
54
48
|
weapps: apps,
|
|
55
49
|
projDir: appBuildDir,
|
|
@@ -99,34 +93,32 @@ async function buildWedaApp({ cals, subAppCalsList = [], dependencies = [], appK
|
|
|
99
93
|
});
|
|
100
94
|
return outDir;
|
|
101
95
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
runtime,
|
|
120
|
-
deployMode,
|
|
121
|
-
ignoreInstall,
|
|
122
|
-
domain,
|
|
123
|
-
});
|
|
124
|
-
cb &&
|
|
125
|
-
cb(null, {
|
|
96
|
+
else {
|
|
97
|
+
const h5BuildDir = await (0, index_2.buildH5App)({
|
|
98
|
+
appKey,
|
|
99
|
+
buildDir: appBuildDir,
|
|
100
|
+
dependencies,
|
|
101
|
+
cals,
|
|
102
|
+
subAppCalsList,
|
|
103
|
+
extraData,
|
|
104
|
+
buildTypeList,
|
|
105
|
+
mode,
|
|
106
|
+
devTool,
|
|
107
|
+
runtime,
|
|
108
|
+
deployMode,
|
|
109
|
+
ignoreInstall,
|
|
110
|
+
domain,
|
|
111
|
+
});
|
|
112
|
+
cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
126
113
|
outDir: h5BuildDir,
|
|
127
114
|
timeElapsed: Date.now() - startTime,
|
|
128
115
|
});
|
|
129
|
-
|
|
116
|
+
return h5BuildDir;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
cb === null || cb === void 0 ? void 0 : cb(e);
|
|
121
|
+
throw e;
|
|
130
122
|
}
|
|
131
123
|
}
|
|
132
124
|
exports.buildWedaApp = buildWedaApp;
|
|
@@ -134,10 +126,6 @@ async function cleanComponentDir() {
|
|
|
134
126
|
return fs_extra_1.default.emptyDir((0, util_1.getCompileDirs)().materialsDir);
|
|
135
127
|
}
|
|
136
128
|
exports.cleanComponentDir = cleanComponentDir;
|
|
137
|
-
function installDep(dir, opts = {}) {
|
|
138
|
-
return (0, webpack_1.installDependencies)(dir, opts);
|
|
139
|
-
}
|
|
140
|
-
exports.installDep = installDep;
|
|
141
129
|
exports.version = pkg.version;
|
|
142
130
|
var generateFiles_1 = require("../util/generateFiles");
|
|
143
131
|
Object.defineProperty(exports, "getFiles", { enumerable: true, get: function () { return generateFiles_1.getFiles; } });
|
|
@@ -145,4 +133,6 @@ Object.defineProperty(exports, "fileToZip", { enumerable: true, get: function ()
|
|
|
145
133
|
Object.defineProperty(exports, "strToBuf", { enumerable: true, get: function () { return generateFiles_1.strToBuf; } });
|
|
146
134
|
var net_2 = require("../util/net");
|
|
147
135
|
Object.defineProperty(exports, "downloadZip", { enumerable: true, get: function () { return net_2.downloadZip; } });
|
|
136
|
+
var util_2 = require("../util");
|
|
137
|
+
Object.defineProperty(exports, "getCompileDirs", { enumerable: true, get: function () { return util_2.getCompileDirs; } });
|
|
148
138
|
exports.default = buildWedaApp;
|
|
@@ -7,4 +7,4 @@ export interface ICompileOpts {
|
|
|
7
7
|
generateMpPath?: string;
|
|
8
8
|
webpackMode: WebpackModeType;
|
|
9
9
|
}
|
|
10
|
-
export declare function startCompile(options: ICompileOpts, cb
|
|
10
|
+
export declare function startCompile(options: ICompileOpts, cb: (error: any, data?: any) => void): void;
|
|
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.startCompile = void 0;
|
|
7
|
-
const
|
|
7
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
8
10
|
const runningCompilations = {};
|
|
9
11
|
function startCompile(options, cb) {
|
|
10
12
|
const key = options.configPath;
|
|
@@ -13,28 +15,65 @@ function startCompile(options, cb) {
|
|
|
13
15
|
console.log(`Compiling ${options.configPath} already running`);
|
|
14
16
|
return;
|
|
15
17
|
}
|
|
16
|
-
console.log(
|
|
18
|
+
console.log(`Running webpack by ${options.configPath}`);
|
|
17
19
|
console.log('Running webpack mode ', options.webpackMode);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
console.log('【编译中】正在进行生产环境编译,请稍等...');
|
|
21
|
+
fs_extra_1.default.emptyDirSync(path_1.default.resolve(options.appBuildDir, 'preview'));
|
|
22
|
+
const watching = (0, webpack_1.default)(require(options.configPath), async (err, stats) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
console.error('webpack config error', err.stack || err);
|
|
25
|
+
if (err.details) {
|
|
26
|
+
console.error('webpack config error detail', err.details);
|
|
27
|
+
}
|
|
28
|
+
cb === null || cb === void 0 ? void 0 : cb(err);
|
|
29
|
+
delete runningCompilations[key];
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const info = stats.toJson('minimal');
|
|
33
|
+
if (stats.hasErrors()) {
|
|
34
|
+
console.error('Webpack compilation errors', info.errors.join('\n'));
|
|
35
|
+
cb === null || cb === void 0 ? void 0 : cb(info.errors);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
let { endTime = 0, startTime = 0 } = stats;
|
|
39
|
+
cb === null || cb === void 0 ? void 0 : cb(null, {
|
|
40
|
+
outDir: options.appBuildDir,
|
|
41
|
+
timeElapsed: endTime - startTime,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (stats.hasWarnings()) {
|
|
45
|
+
console.warn('webpack compiling warnings', info.warnings.join('\n'));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (!(watching instanceof webpack_1.default.Compiler)) {
|
|
49
|
+
runningCompilations[key] = false;
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
console.error('【失败】编译失败,请查看上面的日志修改后重试');
|
|
51
|
+
else {
|
|
52
|
+
runningCompilations[key] = true;
|
|
36
53
|
}
|
|
37
|
-
|
|
54
|
+
// if (options.webpackMode === WebpackModeType.PRODUCTION) {
|
|
55
|
+
// try {
|
|
56
|
+
// console.log('【编译中】正在进行生产环境编译,请稍等...');
|
|
57
|
+
// let startTime = Date.now();
|
|
58
|
+
// runningCompilations[key] = true;
|
|
59
|
+
// const webpackProcess = spawn.sync('npm', ['run', 'build-web'], {
|
|
60
|
+
// cwd: options.appBuildDir,
|
|
61
|
+
// env: process.env,
|
|
62
|
+
// stdio: ['inherit', 'inherit', 'pipe'],
|
|
63
|
+
// });
|
|
64
|
+
// const { stderr } = webpackProcess;
|
|
65
|
+
// if (stderr) {
|
|
66
|
+
// throw new Error(stderr.toString());
|
|
67
|
+
// }
|
|
68
|
+
// cb?.(null, {
|
|
69
|
+
// outDir: options.appBuildDir,
|
|
70
|
+
// timeElapsed: Date.now() - startTime,
|
|
71
|
+
// });
|
|
72
|
+
// } catch (e) {
|
|
73
|
+
// cb?.([e.message]);
|
|
74
|
+
// console.error('【失败】编译失败,请查看上面的日志修改后重试');
|
|
75
|
+
// }
|
|
76
|
+
// runningCompilations[key] = false;
|
|
38
77
|
// }
|
|
39
78
|
}
|
|
40
79
|
exports.startCompile = startCompile;
|
package/lib/builder/h5/copy.js
CHANGED
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.copyMaterialLibraries = exports.runCopy = void 0;
|
|
26
26
|
const path = __importStar(require("path"));
|
|
27
27
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
|
-
const fs_extra_2 = require("fs-extra");
|
|
29
28
|
const chalk_1 = __importDefault(require("chalk"));
|
|
30
29
|
const config_1 = require("../config");
|
|
31
30
|
const generateFiles_1 = require("../util/generateFiles");
|
|
@@ -40,7 +39,7 @@ async function runCopy(appBuildDir, webRuntimeAppData, i18nConfig) {
|
|
|
40
39
|
console.log(chalk_1.default.blue.bold('Copying files:'));
|
|
41
40
|
for (const entry of srcFiles) {
|
|
42
41
|
const dstFile = path.join(appBuildDir, entry);
|
|
43
|
-
await
|
|
42
|
+
await fs_extra_1.default.copy(path.join(config_1.appTemplateDir, entry), dstFile);
|
|
44
43
|
}
|
|
45
44
|
await (0, generateFiles_1.writeFile)(path.join(appBuildDir, 'mainAppData.json'), JSON.stringify(webRuntimeAppData, null, 2));
|
|
46
45
|
const fileDir = path.join(appBuildDir, 'src/i18n/');
|
|
@@ -79,8 +78,7 @@ async function copyMaterialLibraries(dependencies = [], materialsDir, appBuildDi
|
|
|
79
78
|
});
|
|
80
79
|
const nodeModulesPath = path.join(materialDir, 'node_modules');
|
|
81
80
|
const targetNodeModulesPath = path.join(librariesDir, 'node_modules');
|
|
82
|
-
if (fs_extra_1.default.existsSync(nodeModulesPath) &&
|
|
83
|
-
!fs_extra_1.default.existsSync(targetNodeModulesPath)) {
|
|
81
|
+
if (fs_extra_1.default.existsSync(nodeModulesPath) && !fs_extra_1.default.existsSync(targetNodeModulesPath)) {
|
|
84
82
|
await fs_extra_1.default.symlink(nodeModulesPath, targetNodeModulesPath, 'dir');
|
|
85
83
|
}
|
|
86
84
|
// 副作用修改了dependence定义,trycatch 不阻塞主流程
|
|
@@ -11,7 +11,7 @@ const util_1 = require("../util");
|
|
|
11
11
|
const common_1 = require("../util/common");
|
|
12
12
|
const webpack_1 = require("../service/webpack");
|
|
13
13
|
const config_1 = require("../config");
|
|
14
|
-
const lodash_1 =
|
|
14
|
+
const lodash_1 = require("lodash");
|
|
15
15
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
16
|
const common_2 = require("../types/common");
|
|
17
17
|
/**
|
|
@@ -28,12 +28,12 @@ async function generateHTML({ appId, appBuildDir, jsApis, mode, devTool, isBuild
|
|
|
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' });
|
|
31
|
-
await fs_extra_1.default.writeFile(dstFilePath, lodash_1.
|
|
31
|
+
await fs_extra_1.default.writeFile(dstFilePath, (0, lodash_1.template)(packageTpl)({
|
|
32
32
|
appId,
|
|
33
33
|
title: '',
|
|
34
34
|
desc: 'WeDa构建的应用',
|
|
35
35
|
canUseVite: (0, util_1.canUseVite)(mode, devTool),
|
|
36
|
-
jsApis: lodash_1.
|
|
36
|
+
jsApis: (0, lodash_1.uniq)(jsApis),
|
|
37
37
|
mode,
|
|
38
38
|
isBuildApp,
|
|
39
39
|
isAdminPortal: (0, common_2.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { IMaterialItem,
|
|
1
|
+
import { IMaterialItem, 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
|
+
export declare function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList, subAppCalsList, mode, devTool, runtime, deployMode, ignoreInstall, domain, }: {
|
|
5
6
|
appKey: string;
|
|
6
7
|
buildDir: string;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
cals: IPlatformApp;
|
|
9
|
+
subAppCalsList: IPlatformApp[];
|
|
9
10
|
dependencies: IMaterialItem[];
|
|
10
11
|
i18nConfig?: II18nConfig;
|
|
11
12
|
buildTypeList: BuildType[];
|
package/lib/builder/h5/index.js
CHANGED
|
@@ -18,11 +18,14 @@ const compile_1 = require("./compile");
|
|
|
18
18
|
const util_1 = require("../util");
|
|
19
19
|
const types_1 = require("../../types");
|
|
20
20
|
const mp_1 = require("../mp");
|
|
21
|
-
|
|
21
|
+
const common_2 = require("../../utils/common");
|
|
22
|
+
async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraData, cals, buildTypeList = [common_1.BuildType.WEB], subAppCalsList, mode, devTool, runtime = types_1.RUNTIME.NONE, deployMode = types_1.DEPLOY_MODE.PREVIEW, ignoreInstall = false, domain = '', }) {
|
|
22
23
|
var _a, _b;
|
|
23
24
|
try {
|
|
24
25
|
const { materialsDir } = runtime === types_1.RUNTIME.CI ? (0, util_1.getCompileDirs)(appKey) : (0, util_1.getCompileDirs)('app');
|
|
25
26
|
const h5BuildDir = path_1.default.join(buildDir, 'h5');
|
|
27
|
+
const mainAppSerializeData = (0, common_2.processCals2WeappsData)(cals, dependencies);
|
|
28
|
+
const subAppSerializeDataList = (subAppCalsList === null || subAppCalsList === void 0 ? void 0 : subAppCalsList.map((item) => (0, common_2.processCals2WeappsData)(item, dependencies))) || [];
|
|
26
29
|
const buildContext = {
|
|
27
30
|
projDir: buildDir,
|
|
28
31
|
appId: appKey,
|
|
@@ -47,19 +50,17 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
47
50
|
}
|
|
48
51
|
const subAppDataList = subAppSerializeDataList.map((sub) => (0, weapps_core_1.deserialize)(sub));
|
|
49
52
|
// 前置操作
|
|
50
|
-
const { publicPath, basename, assets = ''
|
|
53
|
+
const { publicPath, basename, assets = '' } = ((_b = mainAppData.appConfig) === null || _b === void 0 ? void 0 : _b.window) || {};
|
|
51
54
|
// 获取 插入的cdn 资源
|
|
52
55
|
const jsAssets = await (0, generate_2.handleAssets)({
|
|
53
56
|
appBuildDir: buildDir,
|
|
54
57
|
buildTypeList,
|
|
55
58
|
assets,
|
|
56
59
|
});
|
|
57
|
-
// 拷贝 Builder 需要的文件
|
|
58
|
-
// TODO:验证 router
|
|
59
60
|
await (0, copy_1.runCopy)(h5BuildDir, mainAppData, i18nConfig);
|
|
60
61
|
// 构建 APP 需要的配置文件
|
|
61
62
|
const appConfig = await (0, webpack_2.generateAppConfig)(mainAppData, subAppDataList, h5BuildDir);
|
|
62
|
-
// 素材库
|
|
63
|
+
// // 素材库
|
|
63
64
|
const runHandleMaterialTag = '🚥 buildWebApp-runHandleMaterial';
|
|
64
65
|
console.time(runHandleMaterialTag);
|
|
65
66
|
// 精简只使用用到的组件库
|
|
@@ -68,11 +69,12 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
68
69
|
});
|
|
69
70
|
await (0, material_1.runHandleMaterial)(h5BuildDir, filteredDependiences, materialsDir, runtime, ignoreInstall);
|
|
70
71
|
console.timeEnd(runHandleMaterialTag);
|
|
71
|
-
// 获取 generate 需要的构建文件
|
|
72
|
+
// // 获取 generate 需要的构建文件
|
|
72
73
|
const runGenerateTag = '🚥 buildWebApp-generateProjectFiles';
|
|
73
74
|
console.time(runGenerateTag);
|
|
74
75
|
await (0, generate_1.generateProjectFiles)({
|
|
75
76
|
dependencies: filteredDependiences,
|
|
77
|
+
cals,
|
|
76
78
|
mainAppData,
|
|
77
79
|
subAppDataList,
|
|
78
80
|
appKey,
|
|
@@ -87,7 +89,7 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
87
89
|
deployMode,
|
|
88
90
|
});
|
|
89
91
|
console.timeEnd(runGenerateTag);
|
|
90
|
-
// 构建 NPM 包
|
|
92
|
+
// // 构建 NPM 包
|
|
91
93
|
await (0, npm_1.handleNPM)({
|
|
92
94
|
appKey,
|
|
93
95
|
mainAppData,
|
|
@@ -114,17 +116,26 @@ async function buildH5App({ appKey, buildDir, dependencies, i18nConfig, extraDat
|
|
|
114
116
|
publicPath,
|
|
115
117
|
domain,
|
|
116
118
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
await new Promise((resolve, reject) => {
|
|
120
|
+
// 开始编译前清理一下 lowcode 内容
|
|
121
|
+
(0, compile_1.startCompile)({
|
|
122
|
+
appBuildDir: h5BuildDir,
|
|
123
|
+
configPath: webpackConfigPath,
|
|
124
|
+
appKey,
|
|
125
|
+
webpackMode: mode,
|
|
126
|
+
}, function (err, data) {
|
|
127
|
+
if (err) {
|
|
128
|
+
reject(err);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
resolve(data);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
123
134
|
});
|
|
124
135
|
return h5BuildDir;
|
|
125
136
|
}
|
|
126
137
|
catch (e) {
|
|
127
|
-
console.error('构建失败:', e);
|
|
138
|
+
// console.error('构建失败:', e);
|
|
128
139
|
throw e;
|
|
129
140
|
}
|
|
130
141
|
}
|
|
@@ -18,14 +18,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
18
18
|
__setModuleDefault(result, mod);
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
22
|
exports.runHandleMaterial = void 0;
|
|
26
23
|
const fs = __importStar(require("fs"));
|
|
27
24
|
const path = __importStar(require("path"));
|
|
28
|
-
const lodash_1 =
|
|
25
|
+
const lodash_1 = require("lodash");
|
|
29
26
|
const webpack_1 = require("../service/webpack");
|
|
30
27
|
const copy_1 = require("./copy");
|
|
31
28
|
const types_1 = require("../../types");
|
|
@@ -40,12 +37,12 @@ async function runHandleMaterial(appBuildDir, dependencies = [], materialsDir, r
|
|
|
40
37
|
ignoreInstall,
|
|
41
38
|
}),
|
|
42
39
|
];
|
|
43
|
-
return lodash_1.
|
|
40
|
+
return (0, lodash_1.flatten)(allMaterials);
|
|
44
41
|
// TODO: 确认这里是否需要生成复合组件
|
|
45
42
|
// await handleCompositeComponent({ dependencies, appBuildDir });
|
|
46
43
|
}
|
|
47
44
|
exports.runHandleMaterial = runHandleMaterial;
|
|
48
|
-
async function handleNormalMaterial({ dependencies, materialsDir, appBuildDir, runtime, ignoreInstall = false
|
|
45
|
+
async function handleNormalMaterial({ dependencies, materialsDir, appBuildDir, runtime, ignoreInstall = false }) {
|
|
49
46
|
const timeTag = '-------------------- handleNormalMaterial';
|
|
50
47
|
console.time(timeTag);
|
|
51
48
|
const normalDependencies = dependencies.filter((item) => !item.isComposite);
|
|
@@ -77,10 +74,8 @@ async function handleNormalMaterial({ dependencies, materialsDir, appBuildDir, r
|
|
|
77
74
|
}
|
|
78
75
|
else {
|
|
79
76
|
// 老格式,需要从子目录下读取
|
|
80
|
-
actions =
|
|
81
|
-
|
|
82
|
-
components = (_b = fs
|
|
83
|
-
.readdirSync(materialComponentsPath)) === null || _b === void 0 ? void 0 : _b.map((dirName) => ({ name: dirName }));
|
|
77
|
+
actions = ((_a = fs.readdirSync(actionsDir)) === null || _a === void 0 ? void 0 : _a.map((dirName) => ({ name: dirName }))) || [];
|
|
78
|
+
components = (_b = fs.readdirSync(materialComponentsPath)) === null || _b === void 0 ? void 0 : _b.map((dirName) => ({ name: dirName }));
|
|
84
79
|
}
|
|
85
80
|
// TODO: 根据mata判断而非readdir
|
|
86
81
|
return {
|
|
@@ -102,7 +97,7 @@ async function handleNormalMaterial({ dependencies, materialsDir, appBuildDir, r
|
|
|
102
97
|
// (materialGroupInfoMap[item.name] = {
|
|
103
98
|
// isComposite: item.isComposite,
|
|
104
99
|
// version: item.version,
|
|
105
|
-
//
|
|
100
|
+
// entries: item.entries,
|
|
106
101
|
// schemaVersion: item.schemaVersion,
|
|
107
102
|
// })
|
|
108
103
|
// );
|
package/lib/builder/h5/npm.js
CHANGED
|
@@ -10,7 +10,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
10
10
|
const console_1 = require("../util/console");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
const generateFiles_1 = require("../util/generateFiles");
|
|
13
|
-
const lodash_1 =
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
14
|
const util_1 = require("../util");
|
|
15
15
|
async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [], appKey, appBuildDir, mode, devTool, ignoreInstall = false, }) {
|
|
16
16
|
const allAppDataList = subAppDataList.concat(mainAppData);
|
|
@@ -41,9 +41,10 @@ async function handleNPM({ mainAppData, subAppDataList = [], dependencies = [],
|
|
|
41
41
|
if (!isChange) {
|
|
42
42
|
(0, console_1.notice)('package.json dependencies 已经安装,如出现未安装成功或找不到依赖,请重启wa watch');
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
await (0, webpack_1.installDependencies)(appBuildDir, {
|
|
45
|
+
isDependence: false,
|
|
46
|
+
ignoreInstall,
|
|
47
|
+
});
|
|
47
48
|
}
|
|
48
49
|
exports.handleNPM = handleNPM;
|
|
49
50
|
async function generatePackageJSON(dependencies = {}, appBuildDir, appKey, mode, devTool) {
|
|
@@ -52,7 +53,7 @@ async function generatePackageJSON(dependencies = {}, appBuildDir, appKey, mode,
|
|
|
52
53
|
const dstTempPath = path_1.default.join(appBuildDir, '.temp', 'package.json');
|
|
53
54
|
const packageTpl = await fs_extra_1.default.readFile(templatePath, { encoding: 'utf8' });
|
|
54
55
|
await fs_extra_1.default.ensureFile(dstTempPath);
|
|
55
|
-
await fs_extra_1.default.writeFile(dstTempPath, lodash_1.
|
|
56
|
+
await fs_extra_1.default.writeFile(dstTempPath, (0, lodash_1.template)(packageTpl)({
|
|
56
57
|
canUseVite: (0, util_1.canUseVite)(mode, devTool),
|
|
57
58
|
appKey,
|
|
58
59
|
appId: appKey,
|