当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - getting occasional error when trying to copy files with gulp

问题描述:

I have a gulp task that cleans the dist folder and then copies files there.

Every now and then i get this error:

[15:05:51] copy-fontawsome -

./public/angular-client/font-awesome-4.1.0 [15:05:51]

'copy-fontawsome' errored after 63 ms [15:05:51] Error: ENOENT: no

such file or directory, chmod

'C:\workspace\main\webserver\public\angular-client\dist\cpq\font-awesome-4.1.0'

at Error (native) [15:05:51] 'default' errored after 77 ms [15:05:51] Error in plugin 'run-sequence(copy-fontawsome)'

Usually i just need to run gulp again and it works fine but i would like to avoid it. Any idea why this is happening?

gulpfile.js

var gulp = require('gulp');

var args = require('yargs').argv;

var browserify = require('browserify');

var watchify = require('watchify');

var source = require('vinyl-source-stream');

var buffer = require('vinyl-buffer');

var del = require('del');

var uglify = require('gulp-uglify');

var sass = require('gulp-sass');

var runSequence = require('run-sequence');

var request = require('request');

var $ = require('gulp-load-plugins')({

lazy: true

});

var isDev = true;

var config = require('./gulp.config');

var root = config.root;

gulp.task('browserify', function() {

return _bundle(config.entry, 'bundle.js', config.dest);

});

gulp.task('browserify:mobile', function() {

return _bundle(config.mobileEntry, 'bundle.mobile.js', config.mobileDest);

});

gulp.task('globals', function() {

return _bundle(config.globalsEntry, '3rd.js', config.dest, true);

});

gulp.task('sass', function() {

_log('Compiling scss files', $.util.colors.yellow);

var sassConfig = { outputStyle: isDev ? 'nested' : 'compressed' };

return gulp.src(config.sass)

.pipe(sass(sassConfig).on('error', sass.logError))

.pipe(gulp.dest(config.sassDest));

});

gulp.task('uglify', ['uglify-globals', 'uglify-bundle'], function() {});

gulp.task('uglify:mobile', function() {

return gulp.src(config.mobileDest + 'bundle.mobile.js')

.pipe(uglify())

.pipe(gulp.dest(config.mobileDest));

});

gulp.task('uglify-globals', function() {

return gulp.src(config.dest + '3rd.js')

.pipe(uglify())

.pipe(gulp.dest(config.dest));

});

gulp.task('uglify-bundle', function() {

return gulp.src(config.dest + 'bundle.js')

.pipe(uglify())

.pipe(gulp.dest(config.dest));

});

gulp.task('clean', function() {

return del(config.dest + '**/*');

});

gulp.task('clean:mobile', function() {

return del(config.mobileDest + '**/*');

});

gulp.task('copy-fontawsome', ['clean'], function() {

_log('copy-fontawsome - ' + config.fontawsome);

return gulp.src(config.fontawsome, { base: root })

.pipe(gulp.dest(config.dest));

});

gulp.task('copy', ['copy-fontawsome'], function() {

_log('copy - ' + config.assets);

return gulp.src(config.assets, { base: root + 'app' })

.pipe(gulp.dest(config.dest));

});

gulp.task('change-version', function(done) {

if (args.version) {

//Lets configure and request

request({

url: 'http://localhost:9000/general/setBundleVersion', //URL to hit

method: 'POST',

//Lets post the following key/values as form

json: {

"versionBundle": "" + args.version

}

}, function(error, response, body) {

if (error) {

console.log(error);

} else {

console.log(response.statusCode, body);

}

done();

});

} else {

_log('**** START OF WARNING ***', $.util.colors.yellow);

_log('No version supplied, try running with this command: gulp prod --version <version_number>', $.util.colors.yellow);

_log('**** END OF WARNING ***', $.util.colors.yellow);

//_errorLogger('No version supplied, try running with this command: gulp prod --version <version_number>');

}

});

gulp.task('watch', ['sass'], function() {

_log('watching sass files: ' + config.sassWatch);

gulp.watch(config.sassWatch, ['sass']);

});

gulp.task('prod', ['prod:mobile'], function(done) {

isDev = false;

runSequence('copy', ['sass', 'globals', 'browserify', 'change-version'],

'uglify', done);

});

gulp.task('prod:mobile', ['clean:mobile'], function(done) {

isDev = false;

runSequence('browserify:mobile', 'uglify:mobile', done);

});

gulp.task('default', function(done) {

runSequence('copy', ['watch', 'globals', 'browserify'], done);

});

function _bundle(entry, bundle, dest, isGlobals) {

var b = browserify({

cache: {},

packageCache: {},

debug: isDev

});

// b.plugin(errorify, _logError);

if (isDev && !isGlobals) {

_log("Activating watchify");

b = watchify(b);

b.on('update', function(ids) {

_log('Update occured , re-bundling scripts', $.util.colors.yellow);

_createBundle(b, entry, bundle, dest);

});

}

b.add(entry);

return _createBundle(b, entry, bundle, dest);

}

function _createBundle(b, entry, bundle, dest) {

return b

.bundle()

.on("error", function(err) {

_logError(err.message);

$.util.beep();

this.emit('end');

})

.pipe(source(bundle))

.pipe(buffer())

.pipe(gulp.dest(dest));

}

function _log(msg, color) {

color = color || $.util.colors.blue;

$.util.log(color(msg));

}

function _logError(error) {

_log('**** START OF ERROR ***', $.util.colors.red);

_log(error, $.util.colors.red);

_log('**** END OF ERROR ***', $.util.colors.red);

return error;

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: