8
0
Просмотр исходного кода

Cleaned up bump-year function, added files for git-commit and git-push functions

Maksymilian Barnaś 9 лет назад
Родитель
Сommit
9632d96d86

+ 9 - 38
dev/tasks/exec/functions/bump-year.js

@@ -3,57 +3,28 @@
  * For licensing, see LICENSE.md.
  */
 
-'use strict';
+ 'use strict';
 
 const gulp = require( 'gulp' );
-const through = require( 'through2' );
 const path = require( 'path' );
-const filter = require( 'gulp-filter' );
-const gitignore = require( 'parse-gitignore' );
-const fs = require( 'fs' );
-const PassThrough = require( 'stream' ).PassThrough;
 const replace = require( 'gulp-replace' );
-
-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 );
-}
+const gitignore = require( '../utils/gitignore-filter' );
 
 /**
  * {String} workdir
  */
 module.exports = ( workdir ) => {
+	// Change to correct year
+	const year = '2017';
+	const licenseRegexp = /(@license Copyright \(c\) 2003-)[0-9]{4}/g;
 	const glob = path.join( workdir, '**/*' );
-	const reLicense = /(@license Copyright \(c\) 2003-)[0-9]{4}/g;
-	const yearReplacement = '$12017';
-
-	let fileCount = 0;
 
 	return gulp.src( glob )
-		.pipe( filterGitignore() )
+		.pipe( gitignore() )
 		.pipe( replace(
-			reLicense,
-			yearReplacement,
+			licenseRegexp,
+			`$1${ year }`,
 			{ skipBinary: true }
 		) )
-		.pipe( through.obj( ( file, enc, next ) => {
-			fileCount++;
-
-			next( null, file );
-		} ) )
-		.pipe( gulp.dest( workdir ) )
-		.on( 'end', ( ) => {
-			console.log( 'File count:', fileCount );
-		} );
+		.pipe( gulp.dest( workdir ) );
 };

+ 19 - 0
dev/tasks/exec/functions/git-commit.js

@@ -0,0 +1,19 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+ 'use strict';
+
+const gulp = require( 'gulp' );
+const path = require( 'path' );
+
+/**
+ * {String} workdir
+ */
+module.exports = ( workdir ) => {
+	const glob = path.join( workdir, '**/*' );
+
+	return gulp.src( glob )
+		.pipe( gulp.dest( workdir ) );
+};

+ 0 - 0
dev/tasks/exec/functions/git-push.js


+ 0 - 0
dev/tasks/exec/functions/remove-use-strict.js


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

@@ -41,7 +41,7 @@ module.exports = ( config ) => {
 				execTask = require( `./functions/${ options.task }` );
 			}
 			catch ( error ) {
-				log.err( `Cannot find task ${ options.task }` );
+				log.err( error );
 			}
 
 			if ( execTask ) {

+ 27 - 0
dev/tasks/exec/utils/gitignore-filter.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+ 'use strict';
+
+const fs = require( 'fs' );
+const filter = require( 'gulp-filter' );
+const gitignore = require( 'parse-gitignore' );
+const PassThrough = require( 'stream' ).PassThrough;
+
+module.exports = () => {
+	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 );
+};