Added some comments inside the function; renamed _passExtractor without low dash

This commit is contained in:
alexandercerutti
2018-08-22 22:35:36 +02:00
parent f1f42c2f69
commit 3eac7a4cb5

View File

@@ -39,6 +39,7 @@ class Pass {
return this._parseSettings(this.options) return this._parseSettings(this.options)
.then(() => readdir(this.model)) .then(() => readdir(this.model))
.catch((err) => { .catch((err) => {
// May have not used this catch but ENOENT error is not enough self-explanatory in the case of external usage
if (err.code && err.code === "ENOENT") { if (err.code && err.code === "ENOENT") {
throw new Error(errors.NOT_FOUND.replace("%s", (this.model ? this.model+" " : ""))); throw new Error(errors.NOT_FOUND.replace("%s", (this.model ? this.model+" " : "")));
} }
@@ -59,7 +60,14 @@ 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));
let _passExtractor = (() => { /**
* Reads pass.json file and apply patches on it
* @function
* @name passExtractor
* @return {Promise<Buffer>} The patched pass.json buffer
*/
let passExtractor = (() => {
return readFile(path.resolve(this.model, "pass.json")) return readFile(path.resolve(this.model, "pass.json"))
.then(passStructBuffer => { .then(passStructBuffer => {
if (!this._validateType(passStructBuffer)) { if (!this._validateType(passStructBuffer)) {
@@ -72,8 +80,16 @@ class Pass {
}); });
}); });
/*
* Reading all the localization selected folders and removing hidden files (the ones that starts with ".")
* from the list. Returning a Promise containing all those files
*/
return Promise.all(L10N.map(f => readdir(path.join(this.model, f)).then(removeHidden))) return Promise.all(L10N.map(f => readdir(path.join(this.model, f)).then(removeHidden)))
.then(listByFolder => { .then(listByFolder => {
/* Each file name is joined with its own path and pushed to the bundle files array. */
listByFolder.forEach((folder, index) => bundle.push(...folder.map(f => path.join(L10N[index], f)))); listByFolder.forEach((folder, index) => bundle.push(...folder.map(f => path.join(L10N[index], f))));
return Promise.all([...bundle.map(f => readFile(path.resolve(this.model, f))), _passExtractor()]).then(buffers => { return Promise.all([...bundle.map(f => readFile(path.resolve(this.model, f))), _passExtractor()]).then(buffers => {
@@ -90,9 +106,7 @@ class Pass {
}) })
}) })
.then(([buffers, bundle]) => { .then(([buffers, bundle]) => {
/* /* Parsing the buffers, pushing them into the archive and returning the manifest */
* Parsing the buffers and pushing them into the archive
*/
let manifest = {}; let manifest = {};