Skip to content

react-core npm module #442

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

Closed
wants to merge 1 commit 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
26 changes: 22 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var populistTask = require('./grunt/tasks/populist');
var phantomTask = require('./grunt/tasks/phantom');
var npmTask = require('./grunt/tasks/npm');
var releaseTasks = require('./grunt/tasks/release');
var reactCoreTasks = require('./grunt/tasks/react-core');

module.exports = function(grunt) {

Expand Down Expand Up @@ -52,17 +53,33 @@ module.exports = function(grunt) {

grunt.registerMultiTask('npm', npmTask);

grunt.registerTask('react-core:release', reactCoreTasks.buildRelease);

// Check that the version we're exporting is the same one we expect in the
// package. This is not an ideal way to do this, but makes sure that we keep
// them in sync.
var reactVersionExp = /\bReact\.version\s*=\s*['"]([^'"]+)['"];/;
grunt.registerTask('version-check', function() {
var version = reactVersionExp.exec(
var reactVersion = reactVersionExp.exec(
grunt.file.read('./build/modules/React.js')
)[1];
var expectedVersion = grunt.config.data.pkg.version;
if (version !== expectedVersion) {
grunt.log.error('Versions do not match. Expected %s, saw %s', expectedVersion, version);
var reactCoreVersion = grunt.file.readJSON('./npm-react-core/package.json').version;
var reactToolsVersion = grunt.config.data.pkg.version;

if (reactVersion !== reactToolsVersion) {
grunt.log.error(
'React version does not match react-tools version. Expected %s, saw %s',
reactToolsVersion,
reactVersion
);
return false;
}
if (reactCoreVersion !== reactToolsVersion) {
grunt.log.error(
'react-core version does not match react-tools veersion. Expected %s, saw %s',
reactToolsVersion,
reactCoreVersion
);
return false;
}
});
Expand All @@ -79,6 +96,7 @@ module.exports = function(grunt) {
'populist:jasmine',
'populist:test'
]);
grunt.registerTask('build:react-core', ['version-check', 'jsx:release', 'react-core:release']);

grunt.registerTask('test', ['build:test', 'build:basic', 'phantom:run']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
Expand Down
47 changes: 47 additions & 0 deletions grunt/tasks/react-core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var grunt = require('grunt');

var src = 'npm-react-core/';
var dest = 'build/react-core/';
var modSrc = 'build/modules/';
var lib = dest + 'lib/';

function buildRelease() {
// delete build/react-core for fresh start
grunt.file.exists(dest) && grunt.file.delete(dest);

// mkdir -p build/react-core/lib
grunt.file.mkdir(lib);

// Copy everything over
// console.log(grunt.file.expandMapping(src + '**/*', dest, {flatten: true}));
grunt.file.expandMapping(src + '**/*', dest, {flatten: true}).forEach(function(mapping) {
var src = mapping.src[0];
var dest = mapping.dest;
if (grunt.file.isDir(src)) {
grunt.file.mkdir(dest);
} else {
grunt.file.copy(src, dest);
}
});

// copy build/modules/*.js to build/react-core/lib
grunt.file.expandMapping(modSrc + '*.js', lib, { flatten: true }).forEach(function(mapping) {
grunt.file.copy(mapping.src[0], mapping.dest);
});

// 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 buildDev() {
// TODO: same as above except different destination
}

module.exports = {
buildRelease: buildRelease,
buildDev: buildDev
};
21 changes: 21 additions & 0 deletions npm-react-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# react-core

An npm package to get you immediate access to `React`, without also requiring
the JSX transformer. This is especially useful for cases where you want to
[`browserify`](https://github.com/substack/node-browserify) your module using
`React`.

## Example Usage

```js

// Previously, you might access React with react-tools.
var React = require('react-tools').React;

// Now you can access React directly with react-core.
var React = require('react-core');

// You can also access ReactWithAddons.
var React = require('react-core/addons');
```

1 change: 1 addition & 0 deletions npm-react-core/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/ReactWithAddons');
29 changes: 29 additions & 0 deletions npm-react-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "react-core",
"version": "0.6.0-alpha",
"keywords": [
"react"
],
"homepage": "https://github.com/facebook/react/tree/master/npm-react-core",
"bugs": "https://github.com/facebook/react/issues?labels=react-core",
"licenses": [
{
"type": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
],
"files": [
"README.md",
"addons.js",
"react.js",
"lib/"
],
"main": "react.js",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react"
},
"engines": {
"node": ">=0.10.0"
}
}
1 change: 1 addition & 0 deletions npm-react-core/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/React');