Skip to content

Commit

Permalink
Gulp: lint, flow, and version-check (facebook#7174)
Browse files Browse the repository at this point in the history
* Add plugin loading for gulp

* Convert `lint` task to gulp

* Convert `flow` task to gulp

* Convert `version-check` task to gulp

* Add missing semicolons
  • Loading branch information
maxdeviant authored and usmanajmal committed Jul 11, 2016
1 parent a4c0db7 commit 6b78878
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 84 deletions.
15 changes: 12 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ 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']);

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.
Expand Down Expand Up @@ -84,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',
Expand Down
22 changes: 0 additions & 22 deletions grunt/tasks/eslint.js

This file was deleted.

22 changes: 0 additions & 22 deletions grunt/tasks/flow.js

This file was deleted.

37 changes: 0 additions & 37 deletions grunt/tasks/version-check.js

This file was deleted.

49 changes: 49 additions & 0 deletions gulp/tasks/eslint.js
Original file line number Diff line number Diff line change
@@ -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();
});
};
};
50 changes: 50 additions & 0 deletions gulp/tasks/flow.js
Original file line number Diff line number Diff line change
@@ -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();
});
};
};
55 changes: 55 additions & 0 deletions gulp/tasks/version-check.js
Original file line number Diff line number Diff line change
@@ -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();
};
};
15 changes: 15 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -59,6 +66,14 @@ var babelOpts = {
],
};

gulp.task('eslint', getTask('eslint'));

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]);
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6b78878

Please sign in to comment.