I am running a few tasks via series, with one task scanning some directories, and another zipping the contents of each directory.
Despite the console displaying the message Finished 'cleanAndBuild' after 28 s this isn't actually the case, with the console not exiting until much later, at about 120s.
gulpfile.js
const { exec } = require('child_process');
const { series, dest, src } = require('gulp');
const del = require('del');
const fs = require('fs');
const zip = require('gulp-zip');
function clean() {
return del('.dist/');
}
function installPackages() {
const directories = fs.readdirSync('lambda/');
directories.forEach((dir) => {
if (fs.existsSync('lambda/' + dir + '/package.json')) {
console.log('package.json exists in ' + dir);
const path = `lambda/${dir}/`
exec(`npm --prefix ${path} ci ${path} --production`)
}
});
return Promise.resolve();
}
function buildZip() {
console.log('zipping...');
const directories = fs.readdirSync('lambda/');
directories.forEach((dir) => {
return src('lambda/'+dir+'/**').pipe(zip(`${dir}.zip`)).pipe(dest('.dist/lambda/'+dir));
});
return Promise.resolve();
}
exports.cleanAndBuild = series(clean, installPackages, buildZip);
Using the CLI tool gnomon I was able to get the true timing of running my task.
Why is gulp saying cleanAndBuild has finished when it hasn't? And is there anything I can do to improve this script to make it faster/more efficient?
Thanks
I am running a few tasks via
series, with one task scanning some directories, and another zipping the contents of each directory.Despite the console displaying the message
Finished 'cleanAndBuild' after 28 sthis isn't actually the case, with the console not exiting until much later, at about 120s.gulpfile.js
Using the CLI tool
gnomonI was able to get the true timing of running my task.Why is gulp saying
cleanAndBuildhas finished when it hasn't? And is there anything I can do to improve this script to make it faster/more efficient?Thanks