@cloudbase/lowcode-builder 0.1.3 → 0.1.5-mpbeta.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 +14 -0
- package/lib/builder/config/index.js +21 -2
- package/lib/builder/core/index.d.ts +4 -1
- package/lib/builder/core/index.js +15 -3
- package/lib/builder/h5/copy.js +5 -1
- package/lib/builder/h5/material.js +5 -1
- package/lib/builder/mp/BuildContext.d.ts +1 -0
- package/lib/builder/mp/index.d.ts +2 -1
- package/lib/builder/mp/index.js +70 -54
- package/lib/builder/mp/materials.d.ts +7 -0
- package/lib/builder/mp/materials.js +30 -14
- package/lib/builder/mp/mixMode.js +5 -1
- package/lib/builder/mp/mp_config.js +8 -4
- package/lib/builder/mp/plugin.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 +35 -0
- package/lib/builder/util/generateFiles.js +128 -2
- package/lib/builder/util/index.js +5 -1
- package/lib/builder/util/junk.js +4 -1
- package/lib/builder/util/mp.js +5 -1
- package/lib/builder/util/net.d.ts +20 -1
- package/lib/builder/util/net.js +77 -4
- package/lib/index.js +5 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -1
- package/package.json +21 -7
- package/template/mp/component/index.js +6 -2
- package/template/mp/page/index.js +6 -2
- 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
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { IBuildContext } from '../mp/BuildContext';
|
|
3
|
+
import { OutputType } from 'jszip';
|
|
2
4
|
export default function generateFiles(appFileData: any, srcDir: string, dstDir: string, ctx: IBuildContext): Promise<string[]>;
|
|
3
5
|
export declare function writeFile(outFile: string, content: string): Promise<boolean>;
|
|
4
6
|
export declare function removeFile(file: string): void;
|
|
@@ -14,3 +16,36 @@ export declare function cleanDir(dir: string, allowedFiles: string[]): void;
|
|
|
14
16
|
*/
|
|
15
17
|
export declare function copyFiles(copyFiles: string[], srcDir: string, dstDir: string): Promise<void[]>;
|
|
16
18
|
export declare function copy(src: string, dest: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 复制文件
|
|
21
|
+
* @param source 源文件
|
|
22
|
+
* @param target 目标文件
|
|
23
|
+
*/
|
|
24
|
+
export declare function copyFileSync(source: string, target: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* 根据源文件目录,输出目录,递归复制文件
|
|
27
|
+
* @param {string} src 源文件目录
|
|
28
|
+
* @param {string} dest 输出目录
|
|
29
|
+
*/
|
|
30
|
+
export declare const copyRecursiveSync: (src: string, dest: string, options?: {
|
|
31
|
+
filter: (src: string, dest: string) => boolean;
|
|
32
|
+
} | undefined) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 返回指定目录的文件列表内容,返回map格式
|
|
35
|
+
* @param dir 指定目录
|
|
36
|
+
* @param files_ 文件列表
|
|
37
|
+
* @param replacePath 去掉前面路径
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
export declare function getFiles(dir: string, files_: any, replacePath?: string): any;
|
|
41
|
+
/**
|
|
42
|
+
* 将文件压缩为zip包
|
|
43
|
+
* 参考JSZip例子:https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
|
|
44
|
+
* @param files
|
|
45
|
+
* @param type
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function fileToZip(files: {
|
|
49
|
+
[key: string]: Uint8Array;
|
|
50
|
+
}, type: OutputType): Promise<string | Buffer | Uint8Array | number[] | ArrayBuffer | Blob>;
|
|
51
|
+
export declare function strToBuf(str: any): Buffer;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,12 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
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 = void 0;
|
|
26
30
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
27
31
|
const path_1 = __importDefault(require("path"));
|
|
28
32
|
const lodash_template_1 = __importDefault(require("lodash.template"));
|
|
29
33
|
const junk = __importStar(require("../util/junk"));
|
|
30
34
|
const glob_1 = __importDefault(require("glob"));
|
|
35
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
36
|
+
const buffer_1 = require("buffer");
|
|
31
37
|
const generatedFileContents = {}; // generated files for incrmental build
|
|
32
38
|
async function generateFiles(appFileData, srcDir, dstDir, ctx) {
|
|
33
39
|
const filesGenerated = [];
|
|
@@ -120,3 +126,123 @@ async function copy(src, dest) {
|
|
|
120
126
|
await copyFiles(needCopyFiles, src, dest);
|
|
121
127
|
}
|
|
122
128
|
exports.copy = copy;
|
|
129
|
+
/**
|
|
130
|
+
* 复制文件
|
|
131
|
+
* @param source 源文件
|
|
132
|
+
* @param target 目标文件
|
|
133
|
+
*/
|
|
134
|
+
function copyFileSync(source, target) {
|
|
135
|
+
let targetFile = target;
|
|
136
|
+
// If target is a directory, a new file with the same name will be created
|
|
137
|
+
if (fs_extra_1.default.existsSync(target)) {
|
|
138
|
+
if (fs_extra_1.default.lstatSync(target).isDirectory()) {
|
|
139
|
+
targetFile = path_1.default.join(target, path_1.default.basename(source));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
fs_extra_1.default.writeFileSync(targetFile, fs_extra_1.default.readFileSync(source));
|
|
143
|
+
}
|
|
144
|
+
exports.copyFileSync = copyFileSync;
|
|
145
|
+
/**
|
|
146
|
+
* 根据源文件目录,输出目录,递归复制文件
|
|
147
|
+
* @param {string} src 源文件目录
|
|
148
|
+
* @param {string} dest 输出目录
|
|
149
|
+
*/
|
|
150
|
+
const copyRecursiveSync = function (src, dest, options) {
|
|
151
|
+
const exists = fs_extra_1.default.existsSync(src);
|
|
152
|
+
if (!exists || (options && options.filter && !options.filter(src, dest))) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const stats = fs_extra_1.default.statSync(src);
|
|
156
|
+
const isDirectory = stats.isDirectory();
|
|
157
|
+
if (!fs_extra_1.default.existsSync(dest)) {
|
|
158
|
+
mkDirByPathSync(path_1.default.parse(dest).dir);
|
|
159
|
+
}
|
|
160
|
+
if (isDirectory) {
|
|
161
|
+
const files = fs_extra_1.default.readdirSync(src);
|
|
162
|
+
files.forEach(function (childItemName) {
|
|
163
|
+
(0, exports.copyRecursiveSync)(path_1.default.join(src, childItemName), path_1.default.join(dest, childItemName), options);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
copyFileSync(src, dest);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
exports.copyRecursiveSync = copyRecursiveSync;
|
|
171
|
+
/**
|
|
172
|
+
* 参考:https://stackoverflow.com/questions/31645738/how-to-create-full-path-with-nodes-fs-mkdirsync
|
|
173
|
+
* @param targetDir
|
|
174
|
+
* @param param1
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
177
|
+
function mkDirByPathSync(targetDir, { isRelativeToScript = false } = {}) {
|
|
178
|
+
const sep = path_1.default.sep;
|
|
179
|
+
const initDir = path_1.default.isAbsolute(targetDir) ? sep : '';
|
|
180
|
+
const baseDir = isRelativeToScript ? __dirname : '.';
|
|
181
|
+
return targetDir.split(sep).reduce((parentDir, childDir) => {
|
|
182
|
+
const curDir = path_1.default.resolve(baseDir, parentDir, childDir);
|
|
183
|
+
try {
|
|
184
|
+
fs_extra_1.default.mkdirSync(curDir);
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
if (err.code === 'EEXIST') { // curDir already exists!
|
|
188
|
+
return curDir;
|
|
189
|
+
}
|
|
190
|
+
// To avoid `EISDIR` error on Mac and `EACCES`-->`ENOENT` and `EPERM` on Windows.
|
|
191
|
+
if (err.code === 'ENOENT') { // Throw the original parentDir error on curDir `ENOENT` failure.
|
|
192
|
+
throw new Error(`EACCES: permission denied, mkdir '${parentDir}'`);
|
|
193
|
+
}
|
|
194
|
+
const caughtErr = ['EACCES', 'EPERM', 'EISDIR'].indexOf(err.code) > -1;
|
|
195
|
+
if (!caughtErr || caughtErr && curDir === path_1.default.resolve(targetDir)) {
|
|
196
|
+
throw err; // Throw if it's just the last created dir.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return curDir;
|
|
200
|
+
}, initDir);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 返回指定目录的文件列表内容,返回map格式
|
|
204
|
+
* @param dir 指定目录
|
|
205
|
+
* @param files_ 文件列表
|
|
206
|
+
* @param replacePath 去掉前面路径
|
|
207
|
+
* @returns
|
|
208
|
+
*/
|
|
209
|
+
function getFiles(dir, files_, replacePath = '') {
|
|
210
|
+
files_ = files_ || {};
|
|
211
|
+
const files = fs_extra_1.default.readdirSync(dir);
|
|
212
|
+
let mapName;
|
|
213
|
+
for (let i in files) {
|
|
214
|
+
const name = path_1.default.join(dir, files[i]);
|
|
215
|
+
if (fs_extra_1.default.statSync(name).isDirectory()) {
|
|
216
|
+
getFiles(name, files_, replacePath);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
mapName = name;
|
|
220
|
+
// 替换根路径
|
|
221
|
+
if (name.indexOf(replacePath) === 0) {
|
|
222
|
+
mapName = name.replace(replacePath, '');
|
|
223
|
+
}
|
|
224
|
+
files_[mapName] = fs_extra_1.default.readFileSync(name);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return files_;
|
|
228
|
+
}
|
|
229
|
+
exports.getFiles = getFiles;
|
|
230
|
+
/**
|
|
231
|
+
* 将文件压缩为zip包
|
|
232
|
+
* 参考JSZip例子:https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
|
|
233
|
+
* @param files
|
|
234
|
+
* @param type
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
async function fileToZip(files, type) {
|
|
238
|
+
var zip = new jszip_1.default();
|
|
239
|
+
for (let prop in files) {
|
|
240
|
+
zip.file(prop, files[prop]);
|
|
241
|
+
}
|
|
242
|
+
return zip.generateAsync({ type });
|
|
243
|
+
}
|
|
244
|
+
exports.fileToZip = fileToZip;
|
|
245
|
+
function strToBuf(str) {
|
|
246
|
+
return buffer_1.Buffer.from(str);
|
|
247
|
+
}
|
|
248
|
+
exports.strToBuf = strToBuf;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/builder/util/junk.js
CHANGED
|
@@ -20,7 +20,10 @@ const ignoreList = [
|
|
|
20
20
|
'^Thumbs\\.db$',
|
|
21
21
|
'^ehthumbs\\.db$',
|
|
22
22
|
'^Desktop\\.ini$',
|
|
23
|
-
'@eaDir$',
|
|
23
|
+
'@eaDir$',
|
|
24
|
+
'^.gitignore$',
|
|
25
|
+
'^readme.md$',
|
|
26
|
+
'^README.md$',
|
|
24
27
|
];
|
|
25
28
|
const regex = new RegExp(ignoreList.join('|'));
|
|
26
29
|
const is = (filename) => regex.test(filename);
|
package/lib/builder/util/mp.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -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
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,11 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.downloadZip = exports.downloadFile = void 0;
|
|
29
|
+
exports.downloadBrowserMaterial = exports.downloadZipInBrowser = exports.downloadZipInNode = exports.downloadZip = exports.downloadFile = void 0;
|
|
26
30
|
const axios_1 = __importDefault(require("axios"));
|
|
27
31
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
32
|
const path = __importStar(require("path"));
|
|
29
33
|
const compressing_1 = __importDefault(require("compressing"));
|
|
34
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
35
|
+
const config_1 = require("../config");
|
|
36
|
+
const generateFiles_1 = require("../util/generateFiles");
|
|
30
37
|
async function downloadFile(url, filePath) {
|
|
31
38
|
await fs_extra_1.default.ensureDir(path.dirname(filePath));
|
|
32
39
|
const res = await axios_1.default.get(url, { responseType: 'stream' });
|
|
@@ -38,9 +45,75 @@ exports.downloadFile = downloadFile;
|
|
|
38
45
|
* @param url
|
|
39
46
|
* @param dstDir folder to hold the extract zip content
|
|
40
47
|
*/
|
|
41
|
-
async function downloadZip(url, dstDir) {
|
|
48
|
+
async function downloadZip(url, dstDir, isBrowser = false) {
|
|
49
|
+
// TODO 待加上平台判断
|
|
50
|
+
if (isBrowser) {
|
|
51
|
+
await downloadZipInBrowser(url, dstDir);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await downloadZipInNode(url, dstDir);
|
|
55
|
+
}
|
|
56
|
+
exports.downloadZip = downloadZip;
|
|
57
|
+
/**
|
|
58
|
+
* node中下载和保存zip文件
|
|
59
|
+
* @param url 下载的url
|
|
60
|
+
* @param dstDir 存放文件夹
|
|
61
|
+
*/
|
|
62
|
+
async function downloadZipInNode(url, dstDir) {
|
|
42
63
|
await fs_extra_1.default.ensureDir(dstDir);
|
|
43
64
|
const res = await axios_1.default.get(url, { responseType: 'stream' });
|
|
44
65
|
await compressing_1.default.zip.uncompress(res.data, dstDir);
|
|
45
66
|
}
|
|
46
|
-
exports.
|
|
67
|
+
exports.downloadZipInNode = downloadZipInNode;
|
|
68
|
+
/**
|
|
69
|
+
* 浏览器中下载和保存zip文件
|
|
70
|
+
* @param url 下载的url
|
|
71
|
+
* @param dstDir 存放文件夹
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
async function downloadZipInBrowser(url, dstDir) {
|
|
75
|
+
// IMPORTANT 防止保存的时候保存
|
|
76
|
+
if (fs_extra_1.default.existsSync(dstDir)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
fs_extra_1.default.ensureDirSync(dstDir);
|
|
80
|
+
const res = await axios_1.default.get(url, { responseType: 'arraybuffer' });
|
|
81
|
+
const data = await jszip_1.default.loadAsync(res.data);
|
|
82
|
+
await saveFiles(data.files, dstDir);
|
|
83
|
+
}
|
|
84
|
+
exports.downloadZipInBrowser = downloadZipInBrowser;
|
|
85
|
+
/**
|
|
86
|
+
* 保存JSZip解压的文件内容
|
|
87
|
+
* @param files 文件
|
|
88
|
+
* @param dstDir 指定目录
|
|
89
|
+
*/
|
|
90
|
+
async function saveFiles(files, dstDir) {
|
|
91
|
+
try {
|
|
92
|
+
for (const fileName of Object.keys(files)) {
|
|
93
|
+
const dest = path.join(dstDir, fileName);
|
|
94
|
+
if (files[fileName].dir) { // 如果该文件为目录需先创建文件夹
|
|
95
|
+
fs_extra_1.default.mkdirSync(dest, {
|
|
96
|
+
recursive: true
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const ret = await files[fileName].async('nodebuffer'); // 由于这里有await,不能用forEach
|
|
101
|
+
fs_extra_1.default.writeFileSync(dest, ret);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
console.error('saveFiles catch error:', err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 微信IDE builder需要下载template文件和miniprogram_npm
|
|
111
|
+
* miniprogram_npm待微信提供端能力
|
|
112
|
+
* @param output
|
|
113
|
+
*/
|
|
114
|
+
async function downloadBrowserMaterial(output = '.weapps-build') {
|
|
115
|
+
await Promise.all([downloadZip(config_1.builderTemplateURL, config_1.appTemplateDir, true), downloadZip(config_1.miniprogramURL, config_1.miniprogramDir, true)]);
|
|
116
|
+
// 必须先下载到.weapps-materials目录,因为.weapps-materials是默认下载目录,共享组件逻辑sharedMaterialsDir时会读取文件
|
|
117
|
+
(0, generateFiles_1.copyRecursiveSync)(config_1.miniprogramDir, path.join(output, 'miniprogram_npm'));
|
|
118
|
+
}
|
|
119
|
+
exports.downloadBrowserMaterial = downloadBrowserMaterial;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
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-mpbeta.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",
|
|
@@ -25,32 +25,44 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"dev": "tsc -w",
|
|
27
27
|
"develop": "tsc -w",
|
|
28
|
-
"build": "tsc",
|
|
28
|
+
"build": "rm -rf lib && tsc",
|
|
29
29
|
"test": "jest",
|
|
30
|
-
"test:build": "ts-node ./__test__/build.ts"
|
|
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",
|
|
33
|
+
"prepublish": "npm run build"
|
|
31
34
|
},
|
|
32
35
|
"bugs": {
|
|
33
36
|
"url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"@cloudbase/cals": "0.3.3",
|
|
37
|
-
"@cloudbase/lowcode-generator": "
|
|
39
|
+
"@cloudbase/cals": "^0.3.3",
|
|
40
|
+
"@cloudbase/lowcode-generator": "0.6.17-mpbeta.0",
|
|
38
41
|
"axios": "^0.21.0",
|
|
42
|
+
"browserfs": "^1.4.3",
|
|
43
|
+
"browserify-zlib": "^0.2.0",
|
|
39
44
|
"chalk": "^2.4.2",
|
|
40
45
|
"compare-versions": "^3.6.0",
|
|
41
46
|
"compressing": "^1.4.0",
|
|
42
47
|
"cross-spawn": "^6.0.5",
|
|
43
48
|
"fs-extra": "^7.0.1",
|
|
49
|
+
"constants-browserify": "^1.0.0",
|
|
50
|
+
"crypto-browserify": "^3.12.0",
|
|
51
|
+
"jszip": "^3.7.1",
|
|
44
52
|
"lodash": "^4.17.11",
|
|
45
53
|
"lodash.clone": "^4.5.0",
|
|
46
54
|
"lodash.get": "^4.4.2",
|
|
47
55
|
"lodash.set": "^4.3.2",
|
|
48
56
|
"lodash.template": "^4.5.0",
|
|
49
57
|
"lodash.uniqby": "^4.7.0",
|
|
58
|
+
"os-browserify": "^0.3.0",
|
|
59
|
+
"stream-browserify": "^3.0.0",
|
|
50
60
|
"webpack": "^4.41.4",
|
|
51
61
|
"xml-js": "^1.6.11"
|
|
52
62
|
},
|
|
53
63
|
"devDependencies": {
|
|
64
|
+
"worker-loader": "^3.0.8",
|
|
65
|
+
"@rollup/plugin-alias": "^3.1.9",
|
|
54
66
|
"@types/archiver": "^3.1.0",
|
|
55
67
|
"@types/command-exists": "^1.2.0",
|
|
56
68
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -64,8 +76,10 @@
|
|
|
64
76
|
"@types/weixin-app": "^2.9.0",
|
|
65
77
|
"csstype": "^2.6.10",
|
|
66
78
|
"jest": "^26.0.1",
|
|
67
|
-
"ts-
|
|
79
|
+
"ts-loader": "^8.3.0",
|
|
68
80
|
"ts-node": "^10.4.0",
|
|
69
|
-
"typescript": "^4.4.2"
|
|
81
|
+
"typescript": "^4.4.2",
|
|
82
|
+
"webpack-cli": "^4.9.1",
|
|
83
|
+
"webpack-dev-server": "^4.7.3"
|
|
70
84
|
}
|
|
71
85
|
}
|
|
@@ -20,7 +20,9 @@ const evtListeners = {<% Object.entries(eventHandlers).map(([handlerName, listen
|
|
|
20
20
|
key: '<%= l.key %>',
|
|
21
21
|
handler: <% if (l.type == 'rematch') {%> _handler<%= l.handler %> <%} else if (l.type === 'inline') {%> function({event, lists, forItems}, $comp){ <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
22
22
|
data: <%= stringifyObj(l.data, {depth: null}) %>,
|
|
23
|
-
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return
|
|
23
|
+
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($comp, lists, forItems, event) => {const $for=forItems;return (
|
|
24
|
+
<%= expr %>
|
|
25
|
+
)},
|
|
24
26
|
<%}) %>}
|
|
25
27
|
},<%})%>
|
|
26
28
|
],<%})%>
|
|
@@ -48,7 +50,9 @@ const handler = {<% handlers.forEach(h => {%>
|
|
|
48
50
|
|
|
49
51
|
const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
50
52
|
<%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
|
|
51
|
-
<%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return
|
|
53
|
+
<%= prop %>: function ($comp, lists, forItems, event) {const $for=forItems; return (
|
|
54
|
+
<%= expr %>
|
|
55
|
+
); },<% }) %>
|
|
52
56
|
},<%}) %>
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -17,14 +17,18 @@ const evtListeners = {<% Object.entries(eventHanlders).map(([handlerName, listen
|
|
|
17
17
|
key: '<%= l.key %>',
|
|
18
18
|
handler: <% if (l.type === 'rematch') {%> handlers.<%= l.handler %> <%} else if (l.type == 'material') {%> function(...args) { return require('../../materials/<%= l.handlerModule %>/actions/<%= l.handler %>/index').default(...args) } <%} else if (l.type == 'inline') {%> function({event, lists, forItems}, $page){const $for = forItems; return <%= l.handler %> } <%} else {%> <%= l.handler %> <%} %>,
|
|
19
19
|
data: <%= stringifyObj(l.data, {depth: null}) %>,
|
|
20
|
-
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return
|
|
20
|
+
boundData: {<% Object.entries(l.boundData).map(([prop, expr])=>{%>'<%= prop %>':($page, lists, forItems, event) => {const $for = forItems; return (
|
|
21
|
+
<%= expr %>
|
|
22
|
+
)},
|
|
21
23
|
<%}) %>}
|
|
22
24
|
},<%})%>
|
|
23
25
|
],<%})%>
|
|
24
26
|
}
|
|
25
27
|
const dataBinds = {<% Object.entries(dataBinds).map(([id, widgetBinds])=>{%>
|
|
26
28
|
<%= id %>: { <% Object.entries(widgetBinds).map(([prop, expr]) => { %>
|
|
27
|
-
<%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return
|
|
29
|
+
<%= prop %>: function ($page, lists, forItems, event) {const $for = forItems; return (
|
|
30
|
+
<%= expr %>
|
|
31
|
+
); },<% }) %>
|
|
28
32
|
},<%}) %>
|
|
29
33
|
}
|
|
30
34
|
|
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;
|