Gulp:准备dist文件夹并编辑ini文件 [英] Gulp : Prepare dist folder and edit ini file

查看:159
本文介绍了Gulp:准备dist文件夹并编辑ini文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个负责任的gulp任务:
1.先创建
的clean dist文件夹2.在新的dist文件夹
中复制一些文件夹3.在dist内编辑一个ini文件文件夹更新密钥

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

//将ini文件复制到dist文件夹
gulp.task('prepareDelivery',function(){
gulp.src([source +'/ini/app_sample.ini '))。pipe(gulp.dest(destination +'/ ini /'));
});

//在ini文件中更新版本
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'}))
});

//默认任务
gulp.task('default',['clean','prepareDelivery','prepareAppIni']);

我得到这个错误:

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

我不明白为什么,因为我正在等待prepareDelivery任务在执行prepareAppIni任务之前终止... >你能帮我吗?

解决方案


我不明白为什么,因为我在等待prepareDelivery任务在

之前被终止。这是不正确的。
您的默认任务具有多个依赖项( clean prepareDelivery prepareAppIni ),并且它们都在同一时间开始。



最有可能你想要 prepareAppIni 取决于 prepareDelivery 。反过来,它应该依赖 clean 任务。执行这个操作后, default 应该只依赖于 prepareAppIni

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

此外,您还缺少 return code> prepareDelivery ,所以gulp不知道它何时结束。应该是

  //将ini文件复制到dist文件夹
gulp.task('prepareDelivery',function(){
return gulp.src([source +'/ini/app_sample.ini']).pipe(gulp.dest(destination+'/ ini /'));
});


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 ?

解决方案

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

这篇关于Gulp:准备dist文件夹并编辑ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆