Przeglądaj źródła

Added support for running tasks over root package.

Default behaviour is still to exclude that package from task runner.
You can include root package using command-line param:

  gulp exec --task some-task --include-root

Root package will be added at the end of queue.
Maksymilian Barnaś 9 lat temu
rodzic
commit
0c177fbab7

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

@@ -8,8 +8,8 @@
 const gulp = require( 'gulp' );
 const path = require( 'path' );
 const replace = require( 'gulp-replace' );
-const mergeStream = require( 'merge-stream' );
 const filterGitignore = require( '../utils/filtergitignore' );
+const tools = require( '../../../utils/tools' );
 
 const jshintrcDirs = [
 	'/',
@@ -28,31 +28,26 @@ const jshintrcDirs = [
  * @returns {Stream}
  */
 module.exports = function executeRemoveUseStrict( workdir ) {
-	return mergeStream(
-		updateJshintrc( workdir ),
-		removeUseStrict( workdir )
-	);
+	updateJshintrc( workdir );
+
+	return removeUseStrict( workdir );
 };
 
 // Updates .jshintrc file's `strict` option with `implied` value.
 //
 // @param {String} workdir Path of directory to be processed.
-// @returns {Stream}
 function updateJshintrc( workdir ) {
-	const jshintrcGlob = jshintrcDirs.map(
-		dir => path.join( workdir, dir, '.jshintrc' )
-	);
+	jshintrcDirs.forEach(
+		dir => {
+			const jshintrcPath = path.join( workdir, dir, '.jshintrc' );
 
-	// Match everything after `"strict":` apart from optional comma. This should be matched into separate group.
-	const strictRegex = /"strict":[^,\n\r]*(,?)$/m;
-	const replaceWith = '"strict": "implied"';
+			tools.updateJSONFile( jshintrcPath, json => {
+				json.strict = 'implied';
 
-	return gulp.src( jshintrcGlob, { base: workdir } )
-		.pipe( replace(
-			strictRegex,
-			`${ replaceWith }$1`
-		) )
-		.pipe( gulp.dest( workdir ) );
+				return json;
+			} );
+		}
+	);
 }
 
 // Removes `'use strict';` directive from project's source files. Omits files listed in `.gitignore`.
@@ -60,7 +55,7 @@ function updateJshintrc( workdir ) {
 // @param {String} workdir Path of directory to be processed.
 // @returns {Stream}
 function removeUseStrict( workdir ) {
-	const glob = path.join( workdir, '**/*' );
+	const glob = path.join( workdir, '**/*.js' );
 	const useStrictRegex = /^\s*'use strict';\s*$/gm;
 
 	return gulp.src( glob )

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

@@ -23,6 +23,10 @@ const ckeditor5Dirs = require( '../../utils/ckeditor5-dirs' );
  *
  *		gulp exec --task task-name --repository ckeditor5-utils
  *
+ * Example of running task including root `ckeditor5` package
+ *
+ *		gulp exec --task task-name --include-root
+ *
  * @param {Object} config Task runner configuration.
  * @returns {Stream} Stream with processed files.
  */
@@ -75,8 +79,9 @@ function execute( execTask, ckeditor5Path, packageJSON, workspaceRoot, params )
 	const workspacePath = path.join( ckeditor5Path, workspaceRoot );
 	const mergedStream = merge();
 	const specificRepository = params.repository;
+	const includeRoot = !!params[ 'include-root' ];
 
-	let devDirectories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSON, ckeditor5Path );
+	let devDirectories = ckeditor5Dirs.getDevDirectories( workspacePath, packageJSON, ckeditor5Path, includeRoot );
 
 	if ( specificRepository ) {
 		devDirectories = devDirectories.filter( ( dir ) => {

+ 10 - 2
dev/utils/ckeditor5-dirs.js

@@ -72,18 +72,26 @@ module.exports = {
 	 * @param {String} workspacePath Absolute path to workspace.
 	 * @param {Object} packageJSON Contents of `ckeditor5` repo `package.json` file.
 	 * @param {String} ckeditor5Path Absolute path to ckeditor5 root directory.
+	 * @param {Boolean} includeRoot Include main `ckeditor5` package.
 	 * @returns {Array.<Object>}
 	 */
-	getDevDirectories( workspacePath, packageJSON, ckeditor5Path ) {
+	getDevDirectories( workspacePath, packageJSON, ckeditor5Path, includeRoot ) {
 		const directories = this.getDirectories( workspacePath );
 		const dependencies = this.getDependencies( packageJSON.dependencies );
 
+		if ( includeRoot ) {
+			// Add root dependency and directory.
+			dependencies.ckeditor5 = 'ckeditor/ckeditor5';
+			directories.push( 'ckeditor5' );
+		}
+
 		let devDirectories = [];
 
 		for ( let dependency in dependencies ) {
 			const repositoryURL = dependencies[ dependency ];
 			const urlInfo = git.parseRepositoryUrl( repositoryURL );
-			const repositoryPath = path.join( ckeditor5Path, 'node_modules', dependency );
+			const isRootDep = dependency == 'ckeditor5';
+			const repositoryPath = isRootDep ? ckeditor5Path : path.join( ckeditor5Path, 'node_modules', dependency );
 
 			// Check if repository's directory already exists.
 			if ( directories.indexOf( urlInfo.name ) > -1 ) {