How to create directory with empty files in gulp?

Hello! Study of BEM and so it became necessary in the course of there are blocks. With gulp you can create folders and empty files in them. For example: gulp magic-command blockN
and get:
+ src/blockN
blockN.pug
blockN.js
_blockN.sass
June 14th 19 at 18:52
1 answer
June 14th 19 at 18:54
Solution
Treat com. string galpa.

// fetch command line arguments
const arg = (argList => {

 let arg = {}, a, opt, thisOpt, curOpt;
 for (a = 0; a < argList.length; a++) {

 thisOpt = argList[a].trim();
 opt = thisOpt.replace(/^\-+/, ");

 if (opt === thisOpt) {

 // argument value
 if (curOpt) arg[curOpt] = opt;
 curOpt = null;

}
 else {

 // argument name
 curOpt = opt;
 arg[curOpt] = true;

}

}

 return arg;

})(process.argv);


gulp.task('magic',(cb) => {
fs.mkdirSync(`./src/block${arg.block}`);
fs.touchSync(`./src/block${arg.block}.pug`, ...);
fs.touchSync(`./src/block${arg.block}.js`, ...);
fs.touchSync(`./src/_blockN${arg.block}.sass`, ...);

....
cb();
});


run:
gulp magic --block 1
gulp magic --block 2
gulp magic --block 3
gulp magic --block N

Problem code wrote on the knee.
Read more.

Find more questions by tags Gulp.jsnpm