@cloudbase/lowcode-builder 0.1.3 → 0.1.4
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/mp/index.js +58 -48
- package/package.json +3 -3
- package/lib/generate.d.ts +0 -1
- package/lib/generate.js +0 -60
- package/lib/tests/build.d.ts +0 -1
- package/lib/tests/build.js +0 -19
- package/lib/tests/build.test.d.ts +0 -1
- package/lib/tests/build.test.js +0 -22
- package/lib/tests/data.d.ts +0 -18
- package/lib/tests/data.js +0 -94216
- package/lib/utils/postProcess copy.d.ts +0 -2
- package/lib/utils/postProcess copy.js +0 -27
package/lib/builder/mp/index.js
CHANGED
|
@@ -93,31 +93,42 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
93
93
|
const miniprogramRoot = path_1.default.join(projDir, projectConfigJson.miniprogramRoot || '/');
|
|
94
94
|
await generateFramework(mainAppData, miniprogramRoot, buildContext);
|
|
95
95
|
// #3 生成主包根路径文件
|
|
96
|
-
let appFileData = {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
96
|
+
let appFileData = {};
|
|
97
|
+
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
98
|
+
await generateFramework(mainAppData, miniprogramRoot, buildContext);
|
|
99
|
+
// 有了 framework app 之后,并且是源码的方式,追加 app 引用
|
|
100
|
+
if (mainAppData.mpPkgUrl) {
|
|
101
|
+
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
102
|
+
let appJsContent = await fs.readFile(appJsPath);
|
|
103
|
+
await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
|
|
104
|
+
}
|
|
105
|
+
appFileData = {
|
|
106
|
+
...appFileData,
|
|
107
|
+
'common/style.js': {},
|
|
108
|
+
'common/utils.wxs': {
|
|
109
|
+
domain: domain,
|
|
110
|
+
},
|
|
111
|
+
'common/util.js': {
|
|
112
|
+
isAdminPortal: (0, common_1.buildAsAdminPortalByBuildType)(buildTypeList),
|
|
113
|
+
},
|
|
114
|
+
'common/widget.js': {},
|
|
115
|
+
'common/url.js': {},
|
|
116
|
+
'common/weapp-sdk.js': {},
|
|
117
|
+
'common/weapp-page.js': {
|
|
118
|
+
dataPropNames: wxmlDataPrefix,
|
|
119
|
+
debug: buildContext.debugMode,
|
|
120
|
+
},
|
|
121
|
+
'common/weapp-component.js': {},
|
|
122
|
+
'common/merge-renderer.js': {
|
|
123
|
+
dataPropNames: wxmlDataPrefix,
|
|
124
|
+
debug: buildContext.debugMode,
|
|
125
|
+
},
|
|
126
|
+
'common/process.js': {},
|
|
127
|
+
'common/data-patch.js': {},
|
|
128
|
+
'common/event-emitter.js': {},
|
|
129
|
+
'common/watch.js': {},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
121
132
|
if (mainAppData.mpPkgUrl) {
|
|
122
133
|
// 合并 project 和 app json
|
|
123
134
|
if (!projectConfigJson.setting) {
|
|
@@ -142,9 +153,6 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
142
153
|
}
|
|
143
154
|
appJson.subpackages = subpackages;
|
|
144
155
|
await (0, generateFiles_1.writeFile)(appJsonPath, JSON.stringify(appJson, undefined, 2));
|
|
145
|
-
let appJsPath = path_1.default.join(miniprogramRoot, 'app.js');
|
|
146
|
-
let appJsContent = await fs.readFile(appJsPath);
|
|
147
|
-
await (0, generateFiles_1.writeFile)(appJsPath, `import { app as wedaApp } from './app/weapps-api'\n${appJsContent}`);
|
|
148
156
|
}
|
|
149
157
|
else {
|
|
150
158
|
appFileData = {
|
|
@@ -178,26 +186,28 @@ async function generateWxMp({ weapps, projDir, appId, domain, materials, plugins
|
|
|
178
186
|
await fs.move(path_1.default.join(projDir, config_1.materialsDirName), path_1.default.join(miniprogramRoot, config_1.materialsDirName));
|
|
179
187
|
}
|
|
180
188
|
// 生成数据源
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
if (weapps.find((item) => !item.mpPkgUrl)) {
|
|
190
|
+
const datasourceFileData = {
|
|
191
|
+
'datasources/index.js': {},
|
|
192
|
+
'datasources/config.js.tpl': {
|
|
193
|
+
envID: mainAppData.envId,
|
|
194
|
+
appID: appId,
|
|
195
|
+
resourceAppid: !!options.isCrossAccount ? options.resourceAppId : '',
|
|
196
|
+
isProd: deployMode === types_1.DEPLOY_MODE.UPLOAD,
|
|
197
|
+
},
|
|
198
|
+
'datasources/datasource-profiles.js.tpl': {
|
|
199
|
+
datasourceProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasourceProfiles)(weapps.reduce((datasources, app) => {
|
|
200
|
+
datasources.push(...(app.datasources || []));
|
|
201
|
+
return datasources;
|
|
202
|
+
}, [])), { EOL: false }),
|
|
203
|
+
},
|
|
204
|
+
'datasources/dataset-profiles.js.tpl': {
|
|
205
|
+
datasetProfiles: (0, util_3.JsonToStringWithVariableName)((0, lowcode_generator_1.getDatasetProfiles)(mainAppData, weapps), { EOL: true }),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
console.log('Generating ' + em('datasources') + ' files');
|
|
209
|
+
await (0, generateFiles_1.default)(datasourceFileData, templateDir, miniprogramRoot, buildContext);
|
|
210
|
+
}
|
|
201
211
|
// 生成子包
|
|
202
212
|
await Promise.all(weapps.map(async (app, index) => {
|
|
203
213
|
if (index == 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cloudbase/cals": "0.3.3",
|
|
36
|
+
"@cloudbase/cals": "^0.3.3",
|
|
37
37
|
"@cloudbase/lowcode-generator": "^0.6.13",
|
|
38
38
|
"axios": "^0.21.0",
|
|
39
39
|
"chalk": "^2.4.2",
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"ts-node": "^10.4.0",
|
|
69
69
|
"typescript": "^4.4.2"
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
}
|
package/lib/generate.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function handleMpPlugins(plugins: any[] | undefined, appBuildDir: string): Promise<void>;
|
package/lib/generate.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handleMpPlugins = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const core_1 = require("./builder/core");
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
|
-
async function handleMpPlugins(plugins = [], appBuildDir) {
|
|
12
|
-
const appBuildMpDir = path_1.default.resolve(appBuildDir, 'dist/mp');
|
|
13
|
-
const appBuildNodeModulesDir = path_1.default.resolve(appBuildDir, 'node_modules');
|
|
14
|
-
const mpBuildPkgJsonPath = path_1.default.resolve(appBuildMpDir, 'package.json');
|
|
15
|
-
const buildPkgJson = fs_extra_1.default.readJsonSync(mpBuildPkgJsonPath);
|
|
16
|
-
const sourcePkgJson = fs_extra_1.default.readJsonSync(path_1.default.join(appBuildDir, 'package.json'));
|
|
17
|
-
// 合并插件内容
|
|
18
|
-
plugins
|
|
19
|
-
.filter((plugin) => plugin.type === 'mp')
|
|
20
|
-
.forEach((plugin) => {
|
|
21
|
-
const mpBuildAppJsonPath = path_1.default.resolve(appBuildMpDir, 'app.json');
|
|
22
|
-
const pluginAppJsonPath = path_1.default.resolve(appBuildNodeModulesDir, plugin.module, 'app.json');
|
|
23
|
-
// 合并 app.json
|
|
24
|
-
mergeSubPackages(mpBuildAppJsonPath, pluginAppJsonPath);
|
|
25
|
-
// 加入到包依赖中
|
|
26
|
-
buildPkgJson.dependencies[plugin.module] =
|
|
27
|
-
sourcePkgJson.dependencies[plugin.module];
|
|
28
|
-
});
|
|
29
|
-
// 安装
|
|
30
|
-
fs_extra_1.default.writeJsonSync(mpBuildPkgJsonPath, buildPkgJson, { spaces: 2 });
|
|
31
|
-
console.log('小程序安装依赖', appBuildMpDir);
|
|
32
|
-
await (0, core_1.installDep)(appBuildMpDir);
|
|
33
|
-
}
|
|
34
|
-
exports.handleMpPlugins = handleMpPlugins;
|
|
35
|
-
function mergeSubPackages(baseAppJsonPath, mergeAppJsonPath) {
|
|
36
|
-
const baseJson = fs_extra_1.default.readJSONSync(baseAppJsonPath);
|
|
37
|
-
const mergeJson = fs_extra_1.default.readJSONSync(mergeAppJsonPath);
|
|
38
|
-
if (!mergeJson.subpackages)
|
|
39
|
-
return;
|
|
40
|
-
const newJson = { ...baseJson };
|
|
41
|
-
if (!baseJson.subpackages) {
|
|
42
|
-
newJson.subpackages = mergeJson.subpackages;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
mergeJson.subpackages.forEach((mergeItem) => {
|
|
46
|
-
// 找到重复的进行合并再去重
|
|
47
|
-
const targetItemIdx = newJson.subpackages.findIndex((item) => {
|
|
48
|
-
return item.root === mergeItem.root;
|
|
49
|
-
});
|
|
50
|
-
if (newJson.subpackages[targetItemIdx]) {
|
|
51
|
-
const pages = (0, lodash_1.uniq)([].concat(newJson.subpackages[targetItemIdx].pages, mergeItem.pages));
|
|
52
|
-
newJson.subpackages[targetItemIdx].pages = pages;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
newJson.subpackages.push(mergeItem);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
fs_extra_1.default.writeJSONSync(baseAppJsonPath, newJson, { spaces: 2 });
|
|
60
|
-
}
|
package/lib/tests/build.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/tests/build.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_1 = require("../index");
|
|
7
|
-
const data_1 = __importDefault(require("./data"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const common_1 = require("../src/builder/types/common");
|
|
11
|
-
const outPath = path_1.default.resolve(__dirname, '.temp');
|
|
12
|
-
fs_extra_1.default.emptyDirSync(outPath);
|
|
13
|
-
(0, index_1.buildWedaApp)({
|
|
14
|
-
...data_1.default,
|
|
15
|
-
buildTypeList: [common_1.BuildType.WEB],
|
|
16
|
-
output: { path: outPath },
|
|
17
|
-
}).then((dir) => {
|
|
18
|
-
console.log(dir);
|
|
19
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/tests/build.test.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_1 = require("../index");
|
|
7
|
-
const data_1 = __importDefault(require("./data"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const common_1 = require("../lib/builder/types/common");
|
|
11
|
-
describe('build', () => {
|
|
12
|
-
it('needs tests', async () => {
|
|
13
|
-
const outPath = path_1.default.resolve(__dirname, './temp');
|
|
14
|
-
fs_extra_1.default.emptyDir(outPath);
|
|
15
|
-
let dir = await (0, index_1.buildWedaApp)({
|
|
16
|
-
...data_1.default,
|
|
17
|
-
buildTypeList: [common_1.BuildType.WEB],
|
|
18
|
-
output: { path: outPath },
|
|
19
|
-
});
|
|
20
|
-
console.log(dir);
|
|
21
|
-
});
|
|
22
|
-
});
|
package/lib/tests/data.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BuildType } from '../builder/types/common';
|
|
2
|
-
import { DEPLOY_MODE } from '../types';
|
|
3
|
-
export declare const test: {
|
|
4
|
-
appKey: string;
|
|
5
|
-
cals: any;
|
|
6
|
-
subAppCalsList: never[];
|
|
7
|
-
dependencies: any[];
|
|
8
|
-
buildTypeList: BuildType[];
|
|
9
|
-
deployOptions: {
|
|
10
|
-
mode: DEPLOY_MODE;
|
|
11
|
-
mpAppId: string;
|
|
12
|
-
targetMpAppId: string;
|
|
13
|
-
};
|
|
14
|
-
domain: string;
|
|
15
|
-
resourceAppId: string;
|
|
16
|
-
};
|
|
17
|
-
declare const _default: any;
|
|
18
|
-
export default _default;
|