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

The task should also take care of the gulpfile.js and reformatting jscsrc.

Piotrek Koszuliński 9 лет назад
Родитель
Сommit
e49b349c10
1 измененных файлов с 29 добавлено и 10 удалено
  1. 29 10
      dev/tasks/exec/functions/remove-use-strict.js

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

@@ -9,6 +9,7 @@ const gulp = require( 'gulp' );
 const path = require( 'path' );
 const replace = require( 'gulp-replace' );
 const filterGitignore = require( '../utils/filtergitignore' );
+const filter = require( 'gulp-filter' );
 const tools = require( '../../../utils/tools' );
 
 /**
@@ -16,14 +17,14 @@ const tools = require( '../../../utils/tools' );
  *
  * Example:
  *
- *		gulp exec --task remove-use-strict
+ *		gulp exec --task remove-use-strict --include-root
  *
  * @param {String} workdir
  * @returns {Stream}
  */
 module.exports = function executeRemoveUseStrict( workdir ) {
 	updateJshintrc( workdir );
-	reformatDevsJshintrc( workdir );
+	reformatOtherConfigs( workdir );
 
 	return removeUseStrict( workdir );
 };
@@ -45,13 +46,12 @@ function updateJshintrc( workdir ) {
 	);
 }
 
-// Only reformats (to match other .jshintrc files and package.json code style) the .jshintrc from dev/.
+// Reformats (to match other .jshintrc files and package.json code style) the .jshintrc from dev/ and main .jscsrc.
 //
 // @param {String} workdir Path of directory to be processed.
-function reformatDevsJshintrc( workdir ) {
-	const jshintrcPath = path.join( workdir, 'dev', '.jshintrc' );
-
-	tools.updateJSONFile( jshintrcPath, json => json );
+function reformatOtherConfigs( workdir ) {
+	tools.updateJSONFile( path.join( workdir, 'dev', '.jshintrc' ), json => json );
+	tools.updateJSONFile( path.join( workdir, '.jscsrc' ), json => json );
 }
 
 // Removes `'use strict';` directive from project's source files. Omits files listed in `.gitignore`.
@@ -59,15 +59,34 @@ function reformatDevsJshintrc( workdir ) {
 // @param {String} workdir Path of directory to be processed.
 // @returns {Stream}
 function removeUseStrict( workdir ) {
-	const glob = path.join( workdir, '@(src|tests)/**/*.js' );
+	const glob = path.join( workdir, '**/*.js' );
+	const filterDev = filter( '@(src|tests)/**/*.js', { restore: true } );
+	const filterGulpfileAndBender = filter(
+		[ 'gulpfile.js', 'dev/tasks/dev/templates/gulpfile.js', 'bender.js' ],
+		{ restore: true }
+	);
+
 	const useStrictRegex = /^\s*'use strict';\s*$/gm;
+	const jshintInlineConfigRegex = /\/\* jshint( browser: false,)? node: true \*\//;
 
 	return gulp.src( glob )
 		.pipe( filterGitignore() )
+
+		// Remove use strict from src/ and tests/.
+		.pipe( filterDev )
 		.pipe( replace(
 			useStrictRegex,
-			'',
-			{ skipBinary: true }
+			''
 		) )
+		.pipe( filterDev.restore )
+
+		// Fix gulpfile.js and bender.js.
+		.pipe( filterGulpfileAndBender )
+		.pipe( replace(
+			jshintInlineConfigRegex,
+			'/* jshint browser: false, node: true, strict: true */'
+		) )
+		.pipe( filterGulpfileAndBender.restore )
+
 		.pipe( gulp.dest( workdir ) );
 }