I saw multiple repeated execution of my node script when I try to chain and run my npm script in gulp. Below is my gulp file.
gulp.task('icons', function() {
return gulp.src( base + 'icons/*.svg' )
.pipe($.iconfontCss({
targetPath : "../css/myicons.css",
fontPath : '../fonts/',
cssClass : 'sa-icon',
}))
.pipe($.iconfont({
formats : ['svg', ],
timestamp : Math.round(Date.now()/1000),
}))
.pipe(gulp.dest( dist.fonts ))
.pipe(run('npm run icons-to-json'));
});
My node script, there's nothing wrong with it for sure, I tried node icons-to-json it worked just fine, don't have repeated action.
const iconsFolder = './icons';
const fs = require('fs');
const jsonfile = require('jsonfile');
let json = [];
fs.readdir(iconsFolder, [], (err, files) => {
files.forEach(file => {
if(file.split('.')[0] !== 'icons'){
json.push({'name': file.split('.')[0]})
}
});
jsonfile.writeFile(iconsFolder+'/icons.json' , json);
});
My terminal look like this when I run gulp icons
[12:11:23] Using gulpfile ~\Projects\my-web\gulpfile.js
[12:11:23] Starting 'icons'...
[12:11:23] gulp-svgicons2svgfont: Font created
$ npm run icons-to-json
> @ icons-to-json C:\Users\Superant-Laptop\Projects\my-web\
> node icons-to-json
$ npm run icons-to-json
> @ icons-to-json C:\Users\Superant-Laptop\Projects\my-web\
> node icons-to-json
$ npm run icons-to-json
> @ icons-to-json C:\Users\Superant-Laptop\Projects\my-web
> node icons-to-json
$ npm run icons-to-json
> @ icons-to-json C:\Users\Superant-Laptop\Projects\my-web
> node icons-to-json
[12:11:33] Finished 'icons' after 9.97 s