Skip to content

Commit 0a4d13f

Browse files
committed
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
1 parent c891c2d commit 0a4d13f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

packages/stack/pipeline/src/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ class Pipeline {
3030
},
3131
(next) => {
3232
// TODO: make this async
33-
for (let fileParams of Object.values(this.files)) {
33+
async.each(Object.values(this.files), (fileParams, eachCb) => {
3434
if (fileParams.format === 'json') {
35-
this.writeJSONFile(fileParams);
36-
} else {
37-
this.writeFile(fileParams);
35+
return this.writeJSONFile(fileParams, eachCb);
3836
}
39-
}
40-
next();
37+
this.writeFile(fileParams, eachCb);
38+
}, next);
4139
},
4240
(next) => {
4341
this.plugins.runActionsForEvent("pipeline:generateAll:after", {}, (err) => {
@@ -49,7 +47,7 @@ class Pipeline {
4947
});
5048
}
5149

52-
writeJSONFile(params) {
50+
writeJSONFile(params, cb) {
5351
const self = this;
5452
const dir = dappPath(...params.path);
5553
const filename = dappPath(...params.path, params.file);
@@ -60,14 +58,13 @@ class Pipeline {
6058
self.fs.mkdirp(dir, err => next(err));
6159
},
6260
function writeContractsJSON(next) {
63-
self.fs.writeJson(filename, content, { spaces: 2 }, () => { next(); });
61+
self.fs.writeJson(filename, content, { spaces: 2 }, (e) => { next(e); });
6462
}
65-
], () => {
66-
});
63+
], cb);
6764
}
6865

6966
// TODO: can be refactored by joining with method above
70-
writeFile(params) {
67+
writeFile(params, cb) {
7168
const self = this;
7269
const dir = dappPath(...params.path);
7370
const filename = dappPath(...params.path, params.file);
@@ -78,10 +75,9 @@ class Pipeline {
7875
self.fs.mkdirp(dir, err => next(err));
7976
},
8077
function writeFile(next) {
81-
self.fs.writeFile(filename, content, (err) => { next(err, true); });
78+
self.fs.writeFile(filename, content, (err) => { next(err); });
8279
}
83-
], () => {
84-
});
80+
], cb);
8581
}
8682

8783
}

0 commit comments

Comments
 (0)