@cloudbase/lowcode-builder 1.1.5-alpha.2 → 1.1.6
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 +0 -8
- package/lib/builder/config/index.js +1 -16
- package/lib/builder/core/index.d.ts +2 -32
- package/lib/builder/core/index.js +30 -147
- package/lib/builder/h5/generate.d.ts +1 -3
- package/lib/builder/h5/generate.js +1 -2
- package/lib/builder/h5/index.d.ts +6 -6
- package/lib/builder/h5/index.js +14 -20
- package/lib/builder/h5/webpack.d.ts +1 -3
- package/lib/builder/h5/webpack.js +1 -2
- package/lib/builder/mp/BuildContext.d.ts +0 -4
- package/lib/builder/mp/index.d.ts +14 -5
- package/lib/builder/mp/index.js +28 -17
- package/lib/builder/mp/materials.js +0 -6
- package/lib/builder/mp/mixMode.d.ts +2 -3
- package/lib/builder/mp/mixMode.js +2 -5
- package/lib/builder/mp/mp_config.d.ts +1 -1
- package/lib/builder/mp/mp_config.js +2 -4
- package/lib/builder/mp/util.js +1 -1
- package/lib/builder/service/webpack.d.ts +0 -7
- package/lib/builder/service/webpack.js +21 -31
- package/lib/builder/util/generateFiles.d.ts +1 -0
- package/lib/builder/util/generateFiles.js +8 -6
- package/lib/builder/util/junk.d.ts +1 -0
- package/lib/builder/util/junk.js +7 -1
- package/lib/builder/util/net.js +4 -0
- package/lib/builder.web.js +21 -13
- package/package.json +2 -2
- package/template/html/index.html.ejs +11 -23
- package/template/mp/common/util.js +9 -5
- package/template/mp/common/widget.js +2 -2
- package/template/mp/common/wx_yypt_report_v2.js +460 -0
- package/template/mp/datasources/config.js.tpl +0 -1
- package/template/mp/package.json +6 -6
- package/template/package.json +1 -1
package/lib/builder/mp/index.js
CHANGED
|
@@ -54,18 +54,35 @@ 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({ weapps, projDir, appId, domain, materials, plugins, isProduction, deployMode, extraData, isMixMode, options, buildTypeList, isBrowserMpBuilder = false, ignoreInstall = false, }) {
|
|
58
58
|
var _a;
|
|
59
|
-
const { appId, projDir, materialLibs: materials, isProduction, mainAppData, domain, isBrowserMpBuilder, isPrivateMode = false, } = buildContext;
|
|
60
59
|
const operationLabel = em('Wexin MiniProgram Generated');
|
|
61
60
|
console.time(operationLabel);
|
|
62
61
|
console.log(`Generating ${em('Wexin MiniProgram')} to ${projDir}`);
|
|
63
|
-
|
|
62
|
+
console.log(em('domain') + domain);
|
|
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
|
+
});
|
|
64
81
|
buildContext.miniprogramPlugins = (mainAppData.miniprogramPlugins || []).filter((plugin) => allAppUsedComps[plugin.name]);
|
|
65
82
|
// 安装依赖库,生成 materials 目录
|
|
66
83
|
await (0, materials_1.installMaterials)(projDir, allAppUsedComps, weapps, buildContext);
|
|
67
84
|
const wxmlDataPrefix = (0, mp_1.getWxmlDataPrefix)(!isProduction);
|
|
68
|
-
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext, { mpAppId: options.mpAppId });
|
|
85
|
+
const { projConfig, appConfig, pageConfigs } = (0, mp_config_1.generateMpConfig)(weapps, buildContext, { mpAppId: options === null || options === void 0 ? void 0 : options.mpAppId });
|
|
69
86
|
// #1 generate project files
|
|
70
87
|
if (!mainAppData.mpPkgUrl) {
|
|
71
88
|
const projectFileData = {
|
|
@@ -118,8 +135,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
118
135
|
};
|
|
119
136
|
}
|
|
120
137
|
if (mainAppData.mpPkgUrl) {
|
|
121
|
-
// 合并 project 和 app json
|
|
122
|
-
projectConfigJson.appId = projConfig.appId;
|
|
138
|
+
// 合并 project 和 app json
|
|
123
139
|
if (!projectConfigJson.setting) {
|
|
124
140
|
projectConfigJson.setting = {};
|
|
125
141
|
}
|
|
@@ -137,6 +153,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
137
153
|
const importor = (0, util_3.generateLowcodeImportor)(mainAppData.lowCodes || []);
|
|
138
154
|
appFileData = {
|
|
139
155
|
...appFileData,
|
|
156
|
+
'common/wx_yypt_report_v2.js': {},
|
|
140
157
|
'app.js': { appConfig, importor },
|
|
141
158
|
'app.json': { content: appConfig },
|
|
142
159
|
'app.wxss': {
|
|
@@ -149,7 +166,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
149
166
|
},
|
|
150
167
|
'package.json': {
|
|
151
168
|
appId,
|
|
152
|
-
isPrivateMode,
|
|
153
169
|
extraDeps: resolveNpmDeps(),
|
|
154
170
|
},
|
|
155
171
|
};
|
|
@@ -171,7 +187,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
171
187
|
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
172
188
|
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
173
189
|
clientID: (_a = mainAppData.extra) === null || _a === void 0 ? void 0 : _a.clientId,
|
|
174
|
-
isPrivateMode,
|
|
175
190
|
},
|
|
176
191
|
'datasources/datasource-profiles.js.tpl': {
|
|
177
192
|
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(
|
|
@@ -206,7 +221,6 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
206
221
|
await (0, generateFiles_1.default)({
|
|
207
222
|
'package.json': {
|
|
208
223
|
appId,
|
|
209
|
-
isPrivateMode,
|
|
210
224
|
extraDeps: resolveNpmDeps(),
|
|
211
225
|
},
|
|
212
226
|
}, templateDir, subpackageRootPath, buildContext);
|
|
@@ -214,9 +228,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
214
228
|
}
|
|
215
229
|
}));
|
|
216
230
|
if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
|
|
217
|
-
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
218
|
-
fixNodeModulesMap: { '@cloudbase/js-sdk': !isPrivateMode, mobx: true },
|
|
219
|
-
});
|
|
231
|
+
await (0, webpack_1.installDependencies)(miniprogramRoot, { ignoreInstall });
|
|
220
232
|
}
|
|
221
233
|
await handleMpPlugins();
|
|
222
234
|
console.timeEnd(operationLabel);
|
|
@@ -228,7 +240,7 @@ async function generateWxMp({ buildContext, weapps, plugins, deployMode, options
|
|
|
228
240
|
var _a;
|
|
229
241
|
const deps = [
|
|
230
242
|
{
|
|
231
|
-
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) ||
|
|
243
|
+
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) || [],
|
|
232
244
|
name: '主包',
|
|
233
245
|
},
|
|
234
246
|
];
|
|
@@ -415,7 +427,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
415
427
|
// 混合模式,子包不生成顶级(应用级)的 lowcodes
|
|
416
428
|
if (!(ctx.isMixMode && appData.rootPath)) {
|
|
417
429
|
await Promise.all(lowCodes
|
|
418
|
-
.filter((mod) => mod.type !==
|
|
430
|
+
.filter((mod) => mod.type !== 'renderer')
|
|
419
431
|
.map((m) => {
|
|
420
432
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
|
|
421
433
|
}));
|
|
@@ -423,7 +435,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
423
435
|
await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
|
|
424
436
|
const codes = (0, cals_1.processRuntimeCodeResources)({ id: page.id }, page.lowCodes || page.codeModules, 'page');
|
|
425
437
|
await codes
|
|
426
|
-
.filter((mod) => mod.type !==
|
|
438
|
+
.filter((mod) => mod.type !== 'renderer')
|
|
427
439
|
.forEach((m) => {
|
|
428
440
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
|
|
429
441
|
});
|
|
@@ -451,8 +463,7 @@ function getAppendableJson(json) {
|
|
|
451
463
|
* TODO: 与 cals 里的实现进行整合
|
|
452
464
|
* 关键点在于 appUsedComps 分组, 与 generic componen 的实现
|
|
453
465
|
*/
|
|
454
|
-
function handleUsedComponents({ buildContext, weapps }) {
|
|
455
|
-
const { materialLibs: materials } = buildContext;
|
|
466
|
+
function handleUsedComponents({ buildContext, weapps, materials, }) {
|
|
456
467
|
const appUsedComps = weapps.map((app) => {
|
|
457
468
|
var _a;
|
|
458
469
|
const usedComps = {};
|
|
@@ -327,12 +327,6 @@ 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
|
-
}
|
|
336
330
|
return (0, lowcode_1.writeCode2file)(mod, path.join(outDir, LOWCODE_DIR_NAME), { comp: compositedComp }, themeCode, ctx);
|
|
337
331
|
});
|
|
338
332
|
// await writeLowCodeFiles(weapp, appRoot)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { IWeAppData, IPlugin, IMaterialItem } from '@cloudbase/lowcode-generator/lib/weapps-core';
|
|
2
2
|
import { IAppUsedComp } from '../types/common';
|
|
3
|
-
|
|
4
|
-
export declare function handleMixMode({ buildContext, apps, miniprogramRoot, plugins, }: {
|
|
5
|
-
buildContext: IBuildContext;
|
|
3
|
+
export declare function handleMixMode({ apps, generateMpPath, miniprogramRoot, plugins, }: {
|
|
6
4
|
apps: IWeAppData[];
|
|
5
|
+
generateMpPath: string;
|
|
7
6
|
miniprogramRoot: string;
|
|
8
7
|
plugins: IPlugin[];
|
|
9
8
|
}): Promise<void>;
|
|
@@ -36,16 +36,13 @@ 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({
|
|
40
|
-
const { projDir: generateMpPath, isPrivateMode } = buildContext;
|
|
39
|
+
async function handleMixMode({ apps = [], generateMpPath, miniprogramRoot, plugins = [], }) {
|
|
41
40
|
// await handleMainApp()
|
|
42
41
|
// await handleAppPages()
|
|
43
42
|
await handleSubApps();
|
|
44
43
|
// await handleAppJson()
|
|
45
44
|
// await handlePkgJson()
|
|
46
|
-
await (0, webpack_1.installDependencies)(miniprogramRoot
|
|
47
|
-
fixNodeModulesMap: { mobx: true, '@cloudbase/js-sdk': !isPrivateMode },
|
|
48
|
-
});
|
|
45
|
+
await (0, webpack_1.installDependencies)(miniprogramRoot);
|
|
49
46
|
await handlePlugins();
|
|
50
47
|
// 复制框架公用内容
|
|
51
48
|
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;
|
|
@@ -48,6 +48,7 @@ function generateMpConfig(weapps, ctx, options) {
|
|
|
48
48
|
const { miniprogramPlugins = [] } = ctx;
|
|
49
49
|
const projConfig = (0, lodash_1.merge)({}, mp_1.defaultProjConfig, {
|
|
50
50
|
projectname: (ctx.mainAppData && ctx.mainAppData.label) || `WeDa-${ctx.appId}`,
|
|
51
|
+
appid: (options === null || options === void 0 ? void 0 : options.mpAppId) || mp_1.defaultProjConfig.appid,
|
|
51
52
|
});
|
|
52
53
|
const pageConfigs = weapps.map((app) => {
|
|
53
54
|
var _a;
|
|
@@ -116,9 +117,6 @@ function generateMpConfig(weapps, ctx, options) {
|
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
119
|
});
|
|
119
|
-
if (options.mpAppId) {
|
|
120
|
-
projConfig.appId = options.mpAppId;
|
|
121
|
-
}
|
|
122
120
|
// merge(pageConfigs, extractAllPagesConfig())
|
|
123
121
|
return { appConfig, projConfig, pageConfigs };
|
|
124
122
|
}
|
|
@@ -167,7 +165,7 @@ function transformDynamicData(originData) {
|
|
|
167
165
|
const temp = {};
|
|
168
166
|
for (const key in originData) {
|
|
169
167
|
const target = originData[key];
|
|
170
|
-
if (target
|
|
168
|
+
if (target && target.value) {
|
|
171
169
|
temp[key] = target.value;
|
|
172
170
|
}
|
|
173
171
|
}
|
package/lib/builder/mp/util.js
CHANGED
|
@@ -67,7 +67,7 @@ function generateDataBindMeta(bind) {
|
|
|
67
67
|
imports += (0, lowcode_generator_1.generateExpressionAlias)(value);
|
|
68
68
|
}
|
|
69
69
|
catch (e) {
|
|
70
|
-
console.error('parse expression error', value);
|
|
70
|
+
console.error('parse expression error', value, e === null || e === void 0 ? void 0 : e.message);
|
|
71
71
|
}
|
|
72
72
|
expr = value;
|
|
73
73
|
}
|
|
@@ -2,7 +2,6 @@ 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";
|
|
6
5
|
export interface IMpConfig {
|
|
7
6
|
origin: string;
|
|
8
7
|
entry: string;
|
|
@@ -75,17 +74,11 @@ export interface IInstallOpts {
|
|
|
75
74
|
version: string;
|
|
76
75
|
downloadUrl: string;
|
|
77
76
|
};
|
|
78
|
-
fixNodeModulesMap?: IFixNodeModulesMap;
|
|
79
77
|
}
|
|
80
78
|
export declare function installDependencies(targetDir: string, options?: IInstallOpts): Promise<void>;
|
|
81
|
-
interface IFixNodeModulesMap {
|
|
82
|
-
mobx?: boolean;
|
|
83
|
-
'@cloudbase/js-sdk'?: boolean;
|
|
84
|
-
}
|
|
85
79
|
export declare function getMaterialNodeModulesPathList(dependencies: IMaterialItem[] | undefined, materialsDir: string, base?: string): string[];
|
|
86
80
|
export declare function generateWebpackWebDevServerFile({ appBuildDir, buildTypeList }: {
|
|
87
81
|
appBuildDir: any;
|
|
88
82
|
buildTypeList: any;
|
|
89
83
|
}): Promise<void>;
|
|
90
84
|
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.
|
|
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;
|
|
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,7 +18,6 @@ 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';
|
|
22
21
|
async function fixAppJson(appBuildDir) {
|
|
23
22
|
const appJsonPath = path_1.default.resolve(appBuildDir, 'dist/mp/app.json');
|
|
24
23
|
if (!fs_extra_1.default.existsSync(appJsonPath)) {
|
|
@@ -274,7 +273,7 @@ function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = c
|
|
|
274
273
|
watch: false,
|
|
275
274
|
entry: path_1.default.resolve(appBuildDir, 'src/index.jsx'),
|
|
276
275
|
output: {
|
|
277
|
-
path: path_1.default.resolve(appBuildDir,
|
|
276
|
+
path: path_1.default.resolve(appBuildDir, './preview'),
|
|
278
277
|
filename: '[name].[contenthash].bundle.js',
|
|
279
278
|
chunkFilename: '[name].[contenthash].chunk.js',
|
|
280
279
|
publicPath: buildTypeList.includes(common_1.BuildType.APP) || buildTypeList.includes(common_1.BuildType.ADMIN_PORTAL) ? '' : publicPath,
|
|
@@ -295,6 +294,8 @@ function getWebpackWebBuildParams(appId, appBuildDir, publicPath = '/', mode = c
|
|
|
295
294
|
resolveModules: [path_1.default.resolve(appBuildDir), 'node_modules'],
|
|
296
295
|
definePlugin: {
|
|
297
296
|
'process.env.buildType': `"${buildTypeList[0]}"`,
|
|
297
|
+
'process.env.isApp': buildTypeList.includes(common_1.BuildType.APP),
|
|
298
|
+
'process.env.isAdminPortal': (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
298
299
|
...extraDefine,
|
|
299
300
|
},
|
|
300
301
|
devtool: ['app-nvzcvt10', 'app-msa2ihs9'].includes(appId)
|
|
@@ -455,7 +456,11 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
455
456
|
}
|
|
456
457
|
}
|
|
457
458
|
catch (e) { }
|
|
458
|
-
|
|
459
|
+
// 如果generatedFileContents[path.resolve(targetDir, 'package.json')]不存在,说明是不存在缓存文件,isPkgModify必须是true,才不会忽略install
|
|
460
|
+
const isPkgModify = !generateFiles_1.generatedFileContents[path_1.default.resolve(targetDir, 'package.json')]
|
|
461
|
+
? true
|
|
462
|
+
: generateFiles_1.generatedFileContents[path_1.default.resolve(targetDir, 'package.json')].modify;
|
|
463
|
+
if ((options === null || options === void 0 ? void 0 : options.ignoreInstall) && fs_extra_1.default.existsSync(path_1.default.join(targetDir, 'node_modules')) && !isPkgModify) {
|
|
459
464
|
console.log(`ignore install dependencies in ${targetDir}`);
|
|
460
465
|
return;
|
|
461
466
|
}
|
|
@@ -480,25 +485,20 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
480
485
|
};
|
|
481
486
|
}
|
|
482
487
|
}
|
|
488
|
+
let installProcess;
|
|
483
489
|
// 云端构建, 选用 npm
|
|
484
|
-
const
|
|
490
|
+
const installlProcessOptions = {
|
|
485
491
|
cwd: targetDir,
|
|
486
492
|
// NODE_ENV="production"时,devDependencies里的包不会下载,兼容h5在线编译
|
|
487
493
|
env: { ...process.env, NODE_ENV: '' },
|
|
488
494
|
stdio: 'inherit',
|
|
489
495
|
};
|
|
490
|
-
let installprocess;
|
|
491
|
-
// TODO: install 失败 应该终止进程
|
|
492
496
|
if (yarnExists && (options === null || options === void 0 ? void 0 : options.runtime) !== types_1.RUNTIME.CI) {
|
|
493
497
|
const addPackage = packageName ? ['add', packageName] : [];
|
|
494
|
-
|
|
498
|
+
installProcess = cross_spawn_1.default.sync('yarn', [...addPackage, registry], installlProcessOptions);
|
|
495
499
|
}
|
|
496
500
|
else {
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
// TODO: 确认 process.status 语义来判断是否标识进程正常退出
|
|
500
|
-
if (installprocess.status) {
|
|
501
|
-
throw new Error(`安装依赖失败 ${installprocess.error || ''}`);
|
|
501
|
+
installProcess = cross_spawn_1.default.sync('npm', ['install', packageName, ...npmOptions], installlProcessOptions);
|
|
502
502
|
}
|
|
503
503
|
fixNodeModules(targetDir);
|
|
504
504
|
try {
|
|
@@ -509,24 +509,14 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
509
509
|
console.timeEnd(operationTag);
|
|
510
510
|
}
|
|
511
511
|
exports.installDependencies = installDependencies;
|
|
512
|
-
function fixNodeModules(projDir
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const
|
|
517
|
-
if (fs_extra_1.default.existsSync(
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
mobxPackageFileContent.main = 'lib/mobx.min.js';
|
|
521
|
-
fs_extra_1.default.writeJSONSync(mobxPackageFile, mobxPackageFileContent);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (jsSDK) {
|
|
526
|
-
const scriptPath = path_1.default.resolve(projDir, 'node_modules', '@cloudbase/weda-cloud-sdk/scripts/fix-wx-none-private');
|
|
527
|
-
if (fs_extra_1.default.existsSync(scriptPath)) {
|
|
528
|
-
const fix = require(scriptPath);
|
|
529
|
-
fix();
|
|
512
|
+
function fixNodeModules(projDir) {
|
|
513
|
+
// # fix mobx/package.json: "main": "lib/index.js" -> "main": "lib/index.js"
|
|
514
|
+
const mobxPackageFile = path_1.default.join(projDir, 'node_modules', 'mobx/package.json');
|
|
515
|
+
if (fs_extra_1.default.existsSync(mobxPackageFile)) {
|
|
516
|
+
const mobxPackageFileContent = fs_extra_1.default.readJSONSync(mobxPackageFile);
|
|
517
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(projDir, 'node_modules', 'mobx/lib/mobx.min.js'))) {
|
|
518
|
+
mobxPackageFileContent.main = 'lib/mobx.min.js';
|
|
519
|
+
fs_extra_1.default.writeJSONSync(mobxPackageFile, mobxPackageFileContent);
|
|
530
520
|
}
|
|
531
521
|
}
|
|
532
522
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IBuildContext } from '../mp/BuildContext';
|
|
3
3
|
import { OutputType } from 'jszip';
|
|
4
|
+
export declare const generatedFileContents: {};
|
|
4
5
|
export default function generateFiles(appFileData: any, srcDir: string, dstDir: string, ctx: IBuildContext): Promise<string[]>;
|
|
5
6
|
export declare function writeFile(outFile: string, content: string): Promise<boolean>;
|
|
6
7
|
export declare function removeFile(file: string): void;
|
|
@@ -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.strToBuf = exports.fileToZip = exports.getFiles = exports.copyRecursiveSync = exports.copyFileSync = exports.copy = exports.copyFiles = exports.cleanDir = exports.removeFile = exports.writeFile = void 0;
|
|
29
|
+
exports.strToBuf = exports.fileToZip = exports.getFiles = exports.copyRecursiveSync = exports.copyFileSync = exports.copy = exports.copyFiles = exports.cleanDir = exports.removeFile = exports.writeFile = exports.generatedFileContents = void 0;
|
|
30
30
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const lodash_1 = require("lodash");
|
|
@@ -34,7 +34,7 @@ const junk = __importStar(require("../util/junk"));
|
|
|
34
34
|
const glob_1 = __importDefault(require("glob"));
|
|
35
35
|
const jszip_1 = __importDefault(require("jszip"));
|
|
36
36
|
const buffer_1 = require("buffer");
|
|
37
|
-
|
|
37
|
+
exports.generatedFileContents = {}; // generated files for incrmental build
|
|
38
38
|
async function generateFiles(appFileData, srcDir, dstDir, ctx) {
|
|
39
39
|
const filesGenerated = [];
|
|
40
40
|
// Generating file by template and data
|
|
@@ -67,22 +67,24 @@ async function generateFiles(appFileData, srcDir, dstDir, ctx) {
|
|
|
67
67
|
}
|
|
68
68
|
exports.default = generateFiles;
|
|
69
69
|
async function writeFile(outFile, content) {
|
|
70
|
-
|
|
70
|
+
var _a;
|
|
71
|
+
const generated = (_a = exports.generatedFileContents[outFile]) === null || _a === void 0 ? void 0 : _a.content;
|
|
71
72
|
if (generated === content && fs_extra_1.default.existsSync(outFile)) {
|
|
73
|
+
exports.generatedFileContents[outFile].modify = false;
|
|
72
74
|
return false;
|
|
73
75
|
}
|
|
74
76
|
// console.log(outFile);
|
|
75
77
|
await fs_extra_1.default.ensureFile(outFile);
|
|
76
78
|
await fs_extra_1.default.writeFile(outFile, content);
|
|
77
|
-
generatedFileContents[outFile] = content;
|
|
79
|
+
exports.generatedFileContents[outFile] = { content, modify: true };
|
|
78
80
|
return true;
|
|
79
81
|
}
|
|
80
82
|
exports.writeFile = writeFile;
|
|
81
83
|
function removeFile(file) {
|
|
82
84
|
console.log(`Removing ${file}`);
|
|
83
|
-
Object.keys(generatedFileContents).map((cachedFile) => {
|
|
85
|
+
Object.keys(exports.generatedFileContents).map((cachedFile) => {
|
|
84
86
|
if (cachedFile.indexOf(file) === 0) {
|
|
85
|
-
delete generatedFileContents[cachedFile];
|
|
87
|
+
delete exports.generatedFileContents[cachedFile];
|
|
86
88
|
}
|
|
87
89
|
});
|
|
88
90
|
return fs_extra_1.default.removeSync(file);
|
package/lib/builder/util/junk.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.not = exports.is = void 0;
|
|
3
|
+
exports.isFilePath = exports.not = exports.is = void 0;
|
|
4
4
|
const ignoreList = [
|
|
5
5
|
// # All
|
|
6
6
|
'^npm-debug\\.log$',
|
|
@@ -25,8 +25,14 @@ const ignoreList = [
|
|
|
25
25
|
'^readme.md$',
|
|
26
26
|
'^README.md$',
|
|
27
27
|
];
|
|
28
|
+
const filePathIgnoreList = [
|
|
29
|
+
'__MACOSX', // 路径有__MACOSX就过滤
|
|
30
|
+
];
|
|
28
31
|
const regex = new RegExp(ignoreList.join('|'));
|
|
32
|
+
const filePathRegex = new RegExp(filePathIgnoreList.join('|'));
|
|
29
33
|
const is = (filename) => regex.test(filename);
|
|
30
34
|
exports.is = is;
|
|
31
35
|
const not = (filename) => !(0, exports.is)(filename);
|
|
32
36
|
exports.not = not;
|
|
37
|
+
const isFilePath = (filename) => filePathRegex.test(filename);
|
|
38
|
+
exports.isFilePath = isFilePath;
|
package/lib/builder/util/net.js
CHANGED
|
@@ -34,6 +34,7 @@ const compressing_1 = __importDefault(require("compressing"));
|
|
|
34
34
|
const jszip_1 = __importDefault(require("jszip"));
|
|
35
35
|
const config_1 = require("../config");
|
|
36
36
|
const generateFiles_1 = require("../util/generateFiles");
|
|
37
|
+
const junk_1 = require("../util/junk");
|
|
37
38
|
async function downloadFile(url, filePath) {
|
|
38
39
|
await fs_extra_1.default.ensureDir(path.dirname(filePath));
|
|
39
40
|
const res = await axios_1.default.get(url, { responseType: 'stream' });
|
|
@@ -91,6 +92,9 @@ async function saveFiles(files, dstDir) {
|
|
|
91
92
|
try {
|
|
92
93
|
for (const fileName of Object.keys(files)) {
|
|
93
94
|
const dest = path.join(dstDir, fileName);
|
|
95
|
+
if ((0, junk_1.isFilePath)(dest)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
94
98
|
if (files[fileName].dir) { // 如果该文件为目录需先创建文件夹
|
|
95
99
|
fs_extra_1.default.mkdirSync(dest, {
|
|
96
100
|
recursive: true
|