mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 16:25:21 +00:00
Replaces this.overrides with this.props; all the properties inserted into overrides
now get filtered through _parseSettings and pushed in there; _patch method now accepts only the pass buffer and not anymore the options;
This commit is contained in:
22
index.js
22
index.js
@@ -15,10 +15,10 @@ const readFile = util.promisify(fs.readFile);
|
||||
class Pass {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
this.overrides = this.options.overrides || {};
|
||||
this.Certificates = {};
|
||||
this.model = "";
|
||||
this.l10n = {};
|
||||
this.props = {};
|
||||
|
||||
fields.areas.forEach(a => this[a] = new fields.FieldsArea());
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class Pass {
|
||||
|
||||
bundle.push("pass.json");
|
||||
|
||||
return this._patch(this._filterOptions(this.overrides), passStructBuffer);
|
||||
return this._patch(passStructBuffer);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -257,8 +257,8 @@ class Pass {
|
||||
* @returns {Promise<Buffer>} Edited pass.json buffer or Object containing error.
|
||||
*/
|
||||
|
||||
_patch(options, passBuffer) {
|
||||
if (!options) {
|
||||
_patch(passBuffer) {
|
||||
if (!Object.keys(this.props).length) {
|
||||
return Promise.resolve(passBuffer);
|
||||
}
|
||||
|
||||
@@ -270,12 +270,12 @@ class Pass {
|
||||
if (passFile["barcode"]) {
|
||||
let barcode = passFile["barcode"];
|
||||
|
||||
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.constants.barcode) || !options.barcode && barcode.message === "") {
|
||||
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.constants.barcode) || !this.props.barcode && barcode.message === "") {
|
||||
console.log("\x1b[41m", `Barcode syntax of the chosen model (${path.parse(this.model).base}) is not correct and got removed or the override content was not provided. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
||||
delete passFile["barcode"];
|
||||
} else {
|
||||
// options.barcode may not be defined
|
||||
passFile["barcode"].message = options.barcode || passFile["barcode"].message;
|
||||
passFile["barcode"].message = this.props.barcode || passFile["barcode"].message;
|
||||
}
|
||||
} else {
|
||||
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions lower than iOS 9. Please refer to https://apple.co/2O5K65k to make it backward-compatible.`, "\x1b[0m");
|
||||
@@ -288,21 +288,22 @@ class Pass {
|
||||
}
|
||||
|
||||
passFile["barcodes"].forEach((b,i) => {
|
||||
if (!schema.isValid(b, schema.constants.barcode) && !!options.barcode && b.message !== "") {
|
||||
if (!schema.isValid(b, schema.constants.barcode) && !!this.props.barcode && b.message !== "") {
|
||||
passFile["barcodes"].splice(i, 1);
|
||||
console.log("\x1b[41m", `Barcode @ index ${i} of the chosen model (${path.parse(this.model).base}) is not well-formed or have syntax errors and got removed. Please refer to https://apple.co/2myAbst.`, "\x1b[0m");
|
||||
} else {
|
||||
// options.barcode may not be defined
|
||||
b.message = options.barcode || b.message;
|
||||
b.message = this.props.barcode || b.message;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("\x1b[33m", `Your pass model (${path.parse(this.model).base}) is not compatible with iOS versions greater than iOS 8. Refer to https://apple.co/2O5K65k to make it forward-compatible.`, "\x1b[0m");
|
||||
}
|
||||
|
||||
delete options["barcode"];
|
||||
delete this.props["barcode"];
|
||||
|
||||
Object.assign(passFile, options);
|
||||
// Merging the original and the new properties
|
||||
Object.assign(passFile, this.props);
|
||||
|
||||
fields.areas.forEach(area => {
|
||||
if (this[area].fields.length) {
|
||||
@@ -352,6 +353,7 @@ class Pass {
|
||||
}
|
||||
|
||||
this.model = path.resolve(options.model) + (!!options.model && !path.extname(options.model) ? ".pass" : "");
|
||||
this.props = this._filterOptions(options.overrides);
|
||||
|
||||
let certPaths = Object.keys(options.certificates)
|
||||
.filter(v => v !== "dir")
|
||||
|
||||
Reference in New Issue
Block a user