removed gulp and grunt and moved tasks to standalone node script

This commit is contained in:
Dominic Gannaway
2017-03-31 13:46:09 +01:00
parent 794e0b908e
commit 16fc8d24f4
24 changed files with 110 additions and 1596 deletions
-202
View File
@@ -1,202 +0,0 @@
'use strict';
var path = require('path');
var GULP_EXE = 'gulp';
if (process.platform === 'win32') {
GULP_EXE += '.cmd';
}
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: require('./grunt/config/browserify'),
npm: require('./grunt/config/npm'),
clean: [
'./build',
'./*.gem',
'./docs/_site',
'./examples/shared/*.js',
'.module-cache',
],
'compare_size': require('./grunt/config/compare_size'),
});
function spawnGulp(args, opts, done) {
grunt.util.spawn({
// This could be more flexible (require.resolve & lookup bin in package)
// but if it breaks we'll fix it then.
cmd: path.join('node_modules', '.bin', GULP_EXE),
args: args,
opts: Object.assign({stdio: 'inherit'}, opts),
}, function(err, result, code) {
if (err) {
grunt.fail.fatal('Something went wrong running gulp: ', result);
}
done(code === 0);
});
}
Object.keys(grunt.file.readJSON('package.json').devDependencies)
.filter(function(npmTaskName) {
return npmTaskName.indexOf('grunt-') === 0;
})
.filter(function(npmTaskName) {
return npmTaskName !== 'grunt-cli';
})
.forEach(function(npmTaskName) {
grunt.loadNpmTasks(npmTaskName);
});
grunt.registerTask('eslint', function() {
// Use gulp here.
spawnGulp(['eslint'], null, this.async());
});
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('flow', function() {
// Use gulp here.
spawnGulp(['flow'], null, this.async());
});
grunt.registerTask('delete-build-modules', function() {
// Use gulp here.
spawnGulp(['react:clean'], null, this.async());
});
// Our own browserify-based tasks to build a single JS file build.
grunt.registerMultiTask('browserify', require('./grunt/tasks/browserify'));
grunt.registerMultiTask('npm', require('./grunt/tasks/npm'));
var npmReactTasks = require('./grunt/tasks/npm-react');
grunt.registerTask('npm-react:release', npmReactTasks.buildRelease);
grunt.registerTask('npm-react:pack', npmReactTasks.packRelease);
var npmReactDOMTasks = require('./grunt/tasks/npm-react-dom');
grunt.registerTask('npm-react-dom:release', npmReactDOMTasks.buildRelease);
grunt.registerTask('npm-react-dom:pack', npmReactDOMTasks.packRelease);
var npmReactNativeTasks = require('./grunt/tasks/npm-react-native');
grunt.registerTask('npm-react-native:release', npmReactNativeTasks.buildRelease);
grunt.registerTask('npm-react-native:pack', npmReactNativeTasks.packRelease);
var npmReactTestRendererTasks = require('./grunt/tasks/npm-react-test');
grunt.registerTask('npm-react-test:release', npmReactTestRendererTasks.buildRelease);
grunt.registerTask('npm-react-test:pack', npmReactTestRendererTasks.packRelease);
var npmReactNoopRendererTasks = require('./grunt/tasks/npm-react-noop');
grunt.registerTask('npm-react-noop:release', npmReactNoopRendererTasks.buildRelease);
grunt.registerTask('npm-react-noop:pack', npmReactNoopRendererTasks.packRelease);
grunt.registerTask('version-check', function() {
// Use gulp here.
spawnGulp(['version-check'], null, this.async());
});
grunt.registerTask('build:basic', [
'build-modules',
'version-check',
'browserify:basic',
]);
grunt.registerTask('build:min', [
'build-modules',
'version-check',
'browserify:min',
]);
grunt.registerTask('build:dom', [
'build-modules',
'version-check',
'browserify:dom',
]);
grunt.registerTask('build:dom-min', [
'build-modules',
'version-check',
'browserify:domMin',
]);
grunt.registerTask('build:dom-server', [
'build-modules',
'version-check',
'browserify:domServer',
]);
grunt.registerTask('build:dom-server-min', [
'build-modules',
'version-check',
'browserify:domServerMin',
]);
grunt.registerTask('build:dom-fiber', [
'build-modules',
'version-check',
'browserify:domFiber',
]);
grunt.registerTask('build:dom-fiber-min', [
'build-modules',
'version-check',
'browserify:domFiberMin',
]);
grunt.registerTask('build:npm-react', [
'version-check',
'build-modules',
'npm-react:release',
]);
var jestTasks = require('./grunt/tasks/jest');
grunt.registerTask('jest:normal', jestTasks.normal);
grunt.registerTask('jest:coverage', jestTasks.coverage);
grunt.registerTask('test', ['jest:normal']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
// Optimized build task that does all of our builds. The subtasks will be run
// in order so we can take advantage of that and only run build-modules once.
grunt.registerTask('build', [
'delete-build-modules',
'build-modules',
'version-check',
'browserify:basic',
'browserify:min',
'browserify:dom',
'browserify:domMin',
'browserify:domServer',
'browserify:domServerMin',
'browserify:domFiber',
'browserify:domFiberMin',
'npm-react:release',
'npm-react:pack',
'npm-react-dom:release',
'npm-react-dom:pack',
'npm-react-native:release',
'npm-react-native:pack',
'npm-react-test:release',
'npm-react-test:pack',
'npm-react-noop:release',
'npm-react-noop:pack',
'compare_size',
]);
// Automate the release!
var releaseTasks = require('./grunt/tasks/release');
grunt.registerTask('release:setup', releaseTasks.setup);
grunt.registerTask('release:bower', releaseTasks.bower);
grunt.registerTask('release:docs', releaseTasks.docs);
grunt.registerTask('release:msg', releaseTasks.msg);
grunt.registerTask('release', [
'release:setup',
'clean',
'build',
'release:bower',
'release:docs',
'release:msg',
]);
grunt.registerTask('build-modules', function() {
spawnGulp(['react:modules'], null, this.async());
});
// The default task - build - to keep setup easy.
grunt.registerTask('default', ['build']);
};
-1
View File
@@ -33,7 +33,6 @@ dependencies:
# - npm ls --depth=0
cache_directories:
- docs/vendor/bundle
- .grunt # Show size comparisons between builds
- ~/react-gh-pages # docs checkout
- ~/.yarn
- ~/.yarn-cache
-275
View File
@@ -1,275 +0,0 @@
/*eslint-disable no-multi-str */
'use strict';
var envify = require('loose-envify/custom');
var grunt = require('grunt');
var UglifyJS = require('uglify-js');
var uglifyify = require('uglifyify');
var derequire = require('derequire');
var aliasify = require('aliasify');
var collapser = require('bundle-collapser/plugin');
var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'});
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});
var shimSharedModules = aliasify.configure({
'aliases': {
'react/lib/React': 'react/lib/ReactUMDShim',
'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
},
});
var SIMPLE_TEMPLATE =
grunt.file.read('./grunt/data/header-template-short.txt');
var LICENSE_TEMPLATE =
grunt.file.read('./grunt/data/header-template-extended.txt');
function minify(src) {
return UglifyJS.minify(src, {
fromString: true,
output: {
comments(node, comment) {
// Preserve license headers in dependencies like object-assign.
if (comment.type === 'comment2') {
return /@license/i.test(comment.value);
}
return false;
},
},
}).code;
}
// TODO: move this out to another build step maybe.
function bannerify(src) {
var version = grunt.config.data.pkg.version;
var packageName = this.data.packageName || this.data.standalone;
return (
grunt.template.process(
LICENSE_TEMPLATE,
{data: {package: packageName, version: version}}
) +
src
);
}
function simpleBannerify(src) {
var version = grunt.config.data.pkg.version;
var packageName = this.data.packageName || this.data.standalone;
return (
grunt.template.process(
SIMPLE_TEMPLATE,
{data: {package: packageName, version: version}}
) +
src
);
}
// What is happening here???
// I'm glad you asked. It became really hard to make our bundle splitting work.
// Everything is fine in node and when bundling with those packages, but when
// using our pre-packaged files, the splitting didn't work. Specifically due to
// the UMD wrappers defining their own require and creating their own encapsulated
// "registry" scope, we couldn't require across the boundaries. Webpack tries to
// be smart and looks for top-level requires (even when aliasing to a bundle),
// but since we didn't have those, we couldn't require 'react' from 'react-dom'.
// But we are already shimming in some modules that look for a global React
// variable. So we replace the UMD wrapper that browserify creates with out own,
// in 2 steps.
// 1. We swap out the browserify UMD with a plain function call. This ensures
// that the internal wrapper doesn't interact with the external state. By the
// time we're in the internal wrapper it doesn't matter what the external wrapper
// detected. Browserify insulates its CommonJS system inside closures so can just
// call that function and return it.
// 2. We put our own UMD wrapper around that fixed internal function, ensuring
// React is in scope. This outer wrapper is essentially the same UMD wrapper
// browserify would create, just handling the scope issue.
// Is this insane? Yes.
// Does it work? Yes.
// Should it go away ASAP? Yes.
function wrapperify(src) {
/* eslint-disable max-len*/
var toReplace =
`function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.${this.data.standalone} = f()}}`;
/* eslint-enable max-len */
if (src.indexOf(toReplace) === -1) {
throw new Error('wrapperify failed to find code to replace');
}
src = src.replace(
toReplace,
`function(f){return f()}`
);
return `
;(function(f) {
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = f(require('react'));
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(['react'], f);
// <script>
} else {
var g;
if (typeof window !== "undefined") {
g = window;
} else if (typeof global !== "undefined") {
g = global;
} else if (typeof self !== "undefined") {
g = self;
} else {
// works providing we're not in "use strict";
// needed for Java 8 Nashorn
// see https://github.com/facebook/react/issues/3037
g = this;
}
g.${this.data.standalone} = f(g.React);
}
})(function(React) {
return ${src}
});
`;
}
// Our basic config which we'll add to to make our other builds
var basic = {
entries: [
'./build/node_modules/react/lib/ReactUMDEntry.js',
],
outfile: './build/react.js',
debug: false,
standalone: 'React',
// Apply as global transform so that we also envify fbjs and any other deps
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, simpleBannerify],
};
var min = {
entries: [
'./build/node_modules/react/lib/ReactUMDEntry.js',
],
outfile: './build/react.min.js',
debug: false,
standalone: 'React',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
after: [minify, bannerify],
};
// The DOM Builds
var dom = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
],
outfile: './build/react-dom.js',
debug: false,
standalone: 'ReactDOM',
// Apply as global transform so that we also envify fbjs and any other deps
transforms: [shimSharedModules],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, wrapperify, simpleBannerify],
};
var domMin = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
],
outfile: './build/react-dom.min.js',
debug: false,
standalone: 'ReactDOM',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [shimSharedModules, envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
after: [wrapperify, minify, bannerify],
};
var domServer = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
],
outfile: './build/react-dom-server.js',
debug: false,
standalone: 'ReactDOMServer',
// Apply as global transform so that we also envify fbjs and any other deps
transforms: [shimSharedModules],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, wrapperify, simpleBannerify],
};
var domServerMin = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
],
outfile: './build/react-dom-server.min.js',
debug: false,
standalone: 'ReactDOMServer',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [shimSharedModules, envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
after: [wrapperify, minify, bannerify],
};
var domFiber = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMFiber.js',
],
outfile: './build/react-dom-fiber.js',
debug: false,
standalone: 'ReactDOMFiber',
// Apply as global transform so that we also envify fbjs and any other deps
transforms: [shimSharedModules],
globalTransforms: [envifyDev],
plugins: [collapser],
after: [derequire, wrapperify, simpleBannerify],
};
var domFiberMin = {
entries: [
'./build/node_modules/react-dom/lib/ReactDOMFiber.js',
],
outfile: './build/react-dom-fiber.min.js',
debug: false,
standalone: 'ReactDOMFiber',
// Envify twice. The first ensures that when we uglifyify, we have the right
// conditions to exclude requires. The global transform runs on deps.
transforms: [shimSharedModules, envifyProd, uglifyify],
globalTransforms: [envifyProd],
plugins: [collapser],
// No need to derequire because the minifier will mangle
// the "require" calls.
after: [wrapperify, minify, bannerify],
};
module.exports = {
basic: basic,
min: min,
dom: dom,
domMin: domMin,
domServer: domServer,
domServerMin: domServerMin,
domFiber: domFiber,
domFiberMin: domFiberMin,
};
-17
View File
@@ -1,17 +0,0 @@
'use strict';
var gzip = require('gzip-js');
module.exports = {
files: [
'build/*.js',
],
options: {
compress: {
gz: function(contents) {
return gzip.zip(contents, {}).length;
},
},
cache: '.grunt/sizecache.json',
},
};
-3
View File
@@ -1,3 +0,0 @@
'use strict';
exports.pack = {};
-11
View File
@@ -1,11 +0,0 @@
/**
* <%= 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
View File
@@ -1,3 +0,0 @@
/**
* <%= package %> v<%= version %>
*/
-69
View File
@@ -1,69 +0,0 @@
'use strict';
var browserify = require('browserify');
var grunt = require('grunt');
module.exports = function() {
var config = this.data;
// This task is async...
var done = this.async();
// More/better assertions
// grunt.config.requires('outfile');
// grunt.config.requires('entries');
config.transforms = config.transforms || [];
config.globalTransforms = config.globalTransforms || [];
config.plugins = config.plugins || [];
config.after = config.after || [];
// create the bundle we'll work with
var entries = grunt.file.expand(config.entries);
// Extract other options
var options = {
entries: entries,
debug: config.debug, // sourcemaps
standalone: config.standalone, // global
insertGlobalVars: {
// We can remove this when we remove the few direct
// process.env.NODE_ENV checks against "test".
// The intention is to avoid embedding Browserify's `process` shim
// because we don't really need it.
// See https://github.com/facebook/react/pull/7245 for context.
process: function() {
return 'undefined';
},
},
};
var bundle = browserify(options);
config.transforms.forEach(function(transform) {
bundle.transform({}, transform);
});
config.globalTransforms.forEach(function(transform) {
bundle.transform({global: true}, transform);
});
config.plugins.forEach(bundle.plugin, bundle);
// Actually bundle it up
var _this = this;
bundle.bundle(function(err, buf) {
if (err) {
grunt.log.error(err);
return done();
}
var src = buf.toString();
config.after.forEach(function(fn) {
src = fn.call(_this, src);
});
grunt.file.write(config.outfile, src);
done();
});
};
-51
View File
@@ -1,51 +0,0 @@
'use strict';
var grunt = require('grunt');
var path = require('path');
function run(done, coverage) {
grunt.log.writeln('running jest');
var args = [
path.join('node_modules', 'jest-cli', 'bin', 'jest'),
'--runInBand',
];
if (coverage) {
args.push('--coverage');
}
grunt.util.spawn({
cmd: 'node',
args: args,
opts: {
stdio: 'inherit',
env: Object.assign({}, process.env, {
NODE_ENV: 'test',
}),
},
}, function(spawnErr, result, code) {
if (spawnErr) {
grunt.log.error('jest failed');
grunt.log.error(spawnErr);
} else {
grunt.log.ok('jest passed');
}
grunt.log.writeln(result.stdout);
done(code === 0);
});
}
function runJestNormally() {
var done = this.async();
run(done);
}
function runJestWithCoverage() {
var done = this.async();
run(done, /* coverage */ true);
}
module.exports = {
normal: runJestNormally,
coverage: runJestWithCoverage,
};
-67
View File
@@ -1,67 +0,0 @@
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react-dom/';
var dest = 'build/packages/react-dom/';
var modSrc = 'build/node_modules/react-dom/lib';
var lib = dest + 'lib/';
var dist = dest + 'dist/';
var distFiles = [
'react-dom.js',
'react-dom.min.js',
'react-dom-server.js',
'react-dom-server.min.js',
];
function buildRelease() {
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// Copy to build/packages/react-dom
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
// Make built source available inside npm package
grunt.file.mkdir(dist);
distFiles.forEach(function(file) {
grunt.file.copy('build/' + file, dist + file);
});
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'react-dom'],
opts: {
cwd: 'build/packages/',
},
};
grunt.util.spawn(spawnCmd, function() {
fs.rename(
'build/packages/react-dom-' + grunt.config.data.pkg.version + '.tgz',
'build/packages/react-dom.tgz',
done
);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};
-52
View File
@@ -1,52 +0,0 @@
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react-native-renderer/';
var dest = 'build/packages/react-native-renderer/';
var modSrc = 'build/node_modules/react-native/lib';
var lib = dest + 'lib/';
function buildRelease() {
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// Copy to build/packages/react-native-renderer
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'packages/react-native-renderer'],
opts: {
cwd: 'build/',
},
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = 'build/react-native-renderer-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/react-native-renderer.tgz';
fs.rename(buildSrc, buildDest, done);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};
-52
View File
@@ -1,52 +0,0 @@
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react-noop-renderer/';
var dest = 'build/packages/react-noop-renderer/';
var modSrc = 'build/node_modules/react-noop-renderer/lib';
var lib = dest + 'lib/';
function buildRelease() {
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// Copy to build/packages/react-noop-renderer
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'packages/react-noop-renderer'],
opts: {
cwd: 'build/',
},
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = 'build/react-noop-renderer-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/react-noop-renderer.tgz';
fs.rename(buildSrc, buildDest, done);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};
-52
View File
@@ -1,52 +0,0 @@
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react-test-renderer/';
var dest = 'build/packages/react-test-renderer/';
var modSrc = 'build/node_modules/react-test-renderer/lib';
var lib = dest + 'lib/';
function buildRelease() {
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// Copy to build/packages/react-test-renderer
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'packages/react-test-renderer'],
opts: {
cwd: 'build/',
},
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = 'build/react-test-renderer-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/react-test-renderer.tgz';
fs.rename(buildSrc, buildDest, done);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};
-73
View File
@@ -1,73 +0,0 @@
'use strict';
var fs = require('fs');
var grunt = require('grunt');
var src = 'packages/react/';
var dest = 'build/packages/react/';
var modSrc = 'build/node_modules/react/lib';
var lib = dest + 'lib/';
var dist = dest + 'dist/';
var distFiles = [
'react.js',
'react.min.js',
];
function buildRelease() {
// delete build/react-core for fresh start
if (grunt.file.exists(dest)) {
grunt.file.delete(dest);
}
// mkdir -p build/react-core/lib
grunt.file.mkdir(lib);
// Copy npm-react/**/* to build/npm-react
// and build/modules/**/* to build/react-core/lib
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src}),
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
);
mappings.forEach(function(mapping) {
var mappingSrc = mapping.src[0];
var mappingDest = mapping.dest;
if (grunt.file.isDir(mappingSrc)) {
grunt.file.mkdir(mappingDest);
} else {
grunt.file.copy(mappingSrc, mappingDest);
}
});
// Make built source available inside npm package
grunt.file.mkdir(dist);
distFiles.forEach(function(file) {
grunt.file.copy('build/' + file, dist + file);
});
// modify build/react-core/package.json to set version ##
var pkg = grunt.file.readJSON(dest + 'package.json');
pkg.version = grunt.config.data.pkg.version;
grunt.file.write(dest + 'package.json', JSON.stringify(pkg, null, 2));
}
function packRelease() {
var done = this.async();
var spawnCmd = {
cmd: 'npm',
args: ['pack', 'packages/react'],
opts: {
cwd: 'build/',
},
};
grunt.util.spawn(spawnCmd, function() {
var buildSrc = 'build/react-' + grunt.config.data.pkg.version + '.tgz';
var buildDest = 'build/packages/react.tgz';
fs.rename(buildSrc, buildDest, done);
});
}
module.exports = {
buildRelease: buildRelease,
packRelease: packRelease,
};
-100
View File
@@ -1,100 +0,0 @@
'use strict';
var assert = require('assert');
var path = require('path');
var grunt = require('grunt');
var spawn = grunt.util.spawn;
module.exports = function() {
var done = this.async();
function run(cmd, args, opts, callback) {
assert.strictEqual(typeof cmd, 'string');
assert.ok(args instanceof Array);
if (typeof opts === 'function' && !callback) {
callback = opts;
opts = {};
}
assert.strictEqual(typeof opts, 'object');
assert.strictEqual(typeof callback, 'function');
grunt.log.writeln('> ' + cmd + ' ' + args.join(' '));
// var proc =
spawn({
cmd: cmd,
args: args,
opts: opts,
}, function(error, result, code) {
if (error) {
grunt.log.error(error);
done(false);
} else {
callback(result, code);
}
});
// Uncomment these to see the output of the commands.
// proc.stdout.pipe(process.stdout);
// proc.stderr.pipe(process.stderr);
}
var pkg = grunt.config.data.pkg;
var tgz = pkg.name + '-' + pkg.version + '.tgz';
grunt.log.writeln('Packing ' + tgz + ' (this could take a while)...');
run('npm', ['pack', '--verbose', '.'], function() {
require('tmp').dir(function(err, dir) {
if (err) {
grunt.log.error(err);
done(false);
return;
}
run('cp', [tgz, dir], function() {
run('npm', [
'install',
'--production',
tgz,
], {cwd: dir}, function() {
var nodePath = path.join(dir, 'node_modules');
var pkgDir = path.join(nodePath, pkg.name);
var doneCount = 2;
// Make sure that bin/jsx is runnable by echoing main.js.
run('bin/jsx', ['main.js'], {
cwd: pkgDir,
}, function(result) {
assert.ok(result.stdout.indexOf('transform') >= 0, result.stdout);
if (--doneCount === 0) {
done();
}
});
// Make sure the .transform package method works.
run('node', [
'--print',
'require(\'react-tools\').transform(' +
JSON.stringify(
'/** @jsx React.DOM */ <div>oyez</div>;'
) + ')',
], {
env: {NODE_PATH: nodePath},
}, function(result, code) {
assert.ok(result.stdout.indexOf(
'React.DOM.div(null, \'oyez\');'
) >= 0, result.stdout);
if (--doneCount === 0) {
done();
}
});
});
});
});
});
};
-115
View File
@@ -1,115 +0,0 @@
'use strict';
var grunt = require('grunt');
var BOWER_PATH = '../react-bower/';
var BOWER_GLOB = [BOWER_PATH + '*.{js}'];
var BOWER_FILES = [
'react.js',
'react.min.js',
'react-dom.js',
'react-dom.min.js',
'react-dom-server.js',
'react-dom-server.min.js',
];
var VERSION;
var VERSION_STRING;
function _gitCommitAndTag(cwd, commitMsg, tag, cb) {
// `git add *` to make sure we catch untracked files
// `git add -u` to make sure we remove deleted files
// `git commit -m {commitMsg}`
// `git tag -a {tag}`
var opts = {cwd: cwd};
var gitAddAll = {
cmd: 'git',
args: ['add', '*'],
opts: opts,
};
var gitAddDel = {
cmd: 'git',
args: ['add', '-u'],
opts: opts,
};
var gitCommit = {
cmd: 'git',
args: ['commit', '-m', commitMsg],
opts: opts,
};
var gitTag = {
cmd: 'git',
args: ['tag', tag],
opts: opts,
};
grunt.util.spawn(gitAddAll, function() {
grunt.util.spawn(gitAddDel, function() {
grunt.util.spawn(gitCommit, function() {
if (tag) {
grunt.util.spawn(gitTag, cb);
} else {
cb();
}
});
});
});
}
function setup() {
if (!grunt.file.exists(BOWER_PATH)) {
grunt.log.error('Make sure you have the react-bower repository checked ' +
'out at ../react-bower');
return false;
}
VERSION = grunt.config.data.pkg.version;
VERSION_STRING = 'v' + VERSION;
}
function bower() {
var done = this.async();
// clean out the bower folder in case we're removing files
var files = grunt.file.expand(BOWER_GLOB);
files.forEach(function(file) {
grunt.file.delete(file, {force: true});
});
// Now copy over build files
BOWER_FILES.forEach(function(file) {
grunt.file.copy('build/' + file, BOWER_PATH + file);
});
// Commit and tag the repo
_gitCommitAndTag(BOWER_PATH, VERSION_STRING, VERSION_STRING, done);
}
function docs() {
grunt.file.copy('build/react.js', 'docs/js/react.js');
grunt.file.copy('build/react-dom.js', 'docs/js/react-dom.js');
}
function msg() {
// Just output a friendly reminder message for the rest of the process
grunt.log.subhead('Release *almost* complete...');
var steps = [
'Still todo:',
'* push this repo with tags',
'* push bower repo with tags',
'* run `npm-publish` in rrm',
'* create release on github',
'* for a major release, update docs branch variable in Travis CI',
'* announce it on FB/Twitter/mailing list',
];
steps.forEach(function(ln) {
grunt.log.writeln(ln);
});
}
module.exports = {
setup: setup,
bower: bower,
docs: docs,
msg: msg,
};
-48
View File
@@ -1,48 +0,0 @@
/**
* 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(
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();
});
};
};
-49
View File
@@ -1,49 +0,0 @@
/**
* 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(
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();
});
};
};
-52
View File
@@ -1,52 +0,0 @@
/**
* 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 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-test-renderer/package.json':
require('../../packages/react-test-renderer/package.json').version,
'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();
};
};
-291
View File
@@ -1,291 +0,0 @@
/**
* 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 babel = require('gulp-babel');
var flatten = require('gulp-flatten');
var del = require('del');
var merge = require('merge-stream');
var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
var stripProvidesModule = require('fbjs-scripts/gulp/strip-provides-module');
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: [
'src/umd/ReactUMDEntry.js',
'src/umd/shims/**/*.js',
'src/isomorphic/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react/lib',
},
reactDOM: {
src: [
'src/umd/ReactDOMUMDEntry.js',
'src/umd/ReactDOMServerUMDEntry.js',
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-dom/lib',
},
reactNative: {
src: [
'src/renderers/native/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-native/lib',
},
reactTestRenderer: {
src: [
'src/renderers/testing/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-test-renderer/lib',
},
reactNoopRenderer: {
src: [
'src/renderers/noop/**/*.js',
'src/renderers/shared/**/*.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
'!src/**/__benchmarks__/**/*.js',
'!src/**/__tests__/**/*.js',
'!src/**/__mocks__/**/*.js',
],
lib: 'build/node_modules/react-noop-renderer/lib',
},
};
exports.paths = paths;
var moduleMapBase = {'object-assign': 'object-assign'};
var fbjsModules = require('fbjs/module-map');
for (var key in fbjsModules) {
var path = fbjsModules[key];
moduleMapBase[path] = path;
}
var moduleMapReact = Object.assign(
{
// Addons needs to reach into DOM internals
'react-dom': 'react-dom',
'react-dom/lib/ReactInstanceMap': 'react-dom/lib/ReactInstanceMap',
'react-dom/lib/ReactTestUtils': 'react-dom/lib/ReactTestUtils',
'react-dom/lib/ReactPerf': 'react-dom/lib/ReactPerf',
'react-dom/lib/getVendorPrefixedEventName': 'react-dom/lib/getVendorPrefixedEventName',
// Alias
'react': './React',
// Shared state
'react/lib/ReactCurrentOwner': './ReactCurrentOwner',
'react/lib/checkPropTypes': './checkPropTypes',
'react/lib/ReactComponentTreeHook': './ReactComponentTreeHook',
'react/lib/ReactDebugCurrentFrame': './ReactDebugCurrentFrame',
},
moduleMapBase
);
var rendererSharedState = {
// Alias
'react': 'react/lib/React',
// Shared state
'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwner',
'react/lib/checkPropTypes': 'react/lib/checkPropTypes',
'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHook',
'react/lib/ReactDebugCurrentFrame': 'react/lib/ReactDebugCurrentFrame',
};
var moduleMapReactDOM = Object.assign(
{
'react-dom': './ReactDOMFiber',
'react-dom/lib/ReactInstanceMap': './ReactInstanceMap',
'react-dom/lib/ReactTestUtils': './ReactTestUtils',
'react-dom/lib/ReactPerf': './ReactPerf',
'react-dom/lib/getVendorPrefixedEventName': './getVendorPrefixedEventName',
},
rendererSharedState,
moduleMapBase
);
var moduleMapReactNative = Object.assign(
{
// React Native Hooks
deepDiffer: 'react-native/lib/deepDiffer',
deepFreezeAndThrowOnMutationInDev: 'react-native/lib/deepFreezeAndThrowOnMutationInDev',
flattenStyle: 'react-native/lib/flattenStyle',
InitializeCore: 'react-native/lib/InitializeCore',
RCTEventEmitter: 'react-native/lib/RCTEventEmitter',
TextInputState: 'react-native/lib/TextInputState',
UIManager: 'react-native/lib/UIManager',
UIManagerStatTracker: 'react-native/lib/UIManagerStatTracker',
View: 'react-native/lib/View',
},
rendererSharedState,
moduleMapBase
);
var moduleMapReactTestRenderer = Object.assign(
{},
rendererSharedState,
moduleMapBase
);
var moduleMapReactNoopRenderer = Object.assign(
{},
rendererSharedState,
moduleMapBase
);
var errorCodeOpts = {
errorMapFilePath: 'scripts/error-codes/codes.json',
};
var babelOptsReact = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReact}],
],
};
var babelOptsReactDOM = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactDOM}],
],
};
var babelOptsReactNative = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactNative}],
],
};
var babelOptsReactTestRenderer = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactTestRenderer}],
],
};
var babelOptsReactNoopRenderer = {
plugins: [
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
[babelPluginModules, {map: moduleMapReactNoopRenderer}],
],
};
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,
paths.reactDOM.lib,
paths.reactNative.lib,
paths.reactTestRenderer.lib,
paths.reactNoopRenderer.lib,
]);
});
gulp.task('react:modules', function() {
return merge(
gulp
.src(paths.react.src)
.pipe(babel(babelOptsReact))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.react.lib)),
gulp
.src(paths.reactDOM.src)
.pipe(babel(babelOptsReactDOM))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.reactDOM.lib)),
gulp
.src(paths.reactNative.src)
.pipe(babel(babelOptsReactNative))
.pipe(stripProvidesModule())
.pipe(flatten())
.pipe(gulp.dest(paths.reactNative.lib)),
gulp
.src(paths.reactTestRenderer.src)
.pipe(stripProvidesModule())
.pipe(babel(babelOptsReactTestRenderer))
.pipe(flatten())
.pipe(gulp.dest(paths.reactTestRenderer.lib)),
gulp
.src(paths.reactNoopRenderer.src)
.pipe(stripProvidesModule())
.pipe(babel(babelOptsReactNoopRenderer))
.pipe(flatten())
.pipe(gulp.dest(paths.reactNoopRenderer.lib))
);
});
gulp.task('react:extract-errors', function() {
return gulp.src([].concat(
paths.react.src,
paths.reactDOM.src,
paths.reactNative.src,
paths.reactTestRenderer.src
)).pipe(extractErrors(errorCodeOpts));
});
gulp.task('default', ['react:modules']);
+5 -13
View File
@@ -57,15 +57,6 @@
"flow-bin": "^0.41.0",
"glob": "^6.0.4",
"glob-stream": "^6.1.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-compare-size": "^0.4.0",
"grunt-contrib-clean": "^0.6.0",
"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": "^19.0.1",
"jest-config": "^19.0.1",
@@ -104,13 +95,14 @@
"version": 7
},
"scripts": {
"build": "node scripts/rollup/build.js",
"build": "version-check && node scripts/rollup/build.js",
"linc": "git diff --name-only --diff-filter=ACMRTUB `git merge-base HEAD master` | grep '\\.js$' | xargs eslint --",
"lint": "grunt lint",
"lint": "node ./scripts/tasks/eslint.js",
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json",
"test": "jest",
"flow": "flow",
"prettier": "node ./scripts/prettier/index.js write"
"flow": "node ./scripts/tasks/flow.js",
"prettier": "node ./scripts/prettier/index.js write",
"version-check": "node ./scripts/tasks/version-check.js"
},
"jest": {
"modulePathIgnorePatterns": [
+33
View File
@@ -0,0 +1,33 @@
/**
* 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' : '';
spawn(
path.join('node_modules', '.bin', 'eslint' + extension),
[
'.',
],
{
// Allow colors to pass through
stdio: 'inherit',
}
).on('close', function(code) {
if (code !== 0) {
console.error('Lint failed');
process.exit(code);
}
console.log('Lint passed');
});
+33
View File
@@ -0,0 +1,33 @@
/**
* 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' : '';
spawn(
path.join('node_modules', '.bin', 'flow' + extension),
[
'check',
'.',
],
{
// Allow colors to pass through
stdio: 'inherit',
}
).on('close', function(code) {
if (code !== 0) {
console.log('Flow failed');
process.exit(code);
}
console.log('Flow passed');
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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';
const reactVersion = require('../../package.json').version;
const 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-test-renderer/package.json':
require('../../packages/react-test-renderer/package.json').version,
'src/ReactVersion.js': require('../../src/ReactVersion'),
};
let allVersionsMatch = true;
Object.keys(versions).forEach(function(name) {
const version = versions[name];
if (version !== reactVersion) {
allVersionsMatch = false;
console.log(
'%s version does not match package.json. Expected %s, saw %s.',
name,
reactVersion,
version
);
}
});
if (!allVersionsMatch) {
process.exit(1);
}