Skip to content

Commit

Permalink
fix(@embark/pipeline): make generateAll async so it completes tasks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrainville committed Jan 27, 2020
1 parent c891c2d commit 0a4d13f
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/stack/pipeline/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

}
Expand Down

0 comments on commit 0a4d13f

Please sign in to comment.