zero-tools 1.3.8 → 1.4.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/bin.ts +40 -2
- package/dist/bin.js +81 -3
- package/dist/tinify.js +410 -0
- package/package.json +3 -2
- package/tinify.ts +254 -0
- package/.vscode/tasks.json +0 -14
package/bin.ts
CHANGED
|
@@ -4,13 +4,16 @@ import minimist = require('minimist')
|
|
|
4
4
|
import * as fs from 'fs'
|
|
5
5
|
import * as path from 'path'
|
|
6
6
|
import { xlsxToTs } from './xlsx-ts';
|
|
7
|
+
import { TaskParser } from './tinify';
|
|
7
8
|
let cwd = process.cwd()
|
|
8
9
|
let name = path.basename(cwd)
|
|
9
10
|
let argv = minimist(process.argv.slice(2), {
|
|
10
11
|
// string: ['unitTesting'],
|
|
11
|
-
boolean: ['help', 'version', 'unitTesting', "xlsxToTs"],
|
|
12
|
+
boolean: ['help', 'version', 'unitTesting', "xlsxToTs", "tinify", "packHotup"],
|
|
12
13
|
alias: {
|
|
13
14
|
unitTesting: ['ut'],
|
|
15
|
+
packHotup: ['pp'],
|
|
16
|
+
tinify: ['ty'],
|
|
14
17
|
xlsxToTs: ['xt'],
|
|
15
18
|
help: ['h'],
|
|
16
19
|
version: ['v'],
|
|
@@ -130,6 +133,8 @@ let helpString = `
|
|
|
130
133
|
----------------------开发工具包-----------------------
|
|
131
134
|
zero ut (zero --unitTesting)在当前文件夹新建TS单元测试项目
|
|
132
135
|
zero xt (zero --xlsxToTs)在当前文件夹下的xlsx.json中所描述的Excel文件转换TS文件
|
|
136
|
+
zero ty (zero --tinify)在当前文件夹下的tinify.json中所描述的文件进行压缩
|
|
137
|
+
zero pp (zero --packHotup)在当前文件夹下的packHotup.json中所描述的文件进行打包热更新
|
|
133
138
|
zero h (zero --help)帮助
|
|
134
139
|
zero v (zero --version)版本号
|
|
135
140
|
----------------------蓝面包 制作----------------------`
|
|
@@ -172,11 +177,36 @@ let fn = {
|
|
|
172
177
|
}
|
|
173
178
|
})
|
|
174
179
|
},
|
|
180
|
+
ty: () => {
|
|
181
|
+
|
|
182
|
+
// let p = new TaskParser("../../doomsdayrise-clinet/tinify.json")
|
|
183
|
+
let p = new TaskParser("./tinify.json")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
async function test() {
|
|
187
|
+
await p.parserConfig()
|
|
188
|
+
await p.loadInfo()
|
|
189
|
+
await p.readDir("")
|
|
190
|
+
console.log("转换结束", p.count)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
test().then(() => {
|
|
194
|
+
console.log("完成")
|
|
195
|
+
}).catch((err) => {
|
|
196
|
+
console.log("错误", err)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
},
|
|
202
|
+
pp: () => {
|
|
203
|
+
console.log("to do pp")
|
|
204
|
+
},
|
|
175
205
|
h: () => {
|
|
176
206
|
console.log(helpString)
|
|
177
207
|
},
|
|
178
208
|
v: () => {
|
|
179
|
-
console.log("1.
|
|
209
|
+
console.log("1.4.1")
|
|
180
210
|
}
|
|
181
211
|
}
|
|
182
212
|
let isFree = true
|
|
@@ -188,6 +218,14 @@ if (argv.xt) {
|
|
|
188
218
|
fn.xt()
|
|
189
219
|
isFree = false
|
|
190
220
|
}
|
|
221
|
+
if (argv.ty) {
|
|
222
|
+
fn.ty()
|
|
223
|
+
isFree = false
|
|
224
|
+
}
|
|
225
|
+
if (argv.pp) {
|
|
226
|
+
fn.pp()
|
|
227
|
+
isFree = false
|
|
228
|
+
}
|
|
191
229
|
if (argv.h) {
|
|
192
230
|
fn.h()
|
|
193
231
|
isFree = false
|
package/dist/bin.js
CHANGED
|
@@ -19,18 +19,57 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
__setModuleDefault(result, mod);
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
33
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
+
function step(op) {
|
|
36
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
+
while (_) try {
|
|
38
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
+
switch (op[0]) {
|
|
41
|
+
case 0: case 1: t = op; break;
|
|
42
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
+
default:
|
|
46
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
+
if (t[2]) _.ops.pop();
|
|
51
|
+
_.trys.pop(); continue;
|
|
52
|
+
}
|
|
53
|
+
op = body.call(thisArg, _);
|
|
54
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
22
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
59
|
var minimist = require("minimist");
|
|
24
60
|
var fs = __importStar(require("fs"));
|
|
25
61
|
var path = __importStar(require("path"));
|
|
26
62
|
var xlsx_ts_1 = require("./xlsx-ts");
|
|
63
|
+
var tinify_1 = require("./tinify");
|
|
27
64
|
var cwd = process.cwd();
|
|
28
65
|
var name = path.basename(cwd);
|
|
29
66
|
var argv = minimist(process.argv.slice(2), {
|
|
30
67
|
// string: ['unitTesting'],
|
|
31
|
-
boolean: ['help', 'version', 'unitTesting', "xlsxToTs"],
|
|
68
|
+
boolean: ['help', 'version', 'unitTesting', "xlsxToTs", "tinify", "packHotup"],
|
|
32
69
|
alias: {
|
|
33
70
|
unitTesting: ['ut'],
|
|
71
|
+
packHotup: ['pp'],
|
|
72
|
+
tinify: ['ty'],
|
|
34
73
|
xlsxToTs: ['xt'],
|
|
35
74
|
help: ['h'],
|
|
36
75
|
version: ['v'],
|
|
@@ -41,7 +80,7 @@ var tsconfigTem = "\n{\n \"compilerOptions\": {\n /* Basic Options */\n
|
|
|
41
80
|
var indexTem = "\nlet a=\"test\"\nconsole.log(a)\n";
|
|
42
81
|
var cwsTem = "\n{\n\t\"folders\": [\n\t\t{\n\t\t\t\"path\": \".\"\n\t\t}\n\t],\n\t\"settings\": {}\n}\n";
|
|
43
82
|
var launchTem = "\n{\n \"version\": \"0.2.0\",\n \"configurations\": [\n {\n \"type\": \"node\",\n \"request\": \"launch\",\n \"name\": \"\u542F\u52A8\",\n \"runtimeExecutable\": \"yarn\",\n \"args\": [\n \"debug\",\n ],\n },\n ]\n}\n";
|
|
44
|
-
var helpString = "\n----------------------\u5F00\u53D1\u5DE5\u5177\u5305-----------------------\nzero ut (zero --unitTesting)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u65B0\u5EFATS\u5355\u5143\u6D4B\u8BD5\u9879\u76EE\nzero xt (zero --xlsxToTs)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u4E0B\u7684xlsx.json\u4E2D\u6240\u63CF\u8FF0\u7684Excel\u6587\u4EF6\u8F6C\u6362TS\u6587\u4EF6\nzero h (zero --help)\u5E2E\u52A9\nzero v (zero --version)\u7248\u672C\u53F7\n----------------------\u84DD\u9762\u5305 \u5236\u4F5C----------------------";
|
|
83
|
+
var helpString = "\n----------------------\u5F00\u53D1\u5DE5\u5177\u5305-----------------------\nzero ut (zero --unitTesting)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u65B0\u5EFATS\u5355\u5143\u6D4B\u8BD5\u9879\u76EE\nzero xt (zero --xlsxToTs)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u4E0B\u7684xlsx.json\u4E2D\u6240\u63CF\u8FF0\u7684Excel\u6587\u4EF6\u8F6C\u6362TS\u6587\u4EF6\nzero ty (zero --tinify)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u4E0B\u7684tinify.json\u4E2D\u6240\u63CF\u8FF0\u7684\u6587\u4EF6\u8FDB\u884C\u538B\u7F29\nzero pp (zero --packHotup)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u4E0B\u7684packHotup.json\u4E2D\u6240\u63CF\u8FF0\u7684\u6587\u4EF6\u8FDB\u884C\u6253\u5305\u70ED\u66F4\u65B0\nzero h (zero --help)\u5E2E\u52A9\nzero v (zero --version)\u7248\u672C\u53F7\n----------------------\u84DD\u9762\u5305 \u5236\u4F5C----------------------";
|
|
45
84
|
var fn = {
|
|
46
85
|
ut: function () {
|
|
47
86
|
fs.writeFileSync(cwd + "/package.json", packageTem);
|
|
@@ -81,11 +120,42 @@ var fn = {
|
|
|
81
120
|
}
|
|
82
121
|
});
|
|
83
122
|
},
|
|
123
|
+
ty: function () {
|
|
124
|
+
// let p = new TaskParser("../../doomsdayrise-clinet/tinify.json")
|
|
125
|
+
var p = new tinify_1.TaskParser("./tinify.json");
|
|
126
|
+
function test() {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
+
return __generator(this, function (_a) {
|
|
129
|
+
switch (_a.label) {
|
|
130
|
+
case 0: return [4 /*yield*/, p.parserConfig()];
|
|
131
|
+
case 1:
|
|
132
|
+
_a.sent();
|
|
133
|
+
return [4 /*yield*/, p.loadInfo()];
|
|
134
|
+
case 2:
|
|
135
|
+
_a.sent();
|
|
136
|
+
return [4 /*yield*/, p.readDir("")];
|
|
137
|
+
case 3:
|
|
138
|
+
_a.sent();
|
|
139
|
+
console.log("转换结束", p.count);
|
|
140
|
+
return [2 /*return*/];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
test().then(function () {
|
|
146
|
+
console.log("完成");
|
|
147
|
+
}).catch(function (err) {
|
|
148
|
+
console.log("错误", err);
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
pp: function () {
|
|
152
|
+
console.log("to do pp");
|
|
153
|
+
},
|
|
84
154
|
h: function () {
|
|
85
155
|
console.log(helpString);
|
|
86
156
|
},
|
|
87
157
|
v: function () {
|
|
88
|
-
console.log("1.
|
|
158
|
+
console.log("1.4.1");
|
|
89
159
|
}
|
|
90
160
|
};
|
|
91
161
|
var isFree = true;
|
|
@@ -97,6 +167,14 @@ if (argv.xt) {
|
|
|
97
167
|
fn.xt();
|
|
98
168
|
isFree = false;
|
|
99
169
|
}
|
|
170
|
+
if (argv.ty) {
|
|
171
|
+
fn.ty();
|
|
172
|
+
isFree = false;
|
|
173
|
+
}
|
|
174
|
+
if (argv.pp) {
|
|
175
|
+
fn.pp();
|
|
176
|
+
isFree = false;
|
|
177
|
+
}
|
|
100
178
|
if (argv.h) {
|
|
101
179
|
fn.h();
|
|
102
180
|
isFree = false;
|
package/dist/tinify.js
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.TaskParser = void 0;
|
|
59
|
+
var fs = __importStar(require("fs"));
|
|
60
|
+
var path = __importStar(require("path"));
|
|
61
|
+
var tinify = __importStar(require("tinify"));
|
|
62
|
+
var crypto = __importStar(require("crypto"));
|
|
63
|
+
/**
|
|
64
|
+
* 忽略含有命名为
|
|
65
|
+
* atlas8
|
|
66
|
+
* atlas9
|
|
67
|
+
* 忽略 20000 字节以下的文件
|
|
68
|
+
*/
|
|
69
|
+
var TaskParser = /** @class */ (function () {
|
|
70
|
+
function TaskParser(tinfiyUrl) {
|
|
71
|
+
this.tinfiyUrl = tinfiyUrl;
|
|
72
|
+
this.count = 0;
|
|
73
|
+
this.tinfiyUrlInfo = path.parse(tinfiyUrl);
|
|
74
|
+
}
|
|
75
|
+
TaskParser.prototype.loadInfo = function () {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var buffer;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, this.readBuffer(this.config.info)];
|
|
81
|
+
case 1:
|
|
82
|
+
buffer = _a.sent();
|
|
83
|
+
this.info = JSON.parse(buffer.toString('utf-8'));
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
TaskParser.prototype.saveInfo = function () {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
this.witeBuffer(this.config.info, JSON.stringify(this.info, null, 4));
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
TaskParser.prototype.idDir = function (pathUrl) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
+
var _this = this;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
102
|
+
fs.stat(path.join(_this.config.inPath, pathUrl), function (err, stats) {
|
|
103
|
+
if (err) {
|
|
104
|
+
reject(err);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve(stats.isDirectory());
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
})];
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
TaskParser.prototype.readDir = function (pathUrl) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var data, index, element, isDir, info;
|
|
117
|
+
return __generator(this, function (_a) {
|
|
118
|
+
switch (_a.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, this.readDirData(pathUrl)];
|
|
120
|
+
case 1:
|
|
121
|
+
data = _a.sent();
|
|
122
|
+
index = 0;
|
|
123
|
+
_a.label = 2;
|
|
124
|
+
case 2:
|
|
125
|
+
if (!(index < data.length)) return [3 /*break*/, 8];
|
|
126
|
+
element = path.join(pathUrl, data[index]);
|
|
127
|
+
return [4 /*yield*/, this.idDir(element)];
|
|
128
|
+
case 3:
|
|
129
|
+
isDir = _a.sent();
|
|
130
|
+
if (!isDir) return [3 /*break*/, 5];
|
|
131
|
+
return [4 /*yield*/, this.readDir(element)];
|
|
132
|
+
case 4:
|
|
133
|
+
_a.sent();
|
|
134
|
+
return [3 /*break*/, 7];
|
|
135
|
+
case 5:
|
|
136
|
+
info = path.parse(element);
|
|
137
|
+
if (!(info.ext == ".png")) return [3 /*break*/, 7];
|
|
138
|
+
return [4 /*yield*/, this.pick(element)];
|
|
139
|
+
case 6:
|
|
140
|
+
_a.sent();
|
|
141
|
+
_a.label = 7;
|
|
142
|
+
case 7:
|
|
143
|
+
index++;
|
|
144
|
+
return [3 /*break*/, 2];
|
|
145
|
+
case 8: return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
TaskParser.prototype.pick = function (element) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var inPath, outPath, info, reg, buffer, md5, code, _a, pathKey, doc;
|
|
153
|
+
return __generator(this, function (_b) {
|
|
154
|
+
switch (_b.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
inPath = path.join(this.config.inPath, element);
|
|
157
|
+
outPath = path.join(this.config.outPath, element);
|
|
158
|
+
info = path.parse(inPath);
|
|
159
|
+
reg = /atlas[89]/;
|
|
160
|
+
if (!!reg.test(info.name)) return [3 /*break*/, 15];
|
|
161
|
+
if (!this.config.ignore.has(info.name)) return [3 /*break*/, 1];
|
|
162
|
+
console.log("出现在白名单", inPath);
|
|
163
|
+
return [3 /*break*/, 15];
|
|
164
|
+
case 1: return [4 /*yield*/, this.isSamll(inPath)];
|
|
165
|
+
case 2:
|
|
166
|
+
if (!!(_b.sent())) return [3 /*break*/, 15];
|
|
167
|
+
return [4 /*yield*/, this.readBuffer(inPath)];
|
|
168
|
+
case 3:
|
|
169
|
+
buffer = _b.sent();
|
|
170
|
+
md5 = crypto.createHash('md5');
|
|
171
|
+
code = md5.update(buffer).digest('hex');
|
|
172
|
+
_a = this.config.skipSpine;
|
|
173
|
+
if (!_a) return [3 /*break*/, 5];
|
|
174
|
+
return [4 /*yield*/, this.isSpine(inPath)];
|
|
175
|
+
case 4:
|
|
176
|
+
_a = (_b.sent());
|
|
177
|
+
_b.label = 5;
|
|
178
|
+
case 5:
|
|
179
|
+
if (!_a) return [3 /*break*/, 6];
|
|
180
|
+
return [3 /*break*/, 15];
|
|
181
|
+
case 6:
|
|
182
|
+
pathKey = inPath.replace("\\", "/");
|
|
183
|
+
doc = this.info[pathKey];
|
|
184
|
+
if (!(doc == null)) return [3 /*break*/, 9];
|
|
185
|
+
//没有记录
|
|
186
|
+
// this.count++
|
|
187
|
+
return [4 /*yield*/, this.tinify(inPath, outPath, buffer, code)];
|
|
188
|
+
case 7:
|
|
189
|
+
//没有记录
|
|
190
|
+
// this.count++
|
|
191
|
+
_b.sent();
|
|
192
|
+
return [4 /*yield*/, this.copy(inPath, outPath, buffer, code)];
|
|
193
|
+
case 8:
|
|
194
|
+
_b.sent();
|
|
195
|
+
console.log("没有记录:", inPath);
|
|
196
|
+
return [3 /*break*/, 15];
|
|
197
|
+
case 9:
|
|
198
|
+
if (!(doc.inMd5 == code)) return [3 /*break*/, 11];
|
|
199
|
+
//没有复制
|
|
200
|
+
return [4 /*yield*/, this.copy(inPath, outPath, buffer, code)];
|
|
201
|
+
case 10:
|
|
202
|
+
//没有复制
|
|
203
|
+
_b.sent();
|
|
204
|
+
console.log("没有复制:", inPath);
|
|
205
|
+
return [3 /*break*/, 15];
|
|
206
|
+
case 11:
|
|
207
|
+
if (!(doc.outMd5 == code)) return [3 /*break*/, 12];
|
|
208
|
+
console.log("正常跳过:", inPath);
|
|
209
|
+
return [3 /*break*/, 15];
|
|
210
|
+
case 12:
|
|
211
|
+
//图是新的
|
|
212
|
+
return [4 /*yield*/, this.tinify(inPath, outPath, buffer, code)];
|
|
213
|
+
case 13:
|
|
214
|
+
//图是新的
|
|
215
|
+
_b.sent();
|
|
216
|
+
return [4 /*yield*/, this.copy(inPath, outPath, buffer, code)];
|
|
217
|
+
case 14:
|
|
218
|
+
_b.sent();
|
|
219
|
+
console.log("新图:", inPath);
|
|
220
|
+
_b.label = 15;
|
|
221
|
+
case 15: return [2 /*return*/];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
TaskParser.prototype.tinify = function (inPath, outPath, buffer, code) {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
228
|
+
var outBuffer, md5Hash, inMd5, outMd5, pathKey;
|
|
229
|
+
return __generator(this, function (_a) {
|
|
230
|
+
switch (_a.label) {
|
|
231
|
+
case 0:
|
|
232
|
+
console.log("开始转换" + inPath);
|
|
233
|
+
return [4 /*yield*/, tinify.default.fromBuffer(buffer).toBuffer()];
|
|
234
|
+
case 1:
|
|
235
|
+
outBuffer = _a.sent();
|
|
236
|
+
md5Hash = crypto.createHash('md5');
|
|
237
|
+
inMd5 = code;
|
|
238
|
+
outMd5 = md5Hash.update(outBuffer).digest('hex');
|
|
239
|
+
this.witeBuffer(outPath, outBuffer);
|
|
240
|
+
console.log(inMd5, outMd5);
|
|
241
|
+
pathKey = inPath.replace("\\", "/");
|
|
242
|
+
outPath = outPath.replace("\\", "/");
|
|
243
|
+
this.info[pathKey] = { outPath: outPath, inMd5: inMd5, outMd5: outMd5 };
|
|
244
|
+
this.saveInfo();
|
|
245
|
+
this.count++;
|
|
246
|
+
return [2 /*return*/];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
TaskParser.prototype.copy = function (inPath, outPath, buffer, code) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var _a, _b;
|
|
254
|
+
return __generator(this, function (_c) {
|
|
255
|
+
switch (_c.label) {
|
|
256
|
+
case 0:
|
|
257
|
+
_a = this.witeBuffer;
|
|
258
|
+
_b = [inPath];
|
|
259
|
+
return [4 /*yield*/, this.readBuffer(outPath)];
|
|
260
|
+
case 1: return [4 /*yield*/, _a.apply(this, _b.concat([_c.sent()]))];
|
|
261
|
+
case 2:
|
|
262
|
+
_c.sent();
|
|
263
|
+
return [2 /*return*/];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
TaskParser.prototype.isSamll = function (url) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
272
|
+
fs.stat(url, function (err, s) {
|
|
273
|
+
if (err) {
|
|
274
|
+
reject(err);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
resolve(s.size < 20000);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
})];
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
TaskParser.prototype.isSpine = function (url) {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
288
|
+
var info = path.parse(url);
|
|
289
|
+
var checkUrl = info.dir + "/" + info.name + ".json";
|
|
290
|
+
fs.stat(checkUrl, function (err, s) {
|
|
291
|
+
if (err) {
|
|
292
|
+
resolve(false);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
resolve(s != null);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
})];
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
TaskParser.prototype.readBuffer = function (url) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
304
|
+
return __generator(this, function (_a) {
|
|
305
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
306
|
+
fs.readFile(url, function (err, sourceData) {
|
|
307
|
+
if (err) {
|
|
308
|
+
reject(err);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
resolve(sourceData);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
})];
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
TaskParser.prototype.witeBuffer = function (url, buffer) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
320
|
+
return __generator(this, function (_a) {
|
|
321
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
322
|
+
fs.writeFile(url, buffer, function (err) {
|
|
323
|
+
if (err) {
|
|
324
|
+
reject(err);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
resolve();
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
})];
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
TaskParser.prototype.hasStat = function (url) {
|
|
335
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
+
return __generator(this, function (_a) {
|
|
337
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
338
|
+
fs.stat(url, function (err, s) {
|
|
339
|
+
if (err) {
|
|
340
|
+
resolve(false);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
resolve(s != null);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
})];
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
TaskParser.prototype.mkdirs = function (url) {
|
|
351
|
+
if (!fs.existsSync(url)) {
|
|
352
|
+
this.mkdirs(path.resolve(url, "../"));
|
|
353
|
+
fs.mkdirSync(url);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
TaskParser.prototype.readDirData = function (pathUrl) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
var _this = this;
|
|
359
|
+
return __generator(this, function (_a) {
|
|
360
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
361
|
+
fs.readdir(path.join(_this.config.inPath, pathUrl), function (err, data) {
|
|
362
|
+
if (err) {
|
|
363
|
+
reject("这个目录不存在");
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
resolve(data);
|
|
367
|
+
});
|
|
368
|
+
})];
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
TaskParser.prototype.parserConfig = function () {
|
|
373
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
374
|
+
var _this = this;
|
|
375
|
+
return __generator(this, function (_a) {
|
|
376
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
377
|
+
fs.readFile(_this.tinfiyUrl, function (err, txt) {
|
|
378
|
+
if (err) {
|
|
379
|
+
reject("这个目录下没有目录配置文件tinify.json");
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
var json = JSON.parse(txt.toString());
|
|
383
|
+
var inPath = path.join(_this.tinfiyUrlInfo.dir, json.inPath);
|
|
384
|
+
var outPath = path.join(_this.tinfiyUrlInfo.dir, json.outPath);
|
|
385
|
+
var tinifyKey = json.tinifyKey;
|
|
386
|
+
var skipSpine = json.skipSpine || false;
|
|
387
|
+
var info = path.join(_this.tinfiyUrlInfo.dir, json.info);
|
|
388
|
+
var ignore_1 = new Set();
|
|
389
|
+
json.ignore.forEach(function (ignoreItem) {
|
|
390
|
+
ignore_1.add(ignoreItem);
|
|
391
|
+
});
|
|
392
|
+
tinify.default.key = tinifyKey;
|
|
393
|
+
_this.config = {
|
|
394
|
+
skipSpine: skipSpine,
|
|
395
|
+
inPath: inPath,
|
|
396
|
+
outPath: outPath,
|
|
397
|
+
ignore: ignore_1,
|
|
398
|
+
tinifyKey: tinifyKey,
|
|
399
|
+
info: info,
|
|
400
|
+
};
|
|
401
|
+
resolve(_this.config);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
})];
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
return TaskParser;
|
|
409
|
+
}());
|
|
410
|
+
exports.TaskParser = TaskParser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zero-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Zero游戏开发工具",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"minimist": "^1.2.0",
|
|
16
|
-
"
|
|
16
|
+
"tinify": "^1.6.1",
|
|
17
|
+
"xlsx": "^0.13.5"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@types/minimist": "^1.2.0",
|
package/tinify.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import * as fs from 'fs'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
import * as tinify from 'tinify'
|
|
4
|
+
import * as crypto from 'crypto'
|
|
5
|
+
|
|
6
|
+
interface ITinifyConfig {
|
|
7
|
+
inPath: string
|
|
8
|
+
outPath: string
|
|
9
|
+
info: string
|
|
10
|
+
ignore: Set<string>
|
|
11
|
+
tinifyKey: string
|
|
12
|
+
skipSpine: boolean
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 忽略含有命名为
|
|
16
|
+
* atlas8
|
|
17
|
+
* atlas9
|
|
18
|
+
* 忽略 20000 字节以下的文件
|
|
19
|
+
*/
|
|
20
|
+
export class TaskParser {
|
|
21
|
+
tinfiyUrlInfo: path.ParsedPath
|
|
22
|
+
config!: ITinifyConfig
|
|
23
|
+
info: any;
|
|
24
|
+
constructor(public tinfiyUrl: string) {
|
|
25
|
+
this.tinfiyUrlInfo = path.parse(tinfiyUrl)
|
|
26
|
+
}
|
|
27
|
+
async loadInfo() {
|
|
28
|
+
let buffer = await this.readBuffer(this.config.info)
|
|
29
|
+
this.info = JSON.parse(buffer.toString('utf-8'))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async saveInfo() {
|
|
33
|
+
this.witeBuffer(this.config.info, JSON.stringify(this.info, null, 4))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async idDir(pathUrl: string): Promise<boolean> {
|
|
37
|
+
return new Promise<boolean>(
|
|
38
|
+
(resolve: (value: boolean) => void, reject: (reason?: any) => void) => {
|
|
39
|
+
fs.stat(path.join(this.config.inPath, pathUrl), (err: NodeJS.ErrnoException | null, stats: fs.Stats) => {
|
|
40
|
+
if (err) {
|
|
41
|
+
reject(err)
|
|
42
|
+
} else {
|
|
43
|
+
resolve(stats.isDirectory())
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
async readDir(pathUrl: string) {
|
|
49
|
+
let data = await this.readDirData(pathUrl)
|
|
50
|
+
for (let index = 0; index < data.length; index++) {
|
|
51
|
+
const element = path.join(pathUrl, data[index]);
|
|
52
|
+
let isDir = await this.idDir(element)
|
|
53
|
+
if (isDir) {
|
|
54
|
+
await this.readDir(element)
|
|
55
|
+
} else {
|
|
56
|
+
let info = path.parse(element)
|
|
57
|
+
// if (info.ext == ".png" || info.ext == ".jpg") {
|
|
58
|
+
if (info.ext == ".png") {
|
|
59
|
+
await this.pick(element)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
count = 0
|
|
65
|
+
async pick(element: string): Promise<void> {
|
|
66
|
+
let inPath = path.join(this.config.inPath, element)
|
|
67
|
+
let outPath = path.join(this.config.outPath, element)
|
|
68
|
+
let info = path.parse(inPath)
|
|
69
|
+
let reg = /atlas[89]/;
|
|
70
|
+
|
|
71
|
+
if (!reg.test(info.name)) {
|
|
72
|
+
if (this.config.ignore.has(info.name)) {
|
|
73
|
+
console.log("出现在白名单", inPath)
|
|
74
|
+
} else {
|
|
75
|
+
if (!await this.isSamll(inPath)) {
|
|
76
|
+
let buffer = await this.readBuffer(inPath)
|
|
77
|
+
const md5 = crypto.createHash('md5');
|
|
78
|
+
const code = md5.update(buffer).digest('hex');
|
|
79
|
+
if (this.config.skipSpine && await this.isSpine(inPath)) {
|
|
80
|
+
} else {
|
|
81
|
+
// let doc = await this.db.findOne({ inPath })
|
|
82
|
+
let pathKey = inPath.replace("\\", "/")
|
|
83
|
+
let doc = this.info[pathKey]
|
|
84
|
+
|
|
85
|
+
if (doc == null) {
|
|
86
|
+
//没有记录
|
|
87
|
+
// this.count++
|
|
88
|
+
await this.tinify(inPath, outPath, buffer, code)
|
|
89
|
+
await this.copy(inPath, outPath, buffer, code)
|
|
90
|
+
console.log("没有记录:", inPath)
|
|
91
|
+
} else if (doc.inMd5 == code) {
|
|
92
|
+
//没有复制
|
|
93
|
+
await this.copy(inPath, outPath, buffer, code)
|
|
94
|
+
console.log("没有复制:", inPath)
|
|
95
|
+
} else if (doc.outMd5 == code) {
|
|
96
|
+
console.log("正常跳过:", inPath)
|
|
97
|
+
//正常
|
|
98
|
+
} else {
|
|
99
|
+
//图是新的
|
|
100
|
+
await this.tinify(inPath, outPath, buffer, code)
|
|
101
|
+
await this.copy(inPath, outPath, buffer, code)
|
|
102
|
+
console.log("新图:", inPath)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
async tinify(inPath: string, outPath: string, buffer: Buffer, code: string): Promise<void> {
|
|
111
|
+
console.log("开始转换" + inPath)
|
|
112
|
+
let outBuffer = await tinify.default.fromBuffer(buffer).toBuffer()
|
|
113
|
+
const md5Hash = crypto.createHash('md5');
|
|
114
|
+
let inMd5 = code
|
|
115
|
+
let outMd5 = md5Hash.update(outBuffer).digest('hex');
|
|
116
|
+
this.witeBuffer(outPath, outBuffer)
|
|
117
|
+
console.log(inMd5, outMd5)
|
|
118
|
+
// await this.db.updateOne({ inPath }, { inPath, outPath, inMd5, outMd5 }, { upsert: true })
|
|
119
|
+
let pathKey = inPath.replace("\\", "/")
|
|
120
|
+
outPath = outPath.replace("\\", "/")
|
|
121
|
+
this.info[pathKey] = { outPath, inMd5, outMd5 }
|
|
122
|
+
this.saveInfo()
|
|
123
|
+
this.count++
|
|
124
|
+
}
|
|
125
|
+
async copy(inPath: string, outPath: string, buffer: Buffer, code: string): Promise<void> {
|
|
126
|
+
await this.witeBuffer(inPath, await this.readBuffer(outPath))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async isSamll(url: string): Promise<boolean> {
|
|
130
|
+
return new Promise<boolean>(
|
|
131
|
+
(resolve: (value: boolean) => void, reject: (reason?: any) => void) => {
|
|
132
|
+
fs.stat(url, (err, s) => {
|
|
133
|
+
if (err) {
|
|
134
|
+
reject(err)
|
|
135
|
+
} else {
|
|
136
|
+
resolve(s.size < 20000)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
async isSpine(url: string): Promise<boolean> {
|
|
143
|
+
return new Promise<boolean>(
|
|
144
|
+
(resolve: (value: boolean) => void, reject: (reason?: any) => void) => {
|
|
145
|
+
let info = path.parse(url)
|
|
146
|
+
let checkUrl = info.dir + "/" + info.name + ".json"
|
|
147
|
+
fs.stat(checkUrl, (err, s) => {
|
|
148
|
+
if (err) {
|
|
149
|
+
resolve(false)
|
|
150
|
+
} else {
|
|
151
|
+
resolve(s != null)
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
async readBuffer(url: string): Promise<Buffer> {
|
|
160
|
+
return new Promise<Buffer>(
|
|
161
|
+
(resolve: (value: Buffer) => void, reject: (reason?: any) => void) => {
|
|
162
|
+
fs.readFile(url, (err, sourceData) => {
|
|
163
|
+
if (err) {
|
|
164
|
+
reject(err)
|
|
165
|
+
} else {
|
|
166
|
+
resolve(sourceData)
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async witeBuffer(url: string, buffer: Uint8Array | string): Promise<void> {
|
|
174
|
+
return new Promise<void>(
|
|
175
|
+
(resolve: (value: void) => void, reject: (reason?: any) => void) => {
|
|
176
|
+
fs.writeFile(url, buffer, (err) => {
|
|
177
|
+
if (err) {
|
|
178
|
+
reject(err)
|
|
179
|
+
} else {
|
|
180
|
+
resolve()
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
async hasStat(url: string): Promise<boolean> {
|
|
189
|
+
return new Promise<boolean>(
|
|
190
|
+
(resolve: (value: boolean) => void, reject: (reason?: any) => void) => {
|
|
191
|
+
fs.stat(url, (err, s) => {
|
|
192
|
+
if (err) {
|
|
193
|
+
resolve(false)
|
|
194
|
+
} else {
|
|
195
|
+
resolve(s != null)
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
mkdirs(url: string) {
|
|
203
|
+
if (!fs.existsSync(url)) {
|
|
204
|
+
this.mkdirs(path.resolve(url, "../"))
|
|
205
|
+
fs.mkdirSync(url)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async readDirData(pathUrl: string): Promise<string[]> {
|
|
209
|
+
return new Promise<string[]>(
|
|
210
|
+
(resolve: (value: string[]) => void, reject: (reason?: any) => void) => {
|
|
211
|
+
fs.readdir(path.join(this.config.inPath, pathUrl), function (err, data) {
|
|
212
|
+
if (err) {
|
|
213
|
+
reject("这个目录不存在")
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
resolve(data)
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
async parserConfig(): Promise<ITinifyConfig> {
|
|
222
|
+
return new Promise<ITinifyConfig>((resolve: (value: ITinifyConfig) => void, reject: (reason?: any) => void) => {
|
|
223
|
+
fs.readFile(this.tinfiyUrl, (err, txt) => {
|
|
224
|
+
if (err) {
|
|
225
|
+
reject("这个目录下没有目录配置文件tinify.json")
|
|
226
|
+
} else {
|
|
227
|
+
let json = JSON.parse(txt.toString())
|
|
228
|
+
|
|
229
|
+
let inPath: string = path.join(this.tinfiyUrlInfo.dir, json.inPath)
|
|
230
|
+
let outPath: string = path.join(this.tinfiyUrlInfo.dir, json.outPath)
|
|
231
|
+
|
|
232
|
+
let tinifyKey: string = json.tinifyKey
|
|
233
|
+
let skipSpine: boolean = json.skipSpine || false
|
|
234
|
+
let info: string = path.join(this.tinfiyUrlInfo.dir, json.info)
|
|
235
|
+
let ignore: Set<string> = new Set()
|
|
236
|
+
json.ignore.forEach((ignoreItem: string) => {
|
|
237
|
+
ignore.add(ignoreItem)
|
|
238
|
+
})
|
|
239
|
+
tinify.default.key = tinifyKey
|
|
240
|
+
this.config = {
|
|
241
|
+
skipSpine,
|
|
242
|
+
inPath,
|
|
243
|
+
outPath,
|
|
244
|
+
ignore,
|
|
245
|
+
tinifyKey,
|
|
246
|
+
info,
|
|
247
|
+
}
|
|
248
|
+
resolve(this.config)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
}
|
package/.vscode/tasks.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
3
|
-
// for the documentation about the tasks.json format
|
|
4
|
-
"version": "2.0.0",
|
|
5
|
-
"tasks": [
|
|
6
|
-
{
|
|
7
|
-
"type": "typescript",
|
|
8
|
-
"tsconfig": "tsconfig.json",
|
|
9
|
-
"problemMatcher": [
|
|
10
|
-
"$tsc"
|
|
11
|
-
]
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
}
|