mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Moved bigger functions in generate() into variables;
Fixed some typos
This commit is contained in:
61
index.js
61
index.js
@@ -32,7 +32,7 @@ class Pass {
|
|||||||
this._parseSettings(options)
|
this._parseSettings(options)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._checkReqs()
|
this._checkReqs()
|
||||||
.catch(e => { throw new Error(e) });
|
.catch(e => { throw new Error(e.error.message) });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +68,8 @@ class Pass {
|
|||||||
* a folder.
|
* a folder.
|
||||||
*
|
*
|
||||||
* Therefore, I generate a function for each localization (L10N) folder inside the
|
* Therefore, I generate a function for each localization (L10N) folder inside the
|
||||||
* model. Each function will read at the same time the content of the folder and
|
* model. Each function will read the content of the folder and return an array of
|
||||||
* return an array of the filenames inside that L10N folder.
|
* the filenames inside that L10N folder.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
L10N.extractors = L10N.list.map(f => ((callback) => {
|
L10N.extractors = L10N.list.map(f => ((callback) => {
|
||||||
@@ -85,6 +85,8 @@ class Pass {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// === flow definition ===
|
||||||
|
|
||||||
let passExtractor = (passCallback => {
|
let passExtractor = (passCallback => {
|
||||||
fs.readFile(path.resolve(this.model.computed, "pass.json"), {}, (err, passStructBuffer) => {
|
fs.readFile(path.resolve(this.model.computed, "pass.json"), {}, (err, passStructBuffer) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -126,19 +128,7 @@ class Pass {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async.parallel([passExtractor, ...L10N.extractors], (err, listByFolder) => {
|
let _addBuffers = ((err, modelBuffers) => {
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// removing result of passExtractor, which is undefined or null.
|
|
||||||
listByFolder.shift();
|
|
||||||
|
|
||||||
listByFolder.forEach((folder, index) => bundleList.push(...folder.map(f => path.join(L10N.list[index], f))));
|
|
||||||
|
|
||||||
let pathList = bundleList.map(f => path.resolve(this.model.computed, f));
|
|
||||||
|
|
||||||
async.concat(pathList, fs.readFile, (err, modelBuffers) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
@@ -154,12 +144,15 @@ class Pass {
|
|||||||
archive.file(path.resolve(this.model.computed, bufferKey), { name: bufferKey });
|
archive.file(path.resolve(this.model.computed, bufferKey), { name: bufferKey });
|
||||||
|
|
||||||
return callback();
|
return callback();
|
||||||
}, (error) => {
|
}, _finalize);
|
||||||
if (error) {
|
});
|
||||||
|
|
||||||
|
let _finalize = (err => {
|
||||||
|
if (err) {
|
||||||
return reject({
|
return reject({
|
||||||
status: false,
|
status: false,
|
||||||
error: {
|
error: {
|
||||||
message: `Unable to compile manifest. ${error}`,
|
message: `Unable to compile manifest. ${err}`,
|
||||||
ecode: 418
|
ecode: 418
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -171,6 +164,7 @@ class Pass {
|
|||||||
archive.append(signatureBuffer, { name: "signature" });
|
archive.append(signatureBuffer, { name: "signature" });
|
||||||
|
|
||||||
let passStream = new stream.PassThrough();
|
let passStream = new stream.PassThrough();
|
||||||
|
|
||||||
archive.pipe(passStream);
|
archive.pipe(passStream);
|
||||||
archive.finalize().then(function() {
|
archive.finalize().then(function() {
|
||||||
return success({
|
return success({
|
||||||
@@ -179,7 +173,22 @@ class Pass {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
// === execution ===
|
||||||
|
|
||||||
|
async.parallel([passExtractor, ...L10N.extractors], (err, listByFolder) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// removing result of passExtractor, which is undefined.
|
||||||
|
listByFolder.shift();
|
||||||
|
|
||||||
|
listByFolder.forEach((folder, index) => bundleList.push(...folder.map(f => path.join(L10N.list[index], f))));
|
||||||
|
|
||||||
|
let pathList = bundleList.map(f => path.resolve(this.model.computed, f));
|
||||||
|
|
||||||
|
async.concat(pathList, fs.readFile, _addBuffers);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -339,20 +348,20 @@ class Pass {
|
|||||||
let barcode = passFile["barcode"];
|
let barcode = passFile["barcode"];
|
||||||
let barcodeKeys = Object.keys(barcode);
|
let barcodeKeys = Object.keys(barcode);
|
||||||
|
|
||||||
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.CONSTANTS.barcode)) {
|
if (!(barcode instanceof Object) || !schema.isValid(barcode, schema.constants.barcode)) {
|
||||||
console.log("\x1b[41m", "Barcode syntax is not correct. Please refer to https://apple.co/2myAbst.", "\x1b[0m");
|
console.log("\x1b[41m", "Barcode syntax is not correct. Please refer to https://apple.co/2myAbst.", "\x1b[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passFile["barcodes"] || !(passFiles["barcodes"] instanceof Array)) {
|
if (!passFile["barcodes"] || !(passFile["barcodes"] instanceof Array)) {
|
||||||
console.log("\x1b[33m", "Your pass is not compatible with iOS versions greater than iOS 8. Refer to https://apple.co/2O5K65k to make it backward-compatible.", "\x1b[0m");
|
console.log("\x1b[33m", "Your pass is not compatible with iOS versions greater than iOS 8. Refer to https://apple.co/2O5K65k to make it forward-compatible.", "\x1b[0m");
|
||||||
}
|
}
|
||||||
} else if (passFile["barcodes"] && (passFile["barcodes"] instanceof Array)) {
|
} else if (passFile["barcodes"] && (passFile["barcodes"] instanceof Array)) {
|
||||||
if (!passFile["barcodes"].length || !passFile["barcodes"].every(b => schema.isValid(b, schema.CONSTANTS.barcode))) {
|
if (!passFile["barcodes"].length || !passFile["barcodes"].every(b => schema.isValid(b, schema.constants.barcode))) {
|
||||||
console.log("\x1b[41m", "Some of your barcodes are not well-formed / have syntax errors. Please refer to https://apple.co/2myAbst.", "\x1b[0m");
|
console.log("\x1b[41m", "Some of your barcodes are not well-formed / have syntax errors. Please refer to https://apple.co/2myAbst.", "\x1b[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passFile["barcode"] || !(passFile["barcode"] instanceof Object)) {
|
if (!passFile["barcode"] || !(passFile["barcode"] instanceof Object)) {
|
||||||
console.log("\x1b[33m", "Your pass is not compatible with iOS versions lower than iOS 9. Please refer to https://apple.co/2O5K65k to make it forward-compatible.", "\x1b[0m");
|
console.log("\x1b[33m", "Your pass is not compatible with iOS versions lower than iOS 9. Please refer to https://apple.co/2O5K65k to make it backward-compatible.", "\x1b[0m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +448,7 @@ class Pass {
|
|||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
|
|
||||||
if (!schema.isValid(options, schema.CONSTANTS.instance)) {
|
if (!schema.isValid(options, schema.constants.instance)) {
|
||||||
throw new Error("The options passed to Pass constructor does not meet the requirements. Refer to the documentation to compile them correctly.");
|
throw new Error("The options passed to Pass constructor does not meet the requirements. Refer to the documentation to compile them correctly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user