实际上我有一个基于angularjs的项目,我需要做的是编译代码并使用gulp创建文件夹。
/ 错误 => [12:03:39]使用gulpfile E:\ projects \ public \ public \ gulpfile.js [12:03:39]开始' mkdir:tmp' ... [12:03:39]开始' config' ... [12:03:39]已完成'配置'在9.6毫秒之后[12:03:39]' mkdir:tmp' 23 ms后发生错误[12:03:39]错误:命令失败:rm -rf E:\ projects \ public \ public / tmp&& mkdir -p E:\ projects \ public \ public / tmp' rm'不被识别为内部或外部命令,可操作程序或批处理文件。在childProcess.exithandler(child_process.js:206:12)的emitTwo(events.js:106:13),在childProcess.emit(events.js:191:7)的maybeClose(internal / child_process.js:877:16)在Socket。 (internal / child_process.js:334:11)在emitOne(events.js:96:13)的Socket.emit(events.js:188:7)处于Pipe._handle.close [as _onclose](net.js: 498:12)* /
当我使用del而不是rm命令时,进程没有完成
/ * Gulpfile.js * /
gulp.task('default', ['build']);
gulp.task('watch', ['build'], function(done) { /* gulp watch */
var debug = [].concat(settings.css)
.concat(settings.js.filter(x => {
return !x.match(/node_modules/)
}))
.concat(['./app/js/**/*.js'])
.concat(['./app/views/*.html', './app/views/**/*.html', './app/views/**/**/*.html']);
//console.log(debug);
gulp.watch(debug, ['build']);
})
gulp.task('config', function() { /* gulp config */
var constants = {
"Constants": {
"baseUrl": process.env.baseUrl || "https://localhost:3005",
"language": process.env.language || "en"
}
}
ngConstant({
name: 'app.constants',
wrap: false,
constants: constants,
stream: true
}).pipe(rename('app.constants.js')).pipe(gulp.dest('tmp/js'));
});
gulp.task('build', ['indexPage'], function(done) { /* gulp build */
exec(`rm -rf ${__dirname}/dist && mv ${__dirname}/tmp ${__dirname}/dist`, function(err, stdOut, stdErr) {
if (done && (err || stdErr)) return (done(err || stdErr));
if (done) done();
});
})
gulp.task('indexPage', ['js', 'css'], function(done) {
var sources = [];
if (settings.mode === 'development') {
sources = sources.concat(settings.css).concat(['./tmp/js/app-vendor.js', './tmp/js/core.js', './tmp/js/*.js', './tmp/js/**/*.js', './tmp/js/**/**/*.js']);
} else {
sources = sources.concat('./tmp/css/style.css');
}
gulp.src(settings.index)
.pipe(inject(gulp.src(sources), {
relative: false,
transform: function(filepath) {
filepath = filepath.replace('/app/', '/').replace('/tmp/', '/');
switch (path.extname(filepath)) {
case '.css':
return `<link rel="stylesheet" href=".${filepath}?v=${+new Date()}">`;
break;
case '.js':
return `<script src=".${filepath}?v=${+new Date()}"></script>`;
break;
default:
return inject.transform.apply(inject.transform, arguments);
break;
}
}
}))
.pipe(gulp.dest('./tmp/'))
.on('end', done);
})
gulp.task('mkdir:tmp', function(done) {
exec(`rm -rf ${__dirname}/tmp && mkdir -p ${__dirname}/tmp`, function(err, stdOut, stdErr) {
if (done && (err || stdErr)) return (done(err || stdErr));
if (done) done();
});
});
gulp.task('js', ['mkdir:tmp', 'config'], function(done) {
if (settings.mode === 'development') {
gulp.src(['./app/js/*.js', './app/js/**/*.js', './app/js/**/**/*.js'])
.pipe(gulp.dest('./tmp/js'))
.on('end', function() {
gulp.src(settings.js.filter(function(x) {
return x.match(/node_modules/)
}))
.pipe(concat('app-vendor.js'))
.pipe(gulp.dest('./tmp/js'))
.on('end', function() {
gulp.src(['./app/views/*.html', './app/views/**/*.html', './app/views/**/**/*.html'])
.pipe(gulp.dest('./tmp/app/views'))
.on('end', done);
})
});
return;
}
})
gulp.task('css', ['mkdir:tmp', 'fonts', 'images'], function(done) {
if (settings.mode === 'development') {
gulp.src(settings.css)
.pipe(gulp.dest('./tmp/css'))
.on('end', done);
return;
}
gulp.src(settings.css)
//.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(concat('style.css'))
.pipe(uglifycss({
"maxLineLen": 0,
"uglyComments": true
}))
.pipe(gulp.dest('./tmp/css'))
.on('end', done);
});
gulp.task('fonts', ['mkdir:tmp'], function(cb) {
gulp.src(['./app/fonts/*'])
.pipe(gulp.dest('./tmp/fonts'))
.on('end', cb)
});
gulp.task('images', ['mkdir:tmp'], function(cb) {
gulp.src(['./app/images/*'])
.pipe(gulp.dest('./tmp/images'))
.on('end', cb)
});