2016-03-25 15 views
1

。それはもちろん、バージョン番号を繰り返すでしょう。Gulp:フォルダ名の読み方は?ユーザーが<code>V=1.2.88</code>など</p> <p>を入力する必要はありませんので、私はむしろ、私はちょうど<code>major gulp build</code>、<code>minor gulp build</code>または<code>patch gulp build</code>を入力するようにユーザーをしたいと思い、私のガルプのビルドプロセスをリファクタリングしてい

これが機能するために

しかし、私が作成した最後のビルドのフォルダ名を読み取るために飲み込む必要があります。

enter image description here

バージョン番号を生成し、私の現在のガルプタスク:

var version = ''; 
var env = process.env.V; // V={version number} ie: V=1.0.1 gulp build 

gulp.task('version', function() { 
    return printOut(env); 
}); 

function errorlog(err) { 
    console.log(err.message); 
    this.emit('end'); 
} 

function printOut(ver) { 
    gutil.log(gutil.colors.blue.bold('Last build: '+paths.last)); 
    version = ver; 
    if (version === undefined) { 
     version = '0.0.0'; 
    } 
    gutil.log(gutil.colors.blue.bold('##################################################')); 
    gutil.log(gutil.colors.blue.bold('   Building Dashboard version '+version)); 
    gutil.log(gutil.colors.green.bold('~~   All change is detectable   ~~')); 
    gutil.log(gutil.colors.blue.bold('##################################################')); 
} 

誰でもGulpでこれを達成する方法を知っていますか?私は私のビルドを実行すると、以下のことをチェックアウト今

gulp.task('build:getLastBuild', folders(paths.lastBuild, function(folder) { 
    console.log('Last version number is: '+folder); 
    return lastVersion = folder; 
    //This will loop over all folders inside pathToFolder main, secondary 
    //Return stream so gulp-folders can concatenate all of them 
    //so you still can use safely use gulp multitasking 
    // return gutil.colors.blue.bold('Last build folder: '+folder); 
    // return gulp.src(path.join(paths.lastBuild, folder)) 
    //  .pipe(console.log(' Getting last version number: '+folder)) 
    //  .pipe(lastVersion = folder); 
})); 

この

は、私がこれまで Gulp-folders

は、だから私は、最初に実行、次のタスクを作成しGulp-foldersプラグインを使用して見つけたものです!私は:(しかし、にconsole.logで私のプロセスエラーをフォルダの名前を取得しています

TypeError: e.pipe is not a function

enter image description here

+0

私は、あなたのビルドタスク「フォルダの名前を読んで」との関係を理解し​​ていません。しかし、私は 'yargs'(https://www.npmjs.com/package/yargs)を使うべきだと思うので、' gulp --major 2.2.2 build'のようなことができます。メジャーが最新バージョンの場合は、ノードの 'path'モジュールを使用して、最新のバージョンを見つけるためのソート機能を使用する必要があるかもしれません。 – cl3m

+0

アイデアは、ユーザーがバージョン番号を知る必要もないことを確認することです。上記の例では、フォルダの名前を読みたいと思います: '1.2.8'そしてそれが' Major' 1 + 1、 'Minor' 2 + 1などの場合... –

+0

https:// www.npmjs.com/package/semver-utilsでバージョンを確認し、 'fs.readdir()'や 'fs.readdirSync()'でディレクトリを読み込みますか? – cl3m

答えて

2

I'don't正確に、マイナー/専攻についての一部を取得しますが、ディレクトリのリストについては、次の操作を実行できます。

var fs = require('fs'), 
    gulp = require('gulp'); 

gulp.task('default', function() { 
    var dirs = fs.readdirSync('./build/assets'); 
    console.log(dirs); 
    // do something with your directories 
}) 

// and the async version: 
gulp.task('async', function() { 
    var dirs = []; 
    var print = function(err, files) { 
     // do something with your directories 
     console.log(files) 
    }; 

    fs.readdir('./build/assets', print); 
}) 
+0

これはまさに私が解決した方法です:)これをチェックすると、 'build/assets'に2つのフォルダがあるので、' static'フォルダを反復することを避けるために下のコードにチェックを入れなければなりませんでした。 –

1

はそれを手に入れた私はそれが少し粗い認めるけれども、私は、ノードのreaddirをGoogleで検索して__dirname console.log(__dirname);

を見つけました!だから今、これを取得

var fs = require('fs'), 
    path = require('path'); 

gulp.task('build:getLastBuild', function() { 
    return fs.readdirSync(paths.lastBuild).filter(function(file) { 
     console.log(' build:getLastBuild: '+file); 
     if (file != 'static') { 
      lastVersion = file; 
     } 
     else { 
      console.log(' lastVersion: '+lastVersion); 
     } 
    }); 
}); 

は、だからと、私は、変数と、以下のタスクを作成しました!今、ユーザーがビルドプロセスを実行するときにバージョン番号を増やすために操作できる文字列があります。

enter image description here

+0

ああ、私は答えを投稿するのが遅かった:S。よくやった ;) – cl3m

関連する問題

 関連する問題