Gulp : Prepare dist folder and edit ini file

霸气de小男生 提交于 2019-12-23 16:24:49

问题


I am trying to create a gulp task responsible to : 1. clean dist folder previouly created 2. Copy some folder inside new dist folder 3. Edit a ini file inside dist folder to update a key

var destination = './dist/test/v2';

// Copy ini file to dist folder
gulp.task('prepareDelivery', function () {
  gulp.src([source + '/ini/app_sample.ini']).pipe(gulp.dest(destination + '/ini/'));
});

// update version in ini file
gulp.task('prepareAppIni', ['prepareDelivery'], function () {
  var config = ini.parse(fs.readFileSync(destination + '/ini/app_sample.ini', 'utf-8'))
  config.DATA.version = '1.0'
  fs.writeFileSync(destination + '/ini/app.ini', ini.stringify(config, { section: 'section' }))
});

// default task
gulp.task('default', ['clean', 'prepareDelivery', 'prepareAppIni']);

I get this error :

Error: ENOENT: no such file or directory, open './dist/test/v2/ini/app_sample.ini'

I don't understand why, because i am waiting that prepareDelivery task is terminated before executing prepareAppIni task...

Could you help me ?


回答1:


I don't understand why, because i am waiting that prepareDelivery task is terminated before

That's not correct. Your default task has multiple dependencies (clean, prepareDelivery, prepareAppIni), and all of them start at the same time.

Most likely you want want prepareAppIni to depend on prepareDelivery. Which, in turn, should depend on clean task. Having this implemented, default should depend only on prepareAppIni:

gulp.task('default', ['prepareAppIni']);

Also, you are missing return in prepareDelivery, so gulp doesn't know when it finishes. Should be

// Copy ini file to dist folder
gulp.task('prepareDelivery', function () {
  return gulp.src([source + '/ini/app_sample.ini']).pipe(gulp.dest(destination + '/ini/'));
});


来源:https://stackoverflow.com/questions/40236804/gulp-prepare-dist-folder-and-edit-ini-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!