Moved pass.json handling as parallel activity with L10N extractors

and removed the next parallel action used for pass.json and bundle
files like L10N and assets
This commit is contained in:
alexandercerutti
2018-07-22 18:05:51 +02:00
parent 21c57ba338
commit fb77e6e426

View File

@@ -44,6 +44,9 @@ class Pass {
*/ */
generate() { generate() {
let manifest = {};
let archive = archiver("zip");
return new Promise((success, reject) => { return new Promise((success, reject) => {
fs.readdir(this.model.computed, (err, files) => { fs.readdir(this.model.computed, (err, files) => {
// list without dynamic components like manifest, signature or pass files (will be added later in the flow) and hidden files. // list without dynamic components like manifest, signature or pass files (will be added later in the flow) and hidden files.
@@ -58,11 +61,15 @@ class Pass {
}; };
/* /*
* I may have (and I rathered) used async.concat to achieve this but it returns a list of filenames ordered by folder. * I may have (and I rathered) used async.concat to achieve this but it returns an
* The problem rises when I have to understand which is the first file of a folder which is not the first one. * array of filenames ordered by folder, without any kind of folder indication.
* So, the problem rises when I have to understand which is the first file of a
* folder which is not the first one, as I don't know how many file there are in
* a folder.
* *
* Therefore, I generate a function for each localization (L10N) folder inside the model. * Therefore, I generate a function for each localization (L10N) folder inside the
* Each function will read at the same time the content of the folder and return an array of the filenames inside that L10N folder. * model. Each function will read at the same time the content of the folder and
* return an array of the filenames inside that L10N folder.
*/ */
L10N.extractors = L10N.list.map(f => ((callback) => { L10N.extractors = L10N.list.map(f => ((callback) => {
@@ -78,16 +85,7 @@ class Pass {
}); });
})); }));
async.parallel(L10N.extractors, (err, listByFolder) => { let passExtractor = (passCallback => {
listByFolder.forEach((folder, index) => bundleList.push(...folder.map(f => path.join(L10N.list[index], f))));
let manifest = {};
let archive = archiver("zip");
// Using async.parallel since the final part must be executed only when both are completed.
// Otherwise would had to put everything in editPassStructure's Promise .then().
async.parallel([
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) {
// Flow should never enter in there since pass.json existence-check is already done above. // Flow should never enter in there since pass.json existence-check is already done above.
@@ -126,14 +124,19 @@ class Pass {
}); });
}); });
}); });
}, });
async.parallel([passExtractor, ...L10N.extractors], (err, listByFolder) => {
// 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))));
bundleCallback => {
let pathList = bundleList.map(f => path.resolve(this.model.computed, f)); let pathList = bundleList.map(f => path.resolve(this.model.computed, f));
async.concat(pathList, fs.readFile, (err, modelBuffers) => { async.concat(pathList, fs.readFile, (err, modelBuffers) => {
// I want to get an object containing each buffer associated with its own file name // I want to get an object containing each buffer associated with its own file name
let modelFiles = Object.assign({}, ...modelBuffers.map((buf, index) => ({ [bundleList[index]]: buf }))); let modelFiles = Object.assign(...modelBuffers.map((buf, index) => ({ [bundleList[index]]: buf })));
async.eachOf(modelFiles, (fileBuffer, bufferKey, callback) => { async.eachOf(modelFiles, (fileBuffer, bufferKey, callback) => {
let hashFlow = forge.md.sha1.create(); let hashFlow = forge.md.sha1.create();
@@ -143,7 +146,7 @@ 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();
}, function(error) { }, (error) => {
if (error) { if (error) {
return reject({ return reject({
status: false, status: false,
@@ -154,15 +157,6 @@ class Pass {
}); });
} }
return bundleCallback(null);
});
});
}
], (error) => {
if (error) {
return reject(error);
}
archive.append(JSON.stringify(manifest), { name: "manifest.json" }); archive.append(JSON.stringify(manifest), { name: "manifest.json" });
let signatureBuffer = this._sign(manifest); let signatureBuffer = this._sign(manifest);
@@ -180,6 +174,7 @@ class Pass {
}); });
}); });
}); });
});
} }
/** /**
@@ -457,13 +452,13 @@ class Pass {
this.Certificates[pem.key] = pem.value; this.Certificates[pem.key] = pem.value;
}); });
return __certsParseCallback(); return certsParseCallback();
}); });
}, },
handlersAssignCallback => { handlersAssignCallback => {
this.handlers = options.handlers || {}; this.handlers = options.handlers || {};
return __handlersAssignCallback(); return handlersAssignCallback();
} }
], success); ], success);
}); });