Skip to content

Commit

Permalink
handle resolve and reject of promises
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbreuler committed Jun 17, 2022
1 parent 581a3cb commit d153076
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions gulp/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,26 @@ module.exports = function compile() {
} else {
console.log(`local build: ${packageJson.version}`);
}
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
fs.emptyDirSync(distdir);

const tasks = find.fileSync(/tasks[/\\].*[/\\]index.ts$/, "src");
tasks.map((task, idx) =>{

const promises = tasks.map((task, idx) => {
var baseName = path.basename(path.dirname(task));
var taskName = path.basename(path.join(task, "../.."))
const taskDistDir = path.resolve(distdir, "tasks", taskName, baseName);
console.info(`packaging ${idx} "${task}" into ./dist folder ...`);
esbuild.buildSync({
esbuild.build({
entryPoints: [`./${task}`],
outfile: path.join(taskDistDir, "index.js"),
platform: "node",
}).errors.forEach(error => console.error(error));
})
});
};
}).catch((error) => { console.error(error); reject(error); })
});

// function onBuild(done) {
// return function (err, result) {
// if (err) {
// console.error(`Webpack error:\n${err}`);
// if (done) {
// done();
// }
// } else {
// result.stats.forEach((stats) => {
// Object.keys(stats.compilation.assets).forEach(function (key) {
// console.log(`Webpack: output ${key}`);
// });
// const size = statSync(path.join(stats.compilation.outputOptions.path, stats.compilation.outputOptions.filename)).size;
// console.log(`Webpack: finished, size = ${size}`);
// });
// if (done) {
// done();
// }
// }
// };
// }
Promise.all(promises).then(() => {
message = "all tasks packaged into ./dist folder";
console.log(message);
resolve(message);
});
});
}

0 comments on commit d153076

Please sign in to comment.