Skip to content

Commit 69703e0

Browse files
maxdeviantzpao
authored andcommitted
Gulp: lint, flow, and version-check (#7174)
* Add plugin loading for gulp * Convert `lint` task to gulp * Convert `flow` task to gulp * Convert `version-check` task to gulp * Add missing semicolons
1 parent 2b226f5 commit 69703e0

File tree

9 files changed

+182
-84
lines changed

9 files changed

+182
-84
lines changed

Gruntfile.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ module.exports = function(grunt) {
5252
grunt.loadNpmTasks(npmTaskName);
5353
});
5454

55-
grunt.registerTask('eslint', require('./grunt/tasks/eslint'));
55+
grunt.registerTask('eslint', function() {
56+
// Use gulp here.
57+
spawnGulp(['eslint'], null, this.async());
58+
});
5659

5760
grunt.registerTask('lint', ['eslint']);
5861

59-
grunt.registerTask('flow', require('./grunt/tasks/flow'));
62+
grunt.registerTask('flow', function() {
63+
// Use gulp here.
64+
spawnGulp(['flow'], null, this.async());
65+
});
6066

6167
grunt.registerTask('delete-build-modules', function() {
6268
// Use gulp here.
@@ -84,7 +90,10 @@ module.exports = function(grunt) {
8490
grunt.registerTask('npm-react-addons:release', npmReactAddonsTasks.buildReleases);
8591
grunt.registerTask('npm-react-addons:pack', npmReactAddonsTasks.packReleases);
8692

87-
grunt.registerTask('version-check', require('./grunt/tasks/version-check'));
93+
grunt.registerTask('version-check', function() {
94+
// Use gulp here.
95+
spawnGulp(['version-check'], null, this.async());
96+
});
8897

8998
grunt.registerTask('build:basic', [
9099
'build-modules',

grunt/tasks/eslint.js

-22
This file was deleted.

grunt/tasks/flow.js

-22
This file was deleted.

grunt/tasks/version-check.js

-37
This file was deleted.

gulp/tasks/eslint.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
var path = require('path');
13+
var spawn = require('child_process').spawn;
14+
15+
var extension = process.platform === 'win32' ? '.cmd' : '';
16+
17+
module.exports = function(gulp, plugins) {
18+
var gutil = plugins.util;
19+
20+
return function(done) {
21+
spawn(
22+
process.execPath,
23+
[
24+
path.join('node_modules', '.bin', 'eslint' + extension),
25+
'.',
26+
],
27+
{
28+
// Allow colors to pass through
29+
stdio: 'inherit',
30+
}
31+
).on('close', function(code) {
32+
if (code !== 0) {
33+
gutil.log(
34+
gutil.colors.red(
35+
'Lint failed'
36+
)
37+
);
38+
process.exit(code);
39+
}
40+
41+
gutil.log(
42+
gutil.colors.green(
43+
'Lint passed'
44+
)
45+
);
46+
done();
47+
});
48+
};
49+
};

gulp/tasks/flow.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
var path = require('path');
13+
var spawn = require('child_process').spawn;
14+
15+
var extension = process.platform === 'win32' ? '.cmd' : '';
16+
17+
module.exports = function(gulp, plugins) {
18+
var gutil = plugins.util;
19+
20+
return function(done) {
21+
spawn(
22+
process.execPath,
23+
[
24+
path.join('node_modules', '.bin', 'flow' + extension),
25+
'check',
26+
'.',
27+
],
28+
{
29+
// Allow colors to pass through
30+
stdio: 'inherit',
31+
}
32+
).on('close', function(code) {
33+
if (code !== 0) {
34+
gutil.log(
35+
gutil.colors.red(
36+
'Flow failed'
37+
)
38+
);
39+
process.exit(code);
40+
}
41+
42+
gutil.log(
43+
gutil.colors.green(
44+
'Flow passed'
45+
)
46+
);
47+
done();
48+
});
49+
};
50+
};

gulp/tasks/version-check.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = function(gulp, plugins) {
13+
var gutil = plugins.util;
14+
15+
return function(done) {
16+
var reactVersion = require('../../package.json').version;
17+
18+
var addonsData = require('../../packages/react-addons/package.json');
19+
var versions = {
20+
'packages/react/package.json':
21+
require('../../packages/react/package.json').version,
22+
'packages/react-dom/package.json':
23+
require('../../packages/react-dom/package.json').version,
24+
'packages/react-native-renderer/package.json':
25+
require('../../packages/react-native-renderer/package.json').version,
26+
'packages/react-addons/package.json (version)': addonsData.version,
27+
'packages/react-addons/package.json (react dependency)':
28+
// Get the "version" without the range bit
29+
addonsData.peerDependencies.react.slice(1),
30+
'src/ReactVersion.js': require('../../src/ReactVersion'),
31+
};
32+
33+
var allVersionsMatch = true;
34+
Object.keys(versions).forEach(function(name) {
35+
var version = versions[name];
36+
if (version !== reactVersion) {
37+
allVersionsMatch = false;
38+
gutil.log(
39+
gutil.colors.red(
40+
'%s version does not match package.json. Expected %s, saw %s.'
41+
),
42+
name,
43+
reactVersion,
44+
version
45+
);
46+
}
47+
});
48+
49+
if (!allVersionsMatch) {
50+
process.exit(1);
51+
}
52+
53+
done();
54+
};
55+
};

gulpfile.js

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
1818
var extractErrors = require('./scripts/error-codes/gulp-extract-errors');
1919
var devExpressionWithCodes = require('./scripts/error-codes/dev-expression-with-codes');
2020

21+
// Load all of the Gulp plugins.
22+
var plugins = require('gulp-load-plugins')();
23+
24+
function getTask(name) {
25+
return require(`./gulp/tasks/${name}`)(gulp, plugins);
26+
}
27+
2128
var paths = {
2229
react: {
2330
src: [
@@ -59,6 +66,14 @@ var babelOpts = {
5966
],
6067
};
6168

69+
gulp.task('eslint', getTask('eslint'));
70+
71+
gulp.task('lint', ['eslint']);
72+
73+
gulp.task('flow', getTask('flow'));
74+
75+
gulp.task('version-check', getTask('version-check'));
76+
6277
gulp.task('react:clean', function() {
6378
return del([paths.react.lib]);
6479
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"gulp": "^3.9.0",
5454
"gulp-babel": "^6.0.0",
5555
"gulp-flatten": "^0.2.0",
56+
"gulp-load-plugins": "^1.2.4",
5657
"gulp-util": "^3.0.7",
5758
"gzip-js": "~0.3.2",
5859
"jest": "^12.1.1",

0 commit comments

Comments
 (0)