From 0a4d13f64cbc511c182c8fb39974992588c842e2 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 23 Jan 2020 14:27:10 -0500 Subject: [PATCH] fix(@embark/pipeline): make generateAll async so it completes tasks generateAll was async, but it called the write functions with a sync loop, so at the end of the function, the files were not written yet. This is a problem in `embark build` because the process ends after genrateAll is done, so no artifacts were written --- packages/stack/pipeline/src/index.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/stack/pipeline/src/index.js b/packages/stack/pipeline/src/index.js index 798907a8b4..e6c9b6b41d 100644 --- a/packages/stack/pipeline/src/index.js +++ b/packages/stack/pipeline/src/index.js @@ -30,14 +30,12 @@ class Pipeline { }, (next) => { // TODO: make this async - for (let fileParams of Object.values(this.files)) { + async.each(Object.values(this.files), (fileParams, eachCb) => { if (fileParams.format === 'json') { - this.writeJSONFile(fileParams); - } else { - this.writeFile(fileParams); + return this.writeJSONFile(fileParams, eachCb); } - } - next(); + this.writeFile(fileParams, eachCb); + }, next); }, (next) => { this.plugins.runActionsForEvent("pipeline:generateAll:after", {}, (err) => { @@ -49,7 +47,7 @@ class Pipeline { }); } - writeJSONFile(params) { + writeJSONFile(params, cb) { const self = this; const dir = dappPath(...params.path); const filename = dappPath(...params.path, params.file); @@ -60,14 +58,13 @@ class Pipeline { self.fs.mkdirp(dir, err => next(err)); }, function writeContractsJSON(next) { - self.fs.writeJson(filename, content, { spaces: 2 }, () => { next(); }); + self.fs.writeJson(filename, content, { spaces: 2 }, (e) => { next(e); }); } - ], () => { - }); + ], cb); } // TODO: can be refactored by joining with method above - writeFile(params) { + writeFile(params, cb) { const self = this; const dir = dappPath(...params.path); const filename = dappPath(...params.path, params.file); @@ -78,10 +75,9 @@ class Pipeline { self.fs.mkdirp(dir, err => next(err)); }, function writeFile(next) { - self.fs.writeFile(filename, content, (err) => { next(err, true); }); + self.fs.writeFile(filename, content, (err) => { next(err); }); } - ], () => { - }); + ], cb); } }