zero-tools 1.4.4 → 1.5.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/ConfigParser.ts +79 -0
- package/ZeroWorkBook.ts +332 -0
- package/bin.ts +99 -1
- package/dist/ConfPorxy.js +1 -1
- package/dist/ConfigParser.js +87 -0
- package/dist/ZeroWorkBook.js +343 -0
- package/dist/bin.js +86 -8
- package/dist/shell-ts.js +3 -3
- package/dist/tinify.js +9 -5
- package/dist/xlsx-ts.js +1 -1
- package/package.json +4 -3
- package/tinify.ts +3 -3
- package/type.d.ts +1 -0
package/ConfigParser.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
enum FieldType {
|
|
2
|
+
BOOLEAN,
|
|
3
|
+
NUMBER,
|
|
4
|
+
STRING,
|
|
5
|
+
OBJECT,
|
|
6
|
+
}
|
|
7
|
+
export class ConfigParser {
|
|
8
|
+
static parse(buffer: Buffer): any {
|
|
9
|
+
let index = 0;
|
|
10
|
+
let next = false;
|
|
11
|
+
let tables: any[] = [];
|
|
12
|
+
do {
|
|
13
|
+
let fields: { name: string; type: FieldType; }[] = [];
|
|
14
|
+
do {
|
|
15
|
+
let type = buffer.readUint8(index);
|
|
16
|
+
index += 1;
|
|
17
|
+
let length = buffer.readUInt32BE(index);
|
|
18
|
+
index += 4;
|
|
19
|
+
let name = buffer.toString("utf8", index, index + length);
|
|
20
|
+
index += length;
|
|
21
|
+
next = buffer.readUint8(index) == 1;
|
|
22
|
+
index += 1;
|
|
23
|
+
fields.push({
|
|
24
|
+
name,
|
|
25
|
+
type,
|
|
26
|
+
});
|
|
27
|
+
} while (next);
|
|
28
|
+
let table: any = [];
|
|
29
|
+
do {
|
|
30
|
+
let obj: any = {};
|
|
31
|
+
let fieldIndex = 0;
|
|
32
|
+
do {
|
|
33
|
+
let type = buffer.readUint8(index);
|
|
34
|
+
let fieldKey = fields[fieldIndex].name;
|
|
35
|
+
index += 1;
|
|
36
|
+
let value: any;
|
|
37
|
+
switch (type) {
|
|
38
|
+
case FieldType.BOOLEAN:
|
|
39
|
+
value = buffer.readUint8(index) == 1;
|
|
40
|
+
index += 1;
|
|
41
|
+
break;
|
|
42
|
+
case FieldType.NUMBER:
|
|
43
|
+
value = buffer.readDoubleBE(index);
|
|
44
|
+
index += 8;
|
|
45
|
+
break;
|
|
46
|
+
case FieldType.STRING:
|
|
47
|
+
{
|
|
48
|
+
let length = buffer.readUInt32BE(index);
|
|
49
|
+
index += 4;
|
|
50
|
+
value = buffer.toString("utf8", index, index + length);
|
|
51
|
+
index += length;
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case FieldType.OBJECT:
|
|
55
|
+
{
|
|
56
|
+
let length = buffer.readUInt32BE(index);
|
|
57
|
+
index += 4;
|
|
58
|
+
value = JSON.parse(buffer.toString("utf8", index, index + length));
|
|
59
|
+
index += length;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
default:
|
|
63
|
+
}
|
|
64
|
+
fieldIndex++;
|
|
65
|
+
if (value) {
|
|
66
|
+
obj[fieldKey] = value;
|
|
67
|
+
}
|
|
68
|
+
} while (fieldIndex < fields.length);
|
|
69
|
+
next = buffer.readUint8(index) == 1;
|
|
70
|
+
index += 1;
|
|
71
|
+
table.push(obj);
|
|
72
|
+
} while (next);
|
|
73
|
+
tables.push(table);
|
|
74
|
+
next = buffer.readUint8(index) == 1;
|
|
75
|
+
index += 1;
|
|
76
|
+
} while (next);
|
|
77
|
+
return tables;
|
|
78
|
+
}
|
|
79
|
+
}
|
package/ZeroWorkBook.ts
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { CellObject, WorkBook, utils, WorkSheet } from "xlsx"
|
|
2
|
+
export enum FieldType {
|
|
3
|
+
BOOLEAN,
|
|
4
|
+
NUMBER,
|
|
5
|
+
STRING,
|
|
6
|
+
OBJECT,
|
|
7
|
+
ANY,
|
|
8
|
+
}
|
|
9
|
+
let fieldTypePool = {
|
|
10
|
+
[FieldType.BOOLEAN]: "boolean",
|
|
11
|
+
[FieldType.NUMBER]: "number",
|
|
12
|
+
[FieldType.STRING]: "string",
|
|
13
|
+
[FieldType.ANY]: "any",
|
|
14
|
+
[FieldType.OBJECT]: "any",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface IField {
|
|
18
|
+
index: number
|
|
19
|
+
type: FieldType
|
|
20
|
+
required: boolean
|
|
21
|
+
name: string
|
|
22
|
+
explain: string
|
|
23
|
+
}
|
|
24
|
+
export interface IData {
|
|
25
|
+
type: FieldType
|
|
26
|
+
value: any
|
|
27
|
+
}
|
|
28
|
+
export class ZeroTable {
|
|
29
|
+
fields: IField[] = []
|
|
30
|
+
data: IData[][] = []
|
|
31
|
+
getFieldType(cell?: CellObject): FieldType {
|
|
32
|
+
if (cell != null) {
|
|
33
|
+
if (cell.t == "b") {
|
|
34
|
+
return FieldType.BOOLEAN
|
|
35
|
+
} else if (cell.t == "n") {
|
|
36
|
+
return FieldType.NUMBER
|
|
37
|
+
} else if (cell.t == "s") {
|
|
38
|
+
try {
|
|
39
|
+
if (typeof cell.v == "string") {
|
|
40
|
+
JSON.parse(cell.v)
|
|
41
|
+
}
|
|
42
|
+
return FieldType.OBJECT
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return FieldType.STRING
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
return FieldType.STRING
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
return FieldType.STRING
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
checkCell(cell: CellObject | undefined) {
|
|
54
|
+
if (cell != null && cell.v != null) {
|
|
55
|
+
if (cell.t == "s" && (cell.v == "" || cell.v == " ")) {
|
|
56
|
+
return false
|
|
57
|
+
} else {
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
constructor(sheet: WorkSheet, checkCellName: string, startRow: number, explainRow?: number, checkColumn?: number) {
|
|
65
|
+
let checkCell = utils.decode_cell(checkCellName)
|
|
66
|
+
let rangeString = sheet["!ref"]
|
|
67
|
+
if (rangeString) {
|
|
68
|
+
let range = utils.decode_range(rangeString)
|
|
69
|
+
/**
|
|
70
|
+
* 组织字段
|
|
71
|
+
*/
|
|
72
|
+
for (let index = checkCell.c; index <= range.e.c; index++) {
|
|
73
|
+
// console.log({ c: index, r: checkCell.r }, utils.encode_cell({ c: index, r: checkCell.r }))
|
|
74
|
+
let cell = sheet[utils.encode_cell({ c: index, r: checkCell.r })] as CellObject
|
|
75
|
+
|
|
76
|
+
if (this.checkCell(cell)) {
|
|
77
|
+
|
|
78
|
+
// let typeCell: CellObject | undefined
|
|
79
|
+
let type: FieldType | undefined
|
|
80
|
+
let required = true
|
|
81
|
+
for (let row = startRow; row <= range.e.r; row++) {
|
|
82
|
+
let typeCell = sheet[utils.encode_cell({ c: index, r: row })] as CellObject
|
|
83
|
+
|
|
84
|
+
let isSkip = false
|
|
85
|
+
if (checkColumn) {
|
|
86
|
+
let checkColumnCell = sheet[utils.encode_cell({ c: checkColumn, r: row })] as CellObject
|
|
87
|
+
if (!this.checkCell(checkColumnCell)) {
|
|
88
|
+
isSkip = true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!isSkip) {
|
|
92
|
+
if (this.checkCell(typeCell)) {
|
|
93
|
+
let _type = this.getFieldType(typeCell)
|
|
94
|
+
if (type == null) {
|
|
95
|
+
type = _type
|
|
96
|
+
} else {
|
|
97
|
+
if (type != _type) {
|
|
98
|
+
type = FieldType.ANY
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
required = false
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let info: any = {
|
|
108
|
+
name: cell.w!,
|
|
109
|
+
type,
|
|
110
|
+
index,
|
|
111
|
+
required,
|
|
112
|
+
}
|
|
113
|
+
if (explainRow != null) {
|
|
114
|
+
let explainCell = sheet[utils.encode_cell({ c: index, r: explainRow })] as CellObject
|
|
115
|
+
if (explainCell != null && explainCell.v != null) {
|
|
116
|
+
info.explain = explainCell.v as any
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this.fields.push(info)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 处理数据
|
|
124
|
+
*/
|
|
125
|
+
for (let row = startRow; row <= range.e.r; row++) {
|
|
126
|
+
let item: any = []
|
|
127
|
+
let isSkip = false
|
|
128
|
+
if (checkColumn) {
|
|
129
|
+
let cell = sheet[utils.encode_cell({ c: checkColumn, r: row })] as CellObject
|
|
130
|
+
if (!this.checkCell(cell)) {
|
|
131
|
+
isSkip = true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!isSkip) {
|
|
135
|
+
this.fields.forEach((field, index) => {
|
|
136
|
+
let cell = sheet[utils.encode_cell({ c: field.index, r: row })] as CellObject
|
|
137
|
+
if (this.checkCell(cell)) {
|
|
138
|
+
let type = this.getFieldType(cell)
|
|
139
|
+
let value
|
|
140
|
+
if (type == FieldType.OBJECT) {
|
|
141
|
+
value = JSON.parse(cell.v as string)
|
|
142
|
+
} else if (type == FieldType.STRING) {
|
|
143
|
+
value = (cell.v as string).replace(/\\n/g, "\n")
|
|
144
|
+
} else {
|
|
145
|
+
value = cell.v
|
|
146
|
+
}
|
|
147
|
+
item[index] = {
|
|
148
|
+
value,
|
|
149
|
+
type,
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
item[index] = null
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
this.data.push(item)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
toJson(): any {
|
|
162
|
+
let json: any = []
|
|
163
|
+
this.data.forEach((docs) => {
|
|
164
|
+
let info: any = {}
|
|
165
|
+
docs.forEach((doc, index) => {
|
|
166
|
+
if (doc) {
|
|
167
|
+
info[this.fields[index].name] = doc.value
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
json.push(info)
|
|
171
|
+
})
|
|
172
|
+
return json
|
|
173
|
+
}
|
|
174
|
+
toBin(): Buffer {
|
|
175
|
+
// console.log("数据条数",this.data.length)
|
|
176
|
+
return Buffer.concat(this.fields.map((field, index) => {
|
|
177
|
+
let buffers = []
|
|
178
|
+
buffers[0] = Buffer.alloc(1)
|
|
179
|
+
buffers[0].writeUInt8(field.type)
|
|
180
|
+
buffers[1] = Buffer.alloc(4)
|
|
181
|
+
buffers[2] = Buffer.from(field.name, 'utf8')
|
|
182
|
+
buffers[1].writeUint32BE(buffers[2].length)
|
|
183
|
+
if (index == this.fields.length - 1) {
|
|
184
|
+
buffers[3] = Buffer.alloc(1, 0)
|
|
185
|
+
} else {
|
|
186
|
+
buffers[3] = Buffer.alloc(1, 1)
|
|
187
|
+
}
|
|
188
|
+
return Buffer.concat(buffers)
|
|
189
|
+
}).concat(this.data.map((cow, index) => {
|
|
190
|
+
let cowBuffs: Buffer[] = []
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
for (let cowIndex = 0; cowIndex < cow.length; cowIndex++) {
|
|
194
|
+
const item = cow[cowIndex];
|
|
195
|
+
if (item != null) {
|
|
196
|
+
let typeBuffer = Buffer.alloc(1)
|
|
197
|
+
typeBuffer.writeUint8(item.type)
|
|
198
|
+
let buf!: Buffer
|
|
199
|
+
switch (item.type) {
|
|
200
|
+
case FieldType.BOOLEAN:
|
|
201
|
+
buf = Buffer.alloc(1)
|
|
202
|
+
buf.writeUint8(item.value == true ? 1 : 0)
|
|
203
|
+
|
|
204
|
+
break
|
|
205
|
+
case FieldType.NUMBER:
|
|
206
|
+
buf = Buffer.alloc(8)
|
|
207
|
+
buf.writeDoubleBE(item.value)
|
|
208
|
+
break
|
|
209
|
+
case FieldType.STRING:
|
|
210
|
+
{
|
|
211
|
+
let buffers = []
|
|
212
|
+
buffers[0] = Buffer.alloc(4)
|
|
213
|
+
buffers[1] = Buffer.from(item.value, 'utf8')
|
|
214
|
+
buffers[0].writeUint32BE(buffers[1].length)
|
|
215
|
+
buf = Buffer.concat(buffers)
|
|
216
|
+
}
|
|
217
|
+
break
|
|
218
|
+
case FieldType.OBJECT:
|
|
219
|
+
{
|
|
220
|
+
let buffers = []
|
|
221
|
+
buffers[0] = Buffer.alloc(4)
|
|
222
|
+
buffers[1] = Buffer.from(JSON.stringify(item.value), 'utf8')
|
|
223
|
+
buffers[0].writeUint32BE(buffers[1].length)
|
|
224
|
+
buf = Buffer.concat(buffers)
|
|
225
|
+
}
|
|
226
|
+
break
|
|
227
|
+
}
|
|
228
|
+
cowBuffs.push(typeBuffer)
|
|
229
|
+
cowBuffs.push(buf)
|
|
230
|
+
} else {
|
|
231
|
+
cowBuffs.push(Buffer.alloc(1, 0x255))
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let endBuf: Buffer
|
|
235
|
+
if (index == this.data.length - 1) {
|
|
236
|
+
endBuf = Buffer.alloc(1, 0)
|
|
237
|
+
} else {
|
|
238
|
+
endBuf = Buffer.alloc(1, 1)
|
|
239
|
+
}
|
|
240
|
+
return Buffer.concat([...cowBuffs, endBuf])
|
|
241
|
+
})))
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
export class ZeroWorkBook {
|
|
247
|
+
tables: { [key: string]: ZeroTable } = {}
|
|
248
|
+
constructor(workBook: WorkBook, checkCellName: string, startRow: number, explainRow?: number, checkColumn?: number) {
|
|
249
|
+
workBook.SheetNames.forEach((sheetName) => {
|
|
250
|
+
if (sheetName.charAt(0) != "_") {
|
|
251
|
+
let sheet = workBook.Sheets[sheetName];
|
|
252
|
+
this.tables[sheetName] = new ZeroTable(sheet, checkCellName, startRow, explainRow, checkColumn)
|
|
253
|
+
}
|
|
254
|
+
// this.tables.push();
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
toJson() {
|
|
258
|
+
// return this.tables.map((table) => {
|
|
259
|
+
// return table.toJson();
|
|
260
|
+
// });
|
|
261
|
+
let out: any = {}
|
|
262
|
+
for (const key in this.tables) {
|
|
263
|
+
if (Object.prototype.hasOwnProperty.call(this.tables, key)) {
|
|
264
|
+
const element = this.tables[key];
|
|
265
|
+
if (element.fields.length > 0) {
|
|
266
|
+
out[key] = element.toJson()
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return out
|
|
271
|
+
}
|
|
272
|
+
toBin(): Buffer {
|
|
273
|
+
let out: Buffer[] = []
|
|
274
|
+
let endBuf: Buffer;
|
|
275
|
+
for (const key in this.tables) {
|
|
276
|
+
const table = this.tables[key];
|
|
277
|
+
if (table.fields.length > 0) {
|
|
278
|
+
let titleBuffer = Buffer.from(key, 'utf8')
|
|
279
|
+
let lengthBuffer = Buffer.alloc(4);
|
|
280
|
+
lengthBuffer.writeUint32BE(titleBuffer.length)
|
|
281
|
+
let buffer = table.toBin();
|
|
282
|
+
endBuf = Buffer.alloc(1, 1);
|
|
283
|
+
out.push(lengthBuffer, titleBuffer, buffer, endBuf)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
out[out.length - 1] = Buffer.alloc(1, 0);
|
|
287
|
+
return Buffer.concat(out);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private faceName(value: string) {
|
|
291
|
+
return "I" + value.replace(/(\w)/, function (v) { return v.toUpperCase() })
|
|
292
|
+
}
|
|
293
|
+
private getExplain(value?: string) {
|
|
294
|
+
if (value) {
|
|
295
|
+
return value.split("\n").join("\n\t * ")
|
|
296
|
+
} else {
|
|
297
|
+
return ""
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
toTS(name: string) {
|
|
301
|
+
let out: any = ""
|
|
302
|
+
let tableString: string[] = []
|
|
303
|
+
let tableRoot: string[] = []
|
|
304
|
+
for (const key in this.tables) {
|
|
305
|
+
if (Object.prototype.hasOwnProperty.call(this.tables, key)) {
|
|
306
|
+
const element = this.tables[key];
|
|
307
|
+
let faceName = this.faceName(key)
|
|
308
|
+
if (element.fields.length > 0 && element.data.length > 0) {
|
|
309
|
+
tableRoot.push(`${key}: ${faceName}[]`)
|
|
310
|
+
tableString.push(`export interface ${faceName} {
|
|
311
|
+
${element.fields.map((field) => {
|
|
312
|
+
return ` /**
|
|
313
|
+
* ${this.getExplain(field.explain)}
|
|
314
|
+
*/
|
|
315
|
+
${field.name}${field.required ? "" : "?"}: ${this.getFieldType(field.type)}`
|
|
316
|
+
}).join("\n")}
|
|
317
|
+
}`)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
let rootString = `
|
|
323
|
+
export interface ${this.faceName(name)} {
|
|
324
|
+
${tableRoot.join("\n\t")}
|
|
325
|
+
}`
|
|
326
|
+
return tableString.join("\n") + rootString
|
|
327
|
+
}
|
|
328
|
+
getFieldType(type: FieldType) {
|
|
329
|
+
return fieldTypePool[type]
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
package/bin.ts
CHANGED
|
@@ -5,6 +5,9 @@ import * as fs from 'fs'
|
|
|
5
5
|
import * as path from 'path'
|
|
6
6
|
import { xlsxToTs } from './xlsx-ts';
|
|
7
7
|
import { TaskParser } from './tinify';
|
|
8
|
+
import Config from "config-js"
|
|
9
|
+
import { ZeroWorkBook } from './ZeroWorkBook';
|
|
10
|
+
import { readFile } from 'xlsx';
|
|
8
11
|
let cwd = process.cwd()
|
|
9
12
|
let name = path.basename(cwd)
|
|
10
13
|
let argv = minimist(process.argv.slice(2), {
|
|
@@ -15,6 +18,7 @@ let argv = minimist(process.argv.slice(2), {
|
|
|
15
18
|
packHotup: ['pp'],
|
|
16
19
|
tinify: ['ty'],
|
|
17
20
|
xlsxToTs: ['xt'],
|
|
21
|
+
xlsxToBin: ['xb'],
|
|
18
22
|
help: ['h'],
|
|
19
23
|
version: ['v'],
|
|
20
24
|
}
|
|
@@ -133,6 +137,7 @@ let helpString = `
|
|
|
133
137
|
----------------------开发工具包-----------------------
|
|
134
138
|
zero ut (zero --unitTesting)在当前文件夹新建TS单元测试项目
|
|
135
139
|
zero xt (zero --xlsxToTs)在当前文件夹下的xlsx.json中所描述的Excel文件转换TS文件
|
|
140
|
+
zero xb (zero --xlsxToBin)在当前文件夹下的xlsx.json中所描述的Excel文件转换TS文件或二进制文件
|
|
136
141
|
zero ty (zero --tinify)在当前文件夹下的tinify.json中所描述的文件进行压缩
|
|
137
142
|
zero pp (zero --packHotup)在当前文件夹下的packHotup.json中所描述的文件进行打包热更新
|
|
138
143
|
zero h (zero --help)帮助
|
|
@@ -177,6 +182,99 @@ let fn = {
|
|
|
177
182
|
}
|
|
178
183
|
})
|
|
179
184
|
},
|
|
185
|
+
xb: () => {
|
|
186
|
+
|
|
187
|
+
interface IConfigInfo {
|
|
188
|
+
inPath: string
|
|
189
|
+
jsPath: string
|
|
190
|
+
jsonPath: string
|
|
191
|
+
dtsPath: string
|
|
192
|
+
binPath: string
|
|
193
|
+
tsPath?: string
|
|
194
|
+
checkCell: string
|
|
195
|
+
startRow: number
|
|
196
|
+
checkColumn?: number
|
|
197
|
+
explainRow?: number
|
|
198
|
+
userString?: string
|
|
199
|
+
}
|
|
200
|
+
function checkNull(value: any, error: string) {
|
|
201
|
+
if (value == null) {
|
|
202
|
+
throw error
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let config
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
config = new Config('zeroconfig.config.js');
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.log("这个目录下没有目录配置文件zeroconfig.config.js")
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
checkNull(config.configObj.inPath, "inPath undefined")
|
|
214
|
+
checkNull(config.configObj.checkCell, "checkCell undefined")
|
|
215
|
+
checkNull(config.configObj.startRow, "startRow undefined")
|
|
216
|
+
|
|
217
|
+
let info: IConfigInfo = config.configObj
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
fs.readdir(info.inPath, function (err, data) {
|
|
221
|
+
if (err) {
|
|
222
|
+
console.log("这个目录不存在")
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
data.forEach(ExcelName => {
|
|
227
|
+
if (ExcelName.slice(ExcelName.length - 5, ExcelName.length) == ".xlsx" && ExcelName.charAt(0) != "~") {
|
|
228
|
+
let inPath = path.join(info.inPath, ExcelName)
|
|
229
|
+
// console.log("+++++++1++++=",inPath)
|
|
230
|
+
let book = new ZeroWorkBook(readFile(inPath), info.checkCell, info.startRow, info.explainRow, info.checkColumn)
|
|
231
|
+
// console.log("+++++++2++++=",info.binPath)
|
|
232
|
+
if (info.binPath) {
|
|
233
|
+
let binPath = path.join(info.binPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".bin"))
|
|
234
|
+
fs.writeFileSync(binPath, book.toBin())
|
|
235
|
+
console.log("成功导出配置表到二进制文件" + binPath)
|
|
236
|
+
}
|
|
237
|
+
if (info.jsonPath) {
|
|
238
|
+
let jsonPath = path.join(info.jsonPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".json"))
|
|
239
|
+
fs.writeFileSync(jsonPath, JSON.stringify(book.toJson(), null, 4))
|
|
240
|
+
console.log("成功导出配置表到json文件" + jsonPath)
|
|
241
|
+
}
|
|
242
|
+
if (info.dtsPath) {
|
|
243
|
+
let rootName = path.basename(ExcelName).replace(path.extname(ExcelName), "")
|
|
244
|
+
let userString = ""
|
|
245
|
+
let rootInterface = "I" + rootName.replace(/(\w)/, function (v) { return v.toUpperCase() }) + "Root"
|
|
246
|
+
if (info.userString) {
|
|
247
|
+
userString = info.userString.replace(/%{rootName}/g, rootName).replace(/%{rootInterface}/g, rootInterface)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let jsString = ""
|
|
251
|
+
if (info.jsPath) {
|
|
252
|
+
jsString = `export declare let ${rootName}: ${rootInterface};`
|
|
253
|
+
}
|
|
254
|
+
let dtsPath = path.join(info.dtsPath, rootName + ".d.ts")
|
|
255
|
+
fs.writeFileSync(dtsPath, book.toTS(rootName + "Root") + "\n" + userString + jsString)
|
|
256
|
+
}
|
|
257
|
+
if (info.jsPath) {
|
|
258
|
+
let jsPath = path.join(info.jsPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".js"))
|
|
259
|
+
fs.writeFileSync(jsPath, `"use strict";
|
|
260
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
261
|
+
exports.test = void 0;
|
|
262
|
+
exports.test = ` + JSON.stringify(book.toJson(), null, 4))
|
|
263
|
+
console.log("成功导出配置表到js文件" + jsPath)
|
|
264
|
+
}
|
|
265
|
+
if (info.tsPath) {
|
|
266
|
+
let rootName = path.basename(ExcelName).replace(path.extname(ExcelName), "")
|
|
267
|
+
let rootInterface = "I" + rootName.replace(/(\w)/, function (v) { return v.toUpperCase() }) + "Root"
|
|
268
|
+
let tsPath = path.join(info.tsPath, rootName + ".ts")
|
|
269
|
+
fs.writeFileSync(tsPath, `${book.toTS(rootName + "Root")}
|
|
270
|
+
export let ${rootName}: ${rootInterface} = ${JSON.stringify(book.toJson(), null, 4)}`)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
},
|
|
277
|
+
|
|
180
278
|
ty: () => {
|
|
181
279
|
|
|
182
280
|
// let p = new TaskParser("../../doomsdayrise-clinet/tinify.json")
|
|
@@ -206,7 +304,7 @@ let fn = {
|
|
|
206
304
|
console.log(helpString)
|
|
207
305
|
},
|
|
208
306
|
v: () => {
|
|
209
|
-
console.log("1.
|
|
307
|
+
console.log("1.5.0")
|
|
210
308
|
}
|
|
211
309
|
}
|
|
212
310
|
let isFree = true
|
package/dist/ConfPorxy.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var ConfPorxy = /** @class */ (function () {
|
|
4
4
|
function ConfPorxy(conf) {
|
|
5
|
-
var _this = this;
|
|
6
5
|
var args = [];
|
|
7
6
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
8
7
|
args[_i - 1] = arguments[_i];
|
|
9
8
|
}
|
|
9
|
+
var _this = this;
|
|
10
10
|
this.pool = {};
|
|
11
11
|
conf.forEach(function (element) {
|
|
12
12
|
var _key = ConfPorxy.setKey(element, args);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigParser = void 0;
|
|
4
|
+
var FieldType;
|
|
5
|
+
(function (FieldType) {
|
|
6
|
+
FieldType[FieldType["BOOLEAN"] = 0] = "BOOLEAN";
|
|
7
|
+
FieldType[FieldType["NUMBER"] = 1] = "NUMBER";
|
|
8
|
+
FieldType[FieldType["STRING"] = 2] = "STRING";
|
|
9
|
+
FieldType[FieldType["OBJECT"] = 3] = "OBJECT";
|
|
10
|
+
})(FieldType || (FieldType = {}));
|
|
11
|
+
var ConfigParser = /** @class */ (function () {
|
|
12
|
+
function ConfigParser() {
|
|
13
|
+
}
|
|
14
|
+
ConfigParser.parse = function (buffer) {
|
|
15
|
+
var index = 0;
|
|
16
|
+
var next = false;
|
|
17
|
+
var tables = [];
|
|
18
|
+
do {
|
|
19
|
+
var fields = [];
|
|
20
|
+
do {
|
|
21
|
+
var type = buffer.readUint8(index);
|
|
22
|
+
index += 1;
|
|
23
|
+
var length_1 = buffer.readUInt32BE(index);
|
|
24
|
+
index += 4;
|
|
25
|
+
var name_1 = buffer.toString("utf8", index, index + length_1);
|
|
26
|
+
index += length_1;
|
|
27
|
+
next = buffer.readUint8(index) == 1;
|
|
28
|
+
index += 1;
|
|
29
|
+
fields.push({
|
|
30
|
+
name: name_1,
|
|
31
|
+
type: type,
|
|
32
|
+
});
|
|
33
|
+
} while (next);
|
|
34
|
+
var table = [];
|
|
35
|
+
do {
|
|
36
|
+
var obj = {};
|
|
37
|
+
var fieldIndex = 0;
|
|
38
|
+
do {
|
|
39
|
+
var type = buffer.readUint8(index);
|
|
40
|
+
var fieldKey = fields[fieldIndex].name;
|
|
41
|
+
index += 1;
|
|
42
|
+
var value = void 0;
|
|
43
|
+
switch (type) {
|
|
44
|
+
case FieldType.BOOLEAN:
|
|
45
|
+
value = buffer.readUint8(index) == 1;
|
|
46
|
+
index += 1;
|
|
47
|
+
break;
|
|
48
|
+
case FieldType.NUMBER:
|
|
49
|
+
value = buffer.readDoubleBE(index);
|
|
50
|
+
index += 8;
|
|
51
|
+
break;
|
|
52
|
+
case FieldType.STRING:
|
|
53
|
+
{
|
|
54
|
+
var length_2 = buffer.readUInt32BE(index);
|
|
55
|
+
index += 4;
|
|
56
|
+
value = buffer.toString("utf8", index, index + length_2);
|
|
57
|
+
index += length_2;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
case FieldType.OBJECT:
|
|
61
|
+
{
|
|
62
|
+
var length_3 = buffer.readUInt32BE(index);
|
|
63
|
+
index += 4;
|
|
64
|
+
value = JSON.parse(buffer.toString("utf8", index, index + length_3));
|
|
65
|
+
index += length_3;
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
}
|
|
70
|
+
fieldIndex++;
|
|
71
|
+
if (value) {
|
|
72
|
+
obj[fieldKey] = value;
|
|
73
|
+
}
|
|
74
|
+
} while (fieldIndex < fields.length);
|
|
75
|
+
next = buffer.readUint8(index) == 1;
|
|
76
|
+
index += 1;
|
|
77
|
+
table.push(obj);
|
|
78
|
+
} while (next);
|
|
79
|
+
tables.push(table);
|
|
80
|
+
next = buffer.readUint8(index) == 1;
|
|
81
|
+
index += 1;
|
|
82
|
+
} while (next);
|
|
83
|
+
return tables;
|
|
84
|
+
};
|
|
85
|
+
return ConfigParser;
|
|
86
|
+
}());
|
|
87
|
+
exports.ConfigParser = ConfigParser;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var _a;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ZeroWorkBook = exports.ZeroTable = exports.FieldType = void 0;
|
|
14
|
+
var xlsx_1 = require("xlsx");
|
|
15
|
+
var FieldType;
|
|
16
|
+
(function (FieldType) {
|
|
17
|
+
FieldType[FieldType["BOOLEAN"] = 0] = "BOOLEAN";
|
|
18
|
+
FieldType[FieldType["NUMBER"] = 1] = "NUMBER";
|
|
19
|
+
FieldType[FieldType["STRING"] = 2] = "STRING";
|
|
20
|
+
FieldType[FieldType["OBJECT"] = 3] = "OBJECT";
|
|
21
|
+
FieldType[FieldType["ANY"] = 4] = "ANY";
|
|
22
|
+
})(FieldType || (exports.FieldType = FieldType = {}));
|
|
23
|
+
var fieldTypePool = (_a = {},
|
|
24
|
+
_a[FieldType.BOOLEAN] = "boolean",
|
|
25
|
+
_a[FieldType.NUMBER] = "number",
|
|
26
|
+
_a[FieldType.STRING] = "string",
|
|
27
|
+
_a[FieldType.ANY] = "any",
|
|
28
|
+
_a[FieldType.OBJECT] = "any",
|
|
29
|
+
_a);
|
|
30
|
+
var ZeroTable = /** @class */ (function () {
|
|
31
|
+
function ZeroTable(sheet, checkCellName, startRow, explainRow, checkColumn) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
this.fields = [];
|
|
34
|
+
this.data = [];
|
|
35
|
+
var checkCell = xlsx_1.utils.decode_cell(checkCellName);
|
|
36
|
+
var rangeString = sheet["!ref"];
|
|
37
|
+
if (rangeString) {
|
|
38
|
+
var range = xlsx_1.utils.decode_range(rangeString);
|
|
39
|
+
/**
|
|
40
|
+
* 组织字段
|
|
41
|
+
*/
|
|
42
|
+
for (var index = checkCell.c; index <= range.e.c; index++) {
|
|
43
|
+
// console.log({ c: index, r: checkCell.r }, utils.encode_cell({ c: index, r: checkCell.r }))
|
|
44
|
+
var cell = sheet[xlsx_1.utils.encode_cell({ c: index, r: checkCell.r })];
|
|
45
|
+
if (this.checkCell(cell)) {
|
|
46
|
+
// let typeCell: CellObject | undefined
|
|
47
|
+
var type = void 0;
|
|
48
|
+
var required = true;
|
|
49
|
+
for (var row = startRow; row <= range.e.r; row++) {
|
|
50
|
+
var typeCell = sheet[xlsx_1.utils.encode_cell({ c: index, r: row })];
|
|
51
|
+
var isSkip = false;
|
|
52
|
+
if (checkColumn) {
|
|
53
|
+
var checkColumnCell = sheet[xlsx_1.utils.encode_cell({ c: checkColumn, r: row })];
|
|
54
|
+
if (!this.checkCell(checkColumnCell)) {
|
|
55
|
+
isSkip = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!isSkip) {
|
|
59
|
+
if (this.checkCell(typeCell)) {
|
|
60
|
+
var _type = this.getFieldType(typeCell);
|
|
61
|
+
if (type == null) {
|
|
62
|
+
type = _type;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (type != _type) {
|
|
66
|
+
type = FieldType.ANY;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
required = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var info = {
|
|
77
|
+
name: cell.w,
|
|
78
|
+
type: type,
|
|
79
|
+
index: index,
|
|
80
|
+
required: required,
|
|
81
|
+
};
|
|
82
|
+
if (explainRow != null) {
|
|
83
|
+
var explainCell = sheet[xlsx_1.utils.encode_cell({ c: index, r: explainRow })];
|
|
84
|
+
if (explainCell != null && explainCell.v != null) {
|
|
85
|
+
info.explain = explainCell.v;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.fields.push(info);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var _loop_1 = function (row) {
|
|
92
|
+
var item = [];
|
|
93
|
+
var isSkip = false;
|
|
94
|
+
if (checkColumn) {
|
|
95
|
+
var cell = sheet[xlsx_1.utils.encode_cell({ c: checkColumn, r: row })];
|
|
96
|
+
if (!this_1.checkCell(cell)) {
|
|
97
|
+
isSkip = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!isSkip) {
|
|
101
|
+
this_1.fields.forEach(function (field, index) {
|
|
102
|
+
var cell = sheet[xlsx_1.utils.encode_cell({ c: field.index, r: row })];
|
|
103
|
+
if (_this.checkCell(cell)) {
|
|
104
|
+
var type = _this.getFieldType(cell);
|
|
105
|
+
var value = void 0;
|
|
106
|
+
if (type == FieldType.OBJECT) {
|
|
107
|
+
value = JSON.parse(cell.v);
|
|
108
|
+
}
|
|
109
|
+
else if (type == FieldType.STRING) {
|
|
110
|
+
value = cell.v.replace(/\\n/g, "\n");
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
value = cell.v;
|
|
114
|
+
}
|
|
115
|
+
item[index] = {
|
|
116
|
+
value: value,
|
|
117
|
+
type: type,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
item[index] = null;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
this_1.data.push(item);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var this_1 = this;
|
|
128
|
+
/**
|
|
129
|
+
* 处理数据
|
|
130
|
+
*/
|
|
131
|
+
for (var row = startRow; row <= range.e.r; row++) {
|
|
132
|
+
_loop_1(row);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
ZeroTable.prototype.getFieldType = function (cell) {
|
|
137
|
+
if (cell != null) {
|
|
138
|
+
if (cell.t == "b") {
|
|
139
|
+
return FieldType.BOOLEAN;
|
|
140
|
+
}
|
|
141
|
+
else if (cell.t == "n") {
|
|
142
|
+
return FieldType.NUMBER;
|
|
143
|
+
}
|
|
144
|
+
else if (cell.t == "s") {
|
|
145
|
+
try {
|
|
146
|
+
if (typeof cell.v == "string") {
|
|
147
|
+
JSON.parse(cell.v);
|
|
148
|
+
}
|
|
149
|
+
return FieldType.OBJECT;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return FieldType.STRING;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return FieldType.STRING;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return FieldType.STRING;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
ZeroTable.prototype.checkCell = function (cell) {
|
|
164
|
+
if (cell != null && cell.v != null) {
|
|
165
|
+
if (cell.t == "s" && (cell.v == "" || cell.v == " ")) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
ZeroTable.prototype.toJson = function () {
|
|
177
|
+
var _this = this;
|
|
178
|
+
var json = [];
|
|
179
|
+
this.data.forEach(function (docs) {
|
|
180
|
+
var info = {};
|
|
181
|
+
docs.forEach(function (doc, index) {
|
|
182
|
+
if (doc) {
|
|
183
|
+
info[_this.fields[index].name] = doc.value;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
json.push(info);
|
|
187
|
+
});
|
|
188
|
+
return json;
|
|
189
|
+
};
|
|
190
|
+
ZeroTable.prototype.toBin = function () {
|
|
191
|
+
var _this = this;
|
|
192
|
+
// console.log("数据条数",this.data.length)
|
|
193
|
+
return Buffer.concat(this.fields.map(function (field, index) {
|
|
194
|
+
var buffers = [];
|
|
195
|
+
buffers[0] = Buffer.alloc(1);
|
|
196
|
+
buffers[0].writeUInt8(field.type);
|
|
197
|
+
buffers[1] = Buffer.alloc(4);
|
|
198
|
+
buffers[2] = Buffer.from(field.name, 'utf8');
|
|
199
|
+
buffers[1].writeUint32BE(buffers[2].length);
|
|
200
|
+
if (index == _this.fields.length - 1) {
|
|
201
|
+
buffers[3] = Buffer.alloc(1, 0);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
buffers[3] = Buffer.alloc(1, 1);
|
|
205
|
+
}
|
|
206
|
+
return Buffer.concat(buffers);
|
|
207
|
+
}).concat(this.data.map(function (cow, index) {
|
|
208
|
+
var cowBuffs = [];
|
|
209
|
+
for (var cowIndex = 0; cowIndex < cow.length; cowIndex++) {
|
|
210
|
+
var item = cow[cowIndex];
|
|
211
|
+
if (item != null) {
|
|
212
|
+
var typeBuffer = Buffer.alloc(1);
|
|
213
|
+
typeBuffer.writeUint8(item.type);
|
|
214
|
+
var buf = void 0;
|
|
215
|
+
switch (item.type) {
|
|
216
|
+
case FieldType.BOOLEAN:
|
|
217
|
+
buf = Buffer.alloc(1);
|
|
218
|
+
buf.writeUint8(item.value == true ? 1 : 0);
|
|
219
|
+
break;
|
|
220
|
+
case FieldType.NUMBER:
|
|
221
|
+
buf = Buffer.alloc(8);
|
|
222
|
+
buf.writeDoubleBE(item.value);
|
|
223
|
+
break;
|
|
224
|
+
case FieldType.STRING:
|
|
225
|
+
{
|
|
226
|
+
var buffers = [];
|
|
227
|
+
buffers[0] = Buffer.alloc(4);
|
|
228
|
+
buffers[1] = Buffer.from(item.value, 'utf8');
|
|
229
|
+
buffers[0].writeUint32BE(buffers[1].length);
|
|
230
|
+
buf = Buffer.concat(buffers);
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case FieldType.OBJECT:
|
|
234
|
+
{
|
|
235
|
+
var buffers = [];
|
|
236
|
+
buffers[0] = Buffer.alloc(4);
|
|
237
|
+
buffers[1] = Buffer.from(JSON.stringify(item.value), 'utf8');
|
|
238
|
+
buffers[0].writeUint32BE(buffers[1].length);
|
|
239
|
+
buf = Buffer.concat(buffers);
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
cowBuffs.push(typeBuffer);
|
|
244
|
+
cowBuffs.push(buf);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
cowBuffs.push(Buffer.alloc(1, 0x255));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
var endBuf;
|
|
251
|
+
if (index == _this.data.length - 1) {
|
|
252
|
+
endBuf = Buffer.alloc(1, 0);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
endBuf = Buffer.alloc(1, 1);
|
|
256
|
+
}
|
|
257
|
+
return Buffer.concat(__spreadArray(__spreadArray([], cowBuffs, true), [endBuf], false));
|
|
258
|
+
})));
|
|
259
|
+
};
|
|
260
|
+
return ZeroTable;
|
|
261
|
+
}());
|
|
262
|
+
exports.ZeroTable = ZeroTable;
|
|
263
|
+
var ZeroWorkBook = /** @class */ (function () {
|
|
264
|
+
function ZeroWorkBook(workBook, checkCellName, startRow, explainRow, checkColumn) {
|
|
265
|
+
var _this = this;
|
|
266
|
+
this.tables = {};
|
|
267
|
+
workBook.SheetNames.forEach(function (sheetName) {
|
|
268
|
+
if (sheetName.charAt(0) != "_") {
|
|
269
|
+
var sheet = workBook.Sheets[sheetName];
|
|
270
|
+
_this.tables[sheetName] = new ZeroTable(sheet, checkCellName, startRow, explainRow, checkColumn);
|
|
271
|
+
}
|
|
272
|
+
// this.tables.push();
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
ZeroWorkBook.prototype.toJson = function () {
|
|
276
|
+
// return this.tables.map((table) => {
|
|
277
|
+
// return table.toJson();
|
|
278
|
+
// });
|
|
279
|
+
var out = {};
|
|
280
|
+
for (var key in this.tables) {
|
|
281
|
+
if (Object.prototype.hasOwnProperty.call(this.tables, key)) {
|
|
282
|
+
var element = this.tables[key];
|
|
283
|
+
if (element.fields.length > 0) {
|
|
284
|
+
out[key] = element.toJson();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return out;
|
|
289
|
+
};
|
|
290
|
+
ZeroWorkBook.prototype.toBin = function () {
|
|
291
|
+
var out = [];
|
|
292
|
+
var endBuf;
|
|
293
|
+
for (var key in this.tables) {
|
|
294
|
+
var table = this.tables[key];
|
|
295
|
+
if (table.fields.length > 0) {
|
|
296
|
+
var titleBuffer = Buffer.from(key, 'utf8');
|
|
297
|
+
var lengthBuffer = Buffer.alloc(4);
|
|
298
|
+
lengthBuffer.writeUint32BE(titleBuffer.length);
|
|
299
|
+
var buffer = table.toBin();
|
|
300
|
+
endBuf = Buffer.alloc(1, 1);
|
|
301
|
+
out.push(lengthBuffer, titleBuffer, buffer, endBuf);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
out[out.length - 1] = Buffer.alloc(1, 0);
|
|
305
|
+
return Buffer.concat(out);
|
|
306
|
+
};
|
|
307
|
+
ZeroWorkBook.prototype.faceName = function (value) {
|
|
308
|
+
return "I" + value.replace(/(\w)/, function (v) { return v.toUpperCase(); });
|
|
309
|
+
};
|
|
310
|
+
ZeroWorkBook.prototype.getExplain = function (value) {
|
|
311
|
+
if (value) {
|
|
312
|
+
return value.split("\n").join("\n\t * ");
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
return "";
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
ZeroWorkBook.prototype.toTS = function (name) {
|
|
319
|
+
var _this = this;
|
|
320
|
+
var out = "";
|
|
321
|
+
var tableString = [];
|
|
322
|
+
var tableRoot = [];
|
|
323
|
+
for (var key in this.tables) {
|
|
324
|
+
if (Object.prototype.hasOwnProperty.call(this.tables, key)) {
|
|
325
|
+
var element = this.tables[key];
|
|
326
|
+
var faceName = this.faceName(key);
|
|
327
|
+
if (element.fields.length > 0 && element.data.length > 0) {
|
|
328
|
+
tableRoot.push("".concat(key, ": ").concat(faceName, "[]"));
|
|
329
|
+
tableString.push("export interface ".concat(faceName, " {\n").concat(element.fields.map(function (field) {
|
|
330
|
+
return " /**\n * ".concat(_this.getExplain(field.explain), "\n */\n ").concat(field.name).concat(field.required ? "" : "?", ": ").concat(_this.getFieldType(field.type));
|
|
331
|
+
}).join("\n"), "\n}"));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
var rootString = "\nexport interface ".concat(this.faceName(name), " {\n ").concat(tableRoot.join("\n\t"), "\n}");
|
|
336
|
+
return tableString.join("\n") + rootString;
|
|
337
|
+
};
|
|
338
|
+
ZeroWorkBook.prototype.getFieldType = function (type) {
|
|
339
|
+
return fieldTypePool[type];
|
|
340
|
+
};
|
|
341
|
+
return ZeroWorkBook;
|
|
342
|
+
}());
|
|
343
|
+
exports.ZeroWorkBook = ZeroWorkBook;
|
package/dist/bin.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -34,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
38
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
39
|
function step(op) {
|
|
36
40
|
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
-
while (_) try {
|
|
41
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
38
42
|
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
43
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
44
|
switch (op[0]) {
|
|
@@ -55,12 +59,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
55
59
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
60
|
}
|
|
57
61
|
};
|
|
62
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
63
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
|
+
};
|
|
58
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
66
|
var minimist = require("minimist");
|
|
60
67
|
var fs = __importStar(require("fs"));
|
|
61
68
|
var path = __importStar(require("path"));
|
|
62
69
|
var xlsx_ts_1 = require("./xlsx-ts");
|
|
63
70
|
var tinify_1 = require("./tinify");
|
|
71
|
+
var config_js_1 = __importDefault(require("config-js"));
|
|
72
|
+
var ZeroWorkBook_1 = require("./ZeroWorkBook");
|
|
73
|
+
var xlsx_1 = require("xlsx");
|
|
64
74
|
var cwd = process.cwd();
|
|
65
75
|
var name = path.basename(cwd);
|
|
66
76
|
var argv = minimist(process.argv.slice(2), {
|
|
@@ -71,16 +81,17 @@ var argv = minimist(process.argv.slice(2), {
|
|
|
71
81
|
packHotup: ['pp'],
|
|
72
82
|
tinify: ['ty'],
|
|
73
83
|
xlsxToTs: ['xt'],
|
|
84
|
+
xlsxToBin: ['xb'],
|
|
74
85
|
help: ['h'],
|
|
75
86
|
version: ['v'],
|
|
76
87
|
}
|
|
77
88
|
});
|
|
78
|
-
var packageTem = "\n{\n \"name\": \""
|
|
89
|
+
var packageTem = "\n{\n \"name\": \"".concat(name, "\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.ts\",\n \"scripts\": {\n \"debug\": \"ts-node-dev index.ts\"\n },\n \"author\": \"\",\n \"license\": \"ISC\",\n \"dependencies\": {},\n \"devDependencies\": {\n \"ts-node-dev\": \"^1.1.6\"\n }\n}\n");
|
|
79
90
|
var tsconfigTem = "\n{\n \"compilerOptions\": {\n /* Basic Options */\n \"target\": \"es5\", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */\n \"module\": \"commonjs\", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */\n // \"lib\": [], /* Specify library files to be included in the compilation. */\n // \"allowJs\": true, /* Allow javascript files to be compiled. */\n // \"checkJs\": true, /* Report errors in .js files. */\n // \"jsx\": \"preserve\", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */\n // \"declaration\": true, /* Generates corresponding '.d.ts' file. */\n \"sourceMap\": true, /* Generates corresponding '.map' file. */\n // \"outFile\": \"./\", /* Concatenate and emit output to single file. */\n \"outDir\": \"./dist\", /* Redirect output structure to the directory. */\n // \"rootDir\": \"./\", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */\n // \"removeComments\": true, /* Do not emit comments to output. */\n // \"noEmit\": true, /* Do not emit outputs. */\n // \"importHelpers\": true, /* Import emit helpers from 'tslib'. */\n // \"downlevelIteration\": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */\n // \"isolatedModules\": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */\n \n /* Strict Type-Checking Options */\n \"strict\": true, /* Enable all strict type-checking options. */\n // \"noImplicitAny\": true, /* Raise error on expressions and declarations with an implied 'any' type. */\n // \"strictNullChecks\": true, /* Enable strict null checks. */\n // \"strictFunctionTypes\": true, /* Enable strict checking of function types. */\n // \"strictPropertyInitialization\": true, /* Enable strict checking of property initialization in classes. */\n // \"noImplicitThis\": true, /* Raise error on 'this' expressions with an implied 'any' type. */\n // \"alwaysStrict\": true, /* Parse in strict mode and emit \"use strict\" for each source file. */\n \n /* Additional Checks */\n // \"noUnusedLocals\": true, /* Report errors on unused locals. */\n // \"noUnusedParameters\": true, /* Report errors on unused parameters. */\n // \"noImplicitReturns\": true, /* Report error when not all code paths in function return a value. */\n // \"noFallthroughCasesInSwitch\": true, /* Report errors for fallthrough cases in switch statement. */\n \n /* Module Resolution Options */\n // \"moduleResolution\": \"node\", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */\n // \"baseUrl\": \"./\", /* Base directory to resolve non-absolute module names. */\n // \"paths\": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */\n // \"rootDirs\": [], /* List of root folders whose combined content represents the structure of the project at runtime. */\n // \"typeRoots\": [], /* List of folders to include type definitions from. */\n // \"types\": [], /* Type declaration files to be included in compilation. */\n // \"allowSyntheticDefaultImports\": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */\n \"esModuleInterop\": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */\n // \"preserveSymlinks\": true, /* Do not resolve the real path of symlinks. */\n \n /* Source Map Options */\n // \"sourceRoot\": \"./\", /* Specify the location where debugger should locate TypeScript files instead of source locations. */\n // \"mapRoot\": \"./\", /* Specify the location where debugger should locate map files instead of generated locations. */\n // \"inlineSourceMap\": true, /* Emit a single file with source maps instead of having a separate file. */\n // \"inlineSources\": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */\n \n /* Experimental Options */\n // \"experimentalDecorators\": true, /* Enables experimental support for ES7 decorators. */\n // \"emitDecoratorMetadata\": true, /* Enables experimental support for emitting type metadata for decorators. */\n }\n }\n";
|
|
80
91
|
var indexTem = "\nlet a=\"test\"\nconsole.log(a)\n";
|
|
81
92
|
var cwsTem = "\n{\n\t\"folders\": [\n\t\t{\n\t\t\t\"path\": \".\"\n\t\t}\n\t],\n\t\"settings\": {}\n}\n";
|
|
82
93
|
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";
|
|
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----------------------";
|
|
94
|
+
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 xb (zero --xlsxToBin)\u5728\u5F53\u524D\u6587\u4EF6\u5939\u4E0B\u7684xlsx.json\u4E2D\u6240\u63CF\u8FF0\u7684Excel\u6587\u4EF6\u8F6C\u6362TS\u6587\u4EF6\u6216\u4E8C\u8FDB\u5236\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----------------------";
|
|
84
95
|
var fn = {
|
|
85
96
|
ut: function () {
|
|
86
97
|
fs.writeFileSync(cwd + "/package.json", packageTem);
|
|
@@ -111,15 +122,82 @@ var fn = {
|
|
|
111
122
|
}
|
|
112
123
|
data.forEach(function (ExcelName) {
|
|
113
124
|
if (ExcelName.substr(-5) == ".xlsx" && ExcelName.substr(0, 1) != "~") {
|
|
114
|
-
var FileDir = xlsxPath_1
|
|
115
|
-
xlsx_ts_1.xlsxToTs(FileDir, tsPath_1, checkCell_1, startCell_1, note_1);
|
|
116
|
-
console.log(""
|
|
125
|
+
var FileDir = "".concat(xlsxPath_1, "/").concat(ExcelName);
|
|
126
|
+
(0, xlsx_ts_1.xlsxToTs)(FileDir, tsPath_1, checkCell_1, startCell_1, note_1);
|
|
127
|
+
console.log("".concat(ExcelName));
|
|
117
128
|
}
|
|
118
129
|
});
|
|
119
130
|
});
|
|
120
131
|
}
|
|
121
132
|
});
|
|
122
133
|
},
|
|
134
|
+
xb: function () {
|
|
135
|
+
function checkNull(value, error) {
|
|
136
|
+
if (value == null) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
var config;
|
|
141
|
+
try {
|
|
142
|
+
config = new config_js_1.default('zeroconfig.config.js');
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.log("这个目录下没有目录配置文件zeroconfig.config.js");
|
|
146
|
+
}
|
|
147
|
+
checkNull(config.configObj.inPath, "inPath undefined");
|
|
148
|
+
checkNull(config.configObj.checkCell, "checkCell undefined");
|
|
149
|
+
checkNull(config.configObj.startRow, "startRow undefined");
|
|
150
|
+
var info = config.configObj;
|
|
151
|
+
fs.readdir(info.inPath, function (err, data) {
|
|
152
|
+
if (err) {
|
|
153
|
+
console.log("这个目录不存在");
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
data.forEach(function (ExcelName) {
|
|
157
|
+
if (ExcelName.slice(ExcelName.length - 5, ExcelName.length) == ".xlsx" && ExcelName.charAt(0) != "~") {
|
|
158
|
+
var inPath = path.join(info.inPath, ExcelName);
|
|
159
|
+
// console.log("+++++++1++++=",inPath)
|
|
160
|
+
var book = new ZeroWorkBook_1.ZeroWorkBook((0, xlsx_1.readFile)(inPath), info.checkCell, info.startRow, info.explainRow, info.checkColumn);
|
|
161
|
+
// console.log("+++++++2++++=",info.binPath)
|
|
162
|
+
if (info.binPath) {
|
|
163
|
+
var binPath = path.join(info.binPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".bin"));
|
|
164
|
+
fs.writeFileSync(binPath, book.toBin());
|
|
165
|
+
console.log("成功导出配置表到二进制文件" + binPath);
|
|
166
|
+
}
|
|
167
|
+
if (info.jsonPath) {
|
|
168
|
+
var jsonPath = path.join(info.jsonPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".json"));
|
|
169
|
+
fs.writeFileSync(jsonPath, JSON.stringify(book.toJson(), null, 4));
|
|
170
|
+
console.log("成功导出配置表到json文件" + jsonPath);
|
|
171
|
+
}
|
|
172
|
+
if (info.dtsPath) {
|
|
173
|
+
var rootName = path.basename(ExcelName).replace(path.extname(ExcelName), "");
|
|
174
|
+
var userString = "";
|
|
175
|
+
var rootInterface = "I" + rootName.replace(/(\w)/, function (v) { return v.toUpperCase(); }) + "Root";
|
|
176
|
+
if (info.userString) {
|
|
177
|
+
userString = info.userString.replace(/%{rootName}/g, rootName).replace(/%{rootInterface}/g, rootInterface);
|
|
178
|
+
}
|
|
179
|
+
var jsString = "";
|
|
180
|
+
if (info.jsPath) {
|
|
181
|
+
jsString = "export declare let ".concat(rootName, ": ").concat(rootInterface, ";");
|
|
182
|
+
}
|
|
183
|
+
var dtsPath = path.join(info.dtsPath, rootName + ".d.ts");
|
|
184
|
+
fs.writeFileSync(dtsPath, book.toTS(rootName + "Root") + "\n" + userString + jsString);
|
|
185
|
+
}
|
|
186
|
+
if (info.jsPath) {
|
|
187
|
+
var jsPath = path.join(info.jsPath, path.basename(ExcelName).replace(path.extname(ExcelName), ".js"));
|
|
188
|
+
fs.writeFileSync(jsPath, "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.test = void 0;\nexports.test = " + JSON.stringify(book.toJson(), null, 4));
|
|
189
|
+
console.log("成功导出配置表到js文件" + jsPath);
|
|
190
|
+
}
|
|
191
|
+
if (info.tsPath) {
|
|
192
|
+
var rootName = path.basename(ExcelName).replace(path.extname(ExcelName), "");
|
|
193
|
+
var rootInterface = "I" + rootName.replace(/(\w)/, function (v) { return v.toUpperCase(); }) + "Root";
|
|
194
|
+
var tsPath = path.join(info.tsPath, rootName + ".ts");
|
|
195
|
+
fs.writeFileSync(tsPath, "".concat(book.toTS(rootName + "Root"), "\nexport let ").concat(rootName, ": ").concat(rootInterface, " = ").concat(JSON.stringify(book.toJson(), null, 4)));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
},
|
|
123
201
|
ty: function () {
|
|
124
202
|
// let p = new TaskParser("../../doomsdayrise-clinet/tinify.json")
|
|
125
203
|
var p = new tinify_1.TaskParser("./tinify.json");
|
|
@@ -155,7 +233,7 @@ var fn = {
|
|
|
155
233
|
console.log(helpString);
|
|
156
234
|
},
|
|
157
235
|
v: function () {
|
|
158
|
-
console.log("1.
|
|
236
|
+
console.log("1.5.0");
|
|
159
237
|
}
|
|
160
238
|
};
|
|
161
239
|
var isFree = true;
|
package/dist/shell-ts.js
CHANGED
|
@@ -17,7 +17,7 @@ var JsonMode = /** @class */ (function () {
|
|
|
17
17
|
};
|
|
18
18
|
JsonMode.prototype.save = function (workPath) {
|
|
19
19
|
if (workPath === void 0) { workPath = "./"; }
|
|
20
|
-
fs_1.default.writeFileSync(workPath +
|
|
20
|
+
fs_1.default.writeFileSync(workPath + "/".concat(this.cname, ".json"), JSON.stringify(this.data));
|
|
21
21
|
};
|
|
22
22
|
return JsonMode;
|
|
23
23
|
}());
|
|
@@ -35,7 +35,7 @@ var TSMode = /** @class */ (function () {
|
|
|
35
35
|
};
|
|
36
36
|
TSMode.prototype.save = function (workPath) {
|
|
37
37
|
if (workPath === void 0) { workPath = "./"; }
|
|
38
|
-
fs_1.default.writeFileSync(workPath +
|
|
38
|
+
fs_1.default.writeFileSync(workPath + "/".concat(this.cname, ".ts"), this.toTs());
|
|
39
39
|
};
|
|
40
40
|
TSMode.prototype.faceName = function (value) {
|
|
41
41
|
return "I" + value.replace(/(\w)/, function (v) { return v.toUpperCase(); });
|
|
@@ -84,7 +84,7 @@ var TSMode = /** @class */ (function () {
|
|
|
84
84
|
return types;
|
|
85
85
|
};
|
|
86
86
|
TSMode.prototype.toTs = function () {
|
|
87
|
-
return this.toTsType()
|
|
87
|
+
return "".concat(this.toTsType(), "\nexport let ").concat(this.name, ":").concat(this.faceName(this.name + "Root"), "=").concat(JSON.stringify(this.data, null, "\t").replace(/"(\w+)":/g, "$1:"));
|
|
88
88
|
};
|
|
89
89
|
return TSMode;
|
|
90
90
|
}());
|
package/dist/tinify.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];
|
|
@@ -33,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
33
37
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
38
|
function step(op) {
|
|
35
39
|
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
37
41
|
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
42
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
43
|
switch (op[0]) {
|
|
@@ -179,7 +183,7 @@ var TaskParser = /** @class */ (function () {
|
|
|
179
183
|
if (!_a) return [3 /*break*/, 6];
|
|
180
184
|
return [3 /*break*/, 15];
|
|
181
185
|
case 6:
|
|
182
|
-
pathKey = inPath.replace(
|
|
186
|
+
pathKey = inPath.replace(/\\/g, "/");
|
|
183
187
|
doc = this.info[pathKey];
|
|
184
188
|
if (!(doc == null)) return [3 /*break*/, 9];
|
|
185
189
|
//没有记录
|
|
@@ -238,8 +242,8 @@ var TaskParser = /** @class */ (function () {
|
|
|
238
242
|
outMd5 = md5Hash.update(outBuffer).digest('hex');
|
|
239
243
|
this.witeBuffer(outPath, outBuffer);
|
|
240
244
|
console.log(inMd5, outMd5);
|
|
241
|
-
pathKey = inPath.replace(
|
|
242
|
-
outPath = outPath.replace(
|
|
245
|
+
pathKey = inPath.replace(/\\/g, "/");
|
|
246
|
+
outPath = outPath.replace(/\\/g, "/");
|
|
243
247
|
this.info[pathKey] = { outPath: outPath, inMd5: inMd5, outMd5: outMd5 };
|
|
244
248
|
this.saveInfo();
|
|
245
249
|
this.count++;
|
package/dist/xlsx-ts.js
CHANGED
|
@@ -19,7 +19,7 @@ function xlsxToTs(xlsxFile, savePath, checkCell, startCell, note) {
|
|
|
19
19
|
var basename = path_1.default.basename(xlsxFile, ".xlsx");
|
|
20
20
|
var pr = new shell_ts_1.TSMode(basename);
|
|
21
21
|
// 读取 excel 文件
|
|
22
|
-
var book = xlsx_1.readFile(path_1.default.normalize(xlsxFile));
|
|
22
|
+
var book = (0, xlsx_1.readFile)(path_1.default.normalize(xlsxFile));
|
|
23
23
|
// 得到 excel 里每张工作表数组
|
|
24
24
|
book.SheetNames.forEach(function (element) {
|
|
25
25
|
// sheet每一张工作表的对象
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zero-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Zero游戏开发工具",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"config-js": "^1.1.15",
|
|
15
16
|
"minimist": "^1.2.0",
|
|
16
17
|
"tinify": "^1.6.1",
|
|
17
18
|
"xlsx": "^0.13.5"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/minimist": "^1.2.0",
|
|
21
|
-
"@types/node": "^
|
|
22
|
+
"@types/node": "^18.7.14",
|
|
22
23
|
"@types/xlsx": "0.0.36"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
@@ -31,4 +32,4 @@
|
|
|
31
32
|
"bin": {
|
|
32
33
|
"zero": "dist/bin.js"
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
|
+
}
|
package/tinify.ts
CHANGED
|
@@ -79,7 +79,7 @@ export class TaskParser {
|
|
|
79
79
|
if (this.config.skipSpine && await this.isSpine(inPath)) {
|
|
80
80
|
} else {
|
|
81
81
|
// let doc = await this.db.findOne({ inPath })
|
|
82
|
-
let pathKey = inPath.replace(
|
|
82
|
+
let pathKey = inPath.replace(/\\/g, "/")
|
|
83
83
|
let doc = this.info[pathKey]
|
|
84
84
|
|
|
85
85
|
if (doc == null) {
|
|
@@ -116,8 +116,8 @@ export class TaskParser {
|
|
|
116
116
|
this.witeBuffer(outPath, outBuffer)
|
|
117
117
|
console.log(inMd5, outMd5)
|
|
118
118
|
// await this.db.updateOne({ inPath }, { inPath, outPath, inMd5, outMd5 }, { upsert: true })
|
|
119
|
-
let pathKey = inPath.replace(
|
|
120
|
-
outPath = outPath.replace(
|
|
119
|
+
let pathKey = inPath.replace(/\\/g, "/")
|
|
120
|
+
outPath = outPath.replace(/\\/g, "/")
|
|
121
121
|
this.info[pathKey] = { outPath, inMd5, outMd5 }
|
|
122
122
|
this.saveInfo()
|
|
123
123
|
this.count++
|
package/type.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'config-js';
|