浏览代码

Added sample task with simple filtering with .gitignore ruleset. Updated task runner to forward streams back to gulp

Maksymilian Barnaś 9 年之前
父节点
当前提交
86a6ff56fa
共有 3 个文件被更改,包括 51 次插入7 次删除
  1. 42 4
      dev/tasks/exec/functions/bump-year.js
  2. 2 1
      dev/tasks/exec/tasks.js
  3. 7 2
      dev/tasks/exec/tasks/exec.js

+ 42 - 4
dev/tasks/exec/functions/bump-year.js

@@ -5,10 +5,48 @@
 
 'use strict';
 
+const gulp = require( 'gulp' );
+const through = require( 'through2' );
+const path = require( 'path' );
+// const gitignore = require( 'gulp-gitignore' );
+
+const filter = require( 'gulp-filter' );
+const gitignore = require( 'parse-gitignore' );
+const fs = require( 'fs' );
+
+const PassThrough = require( 'stream' ).PassThrough;
+
+function filterGitignore() {
+	const fp = '.gitignore';
+
+	if ( !fs.existsSync( fp ) ) {
+		return new PassThrough( { objectMode: true } );
+	}
+
+	let glob = gitignore( fp );
+	let inverted = glob.map( pattern => pattern.startsWith( '!' ) ? pattern.slice( 1 ) : '!' + pattern );
+	inverted.unshift( '**/*' );
+
+	return filter( inverted );
+}
+
 /**
- * {String} packagePath
- * {Minimatch} params
+ * {String} workdir
  */
-module.exports = () => {
-	return 'bump-year!';
+module.exports = ( workdir ) => {
+	const glob = path.join( workdir, '**/*' );
+
+	let fileCount = 0;
+
+	return gulp.src( glob )
+		.pipe( filterGitignore() )
+		.pipe( through.obj( ( file, enc, cb ) => {
+			fileCount++;
+			// console.log( file.path );
+
+			cb( );
+		} ) )
+		.on( 'end', ( ) => {
+			console.log( 'File count:', fileCount );
+		} );
 };

+ 2 - 1
dev/tasks/exec/tasks.js

@@ -12,6 +12,7 @@ const exec = require( './tasks/exec' );
 
 const log = require( './utils/log' );
 const gutil = require( 'gulp-util' );
+// const through = require( 'through2' );
 
 module.exports = ( config ) => {
 	const ckeditor5Path = process.cwd();
@@ -44,7 +45,7 @@ module.exports = ( config ) => {
 			}
 
 			if ( execTask ) {
-				exec( execTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'dry-run' ] );
+				return exec( execTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'dry-run' ] );
 			}
 		},
 

+ 7 - 2
dev/tasks/exec/tasks/exec.js

@@ -9,6 +9,7 @@ const tools = require( '../utils/tools' );
 const git = require( '../utils/git' );
 const path = require( 'path' );
 const log = require( '../utils/log' );
+const merge = require( 'merge-stream' );
 
 /**
  * @param {Function} execTask Task to use on each dependency.
@@ -22,6 +23,7 @@ module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun )
 
 	// Get all CKEditor dependencies from package.json.
 	const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
+	const streams = merge();
 
 	if ( dependencies ) {
 		const directories = tools.getCKE5Directories( workspaceAbsolutePath );
@@ -30,7 +32,7 @@ module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun )
 			for ( let dependency in dependencies ) {
 				const repositoryURL = dependencies[ dependency ];
 				const urlInfo = git.parseRepositoryUrl( repositoryURL );
-				// const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
+				const repositoryAbsolutePath = path.join( ckeditor5Path, 'node_modules', dependency );
 
 				// Check if repository's directory already exists.
 				if ( directories.indexOf( urlInfo.name ) > -1 ) {
@@ -39,7 +41,8 @@ module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun )
 					} else {
 						try {
 							log.out( `Executing task on ${ repositoryURL }...` );
-							log.out( execTask() );
+
+							streams.add( execTask( repositoryAbsolutePath ) );
 						} catch ( error ) {
 							log.err( error );
 						}
@@ -52,4 +55,6 @@ module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun )
 	} else {
 		log.out( 'No CKEditor5 dependencies found in package.json file.' );
 	}
+
+	return streams;
 };