瀏覽代碼

Added updating of .jshintrc files in project's subdirectories.

Maksymilian Barnaś 9 年之前
父節點
當前提交
629776dc04
共有 1 個文件被更改,包括 15 次插入5 次删除
  1. 15 5
      dev/tasks/exec/functions/remove-use-strict.js

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

@@ -11,6 +11,12 @@ const replace = require( 'gulp-replace' );
 const mergeStream = require( 'merge-stream' );
 const filterGitignore = require( '../utils/filtergitignore' );
 
+const jshintrcDirs = [
+	'/',
+	'dev/',
+	'tests/'
+];
+
 /**
  * Removes lines with `'use strict';` directive.
  *
@@ -33,14 +39,18 @@ module.exports = function executeRemoveUseStrict( workdir ) {
 // @param {String} workdir Path of directory to be processed.
 // @returns {Stream}
 function updateJshintrc( workdir ) {
-	const jshintrcPath = path.join( workdir, '.jshintrc' );
-	const strictRegex = /("strict":.*?").*?(".*)/;
-	const replaceWith = 'implied';
+	const jshintrcGlob = jshintrcDirs.map(
+		dir => 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"';
 
-	return gulp.src( jshintrcPath )
+	return gulp.src( jshintrcGlob, { base: workdir } )
 		.pipe( replace(
 			strictRegex,
-			`$1${ replaceWith }$2`
+			`${ replaceWith }$1`
 		) )
 		.pipe( gulp.dest( workdir ) );
 }