Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Gulp conversion #7172

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ module.exports = function(grunt) {
grunt.loadNpmTasks(npmTaskName);
});

grunt.registerTask('eslint', require('./grunt/tasks/eslint'));
grunt.registerTask('eslint', function() {
spawnGulp(['eslint'], null, this.async());
});

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

grunt.registerTask('flow', require('./grunt/tasks/flow'));
grunt.registerTask('flow', function() {
spawnGulp(['flow'], null, this.async());
});

grunt.registerTask('delete-build-modules', function() {
// Use gulp here.
Expand Down Expand Up @@ -84,7 +88,9 @@ 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() {
spawnGulp(['version-check'], null, this.async());
});

grunt.registerTask('build:basic', [
'build-modules',
Expand All @@ -109,7 +115,9 @@ module.exports = function(grunt) {
'build-modules',
'npm-react:release',
]);
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
grunt.registerTask('build:react-dom', function() {
spawnGulp(['build:react-dom'], null, this.async());
});

var jestTasks = require('./grunt/tasks/jest');
grunt.registerTask('jest:normal', jestTasks.normal);
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.

30 changes: 0 additions & 30 deletions grunt/tasks/react-dom.js

This file was deleted.

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

This file was deleted.

11 changes: 11 additions & 0 deletions gulp/data/header-template-extended.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* <%= package %> v<%= version %>
*
* 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.
*
*/
3 changes: 3 additions & 0 deletions gulp/data/header-template-short.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* <%= package %> v<%= version %>
*/
32 changes: 32 additions & 0 deletions gulp/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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 fs = require('fs');

function buildHeader(name, version, templateFile) {
var TEMPLATE = fs.readFileSync(templateFile, 'utf8');
return TEMPLATE
.replace('<%= package %>', name)
.replace('<%= version %>', version);
}

function buildSimpleHeader(name, version) {
return buildHeader(name, version, './gulp/data/header-template-short.txt');
}

function buildLicenseHeader(name, version) {
return buildHeader(name, version, './gulp/data/header-template-extended.txt');
}

module.exports = {
buildSimpleHeader,
buildLicenseHeader,
};
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 gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
var spawn = require('child_process').spawn;

var extension = process.platform === 'win32' ? '.cmd' : '';

gulp.task('eslint', 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();
});
});

gulp.task('lint', ['eslint']);
48 changes: 48 additions & 0 deletions gulp/tasks/flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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 gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
var spawn = require('child_process').spawn;

var extension = process.platform === 'win32' ? '.cmd' : '';

gulp.task('flow', 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/react-dom.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';

var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs');
var merge = require('merge2');
var through = require('through2');
var UglifyJS = require('uglify-js');
var helpers = require('../helpers');

var packageJson = require('../../package.json');

function build(name, filename) {
var header = helpers.buildLicenseHeader(name, packageJson.version);
var srcFile = `vendor/${filename}.js`;
var src = fs.readFileSync(srcFile, 'utf8');
var srcMin = UglifyJS.minify(src, {
fromString: true,
}).code;

var destFile = new gutil.File({
path: `${filename}.js`,
contents: new Buffer(header + src),
});
var destFileMin = new gutil.File({
path: `${filename}.min.js`,
contents: new Buffer(header + srcMin),
});

var out = through.obj();
out.push(destFile);
out.push(destFileMin);

return out
.pipe(gulp.dest('build'));
}

gulp.task('build:react-dom', function() {
var reactDom = build('ReactDOM', 'react-dom');
var reactDomServer = build('ReactDOMServer', 'react-dom-server');

merge([
reactDom,
reactDomServer,
]);
});
Loading