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

Added git-commit and git-push, cleaned up a bit task runner

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

+ 6 - 2
dev/tasks/exec/functions/bump-year.js

@@ -11,11 +11,15 @@ const replace = require( 'gulp-replace' );
 const gitignore = require( '../utils/gitignore-filter' );
 
 /**
- * {String} workdir
+ * Replaces license date in source files with new date
+ *
+ * @param {String} workdir
+ * @returns {Object} stream
  */
 module.exports = ( workdir ) => {
-	// Change to correct year
+	// Change this to correct year
 	const year = '2017';
+
 	const licenseRegexp = /(@license Copyright \(c\) 2003-)[0-9]{4}/g;
 	const glob = path.join( workdir, '**/*' );
 

+ 16 - 7
dev/tasks/exec/functions/git-commit.js

@@ -5,15 +5,24 @@
 
  'use strict';
 
-const gulp = require( 'gulp' );
-const path = require( 'path' );
+const git = require( '../utils/git' );
+const PassThrough = require( 'stream' ).PassThrough;
 
 /**
- * {String} workdir
+ * Adds only modified files to git repository and commits them with provided message
+ *
+ * @param {String} workdir
+ * @param {Object} params
+ * @returns {Object} stream
  */
-module.exports = ( workdir ) => {
-	const glob = path.join( workdir, '**/*' );
+module.exports = ( workdir, params ) => {
+	if ( !( params.message || params.m ) ) {
+		throw new Error( 'You must provide commit message with parameter: --message | -m ' );
+	}
+	const message = params.message || params.m;
 
-	return gulp.src( glob )
-		.pipe( gulp.dest( workdir ) );
+	git.commit( message, workdir );
+
+	// Return dummy stream to inform gulp about finishing task
+	return new PassThrough();
 };

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

@@ -0,0 +1,22 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+ 'use strict';
+
+const git = require( '../utils/git' );
+const PassThrough = require( 'stream' ).PassThrough;
+
+/**
+ * Pushes changes of current branch in repository to default origin
+ *
+ * @param {String} workdir
+ * @returns {Object} stream
+ */
+module.exports = ( workdir ) => {
+	git.push( workdir );
+
+	// Return dummy stream to inform gulp about finishing task
+	return new PassThrough();
+};

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

@@ -28,13 +28,10 @@ module.exports = ( config ) => {
 		execOnRepositories() {
 			// Omit `gulp exec` part of arguments
 			const options = minimist( process.argv.slice( 3 ), {
-				boolean: [ 'dry-run' ],
 				alias: { t: 'task' },
-				default: {
-					'dry-run': false
-				},
 				stopEarly: false
 			} );
+
 			let execTask;
 
 			try {
@@ -45,7 +42,7 @@ module.exports = ( config ) => {
 			}
 
 			if ( execTask ) {
-				return exec( execTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options[ 'dry-run' ] );
+				return exec( execTask, ckeditor5Path, packageJSON, config.WORKSPACE_DIR, options );
 			}
 		},
 

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

@@ -18,7 +18,7 @@ const merge = require( 'merge-stream' );
  * @param {String} workspaceRoot Relative path to workspace root.
  * @param {Boolean} dryRun
  */
-module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun ) => {
+module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, params ) => {
 	const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
 
 	// Get all CKEditor dependencies from package.json.
@@ -36,21 +36,14 @@ module.exports = ( execTask, ckeditor5Path, packageJSON, workspaceRoot, dryRun )
 
 				// Check if repository's directory already exists.
 				if ( directories.indexOf( urlInfo.name ) > -1 ) {
-					if ( dryRun ) {
-						log.out( `Dry run in ${ urlInfo.name }...` );
-					} else {
-						try {
-							log.out( `Executing task on ${ repositoryURL }...` );
-
-							streams.add( execTask( repositoryAbsolutePath ) );
-						} catch ( error ) {
-							log.err( error );
-						}
+					try {
+						log.out( `Executing task on ${ repositoryURL }...` );
+
+						streams.add( execTask( repositoryAbsolutePath, params ) );
+					} catch ( error ) {
+						log.err( error );
 					}
 				}
-
-				// FIXME stop after first repository
-				return;
 			}
 		} else {
 			log.out( 'No CKEditor5 plugins in development mode.' );