mm_expand 1.5.7 → 1.5.8
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/index.js +32 -8
- package/package.json +3 -2
- package/test.js +6 -2
- package/demo/test/image/logo.png +0 -0
- package/demo/test/local.json +0 -4
- package/demo/test3/image/logo.png +0 -0
- package/demo/test3/local.json +0 -4
- package/demo/test4/image/logo.png +0 -0
- package/demo/test4/local.json +0 -4
- package/demo/test5/local.json +0 -4
- package/demo/test5/local2.json +0 -4
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const JSON5 = require('json5');
|
|
7
7
|
var ncp = require('ncp').ncp;
|
|
8
|
+
const { rimraf, rimrafSync } = require('rimraf');
|
|
8
9
|
const {
|
|
9
10
|
j2xParser,
|
|
10
11
|
parse
|
|
@@ -17,7 +18,7 @@ const {
|
|
|
17
18
|
statSync,
|
|
18
19
|
readdirSync,
|
|
19
20
|
mkdirSync,
|
|
20
|
-
|
|
21
|
+
unlinkSync,
|
|
21
22
|
rmdir
|
|
22
23
|
} = require('fs');
|
|
23
24
|
const {
|
|
@@ -1356,10 +1357,10 @@ if (typeof($) === "undefined") {
|
|
|
1356
1357
|
|
|
1357
1358
|
/**
|
|
1358
1359
|
* @description 删除文件
|
|
1359
|
-
* @param {String}
|
|
1360
|
+
* @param {String} dir 当前路径
|
|
1360
1361
|
*/
|
|
1361
|
-
String.prototype.delFile = function(
|
|
1362
|
-
|
|
1362
|
+
String.prototype.delFile = function(dir) {
|
|
1363
|
+
unlinkSync(this.fullname(dir), function(e) {});
|
|
1363
1364
|
};
|
|
1364
1365
|
|
|
1365
1366
|
/**
|
|
@@ -1374,9 +1375,10 @@ if (typeof($) === "undefined") {
|
|
|
1374
1375
|
/**
|
|
1375
1376
|
* @description 删除目录
|
|
1376
1377
|
* @param {String} dir 当前路径
|
|
1378
|
+
* @param {Function} func 回调函数
|
|
1377
1379
|
*/
|
|
1378
|
-
String.prototype.delDir = function(dir) {
|
|
1379
|
-
|
|
1380
|
+
String.prototype.delDir = function(dir, func) {
|
|
1381
|
+
rimrafSync(this.fullname(dir), func);
|
|
1380
1382
|
};
|
|
1381
1383
|
|
|
1382
1384
|
/**
|
|
@@ -2269,10 +2271,20 @@ if (typeof($) === "undefined") {
|
|
|
2269
2271
|
* 复制目录
|
|
2270
2272
|
* @param {String} sourcePath 源路径
|
|
2271
2273
|
* @param {String} targetPath 目标路径
|
|
2274
|
+
* @param {Function} func 回调函数
|
|
2272
2275
|
*/
|
|
2273
2276
|
Dir.prototype.copy = function(sourcePath, targetPath, func) {
|
|
2274
2277
|
ncp(sourcePath.fullname(), targetPath.fullname(), func);
|
|
2275
2278
|
}
|
|
2279
|
+
/**
|
|
2280
|
+
* @description 删除目录
|
|
2281
|
+
* @param {String} dir 目录路径
|
|
2282
|
+
* @param {Function} func 回调函数
|
|
2283
|
+
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2284
|
+
*/
|
|
2285
|
+
Dir.prototype.del = function(dir, func) {
|
|
2286
|
+
rimrafSync(dir.fullname(), func);
|
|
2287
|
+
}
|
|
2276
2288
|
}
|
|
2277
2289
|
/**
|
|
2278
2290
|
* 文件类函数
|
|
@@ -2340,8 +2352,8 @@ if (typeof($) === "undefined") {
|
|
|
2340
2352
|
}
|
|
2341
2353
|
/**
|
|
2342
2354
|
* @description 加载文件
|
|
2343
|
-
* @param {String}
|
|
2344
|
-
* @param {String}
|
|
2355
|
+
* @param {String} sourcePath 文件原路径
|
|
2356
|
+
* @param {String} targetPath 目标路径
|
|
2345
2357
|
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2346
2358
|
*/
|
|
2347
2359
|
File.prototype.copy = function(sourcePath, targetPath) {
|
|
@@ -2351,6 +2363,18 @@ if (typeof($) === "undefined") {
|
|
|
2351
2363
|
console.error(err);
|
|
2352
2364
|
}
|
|
2353
2365
|
}
|
|
2366
|
+
/**
|
|
2367
|
+
* @description 删除文件
|
|
2368
|
+
* @param {String} file 文件路径
|
|
2369
|
+
* @return {Boolean} 保存成功返回true,否则返回false
|
|
2370
|
+
*/
|
|
2371
|
+
File.prototype.del = function(file) {
|
|
2372
|
+
try {
|
|
2373
|
+
unlinkSync(file.fullname());
|
|
2374
|
+
} catch (err) {
|
|
2375
|
+
console.error(err);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2354
2378
|
}
|
|
2355
2379
|
$.file = new File();
|
|
2356
2380
|
$.dir = new Dir();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_expand",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"fast-xml-parser": "^3.21.1",
|
|
33
33
|
"json5": "^2.2.3",
|
|
34
34
|
"ncp": "^2.0.0",
|
|
35
|
-
"pinyinlite": "^1.2.1"
|
|
35
|
+
"pinyinlite": "^1.2.1",
|
|
36
|
+
"rimraf": "^5.0.5"
|
|
36
37
|
}
|
|
37
38
|
}
|
package/test.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
require('./index.js');
|
|
2
2
|
|
|
3
3
|
// 测试复制目录
|
|
4
|
+
"./demo/test3".delDir();
|
|
5
|
+
$.dir.del("./demo/test4");
|
|
4
6
|
// "./demo/test".copyDir("./demo/test3"); // 方法1
|
|
5
7
|
// $.dir.copy("./demo/test", "./demo/test4"); // 方法2
|
|
6
8
|
|
|
7
9
|
// 测试复制文件
|
|
8
10
|
"./demo/test5/".addDir();
|
|
9
|
-
"./demo/test/local.json".
|
|
10
|
-
$.
|
|
11
|
+
"./demo/test/local.json".copyFile("./demo/test5/local.json"); // 方法1
|
|
12
|
+
$.file.copy("./demo/test/local.json", "./demo/test5/local2.json"); // 方法2
|
|
13
|
+
"./demo/test5/local.json".delFile();
|
|
14
|
+
$.file.del("./demo/test5/local2.json");
|
|
11
15
|
|
|
12
16
|
// var timeStr = "1970-01-01 00:00:00";
|
|
13
17
|
|
package/demo/test/image/logo.png
DELETED
|
Binary file
|
package/demo/test/local.json
DELETED
|
Binary file
|
package/demo/test3/local.json
DELETED
|
Binary file
|
package/demo/test4/local.json
DELETED
package/demo/test5/local.json
DELETED
package/demo/test5/local2.json
DELETED