wawanopoulos
wawanopoulos

Reputation: 9804

Gulp : Prepare dist folder and edit ini file

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 ?

Upvotes: 3

Views: 359

Answers (1)

Sergey Lapin
Sergey Lapin

Reputation: 2693

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/'));
});

Upvotes: 6

Related Questions