madden-franchise 2.5.0 → 2.5.4
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/FranchiseFile.js +38 -23
- package/FranchiseSchema.js +7 -0
- package/package.json +1 -1
- package/services/schemaGenerator.js +4 -16
package/FranchiseFile.js
CHANGED
|
@@ -175,39 +175,41 @@ class FranchiseFile extends EventEmitter {
|
|
|
175
175
|
});
|
|
176
176
|
};
|
|
177
177
|
|
|
178
|
-
save(outputFilePath) {
|
|
179
|
-
return this.packFile(outputFilePath);
|
|
178
|
+
save(outputFilePath, options) {
|
|
179
|
+
return this.packFile(outputFilePath, options);
|
|
180
180
|
};
|
|
181
181
|
|
|
182
|
-
packFile(outputFilePath) {
|
|
182
|
+
packFile(outputFilePath, options) {
|
|
183
183
|
const that = this;
|
|
184
184
|
this.emit('saving');
|
|
185
185
|
|
|
186
186
|
return new Promise((resolve, reject) => {
|
|
187
187
|
this.unpackedFileContents = this.strategy.file.generateUnpackedContents(this.tables, this.unpackedFileContents);
|
|
188
|
-
// const changedTables = this.tables.filter((table) => { return table.isChanged; });
|
|
189
|
-
|
|
190
|
-
// for (let i = 0; i < changedTables.length; i++) {
|
|
191
|
-
// let table = changedTables[i];
|
|
192
|
-
// const header = that.unpackedFileContents.slice(0, table.offset);
|
|
193
|
-
// const trailer = that.unpackedFileContents.slice(table.offset + table.data.length);
|
|
194
|
-
// that.unpackedFileContents = Buffer.concat([header, table.hexData, trailer]);
|
|
195
|
-
|
|
196
|
-
// table.isChanged = false;
|
|
197
|
-
// }
|
|
198
188
|
|
|
199
189
|
let destination = outputFilePath ? outputFilePath : this.filePath;
|
|
200
190
|
|
|
201
|
-
_packFile(this.unpackedFileContents).then((data) => {
|
|
191
|
+
_packFile(this.unpackedFileContents, options).then((data) => {
|
|
202
192
|
const dataToSave = this.strategy.file.postPackFile(this.packedFileContents, data);
|
|
203
|
-
|
|
193
|
+
|
|
194
|
+
if (options && options.sync) {
|
|
195
|
+
_saveSync(destination, dataToSave);
|
|
196
|
+
postSaveActions();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
_save(destination, dataToSave, (err) => {
|
|
200
|
+
postSaveActions(err);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function postSaveActions(err) {
|
|
204
205
|
if (err) {
|
|
205
206
|
reject(err);
|
|
206
207
|
that.emit('save-error');
|
|
207
208
|
}
|
|
209
|
+
|
|
208
210
|
resolve('saved');
|
|
209
211
|
that.emit('saved');
|
|
210
|
-
}
|
|
212
|
+
}
|
|
211
213
|
});
|
|
212
214
|
});
|
|
213
215
|
};
|
|
@@ -346,15 +348,24 @@ function unpackFile (data, type) {
|
|
|
346
348
|
return zlib.inflateSync(data.slice(offset));
|
|
347
349
|
};
|
|
348
350
|
|
|
349
|
-
function _packFile (data) {
|
|
351
|
+
function _packFile (data, options) {
|
|
350
352
|
return new Promise((resolve, reject) => {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
if (options && options.sync) {
|
|
354
|
+
const newData = zlib.deflateSync(data, {
|
|
355
|
+
windowBits: 15
|
|
356
|
+
});
|
|
357
|
+
|
|
356
358
|
resolve(newData);
|
|
357
|
-
}
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
zlib.deflate(data, {
|
|
362
|
+
windowBits: 15
|
|
363
|
+
}, function (err, newData) {
|
|
364
|
+
if (err) reject(err);
|
|
365
|
+
|
|
366
|
+
resolve(newData);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
358
369
|
});
|
|
359
370
|
};
|
|
360
371
|
|
|
@@ -362,6 +373,10 @@ function _save (destination, packedContents, callback) {
|
|
|
362
373
|
fs.writeFile(destination, packedContents, callback);
|
|
363
374
|
};
|
|
364
375
|
|
|
376
|
+
function _saveSync (destination, packedContents) {
|
|
377
|
+
fs.writeFileSync(destination, packedContents);
|
|
378
|
+
};
|
|
379
|
+
|
|
365
380
|
function getFileType(data) {
|
|
366
381
|
const isDataCompressed = isCompressed(data);
|
|
367
382
|
const format = getFormat(data, isDataCompressed);
|
package/FranchiseSchema.js
CHANGED
|
@@ -46,6 +46,7 @@ class FranchiseSchema extends EventEmitter {
|
|
|
46
46
|
this.meta = this.schema.meta;
|
|
47
47
|
this.schemas = this.schema.schemas;
|
|
48
48
|
this.schemaMap = {};
|
|
49
|
+
this.enumMap = {};
|
|
49
50
|
|
|
50
51
|
for (let i = 0; i < this.schemas.length; i++) {
|
|
51
52
|
const schema = this.schemas[i];
|
|
@@ -56,6 +57,7 @@ class FranchiseSchema extends EventEmitter {
|
|
|
56
57
|
|
|
57
58
|
if (attribute.enum) {
|
|
58
59
|
attribute.enum = new FranchiseEnum(attribute.enum);
|
|
60
|
+
this.enumMap[attribute.enum.name] = attribute.enum;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -64,6 +66,11 @@ class FranchiseSchema extends EventEmitter {
|
|
|
64
66
|
const extraSchemas = schemaGenerator.getExtraSchemas();
|
|
65
67
|
extraSchemas.forEach((schema) => {
|
|
66
68
|
if (!this.schemaMap[schema.name]) {
|
|
69
|
+
schema.attributes.forEach((attrib) => {
|
|
70
|
+
if (attrib.enum) {
|
|
71
|
+
attrib.enum = new FranchiseEnum(this.enumMap[attrib.enum]);
|
|
72
|
+
}
|
|
73
|
+
})
|
|
67
74
|
this.schemas.unshift(schema);
|
|
68
75
|
this.schemaMap[schema.name] = schema;
|
|
69
76
|
addedExtraSchema = true;
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@ const utilService = require('./utilService');
|
|
|
6
6
|
const FranchiseEnum = require('../FranchiseEnum');
|
|
7
7
|
const XmlParser = require('node-xml-stream-parser');
|
|
8
8
|
const EventEmitter = require('events').EventEmitter;
|
|
9
|
-
const extraSchemas = JSON.parse(JSON.stringify(require(path.join(__dirname, '../data/schemas/extra-schemas.json'))));
|
|
10
9
|
|
|
11
10
|
let schemaGenerator = {};
|
|
12
11
|
schemaGenerator.eventEmitter = new EventEmitter();
|
|
@@ -22,6 +21,7 @@ schemaGenerator.generateFromStream = (stream, showOutput, outputFile) => {
|
|
|
22
21
|
schemaGenerator.schemaMap = {};
|
|
23
22
|
schemaGenerator.schemaMeta = {};
|
|
24
23
|
schemaGenerator.enums = [];
|
|
24
|
+
const extraSchemas = schemaGenerator.getExtraSchemas();
|
|
25
25
|
|
|
26
26
|
schemaGenerator.xml = new XmlParser();
|
|
27
27
|
|
|
@@ -33,7 +33,7 @@ schemaGenerator.generateFromStream = (stream, showOutput, outputFile) => {
|
|
|
33
33
|
console.error(err);
|
|
34
34
|
throw err;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
schemaGenerator.enums.forEach((theEnum) => {
|
|
38
38
|
theEnum.setMemberLength();
|
|
39
39
|
});
|
|
@@ -159,7 +159,7 @@ schemaGenerator.generateFromStream = (stream, showOutput, outputFile) => {
|
|
|
159
159
|
function addExtraSchemas() {
|
|
160
160
|
extraSchemas.forEach((schema) => {
|
|
161
161
|
if (!schemaGenerator.schemaMap[schema.name]) {
|
|
162
|
-
schema.attributes.filter((attrib) => {
|
|
162
|
+
schema.attributes.filter((attrib) => {
|
|
163
163
|
return attrib.enum && !(attrib.enum instanceof FranchiseEnum);
|
|
164
164
|
}).forEach((attrib) => {
|
|
165
165
|
attrib.enum = getEnum(attrib.enum);
|
|
@@ -184,19 +184,7 @@ schemaGenerator.generateFromStream = (stream, showOutput, outputFile) => {
|
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
schemaGenerator.getExtraSchemas = () => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
extraSchemas.forEach((schema) => {
|
|
190
|
-
schema.attributes.filter((attrib) => {
|
|
191
|
-
return attrib.enum && !(attrib.enum instanceof FranchiseEnum);
|
|
192
|
-
}).forEach((attrib) => {
|
|
193
|
-
attrib.enum = new FranchiseEnum(attrib.enum);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
newSchemas.push(schema);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return newSchemas;
|
|
187
|
+
return JSON.parse(JSON.stringify(require(path.join(__dirname, '../data/schemas/extra-schemas.json'))));
|
|
200
188
|
};
|
|
201
189
|
|
|
202
190
|
schemaGenerator.calculateInheritedSchemas = (schemaList) => {
|