From b3e9703a98041d85d35f819e3a809386487c1686 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Jul 2016 15:37:18 -0400 Subject: [PATCH 1/5] Add plugin loading for gulp --- gulpfile.js | 7 +++++++ package.json | 1 + 2 files changed, 8 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 103f608e208f..9f6001801777 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,6 +18,13 @@ var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules'); var extractErrors = require('./scripts/error-codes/gulp-extract-errors'); var devExpressionWithCodes = require('./scripts/error-codes/dev-expression-with-codes'); +// Load all of the Gulp plugins. +var plugins = require('gulp-load-plugins')(); + +function getTask(name) { + return require(`./gulp/tasks/${name}`)(gulp, plugins); +} + var paths = { react: { src: [ diff --git a/package.json b/package.json index 67ac99e5f847..117be7edfb20 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "gulp": "^3.9.0", "gulp-babel": "^6.0.0", "gulp-flatten": "^0.2.0", + "gulp-load-plugins": "^1.2.4", "gulp-util": "^3.0.7", "gzip-js": "~0.3.2", "jest": "^12.1.1", From 8ae9f0600cff82c8d7c5b4587446ed6e8e3070dc Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Jul 2016 15:41:41 -0400 Subject: [PATCH 2/5] Convert `lint` task to gulp --- Gruntfile.js | 5 ++++- grunt/tasks/eslint.js | 22 ------------------- gulp/tasks/eslint.js | 49 +++++++++++++++++++++++++++++++++++++++++++ gulpfile.js | 4 ++++ 4 files changed, 57 insertions(+), 23 deletions(-) delete mode 100644 grunt/tasks/eslint.js create mode 100644 gulp/tasks/eslint.js diff --git a/Gruntfile.js b/Gruntfile.js index 9562542441e2..b379d43f1004 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,7 +52,10 @@ module.exports = function(grunt) { grunt.loadNpmTasks(npmTaskName); }); - grunt.registerTask('eslint', require('./grunt/tasks/eslint')); + grunt.registerTask('eslint', function() { + // Use gulp here. + spawnGulp(['eslint'], null, this.async()); + }); grunt.registerTask('lint', ['eslint']); diff --git a/grunt/tasks/eslint.js b/grunt/tasks/eslint.js deleted file mode 100644 index 4f364a6d9075..000000000000 --- a/grunt/tasks/eslint.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var grunt = require('grunt'); - -var extension = process.platform === 'win32' ? '.cmd': ''; - -module.exports = function() { - var done = this.async(); - grunt.util.spawn({ - cmd: 'node_modules/.bin/eslint' + extension, - args: ['.'], - opts: {stdio: 'inherit'}, // allows colors to passthrough - }, function(err, result, code) { - if (err) { - grunt.log.error('Lint failed'); - } else { - grunt.log.ok('Lint passed'); - } - - done(code === 0); - }); -}; diff --git a/gulp/tasks/eslint.js b/gulp/tasks/eslint.js new file mode 100644 index 000000000000..6d87cdfd4338 --- /dev/null +++ b/gulp/tasks/eslint.js @@ -0,0 +1,49 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +var path = require('path'); +var spawn = require('child_process').spawn; + +var extension = process.platform === 'win32' ? '.cmd' : ''; + +module.exports = function(gulp, plugins) { + var gutil = plugins.util; + + return function(done) { + spawn( + process.execPath, + [ + path.join('node_modules', '.bin', 'eslint' + extension), + '.', + ], + { + // Allow colors to pass through + stdio: 'inherit', + } + ).on('close', function(code) { + if (code !== 0) { + gutil.log( + gutil.colors.red( + 'Lint failed' + ) + ); + process.exit(code); + } + + gutil.log( + gutil.colors.green( + 'Lint passed' + ) + ); + done(); + }); + }; +}; diff --git a/gulpfile.js b/gulpfile.js index 9f6001801777..3ca8c8824eca 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -66,6 +66,10 @@ var babelOpts = { ], }; +gulp.task('eslint', getTask('eslint')); + +gulp.task('lint', ['eslint']); + gulp.task('react:clean', function() { return del([paths.react.lib]); }); From d7e9e591991b5bbd5abca403abc294a74dec83ea Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Jul 2016 15:47:57 -0400 Subject: [PATCH 3/5] Convert `flow` task to gulp --- Gruntfile.js | 5 ++++- grunt/tasks/flow.js | 22 -------------------- gulp/tasks/flow.js | 50 +++++++++++++++++++++++++++++++++++++++++++++ gulpfile.js | 2 ++ 4 files changed, 56 insertions(+), 23 deletions(-) delete mode 100644 grunt/tasks/flow.js create mode 100644 gulp/tasks/flow.js diff --git a/Gruntfile.js b/Gruntfile.js index b379d43f1004..56a9112ce1e6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -59,7 +59,10 @@ module.exports = function(grunt) { grunt.registerTask('lint', ['eslint']); - grunt.registerTask('flow', require('./grunt/tasks/flow')); + grunt.registerTask('flow', function() { + // Use gulp here. + spawnGulp(['flow'], null, this.async()); + }); grunt.registerTask('delete-build-modules', function() { // Use gulp here. diff --git a/grunt/tasks/flow.js b/grunt/tasks/flow.js deleted file mode 100644 index 767fc4eea65b..000000000000 --- a/grunt/tasks/flow.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -var grunt = require('grunt'); - -var extension = process.platform === 'win32' ? '.cmd': ''; - -module.exports = function() { - var done = this.async(); - grunt.util.spawn({ - cmd: 'node_modules/.bin/flow' + extension, - args: ['check', '.'], - opts: {stdio: 'inherit'}, - }, function(err, result, code) { - if (err) { - grunt.log.error('Flow failed'); - } else { - grunt.log.ok('Flow passed'); - } - - done(code === 0); - }); -}; diff --git a/gulp/tasks/flow.js b/gulp/tasks/flow.js new file mode 100644 index 000000000000..9c033cc4e337 --- /dev/null +++ b/gulp/tasks/flow.js @@ -0,0 +1,50 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +var path = require('path'); +var spawn = require('child_process').spawn; + +var extension = process.platform === 'win32' ? '.cmd' : ''; + +module.exports = function(gulp, plugins) { + var gutil = plugins.util; + + return function(done) { + spawn( + process.execPath, + [ + path.join('node_modules', '.bin', 'flow' + extension), + 'check', + '.', + ], + { + // Allow colors to pass through + stdio: 'inherit', + } + ).on('close', function(code) { + if (code !== 0) { + gutil.log( + gutil.colors.red( + 'Flow failed' + ) + ); + process.exit(code); + } + + gutil.log( + gutil.colors.green( + 'Flow passed' + ) + ); + done(); + }); + } +} diff --git a/gulpfile.js b/gulpfile.js index 3ca8c8824eca..66c68df69198 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -70,6 +70,8 @@ gulp.task('eslint', getTask('eslint')); gulp.task('lint', ['eslint']); +gulp.task('flow', getTask('flow')); + gulp.task('react:clean', function() { return del([paths.react.lib]); }); From c0a7fb7e7db806367a0707f8e09593e4895d38d8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Jul 2016 15:53:23 -0400 Subject: [PATCH 4/5] Convert `version-check` task to gulp --- Gruntfile.js | 5 +++- grunt/tasks/version-check.js | 37 ------------------------ gulp/tasks/version-check.js | 55 ++++++++++++++++++++++++++++++++++++ gulpfile.js | 2 ++ 4 files changed, 61 insertions(+), 38 deletions(-) delete mode 100644 grunt/tasks/version-check.js create mode 100644 gulp/tasks/version-check.js diff --git a/Gruntfile.js b/Gruntfile.js index 56a9112ce1e6..e2f2faa59c29 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -90,7 +90,10 @@ module.exports = function(grunt) { grunt.registerTask('npm-react-addons:release', npmReactAddonsTasks.buildReleases); grunt.registerTask('npm-react-addons:pack', npmReactAddonsTasks.packReleases); - grunt.registerTask('version-check', require('./grunt/tasks/version-check')); + grunt.registerTask('version-check', function() { + // Use gulp here. + spawnGulp(['version-check'], null, this.async()); + }); grunt.registerTask('build:basic', [ 'build-modules', diff --git a/grunt/tasks/version-check.js b/grunt/tasks/version-check.js deleted file mode 100644 index 99f55feac010..000000000000 --- a/grunt/tasks/version-check.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -var grunt = require('grunt'); - -module.exports = function() { - var pkgVersion = grunt.config.data.pkg.version; - - var addonsData = grunt.file.readJSON('./packages/react-addons/package.json'); - var versions = { - 'packages/react/package.json': - grunt.file.readJSON('./packages/react/package.json').version, - 'packages/react-dom/package.json': - grunt.file.readJSON('./packages/react-dom/package.json').version, - 'packages/react-native-renderer/package.json': - grunt.file.readJSON('./packages/react-native-renderer/package.json').version, - 'packages/react-addons/package.json (version)': addonsData.version, - // Get the "version" without the range bit - 'packages/react-addons/package.json (react dependency)': addonsData.peerDependencies.react.slice(1), - 'src/ReactVersion.js': require('../../src/ReactVersion'), - }; - - // Return true (ok) or false (failed) - return Object.keys(versions).reduce(function(prev, name) { - var version = versions[name]; - var ok = true; - if (version !== pkgVersion) { - grunt.log.error( - '%s version does not match package.json. Expected %s, saw %s.', - name, - pkgVersion, - version - ); - ok = false; - } - return prev && ok; - }, true); -}; diff --git a/gulp/tasks/version-check.js b/gulp/tasks/version-check.js new file mode 100644 index 000000000000..0d22595dc159 --- /dev/null +++ b/gulp/tasks/version-check.js @@ -0,0 +1,55 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +module.exports = function(gulp, plugins) { + var gutil = plugins.util; + + return function(done) { + var reactVersion = require('../../package.json').version; + + var addonsData = require('../../packages/react-addons/package.json'); + var versions = { + 'packages/react/package.json': + require('../../packages/react/package.json').version, + 'packages/react-dom/package.json': + require('../../packages/react-dom/package.json').version, + 'packages/react-native-renderer/package.json': + require('../../packages/react-native-renderer/package.json').version, + 'packages/react-addons/package.json (version)': addonsData.version, + 'packages/react-addons/package.json (react dependency)': + // Get the "version" without the range bit + addonsData.peerDependencies.react.slice(1), + 'src/ReactVersion.js': require('../../src/ReactVersion'), + }; + + var allVersionsMatch = true; + Object.keys(versions).forEach(function(name) { + var version = versions[name]; + if (version !== reactVersion) { + allVersionsMatch = false; + gutil.log( + gutil.colors.red( + '%s version does not match package.json. Expected %s, saw %s.' + ), + name, + reactVersion, + version + ); + } + }); + + if (!allVersionsMatch) { + process.exit(1); + } + + done(); + }; +}; diff --git a/gulpfile.js b/gulpfile.js index 66c68df69198..82556ac429b5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -72,6 +72,8 @@ gulp.task('lint', ['eslint']); gulp.task('flow', getTask('flow')); +gulp.task('version-check', getTask('version-check')); + gulp.task('react:clean', function() { return del([paths.react.lib]); }); From 373930c4871c6948a839aa75903151a4e23f0022 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Jul 2016 15:54:04 -0400 Subject: [PATCH 5/5] Add missing semicolons --- gulp/tasks/flow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gulp/tasks/flow.js b/gulp/tasks/flow.js index 9c033cc4e337..a32d8837b616 100644 --- a/gulp/tasks/flow.js +++ b/gulp/tasks/flow.js @@ -46,5 +46,5 @@ module.exports = function(gulp, plugins) { ); done(); }); - } -} + }; +};