@cloudbase/lowcode-builder 0.1.4 → 0.1.5-mpbeta.1
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/README.md +59 -0
- 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 +12 -6
- 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/mp/util.js +14 -1
- package/lib/builder/mp/wxml.js +4 -0
- 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/builder.web.js +94 -0
- 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/common/util.js +2 -2
- package/template/mp/common/weapp-component.js +3 -3
- package/template/mp/common/weapp-page.js +4 -3
- package/template/mp/common/widget.js +10 -10
- package/template/mp/component/index.js +10 -4
- package/template/mp/page/index.js +11 -4
|
@@ -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;
|