如何对每个文件执行命令,替换每个文件的内容?
How to execute a command against every file, replacing the contents of each file?
对此使用模块不感兴趣。
我相信要遍历文件夹中的所有文件,我可以这样做:
gulp.src(__dirname + '\mysource\**\*.php', {read: false})
对于找到的每个文件,我想运行一个命令,并将内容保存在该文件中。
(php -w FILE > FILE
)
我的理解是我可以用 "spawn",
.pipe(spawn('php', ['-w'], ...))
但我不确定如何获得 "current file",除非我做某种 "forEach"。
这是使用 https://www.npmjs.com/package/glob glob.sync
的一般形式,其中 returns 是一个数组。
const gulp = require("gulp");
const glob = require("glob");
const path = require("path");
// get an array of files
const files = glob.sync(path.join(__dirname, 'mysource\**\*.php');
gulp.task('default', function (done) {
files.forEach(function (file) {
return gulp.src(file, {read: false})
// .pipe(do your stuff here)
.pipe(gulp.dest("dist/" + path.basename(file, '.php')));
});
done();
});
对此使用模块不感兴趣。
我相信要遍历文件夹中的所有文件,我可以这样做:
gulp.src(__dirname + '\mysource\**\*.php', {read: false})
对于找到的每个文件,我想运行一个命令,并将内容保存在该文件中。
(php -w FILE > FILE
)
我的理解是我可以用 "spawn",
.pipe(spawn('php', ['-w'], ...))
但我不确定如何获得 "current file",除非我做某种 "forEach"。
这是使用 https://www.npmjs.com/package/glob glob.sync
的一般形式,其中 returns 是一个数组。
const gulp = require("gulp");
const glob = require("glob");
const path = require("path");
// get an array of files
const files = glob.sync(path.join(__dirname, 'mysource\**\*.php');
gulp.task('default', function (done) {
files.forEach(function (file) {
return gulp.src(file, {read: false})
// .pipe(do your stuff here)
.pipe(gulp.dest("dist/" + path.basename(file, '.php')));
});
done();
});