@cloudbase/lowcode-builder 0.1.1 → 0.1.5-mp-beta
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 +14 -0
- package/lib/builder/config/index.js +16 -1
- package/lib/builder/core/index.d.ts +4 -1
- package/lib/builder/core/index.js +15 -3
- package/lib/builder/h5/copy.js +17 -3
- package/lib/builder/mp/BuildContext.d.ts +1 -0
- package/lib/builder/mp/index.d.ts +2 -1
- package/lib/builder/mp/index.js +65 -53
- package/lib/builder/mp/materials.js +12 -14
- package/lib/builder/mp/mp_config.js +1 -1
- package/lib/builder/mp/wxml.js +5 -1
- package/lib/builder/service/webpack.js +10 -10
- package/lib/builder/util/common.js +5 -4
- package/lib/builder/util/generateFiles.d.ts +33 -0
- package/lib/builder/util/generateFiles.js +120 -1
- package/lib/builder/util/net.d.ts +20 -1
- package/lib/builder/util/net.js +72 -3
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -1
- package/package.json +21 -7
- package/template/html/index.html.ejs +6 -9
- package/template/mp/app/weapps-api.js +17 -45
- package/template/mp/app.js +66 -66
- package/template/mp/common/weapp-page.js +3 -1
- package/template/mp/component/index.js +6 -2
- package/template/mp/datasources/config.js.tpl +1 -1
- package/template/mp/datasources/datasource-profiles.js.tpl +1 -1
- package/template/mp/datasources/index.js +13 -4
- package/template/mp/package.json +12 -11
- package/template/mp/page/index.js +6 -2
- package/template/package.json +4 -2
- package/template/src/app/global-api.js +6 -83
- package/template/src/app/material-actions.js +15 -13
- package/template/src/datasources/index.js +15 -2
- package/template/src/index.jsx +1 -1
- package/template/webpack/web.prod.js +62 -41
- 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/template/src/pages/composite.tpl +0 -151
|
@@ -22,12 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.copy = exports.copyFiles = exports.cleanDir = exports.removeFile = exports.writeFile = void 0;
|
|
25
|
+
exports.strToBuf = exports.fileToZip = exports.getFiles = exports.copyRecursiveSync = exports.copyFileSync = exports.copy = exports.copyFiles = exports.cleanDir = exports.removeFile = exports.writeFile = void 0;
|
|
26
26
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
28
|
const lodash_template_1 = __importDefault(require("lodash.template"));
|
|
29
29
|
const junk = __importStar(require("../util/junk"));
|
|
30
30
|
const glob_1 = __importDefault(require("glob"));
|
|
31
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
32
|
+
const buffer_1 = require("buffer");
|
|
31
33
|
const generatedFileContents = {}; // generated files for incrmental build
|
|
32
34
|
async function generateFiles(appFileData, srcDir, dstDir, ctx) {
|
|
33
35
|
const filesGenerated = [];
|
|
@@ -120,3 +122,120 @@ async function copy(src, dest) {
|
|
|
120
122
|
await copyFiles(needCopyFiles, src, dest);
|
|
121
123
|
}
|
|
122
124
|
exports.copy = copy;
|
|
125
|
+
/**
|
|
126
|
+
* 复制文件
|
|
127
|
+
* @param source 源文件
|
|
128
|
+
* @param target 目标文件
|
|
129
|
+
*/
|
|
130
|
+
function copyFileSync(source, target) {
|
|
131
|
+
let targetFile = target;
|
|
132
|
+
// If target is a directory, a new file with the same name will be created
|
|
133
|
+
if (fs_extra_1.default.existsSync(target)) {
|
|
134
|
+
if (fs_extra_1.default.lstatSync(target).isDirectory()) {
|
|
135
|
+
targetFile = path_1.default.join(target, path_1.default.basename(source));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
fs_extra_1.default.writeFileSync(targetFile, fs_extra_1.default.readFileSync(source));
|
|
139
|
+
}
|
|
140
|
+
exports.copyFileSync = copyFileSync;
|
|
141
|
+
/**
|
|
142
|
+
* 根据源文件目录,输出目录,递归复制文件
|
|
143
|
+
* @param {string} src 源文件目录
|
|
144
|
+
* @param {string} dest 输出目录
|
|
145
|
+
*/
|
|
146
|
+
const copyRecursiveSync = function (src, dest) {
|
|
147
|
+
var exists = fs_extra_1.default.existsSync(src);
|
|
148
|
+
var stats = exists && fs_extra_1.default.statSync(src);
|
|
149
|
+
var isDirectory = exists && stats.isDirectory();
|
|
150
|
+
if (!fs_extra_1.default.existsSync(dest)) {
|
|
151
|
+
mkDirByPathSync(path_1.default.parse(dest).dir);
|
|
152
|
+
}
|
|
153
|
+
if (isDirectory) {
|
|
154
|
+
const files = fs_extra_1.default.readdirSync(src);
|
|
155
|
+
files.forEach(function (childItemName) {
|
|
156
|
+
(0, exports.copyRecursiveSync)(path_1.default.join(src, childItemName), path_1.default.join(dest, childItemName));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
copyFileSync(src, dest);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
exports.copyRecursiveSync = copyRecursiveSync;
|
|
164
|
+
/**
|
|
165
|
+
* 参考:https://stackoverflow.com/questions/31645738/how-to-create-full-path-with-nodes-fs-mkdirsync
|
|
166
|
+
* @param targetDir
|
|
167
|
+
* @param param1
|
|
168
|
+
* @returns
|
|
169
|
+
*/
|
|
170
|
+
function mkDirByPathSync(targetDir, { isRelativeToScript = false } = {}) {
|
|
171
|
+
const sep = path_1.default.sep;
|
|
172
|
+
const initDir = path_1.default.isAbsolute(targetDir) ? sep : '';
|
|
173
|
+
const baseDir = isRelativeToScript ? __dirname : '.';
|
|
174
|
+
return targetDir.split(sep).reduce((parentDir, childDir) => {
|
|
175
|
+
const curDir = path_1.default.resolve(baseDir, parentDir, childDir);
|
|
176
|
+
try {
|
|
177
|
+
fs_extra_1.default.mkdirSync(curDir);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
if (err.code === 'EEXIST') { // curDir already exists!
|
|
181
|
+
return curDir;
|
|
182
|
+
}
|
|
183
|
+
// To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
|
|
184
|
+
if (err.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
|
|
185
|
+
throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
|
|
186
|
+
}
|
|
187
|
+
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
|
|
188
|
+
if (!caughtErr || caughtErr && curDir === path_1.default.resolve(targetDir)) {
|
|
189
|
+
throw err; // Throw if it's just the last created dir.
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return curDir;
|
|
193
|
+
}, initDir);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 返回指定目录的文件列表内容,返回map格式
|
|
197
|
+
* @param dir 指定目录
|
|
198
|
+
* @param files_ 文件列表
|
|
199
|
+
* @param replacePath 去掉前面路径
|
|
200
|
+
* @returns
|
|
201
|
+
*/
|
|
202
|
+
function getFiles(dir, files_, replacePath = '') {
|
|
203
|
+
files_ = files_ || {};
|
|
204
|
+
const files = fs_extra_1.default.readdirSync(dir);
|
|
205
|
+
let mapName;
|
|
206
|
+
for (let i in files) {
|
|
207
|
+
const name = path_1.default.join(dir, files[i]);
|
|
208
|
+
if (fs_extra_1.default.statSync(name).isDirectory()) {
|
|
209
|
+
getFiles(name, files_, replacePath);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
mapName = name;
|
|
213
|
+
// 替换根路径
|
|
214
|
+
if (name.indexOf(replacePath) === 0) {
|
|
215
|
+
mapName = name.replace(replacePath, '');
|
|
216
|
+
}
|
|
217
|
+
files_[mapName] = fs_extra_1.default.readFileSync(name);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return files_;
|
|
221
|
+
}
|
|
222
|
+
exports.getFiles = getFiles;
|
|
223
|
+
/**
|
|
224
|
+
* 将文件压缩为zip包
|
|
225
|
+
* 参考JSZip例子:https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
|
|
226
|
+
* @param files
|
|
227
|
+
* @param type
|
|
228
|
+
* @returns
|
|
229
|
+
*/
|
|
230
|
+
async function fileToZip(files, type) {
|
|
231
|
+
var zip = new jszip_1.default();
|
|
232
|
+
for (let prop in files) {
|
|
233
|
+
zip.file(prop, files[prop]);
|
|
234
|
+
}
|
|
235
|
+
return zip.generateAsync({ type });
|
|
236
|
+
}
|
|
237
|
+
exports.fileToZip = fileToZip;
|
|
238
|
+
function strToBuf(str) {
|
|
239
|
+
return buffer_1.Buffer.from(str);
|
|
240
|
+
}
|
|
241
|
+
exports.strToBuf = strToBuf;
|
|
@@ -4,4 +4,23 @@ export declare function downloadFile(url: string, filePath: string): Promise<voi
|
|
|
4
4
|
* @param url
|
|
5
5
|
* @param dstDir folder to hold the extract zip content
|
|
6
6
|
*/
|
|
7
|
-
export declare function downloadZip(url: string, dstDir: string): Promise<void>;
|
|
7
|
+
export declare function downloadZip(url: string, dstDir: string, isBrowser?: boolean): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* node中下载和保存zip文件
|
|
10
|
+
* @param url 下载的url
|
|
11
|
+
* @param dstDir 存放文件夹
|
|
12
|
+
*/
|
|
13
|
+
export declare function downloadZipInNode(url: string, dstDir: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* 浏览器中下载和保存zip文件
|
|
16
|
+
* @param url 下载的url
|
|
17
|
+
* @param dstDir 存放文件夹
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function downloadZipInBrowser(url: string, dstDir: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* 微信IDE builder需要下载template文件和miniprogram_npm
|
|
23
|
+
* miniprogram_npm待微信提供端能力
|
|
24
|
+
* @param output
|
|
25
|
+
*/
|
|
26
|
+
export declare function downloadBrowserMaterial(output?: string): Promise<void>;
|
package/lib/builder/util/net.js
CHANGED
|
@@ -22,11 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.downloadZip = exports.downloadFile = void 0;
|
|
25
|
+
exports.downloadBrowserMaterial = exports.downloadZipInBrowser = exports.downloadZipInNode = exports.downloadZip = exports.downloadFile = void 0;
|
|
26
26
|
const axios_1 = __importDefault(require("axios"));
|
|
27
27
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
29
|
const compressing_1 = __importDefault(require("compressing"));
|
|
30
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
31
|
+
const config_1 = require("../config");
|
|
32
|
+
const generateFiles_1 = require("../util/generateFiles");
|
|
30
33
|
async function downloadFile(url, filePath) {
|
|
31
34
|
await fs_extra_1.default.ensureDir(path.dirname(filePath));
|
|
32
35
|
const res = await axios_1.default.get(url, { responseType: 'stream' });
|
|
@@ -38,9 +41,75 @@ exports.downloadFile = downloadFile;
|
|
|
38
41
|
* @param url
|
|
39
42
|
* @param dstDir folder to hold the extract zip content
|
|
40
43
|
*/
|
|
41
|
-
async function downloadZip(url, dstDir) {
|
|
44
|
+
async function downloadZip(url, dstDir, isBrowser = false) {
|
|
45
|
+
// TODO 待加上平台判断
|
|
46
|
+
if (isBrowser) {
|
|
47
|
+
await downloadZipInBrowser(url, dstDir);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await downloadZipInNode(url, dstDir);
|
|
51
|
+
}
|
|
52
|
+
exports.downloadZip = downloadZip;
|
|
53
|
+
/**
|
|
54
|
+
* node中下载和保存zip文件
|
|
55
|
+
* @param url 下载的url
|
|
56
|
+
* @param dstDir 存放文件夹
|
|
57
|
+
*/
|
|
58
|
+
async function downloadZipInNode(url, dstDir) {
|
|
42
59
|
await fs_extra_1.default.ensureDir(dstDir);
|
|
43
60
|
const res = await axios_1.default.get(url, { responseType: 'stream' });
|
|
44
61
|
await compressing_1.default.zip.uncompress(res.data, dstDir);
|
|
45
62
|
}
|
|
46
|
-
exports.
|
|
63
|
+
exports.downloadZipInNode = downloadZipInNode;
|
|
64
|
+
/**
|
|
65
|
+
* 浏览器中下载和保存zip文件
|
|
66
|
+
* @param url 下载的url
|
|
67
|
+
* @param dstDir 存放文件夹
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
async function downloadZipInBrowser(url, dstDir) {
|
|
71
|
+
// IMPORTANT 防止保存的时候保存
|
|
72
|
+
if (fs_extra_1.default.existsSync(dstDir)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
fs_extra_1.default.ensureDirSync(dstDir);
|
|
76
|
+
const res = await axios_1.default.get(url, { responseType: 'arraybuffer' });
|
|
77
|
+
const data = await jszip_1.default.loadAsync(res.data);
|
|
78
|
+
await saveFiles(data.files, dstDir);
|
|
79
|
+
}
|
|
80
|
+
exports.downloadZipInBrowser = downloadZipInBrowser;
|
|
81
|
+
/**
|
|
82
|
+
* 保存JSZip解压的文件内容
|
|
83
|
+
* @param files 文件
|
|
84
|
+
* @param dstDir 指定目录
|
|
85
|
+
*/
|
|
86
|
+
async function saveFiles(files, dstDir) {
|
|
87
|
+
try {
|
|
88
|
+
for (const fileName of Object.keys(files)) {
|
|
89
|
+
const dest = path.join(dstDir, fileName);
|
|
90
|
+
if (files[fileName].dir) { // 如果该文件为目录需先创建文件夹
|
|
91
|
+
fs_extra_1.default.mkdirSync(dest, {
|
|
92
|
+
recursive: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const ret = await files[fileName].async('nodebuffer'); // 由于这里有await,不能用forEach
|
|
97
|
+
fs_extra_1.default.writeFileSync(dest, ret);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
console.error('saveFiles catch error:', err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 微信IDE builder需要下载template文件和miniprogram_npm
|
|
107
|
+
* miniprogram_npm待微信提供端能力
|
|
108
|
+
* @param output
|
|
109
|
+
*/
|
|
110
|
+
async function downloadBrowserMaterial(output = '.weapps-build') {
|
|
111
|
+
await Promise.all([downloadZip(config_1.builderTemplateURL, config_1.appTemplateDir, true), downloadZip(config_1.miniprogramURL, config_1.miniprogramDir, true)]);
|
|
112
|
+
// 必须先下载到.weapps-materials目录,因为.weapps-materials是默认下载目录,共享组件逻辑sharedMaterialsDir时会读取文件
|
|
113
|
+
(0, generateFiles_1.copyRecursiveSync)(config_1.miniprogramDir, path.join(output, 'miniprogram_npm'));
|
|
114
|
+
}
|
|
115
|
+
exports.downloadBrowserMaterial = downloadBrowserMaterial;
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HISTORY_TYPE = exports.RUNTIME = exports.DEPLOY_MODE = void 0;
|
|
3
|
+
exports.PropBindType = exports.HISTORY_TYPE = exports.RUNTIME = exports.DEPLOY_MODE = void 0;
|
|
4
4
|
var DEPLOY_MODE;
|
|
5
5
|
(function (DEPLOY_MODE) {
|
|
6
6
|
DEPLOY_MODE["PREVIEW"] = "preview";
|
|
@@ -17,3 +17,5 @@ var HISTORY_TYPE;
|
|
|
17
17
|
HISTORY_TYPE["BROWSER"] = "BROWSER";
|
|
18
18
|
HISTORY_TYPE["HASH"] = "HASH";
|
|
19
19
|
})(HISTORY_TYPE = exports.HISTORY_TYPE || (exports.HISTORY_TYPE = {}));
|
|
20
|
+
var cals_1 = require("@cloudbase/cals");
|
|
21
|
+
Object.defineProperty(exports, "PropBindType", { enumerable: true, get: function () { return cals_1.PropBindType; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/lowcode-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5-mp-beta",
|
|
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",
|
|
@@ -25,31 +25,43 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "tsc -w",
|
|
27
27
|
"develop": "tsc -w",
|
|
28
|
-
"build": "tsc",
|
|
29
|
-
"test": "jest"
|
|
28
|
+
"build": "rm -rf lib && tsc",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:build": "ts-node ./__test__/build.ts",
|
|
31
|
+
"dev:mpweb": "rm -rf dist && cross-env NODE_ENV=development webpack-dev-server --config ./webpack/mpweb.config.js",
|
|
32
|
+
"build:mpweb": "rm -rf dist && cross-env NODE_ENV=production webpack --config ./webpack/mpweb.config.js"
|
|
30
33
|
},
|
|
31
34
|
"bugs": {
|
|
32
35
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
|
-
"@cloudbase/cals": "0.3.3",
|
|
36
|
-
"@cloudbase/lowcode-generator": "0.
|
|
38
|
+
"@cloudbase/cals": "^0.3.3",
|
|
39
|
+
"@cloudbase/lowcode-generator": "0.4.22-mp-beta",
|
|
37
40
|
"axios": "^0.21.0",
|
|
41
|
+
"browserfs": "^1.4.3",
|
|
42
|
+
"browserify-zlib": "^0.2.0",
|
|
38
43
|
"chalk": "^2.4.2",
|
|
39
44
|
"compare-versions": "^3.6.0",
|
|
40
45
|
"compressing": "^1.4.0",
|
|
41
46
|
"cross-spawn": "^6.0.5",
|
|
42
47
|
"fs-extra": "^7.0.1",
|
|
48
|
+
"constants-browserify": "^1.0.0",
|
|
49
|
+
"crypto-browserify": "^3.12.0",
|
|
50
|
+
"jszip": "^3.7.1",
|
|
43
51
|
"lodash": "^4.17.11",
|
|
44
52
|
"lodash.clone": "^4.5.0",
|
|
45
53
|
"lodash.get": "^4.4.2",
|
|
46
54
|
"lodash.set": "^4.3.2",
|
|
47
55
|
"lodash.template": "^4.5.0",
|
|
48
56
|
"lodash.uniqby": "^4.7.0",
|
|
57
|
+
"os-browserify": "^0.3.0",
|
|
58
|
+
"stream-browserify": "^3.0.0",
|
|
49
59
|
"webpack": "^4.41.4",
|
|
50
60
|
"xml-js": "^1.6.11"
|
|
51
61
|
},
|
|
52
62
|
"devDependencies": {
|
|
63
|
+
"worker-loader": "^3.0.8",
|
|
64
|
+
"@rollup/plugin-alias": "^3.1.9",
|
|
53
65
|
"@types/archiver": "^3.1.0",
|
|
54
66
|
"@types/command-exists": "^1.2.0",
|
|
55
67
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -63,8 +75,10 @@
|
|
|
63
75
|
"@types/weixin-app": "^2.9.0",
|
|
64
76
|
"csstype": "^2.6.10",
|
|
65
77
|
"jest": "^26.0.1",
|
|
66
|
-
"ts-
|
|
78
|
+
"ts-loader": "^8.3.0",
|
|
67
79
|
"ts-node": "^10.4.0",
|
|
68
|
-
"typescript": "^4.4.2"
|
|
80
|
+
"typescript": "^4.4.2",
|
|
81
|
+
"webpack-cli": "^4.9.1",
|
|
82
|
+
"webpack-dev-server": "^4.7.3"
|
|
69
83
|
}
|
|
70
84
|
}
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
<% if(mode !== 'production'){ %>
|
|
27
27
|
<!-- <script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
|
|
28
28
|
<script>new VConsole()</script> -->
|
|
29
|
-
<% }%> <% Array.isArray(jsApis) &&
|
|
30
|
-
|
|
29
|
+
<% }%> <% Array.isArray(jsApis) && jsApis.filter(function(item){return
|
|
30
|
+
!!item}).forEach(function(jsApi){%>
|
|
31
31
|
<script src="<%=jsApi %>"></script>
|
|
32
32
|
<% })%>
|
|
33
33
|
|
|
@@ -373,10 +373,8 @@
|
|
|
373
373
|
<div id="root" class="main-wrap"></div>
|
|
374
374
|
<% if(canUseVite){ %>
|
|
375
375
|
<script type="module" src="/src/index.jsx"></script>
|
|
376
|
-
<% } %>
|
|
377
|
-
|
|
378
|
-
<% if(!isAdminPortal){ %>
|
|
379
|
-
<script src="//imgcache.qq.com/qcloud/cloudbase-js-sdk/1.5.3-alpha.0/cloudbase.full.js"></script>
|
|
376
|
+
<% } %> <% if(!isAdminPortal){ %>
|
|
377
|
+
<script src="https://imgcache.qq.com/qcloud/cloudbase-js-sdk/1.5.3-alpha.0/cloudbase.full.js"></script>
|
|
380
378
|
<% }%>
|
|
381
379
|
<script>
|
|
382
380
|
if (window.cloudbase) {
|
|
@@ -431,10 +429,9 @@
|
|
|
431
429
|
}
|
|
432
430
|
</script>
|
|
433
431
|
<script
|
|
434
|
-
src="
|
|
432
|
+
src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/ajax/libs/mobx/5.15.7/mobx.umd.js"
|
|
435
433
|
crossorigin="anonymous"
|
|
436
434
|
></script>
|
|
437
|
-
<script src="
|
|
438
|
-
<script src="//qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"></script>
|
|
435
|
+
<script src="https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/0.1.2/_url/npm/@zxing/library@0.18.6/umd/index.min.js"></script>
|
|
439
436
|
</body>
|
|
440
437
|
</html>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { observable } from 'mobx'
|
|
2
|
-
import {
|
|
2
|
+
import { createMpApp } from '@cloudbase/weda-client';
|
|
3
|
+
import { createComputed } from '<%= subLevelPath %>../common/util'
|
|
3
4
|
import process from '<%= subLevelPath %>../common/process'
|
|
4
|
-
import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
5
5
|
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
6
|
-
import
|
|
6
|
+
import { createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
7
7
|
|
|
8
8
|
<% if (!isBare) {%>
|
|
9
9
|
import state from '../lowcode/state'
|
|
10
|
-
import computed from '../lowcode/computed'
|
|
11
|
-
import common from './common'
|
|
10
|
+
import computed from '../lowcode/computed'
|
|
11
|
+
import common from './common'
|
|
12
12
|
<%} else {%>
|
|
13
13
|
const state = {}
|
|
14
|
-
const computed ={}
|
|
15
|
-
const common = {}
|
|
16
|
-
<%}%>
|
|
14
|
+
const computed = {}
|
|
15
|
+
const common = {}
|
|
16
|
+
<%}%>
|
|
17
17
|
|
|
18
18
|
const mainAppKey = '__weappsMainApp'
|
|
19
19
|
|
|
@@ -21,12 +21,11 @@ export const app = createGlboalApi()
|
|
|
21
21
|
export { process }
|
|
22
22
|
|
|
23
23
|
function createGlboalApi() {
|
|
24
|
+
const mpApp = createMpApp();
|
|
24
25
|
const globalAPI = {
|
|
25
26
|
id: '<%= appId %>',
|
|
26
27
|
domain: '<%= domain %>',
|
|
27
|
-
platform: 'MINIPROGRAME',
|
|
28
28
|
activePage: null,
|
|
29
|
-
dataSources: DS_SDK,
|
|
30
29
|
pages: {},
|
|
31
30
|
session: {
|
|
32
31
|
//configure: sdk.configure,
|
|
@@ -36,11 +35,7 @@ function createGlboalApi() {
|
|
|
36
35
|
state: observable(state),
|
|
37
36
|
computed: createComputed(computed),
|
|
38
37
|
common,
|
|
39
|
-
|
|
40
|
-
formatDate,
|
|
41
|
-
get: getter,
|
|
42
|
-
set: setter,
|
|
43
|
-
},
|
|
38
|
+
...mpApp
|
|
44
39
|
// ... other sdk apis & apis from mp
|
|
45
40
|
} // The global api exposed to lowcode
|
|
46
41
|
|
|
@@ -52,18 +47,16 @@ function createGlboalApi() {
|
|
|
52
47
|
globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
|
|
53
48
|
});
|
|
54
49
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
/**
|
|
51
|
+
* 内部通用的设置状态变量值的方法
|
|
52
|
+
* varPath 结构为 $global.<变量名> 即全局变量
|
|
53
|
+
* $page.<变量名> 即当前页面变量
|
|
54
|
+
* <pageId>.<变量名> 指定页面 pageId 的变量 (应当避免修改非当前页面的变量值)
|
|
55
|
+
*/
|
|
61
56
|
globalAPI._setStateVal = (config) => {
|
|
62
57
|
// @ts-ignore
|
|
63
58
|
EXTRA_API.setState(config.varPath, config.val);
|
|
64
59
|
};
|
|
65
|
-
// mount wx apis
|
|
66
|
-
Object.assign(globalAPI, weappApis)
|
|
67
60
|
|
|
68
61
|
const subPackageName = '<%= subPackageName %>'
|
|
69
62
|
if (subPackageName) {
|
|
@@ -75,33 +68,12 @@ function createGlboalApi() {
|
|
|
75
68
|
// is mainApp
|
|
76
69
|
appGlobal[mainAppKey] = globalAPI
|
|
77
70
|
}
|
|
78
|
-
// 避免被wx.cloud 覆盖
|
|
79
|
-
globalAPI.cloud = CLOUD_SDK
|
|
80
71
|
|
|
81
72
|
// # expose some sdk modules
|
|
82
73
|
/* const sdkModsIncluded = ['flow', 'getPageOptions', 'getLaunchOptions']
|
|
83
74
|
sdkModsIncluded.forEach(key => {
|
|
84
75
|
globalAPI[key] = sdk[key]
|
|
85
76
|
}) */
|
|
86
|
-
|
|
87
|
-
globalAPI.scanCode = (options) => {
|
|
88
|
-
const {enableDefaultBehavior, ...restOptions} = options;
|
|
89
|
-
const shouldReturnPromise = (!restOptions.success && !restOptions.complete && !restOptions.fail);
|
|
90
|
-
if(shouldReturnPromise) {
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
scanCode(restOptions).then((res) => {
|
|
93
|
-
if(enableDefaultBehavior) {
|
|
94
|
-
globalAPI.showModal({
|
|
95
|
-
title: '扫描到以下内容',
|
|
96
|
-
content: res.result,
|
|
97
|
-
showCancel: false,
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
resolve(res)
|
|
101
|
-
})
|
|
102
|
-
.catch(reject)
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
}
|
|
77
|
+
|
|
106
78
|
return globalAPI
|
|
107
79
|
}
|
package/template/mp/app.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { setConfig } from '
|
|
1
|
+
import { setConfig } from './datasources/index'
|
|
2
2
|
import lifeCycle from './lowcode/lifecycle'
|
|
3
3
|
import { app } from './app/weapps-api'
|
|
4
4
|
import WxReportV2 from './common/wx_yypt_report_v2'
|
|
5
5
|
// 引入数据源管理器并进行初始化
|
|
6
6
|
import { EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index'
|
|
7
7
|
const $app = app;
|
|
8
|
-
<% if(yyptConfig.yyptAppKey) { %>
|
|
8
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
9
9
|
const wxReport = new WxReportV2({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
appKey: '<%= yyptConfig.yyptAppKey %>', // 填入你申请的运营平台的应用key(必填)
|
|
11
|
+
reportUrl: '<%= yyptConfig.reportUrl %><%= yyptConfig.yyptAppKey %>', // 上报url(把后端上报接口需要先挂网关,该url填写网关地址)
|
|
12
|
+
autoReportPV: true, // 是否自动上报页面PV
|
|
13
|
+
// getRemoteParamsUrl获取远程参数url,主要用于获取intervalTime、reportLogsNum和stopReport参数,
|
|
14
|
+
// 返回格式{stopReport:true,intervalTime:3,reportLogsNum:5}
|
|
15
|
+
getRemoteParamsUrl: '',
|
|
16
|
+
stopReport: <%= yyptConfig.stopReport %>, // 停止上报
|
|
17
|
+
intervalTime: 3, // 间隔多久执行一次上报,默认3秒
|
|
18
|
+
reportLogsNum: 5, // 每次合并上报记录条数,默认5次
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
// 设置数据源请求的 loading 及 toast 处理
|
|
22
|
-
setConfig({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
<% }%>
|
|
37
|
-
App({
|
|
38
|
-
onLaunch(options) {
|
|
39
|
-
this.app = app
|
|
40
|
-
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
41
|
-
let { query={} } = options
|
|
42
|
-
EXTRA_API.setParams('$global', query )
|
|
43
|
-
createStateDataSourceVar('$global', generateParamsParser({app}))
|
|
21
|
+
// 设置数据源请求的 loading 及 toast 处理
|
|
22
|
+
setConfig({
|
|
23
|
+
beforeDSRequest: (cfg) => {
|
|
24
|
+
if (!cfg.options || !cfg.options.showLoading) return
|
|
25
|
+
app.showLoading()
|
|
26
|
+
},
|
|
27
|
+
afterDSRequest: (cfg, error, result) => {
|
|
28
|
+
if (!cfg.options) return
|
|
29
|
+
if (cfg.options.showLoading) app.hideLoading()
|
|
30
|
+
if (!cfg.options.showToast) return
|
|
31
|
+
const isSuccess = !error && result && !result.code
|
|
32
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
33
|
+
}
|
|
34
|
+
})
|
|
44
35
|
|
|
45
|
-
onLaunch && onLaunch.call(this, options)
|
|
46
|
-
<% if(yyptConfig.yyptAppKey) { %>
|
|
47
|
-
// 挂运营平台上报对象到app里
|
|
48
|
-
app.yyptReport = wxReport
|
|
49
36
|
<% }%>
|
|
37
|
+
App({
|
|
38
|
+
onLaunch(options) {
|
|
39
|
+
this.app = app
|
|
40
|
+
const onLaunch = lifeCycle.onLaunch || lifeCycle.onAppLaunch
|
|
41
|
+
let { query = {} } = options
|
|
42
|
+
EXTRA_API.setParams('$global', query)
|
|
43
|
+
createStateDataSourceVar('$global', generateParamsParser({ app }))
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
69
|
-
fn && fn.call(this, msg)
|
|
70
|
-
},
|
|
71
|
-
onPageNotFound() {
|
|
72
|
-
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
|
|
73
|
-
fn && fn.call(this)
|
|
74
|
-
},
|
|
75
|
-
onUnhandledRejection() {
|
|
76
|
-
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
|
|
77
|
-
fn && fn.call(this)
|
|
45
|
+
onLaunch && onLaunch.call(this, options)
|
|
46
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
47
|
+
// 挂运营平台上报对象到app里
|
|
48
|
+
app.yyptReport = wxReport
|
|
49
|
+
<% }%>
|
|
50
|
+
|
|
51
|
+
// 初始私有全局数据
|
|
52
|
+
this.$$global = {
|
|
53
|
+
homePageId: '<%= appConfig.homePageId %>'
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
onShow(options) {
|
|
57
|
+
const fn = lifeCycle.onShow || lifeCycle.onAppShow
|
|
58
|
+
fn && fn.call(this, options)
|
|
59
|
+
<% if (yyptConfig.yyptAppKey) { %>
|
|
60
|
+
wxReport.startReport()
|
|
61
|
+
<% }%>
|
|
78
62
|
},
|
|
79
|
-
|
|
63
|
+
onHide() {
|
|
64
|
+
const fn = lifeCycle.onHide || lifeCycle.onAppHide
|
|
65
|
+
fn && fn.call(this)
|
|
66
|
+
},
|
|
67
|
+
onError(msg) {
|
|
68
|
+
const fn = lifeCycle.onError || lifeCycle.onAppError
|
|
69
|
+
fn && fn.call(this, msg)
|
|
70
|
+
},
|
|
71
|
+
onPageNotFound() {
|
|
72
|
+
const fn = lifeCycle.onPageNotFound || lifeCycle.onAppPageNotFound
|
|
73
|
+
fn && fn.call(this)
|
|
74
|
+
},
|
|
75
|
+
onUnhandledRejection() {
|
|
76
|
+
const fn = lifeCycle.onUnhandledRejection || lifeCycle.onAppUnhandledRejection
|
|
77
|
+
fn && fn.call(this)
|
|
78
|
+
},
|
|
79
|
+
})
|
|
@@ -2,7 +2,7 @@ import { observable } from 'mobx';
|
|
|
2
2
|
import { createComputed, createEventHandlers, checkAuth } from './util';
|
|
3
3
|
import { createWidgets, createInitData, disposeWidget } from './widget';
|
|
4
4
|
import mergeRenderer from './merge-renderer';
|
|
5
|
-
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser } from '../datasources/index';
|
|
5
|
+
import { createDataset, EXTRA_API, createStateDataSourceVar, generateParamsParser, setConfig } from '../datasources/index';
|
|
6
6
|
import { runWatchers } from './watch'
|
|
7
7
|
|
|
8
8
|
export function createPage(
|
|
@@ -71,6 +71,7 @@ export function createPage(
|
|
|
71
71
|
...mergeRenderer,
|
|
72
72
|
onLoad(options) {
|
|
73
73
|
const $page = this.getWeAppInst()
|
|
74
|
+
setConfig({ currentPageId: $page.uuid });
|
|
74
75
|
app.activePage = $page;
|
|
75
76
|
this._pageActive = true;
|
|
76
77
|
|
|
@@ -97,6 +98,7 @@ export function createPage(
|
|
|
97
98
|
},
|
|
98
99
|
async onShow() {
|
|
99
100
|
const $page = this.getWeAppInst()
|
|
101
|
+
setConfig({ currentPageId: $page.uuid });
|
|
100
102
|
app.activePage = $page;
|
|
101
103
|
this._pageActive = true;
|
|
102
104
|
|