mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 18:25:24 +00:00
Moved passExtractor function to class scope as 'private'
This commit is contained in:
53
src/pass.js
53
src/pass.js
@@ -102,26 +102,6 @@ class Pass {
|
|||||||
// Localization folders only
|
// Localization folders only
|
||||||
const L10N = noDynList.filter(f => f.includes(".lproj") && Object.keys(this.l10n).includes(path.parse(f).name));
|
const L10N = noDynList.filter(f => f.includes(".lproj") && Object.keys(this.l10n).includes(path.parse(f).name));
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads pass.json file and apply patches on it
|
|
||||||
* @function
|
|
||||||
* @name passExtractor
|
|
||||||
* @return {Promise<Buffer>} The patched pass.json buffer
|
|
||||||
*/
|
|
||||||
|
|
||||||
const passExtractor = async () => {
|
|
||||||
const passStructBuffer = await readFile(path.resolve(this.model, "pass.json"))
|
|
||||||
|
|
||||||
if (!this._validateType(passStructBuffer)) {
|
|
||||||
const eMessage = formatMessage("PASSFILE_VALIDATION_FAILED");
|
|
||||||
throw new Error(eMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
bundle.push("pass.json");
|
|
||||||
|
|
||||||
return this._patch(passStructBuffer);
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reading all the localization selected folders and removing hidden files (the ones that starts with ".")
|
* Reading all the localization selected folders and removing hidden files (the ones that starts with ".")
|
||||||
* from the list.
|
* from the list.
|
||||||
@@ -151,8 +131,12 @@ class Pass {
|
|||||||
bundle = bundle.filter(file => !remoteFilesList.includes(file));
|
bundle = bundle.filter(file => !remoteFilesList.includes(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reading bundle files to buffers without pass.json - it gets read below
|
||||||
|
// to use a different parsing process
|
||||||
|
|
||||||
const bundleBuffers = bundle.map(f => readFile(path.resolve(this.model, f)));
|
const bundleBuffers = bundle.map(f => readFile(path.resolve(this.model, f)));
|
||||||
const passBuffer = passExtractor();
|
const passBuffer = this._extractPassDefinition();
|
||||||
|
bundle.push("pass.json");
|
||||||
|
|
||||||
const buffers = await Promise.all([...bundleBuffers, passBuffer, ...buffersPromise]);
|
const buffers = await Promise.all([...bundleBuffers, passBuffer, ...buffersPromise]);
|
||||||
|
|
||||||
@@ -534,19 +518,38 @@ class Pass {
|
|||||||
* @returns {Boolean} true if type is supported, false otherwise.
|
* @returns {Boolean} true if type is supported, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_validateType(passBuffer) {
|
_validateType(passFile) {
|
||||||
let passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
|
let passTypes = ["boardingPass", "eventTicket", "coupon", "generic", "storeCard"];
|
||||||
|
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
|
||||||
this.type = passTypes.find(type => passFile.hasOwnProperty(type));
|
this.type = passTypes.find(type => passFile.hasOwnProperty(type));
|
||||||
|
|
||||||
if (!this.type) {
|
if (!this.type) {
|
||||||
|
genericDebug(formatMessage("NO_PASS_TYPE"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema.isValid(passFile[this.type], "passDict");
|
return schema.isValid(passFile[this.type], "passDict");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads pass.json file and returns the patched version
|
||||||
|
* @function
|
||||||
|
* @name passExtractor
|
||||||
|
* @return {Promise<Buffer>} The patched pass.json buffer
|
||||||
|
*/
|
||||||
|
|
||||||
|
async _extractPassDefinition() {
|
||||||
|
const passStructBuffer = await readFile(path.resolve(this.model, "pass.json"))
|
||||||
|
const parsedPassDefinition = JSON.parse(passStructBuffer.toString("utf8"));
|
||||||
|
|
||||||
|
if (!this._validateType(parsedPassDefinition)) {
|
||||||
|
const eMessage = formatMessage("PASSFILE_VALIDATION_FAILED");
|
||||||
|
throw new Error(eMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._patch(parsedPassDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the PKCS #7 cryptografic signature for the manifest file.
|
* Generates the PKCS #7 cryptografic signature for the manifest file.
|
||||||
*
|
*
|
||||||
@@ -617,9 +620,7 @@ class Pass {
|
|||||||
* @returns {Promise<Buffer>} Edited pass.json buffer or Object containing error.
|
* @returns {Promise<Buffer>} Edited pass.json buffer or Object containing error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_patch(passBuffer) {
|
_patch(passFile) {
|
||||||
let passFile = JSON.parse(passBuffer.toString("utf8"));
|
|
||||||
|
|
||||||
if (Object.keys(this._props).length) {
|
if (Object.keys(this._props).length) {
|
||||||
const rgbValues = ["backgroundColor", "foregroundColor", "labelColor"];
|
const rgbValues = ["backgroundColor", "foregroundColor", "labelColor"];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user