@cloudbase/lowcode-builder 1.1.10 → 1.2.1-alpha.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/config/index.d.ts +8 -0
- package/lib/builder/config/index.js +16 -1
- package/lib/builder/core/index.d.ts +33 -2
- package/lib/builder/core/index.js +147 -27
- package/lib/builder/h5/generate.d.ts +5 -2
- package/lib/builder/h5/generate.js +19 -2
- package/lib/builder/h5/index.d.ts +6 -6
- package/lib/builder/h5/index.js +21 -14
- package/lib/builder/h5/webpack.d.ts +5 -1
- package/lib/builder/h5/webpack.js +7 -2
- package/lib/builder/mp/BuildContext.d.ts +11 -0
- package/lib/builder/mp/index.d.ts +5 -12
- package/lib/builder/mp/index.js +22 -30
- package/lib/builder/mp/materials.js +6 -0
- package/lib/builder/mp/mixMode.d.ts +3 -2
- package/lib/builder/mp/mixMode.js +6 -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 +32 -20
- package/package.json +3 -3
- package/template/html/index.html.ejs +29 -15
- package/template/mp/app.js +4 -7
- package/template/mp/common/util.js +18 -7
- package/template/mp/datasources/config.js.tpl +14 -1
- package/template/mp/datasources/index.js +3 -1
- package/template/mp/package.json +6 -6
- package/template/package.json +1 -2
- package/template/mp/common/wx_yypt_report_v2.js +0 -460
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, endpointType = '', } = 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
|
+
importJSSDK: endpointType === 'tcb-api',
|
|
169
153
|
extraDeps: resolveNpmDeps(),
|
|
170
154
|
},
|
|
171
155
|
};
|
|
@@ -187,6 +171,9 @@ 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,
|
|
175
|
+
endpointType,
|
|
176
|
+
tcbApiOrigin: endpointType === 'tcb-api' && isPrivateMode && domain ? `https://${domain}` : '',
|
|
190
177
|
},
|
|
191
178
|
'datasources/datasource-profiles.js.tpl': {
|
|
192
179
|
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(
|
|
@@ -221,6 +208,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
221
208
|
await (0, generateFiles_1.default)({
|
|
222
209
|
'package.json': {
|
|
223
210
|
appId,
|
|
211
|
+
importJSSDK: endpointType === 'tcb-api',
|
|
224
212
|
extraDeps: resolveNpmDeps(),
|
|
225
213
|
},
|
|
226
214
|
}, templateDir, subpackageRootPath, buildContext);
|
|
@@ -228,7 +216,10 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
228
216
|
}
|
|
229
217
|
}));
|
|
230
218
|
if (!isBrowserMpBuilder && fs.existsSync(path_1.default.join(miniprogramRoot, 'package.json'))) {
|
|
231
|
-
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
219
|
+
await (0, webpack_1.installDependencies)(miniprogramRoot, {
|
|
220
|
+
ignoreInstall,
|
|
221
|
+
fixNodeModulesMap: { '@cloudbase/js-sdk': endpointType !== 'tcb-api', mobx: true },
|
|
222
|
+
});
|
|
232
223
|
}
|
|
233
224
|
await handleMpPlugins();
|
|
234
225
|
console.timeEnd(operationLabel);
|
|
@@ -236,11 +227,11 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
236
227
|
!isBrowserMpBuilder && cleanProj(weapps, miniprogramRoot);
|
|
237
228
|
!isBrowserMpBuilder && cleanMaterils(path_1.default.join(miniprogramRoot, config_1.materialsDirName), allAppUsedComps);
|
|
238
229
|
return { miniprogramRoot };
|
|
239
|
-
function resolveNpmDeps() {
|
|
230
|
+
function resolveNpmDeps(extra = {}) {
|
|
240
231
|
var _a;
|
|
241
232
|
const deps = [
|
|
242
233
|
{
|
|
243
|
-
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) ||
|
|
234
|
+
deps: ((_a = weapps.find((a) => !a.rootPath)) === null || _a === void 0 ? void 0 : _a.npmDependencies) || {},
|
|
244
235
|
name: '主包',
|
|
245
236
|
},
|
|
246
237
|
];
|
|
@@ -273,7 +264,7 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
273
264
|
}
|
|
274
265
|
});
|
|
275
266
|
return result;
|
|
276
|
-
},
|
|
267
|
+
}, extra);
|
|
277
268
|
}
|
|
278
269
|
// SDK 插件
|
|
279
270
|
async function handleMpPlugins() {
|
|
@@ -427,7 +418,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
427
418
|
// 混合模式,子包不生成顶级(应用级)的 lowcodes
|
|
428
419
|
if (!(ctx.isMixMode && appData.rootPath)) {
|
|
429
420
|
await Promise.all(lowCodes
|
|
430
|
-
.filter((mod) => mod.type !==
|
|
421
|
+
.filter((mod) => mod.type !== cals_1.ECodeType.RENDERER)
|
|
431
422
|
.map((m) => {
|
|
432
423
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { appDir: outDir }, themeStyle.code);
|
|
433
424
|
}));
|
|
@@ -435,7 +426,7 @@ async function writeLowCodeFiles(appData, outDir, ctx) {
|
|
|
435
426
|
await Promise.all((0, weapps_core_1.loopDealWithFn)(appData.pageInstanceList, async (page) => {
|
|
436
427
|
const codes = (0, cals_1.processRuntimeCodeResources)({ id: page.id }, page.lowCodes || page.codeModules, 'page');
|
|
437
428
|
await codes
|
|
438
|
-
.filter((mod) => mod.type !==
|
|
429
|
+
.filter((mod) => mod.type !== cals_1.ECodeType.RENDERER)
|
|
439
430
|
.forEach((m) => {
|
|
440
431
|
(0, lowcode_1.writeCode2file)(m, lowcodeRootDir, { pageId: page.id, appDir: outDir }, themeStyle.code, ctx);
|
|
441
432
|
});
|
|
@@ -463,7 +454,8 @@ function getAppendableJson(json) {
|
|
|
463
454
|
* TODO: 与 cals 里的实现进行整合
|
|
464
455
|
* 关键点在于 appUsedComps 分组, 与 generic componen 的实现
|
|
465
456
|
*/
|
|
466
|
-
function handleUsedComponents({ buildContext, weapps
|
|
457
|
+
function handleUsedComponents({ buildContext, weapps }) {
|
|
458
|
+
const { materialLibs: materials } = buildContext;
|
|
467
459
|
const appUsedComps = weapps.map((app) => {
|
|
468
460
|
var _a;
|
|
469
461
|
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, ignoreInstall, }: {
|
|
5
|
+
buildContext: IBuildContext;
|
|
4
6
|
apps: IWeAppData[];
|
|
5
|
-
generateMpPath: string;
|
|
6
7
|
miniprogramRoot: string;
|
|
7
8
|
plugins: IPlugin[];
|
|
8
9
|
ignoreInstall: boolean;
|
|
@@ -36,13 +36,17 @@ 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 = [], ignoreInstall, }) {
|
|
40
|
+
const { projDir: generateMpPath, endpointType } = 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
|
+
ignoreInstall,
|
|
48
|
+
fixNodeModulesMap: { mobx: true, '@cloudbase/js-sdk': endpointType !== 'tcb-api' },
|
|
49
|
+
});
|
|
46
50
|
await handlePlugins();
|
|
47
51
|
// 复制框架公用内容
|
|
48
52
|
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)
|
|
@@ -476,7 +475,7 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
476
475
|
console.log(`Installing dependencies in ${targetDir}`);
|
|
477
476
|
const operationTag = `---------------- ${yarnExists ? 'yarn' : 'npm'} Install dependencies`;
|
|
478
477
|
console.time(operationTag);
|
|
479
|
-
const registry = `--registry=${config_1.npmRegistry}`;
|
|
478
|
+
const registry = `--registry=${process.env.NPM_REGISTRY || config_1.npmRegistry}`;
|
|
480
479
|
const npmOptions = ['--prefer-offline', '--no-audit', '--progress=false', registry];
|
|
481
480
|
if (options === null || options === void 0 ? void 0 : options.dependenceMeta) {
|
|
482
481
|
npmOptions.push('--production');
|
|
@@ -488,25 +487,28 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
488
487
|
};
|
|
489
488
|
}
|
|
490
489
|
}
|
|
491
|
-
let installProcess;
|
|
492
490
|
// 云端构建, 选用 npm
|
|
493
|
-
const
|
|
491
|
+
const installProcessOptions = {
|
|
494
492
|
cwd: targetDir,
|
|
495
493
|
// NODE_ENV="production"时,devDependencies里的包不会下载,兼容h5在线编译
|
|
496
494
|
env: { ...process.env, NODE_ENV: '' },
|
|
497
495
|
stdio: 'inherit',
|
|
498
496
|
};
|
|
497
|
+
let installprocess;
|
|
498
|
+
// TODO: install 失败 应该终止进程
|
|
499
499
|
if (yarnExists && (options === null || options === void 0 ? void 0 : options.runtime) !== types_1.RUNTIME.CI) {
|
|
500
500
|
const addPackage = packageName ? ['add', packageName] : [];
|
|
501
|
-
|
|
501
|
+
installprocess = cross_spawn_1.default.sync('yarn', [...addPackage, registry], installProcessOptions);
|
|
502
502
|
}
|
|
503
503
|
else {
|
|
504
|
-
|
|
504
|
+
installprocess = cross_spawn_1.default.sync('npm', ['install', packageName, ...npmOptions], installProcessOptions);
|
|
505
505
|
}
|
|
506
|
-
|
|
507
|
-
|
|
506
|
+
// TODO: 确认 process.status 语义来判断是否标识进程正常退出
|
|
507
|
+
if (installprocess.status) {
|
|
508
|
+
throw new Error(`安装依赖失败 ${installprocess.error || ''}`);
|
|
508
509
|
}
|
|
509
|
-
fixNodeModules(targetDir);
|
|
510
|
+
console.log('fixNodeModules(targetDir, options?.fixNodeModulesMap)');
|
|
511
|
+
fixNodeModules(targetDir, options === null || options === void 0 ? void 0 : options.fixNodeModulesMap);
|
|
510
512
|
try {
|
|
511
513
|
await fs_extra_1.default.remove(path_1.default.join(path_1.default.join(targetDir, 'package-lock.json')));
|
|
512
514
|
await fs_extra_1.default.remove(path_1.default.join(path_1.default.join(targetDir, 'yarn.lock')));
|
|
@@ -515,14 +517,24 @@ async function installDependencies(targetDir, options = {}) {
|
|
|
515
517
|
console.timeEnd(operationTag);
|
|
516
518
|
}
|
|
517
519
|
exports.installDependencies = installDependencies;
|
|
518
|
-
function fixNodeModules(projDir) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
const
|
|
523
|
-
if (fs_extra_1.default.existsSync(
|
|
524
|
-
mobxPackageFileContent
|
|
525
|
-
fs_extra_1.default.
|
|
520
|
+
function fixNodeModules(projDir, options = { mobx: false, '@cloudbase/js-sdk': false }) {
|
|
521
|
+
const { mobx = false, ['@cloudbase/js-sdk']: jsSDK = false } = options;
|
|
522
|
+
if (mobx) {
|
|
523
|
+
// # fix mobx/package.json: "main": "lib/index.js" -> "main": "lib/index.js"
|
|
524
|
+
const mobxPackageFile = path_1.default.join(projDir, 'node_modules', 'mobx/package.json');
|
|
525
|
+
if (fs_extra_1.default.existsSync(mobxPackageFile)) {
|
|
526
|
+
const mobxPackageFileContent = fs_extra_1.default.readJSONSync(mobxPackageFile);
|
|
527
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(projDir, 'node_modules', 'mobx/lib/mobx.min.js'))) {
|
|
528
|
+
mobxPackageFileContent.main = 'lib/mobx.min.js';
|
|
529
|
+
fs_extra_1.default.writeJSONSync(mobxPackageFile, mobxPackageFileContent);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (jsSDK) {
|
|
534
|
+
const scriptPath = path_1.default.resolve(projDir, 'node_modules', '@cloudbase/weda-cloud-sdk/scripts/fix-wx-none-private.js');
|
|
535
|
+
if (fs_extra_1.default.existsSync(scriptPath)) {
|
|
536
|
+
const fix = require(scriptPath);
|
|
537
|
+
fix();
|
|
526
538
|
}
|
|
527
539
|
}
|
|
528
540
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.2.1-alpha.0",
|
|
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",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@cloudbase/cals": "^0.5.
|
|
42
|
-
"@cloudbase/lowcode-generator": "
|
|
41
|
+
"@cloudbase/cals": "^0.5.2",
|
|
42
|
+
"@cloudbase/lowcode-generator": "1.2.1-alpha.0",
|
|
43
43
|
"axios": "^0.21.0",
|
|
44
44
|
"browserfs": "^1.4.3",
|
|
45
45
|
"browserify-zlib": "^0.2.0",
|
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
<meta name="description" content="<%= desc %>" />
|
|
13
13
|
<link
|
|
14
14
|
rel="stylesheet"
|
|
15
|
-
href="
|
|
15
|
+
href="<%=
|
|
16
|
+
cdnEndpoints.cdngo
|
|
17
|
+
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.ba91c21b0d605c84ac7f.css"
|
|
16
18
|
/>
|
|
17
|
-
|
|
19
|
+
<% cssStyles.forEach(function(styleUrl){%>
|
|
20
|
+
<link type="text/css" rel="stylesheet" href="<%=styleUrl %>" />
|
|
21
|
+
<% })%> <% if(cdnEndpoints.aegis){ %>
|
|
22
|
+
<script crossorigin="anonymous" src="<%= cdnEndpoints.aegis %>/aegis/aegis-sdk/latest/aegis.min.js?v=1"></script>
|
|
18
23
|
<script>
|
|
19
24
|
<% if(!isAdminPortal){ %>
|
|
20
25
|
const _aegis = new Aegis({
|
|
@@ -36,13 +41,12 @@
|
|
|
36
41
|
window._aegis = _aegis;
|
|
37
42
|
window._aegis_inited = Date.now()
|
|
38
43
|
</script>
|
|
44
|
+
<% }%>
|
|
39
45
|
<title><%= title %></title>
|
|
40
46
|
<% if(mode !== 'production'){ %>
|
|
41
47
|
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
|
|
42
48
|
<script>new VConsole()</script> -->
|
|
43
|
-
<% }%>
|
|
44
|
-
<script src="<%=jsApi %>"></script>
|
|
45
|
-
<% })%>
|
|
49
|
+
<% }%>
|
|
46
50
|
|
|
47
51
|
<!-- 重置浏览器样式 -->
|
|
48
52
|
<style type="text/css">
|
|
@@ -383,14 +387,16 @@
|
|
|
383
387
|
|
|
384
388
|
<body data-weui-theme="light">
|
|
385
389
|
<div id="root" class="main-wrap"></div>
|
|
386
|
-
<%
|
|
390
|
+
<% jsApis.forEach(function(jsApi){%>
|
|
391
|
+
<script src="<%=jsApi %>"></script>
|
|
392
|
+
<% })%> <% if(canUseVite){ %>
|
|
387
393
|
<script type="module" src="/src/index.jsx"></script>
|
|
388
394
|
<% } %> <% if(!isAdminPortal){ %>
|
|
389
395
|
<script src="/weda-config/weda-private.js"></script>
|
|
390
|
-
<script src="
|
|
396
|
+
<script src="<%= cdnEndpoints.cloudbase %>/cloudbase-js-sdk/2.4.7-beta.0/cloudbase.full.js?v=1"></script>
|
|
391
397
|
<% }%>
|
|
392
398
|
<script>
|
|
393
|
-
if (window.cloudbase) {
|
|
399
|
+
if (window.cloudbase && window._aegis) {
|
|
394
400
|
const _callFunction = window.cloudbase.__proto__.callFunction;
|
|
395
401
|
window.cloudbase.__proto__.callFunction = function (args) {
|
|
396
402
|
let promise = _callFunction.call(window.cloudbase, ...arguments);
|
|
@@ -431,19 +437,23 @@
|
|
|
431
437
|
</script>
|
|
432
438
|
<script
|
|
433
439
|
crossorigin
|
|
434
|
-
src="
|
|
440
|
+
src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/release/_npm/react@16.14.0/umd/react.production.min.js"
|
|
435
441
|
></script>
|
|
436
442
|
<script
|
|
437
443
|
crossorigin
|
|
438
|
-
src="
|
|
444
|
+
src="<%=
|
|
445
|
+
cdnEndpoints.cdngo
|
|
446
|
+
%>/lcap/lcap-resource-cdngo/-/release/_npm/react-dom@16.14.0/umd/react-dom.production.min.js"
|
|
439
447
|
></script>
|
|
440
448
|
<script
|
|
441
|
-
src="
|
|
449
|
+
src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js"
|
|
442
450
|
crossorigin="anonymous"
|
|
443
451
|
></script>
|
|
444
452
|
<script
|
|
445
453
|
crossorigin="anonymous"
|
|
446
|
-
src="
|
|
454
|
+
src="<%=
|
|
455
|
+
cdnEndpoints.cdngo
|
|
456
|
+
%>/lcap/lcap-resource-cdngo/-/release/_npm/@cloudbase/weda-cloud-sdk@1.0.19/dist/h5.browser.js"
|
|
447
457
|
></script>
|
|
448
458
|
<script>
|
|
449
459
|
// zxing polifill
|
|
@@ -453,15 +463,19 @@
|
|
|
453
463
|
</script>
|
|
454
464
|
<script
|
|
455
465
|
crossorigin="anonymous"
|
|
456
|
-
src="
|
|
466
|
+
src="<%= cdnEndpoints.cdngo %>/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"
|
|
457
467
|
></script>
|
|
458
468
|
<script
|
|
459
469
|
crossorigin
|
|
460
|
-
src="
|
|
470
|
+
src="<%=
|
|
471
|
+
cdnEndpoints.cdngo
|
|
472
|
+
%>/lcap/lcap-resource-cdngo/-/release/_url/qcloud/lowcode/static/ide/assets/js/babel.min.js"
|
|
461
473
|
></script>
|
|
462
474
|
<script
|
|
463
475
|
crossorigin
|
|
464
|
-
src="
|
|
476
|
+
src="<%=
|
|
477
|
+
cdnEndpoints.cdngo
|
|
478
|
+
%>/lcap/lcap-resource-cdngo/-/0.1.4/_files/static/weda-render/main.90a1845eb61a012b3d66.bundle.js"
|
|
465
479
|
></script>
|
|
466
480
|
</body>
|
|
467
481
|
</html>
|
package/template/mp/app.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { app } from './app/weapps-api'
|
|
3
3
|
// 引入数据源管理器并进行初始化
|
|
4
4
|
import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
|
|
5
|
-
import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
|
|
5
|
+
import { redirectToLogin, findLoginPage, getAuthConfig, checkAnonymous } from './common/util'
|
|
6
6
|
|
|
7
7
|
// 防止报类型不匹配warning
|
|
8
8
|
const originWarn = console.warn;
|
|
@@ -37,7 +37,8 @@ setConfig({
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// 后续做过滤处理
|
|
40
|
-
|
|
40
|
+
const endpointType = app?.__internal__?.getCloudSdkConfig('endpointType');
|
|
41
|
+
if ((params?.data?.mode === 'c' && skip) || (endpointType !== 'tcb-api' && !loginPage)) {
|
|
41
42
|
return params;
|
|
42
43
|
}
|
|
43
44
|
// await initTcb();
|
|
@@ -68,11 +69,7 @@ setConfig({
|
|
|
68
69
|
const loginPage = findLoginPage();
|
|
69
70
|
if (loginPage) {
|
|
70
71
|
const authConfig = await getAuthConfig();
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
const { accessToken } = await getAccessToken();
|
|
74
|
-
isAnonymous = !accessToken;
|
|
75
|
-
} catch (e) { }
|
|
72
|
+
const isAnonymous = await checkAnonymous();
|
|
76
73
|
if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
|
|
77
74
|
redirectToLogin();
|
|
78
75
|
} else if (authConfig.RejectStrategy == 'show_warning') {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
import { findForItemsOfWidget, getWidget } from './widget'
|
|
3
3
|
import { observable, untracked } from 'mobx';
|
|
4
|
-
import { getAccessToken } from '../datasources/index'
|
|
4
|
+
import { getAccessToken, loginScope } from '../datasources/index'
|
|
5
5
|
import { app } from '../app/weapps-api'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -61,7 +61,7 @@ export function createEventHandlers(evtListeners) {
|
|
|
61
61
|
const [prefix = ''] = name.split('$');
|
|
62
62
|
// The page event handler
|
|
63
63
|
const { lists = [], itemsById = {} } = !!currentTarget && findForItemsOfWidget(currentTarget) || {}
|
|
64
|
-
const dataContext = untracked(()=>generateDataContext(currentTarget))
|
|
64
|
+
const dataContext = untracked(() => generateDataContext(currentTarget))
|
|
65
65
|
|
|
66
66
|
listeners.forEach(async l => {
|
|
67
67
|
let { data = {}, boundData = {} } = l;
|
|
@@ -310,6 +310,21 @@ async function getAccessPermission(app, appId, pageId) {
|
|
|
310
310
|
return isAccess
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
+
export async function checkAnonymous() {
|
|
314
|
+
let isAnonymous = true;
|
|
315
|
+
try {
|
|
316
|
+
const { accessToken } = await getAccessToken();
|
|
317
|
+
isAnonymous = !accessToken;
|
|
318
|
+
const { app } = getApp();
|
|
319
|
+
// 私密链路有token则不是匿名; tcb链路会匿名登录需要多验证scope === 'anonymous'
|
|
320
|
+
if (accessToken && app.__internal__.getCloudSdkConfig('endpointType') === 'tcb-api') {
|
|
321
|
+
const scope = await loginScope();
|
|
322
|
+
isAnonymous = scope === 'anonymous';
|
|
323
|
+
}
|
|
324
|
+
} catch (e) { }
|
|
325
|
+
return isAnonymous;
|
|
326
|
+
}
|
|
327
|
+
|
|
313
328
|
/**
|
|
314
329
|
* 检查页面权限
|
|
315
330
|
**/
|
|
@@ -327,11 +342,7 @@ export async function checkAuth(app, appId, $page) {
|
|
|
327
342
|
const [isAccess, authConfig] = await Promise.all(requestList);
|
|
328
343
|
app.hideNavigationBarLoading();
|
|
329
344
|
|
|
330
|
-
|
|
331
|
-
try {
|
|
332
|
-
const { accessToken } = await getAccessToken();
|
|
333
|
-
isAnonymousUser = !accessToken;
|
|
334
|
-
} catch (e) { }
|
|
345
|
+
const isAnonymousUser = await checkAnonymous();
|
|
335
346
|
|
|
336
347
|
if (!isAccess) {
|
|
337
348
|
if (isAnonymousUser && loginPage && (authConfig.NeedLogin || authConfig.RejectStrategy == 'to_login')) {
|
|
@@ -19,7 +19,20 @@ export default {
|
|
|
19
19
|
dataSourceProfiles: dataSourceProfiles,
|
|
20
20
|
/**
|
|
21
21
|
* 新的dataset变量配置对象
|
|
22
|
-
*
|
|
22
|
+
* key 为页面ID(全局为$global), val 为变量配置数组
|
|
23
23
|
*/
|
|
24
24
|
datasetProfiles: datasetProfiles,
|
|
25
|
+
/**
|
|
26
|
+
* 确定调用链路
|
|
27
|
+
*/
|
|
28
|
+
endpointType: '<%= endpointType %>',
|
|
29
|
+
/**
|
|
30
|
+
* 调用链路为 tcb-api 时有效
|
|
31
|
+
* 私有化需要设置
|
|
32
|
+
*/
|
|
33
|
+
tcbApiOrigin: '<%= tcbApiOrigin %>',
|
|
34
|
+
/**
|
|
35
|
+
* 是否是处于私有化版本
|
|
36
|
+
*/
|
|
37
|
+
isPrivate: <%= isPrivateMode %>
|
|
25
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth} from '@cloudbase/weda-client'
|
|
1
|
+
import { _WEDA_CLOUD_SDK as WEDA_CLOUD_SDK, auth } from '@cloudbase/weda-client'
|
|
2
2
|
const {
|
|
3
3
|
setConfig,
|
|
4
4
|
initTcb,
|
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
DS_SDK,
|
|
11
11
|
} = WEDA_CLOUD_SDK
|
|
12
12
|
const getAccessToken = auth.getAccessToken
|
|
13
|
+
const loginScope = auth.loginScope
|
|
13
14
|
|
|
14
15
|
export {
|
|
15
16
|
createDataset,
|
|
@@ -20,6 +21,7 @@ export {
|
|
|
20
21
|
DS_SDK,
|
|
21
22
|
setConfig,
|
|
22
23
|
getAccessToken,
|
|
24
|
+
loginScope,
|
|
23
25
|
initTcb,
|
|
24
26
|
}
|
|
25
27
|
|
package/template/mp/package.json
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
"name": "lcap-<%= appId%>",
|
|
3
3
|
"version": "1.0.8",
|
|
4
4
|
"scripts": {},
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"@cloudbase/
|
|
7
|
-
"@cloudbase/weda-cloud-sdk": "1.0.19",
|
|
5
|
+
"dependencies": {<% if(importJSSDK) {%>
|
|
6
|
+
"@cloudbase/js-sdk": "2.5.6-beta.1",<% } %>
|
|
8
7
|
"@cloudbase/oauth": "0.1.1-alpha.5",
|
|
8
|
+
"@cloudbase/weda-client": "0.2.36",
|
|
9
|
+
"@cloudbase/weda-cloud-sdk": "1.0.24-alpha.6",
|
|
9
10
|
"mobx": "^5.15.4",
|
|
10
11
|
"lodash.get": "^4.4.2",
|
|
11
12
|
"lodash.set": "^4.3.2",
|
|
12
13
|
"miniprogram-gesture": "^1.0.6",
|
|
13
14
|
"miniprogram-api-promise": "^1.0.4"<% Object.keys(extraDeps).map(depName => {%>,
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
%>
|
|
15
|
+
"<%= depName%>": "<%= extraDeps[depName]%>"<%
|
|
16
|
+
})%>
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|