|
|
@@ -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 )
|