From 7be14d81552e8097eee6ed21a048fa23d4fce596 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 16 Jul 2013 20:38:40 -0700 Subject: [PATCH] Add React.version getConfig needs to be a function because grunt.config.data.pkg.version isn't available at the time that grunt/config/jsx/jsx.js is required. Test Plan: grunt build, grunt lint, grunt test all work. After building, both react.js and react.min.js contain the version number. --- grunt/config/jsx/debug.json | 6 ------ grunt/config/jsx/jsx.js | 39 +++++++++++++++++++++++++++++++---- grunt/config/jsx/release.json | 6 ------ grunt/config/jsx/test.json | 7 ------- grunt/tasks/jsx.js | 5 ++++- src/.jshintrc | 1 + src/core/React.js | 1 + 7 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 grunt/config/jsx/debug.json delete mode 100644 grunt/config/jsx/release.json delete mode 100644 grunt/config/jsx/test.json diff --git a/grunt/config/jsx/debug.json b/grunt/config/jsx/debug.json deleted file mode 100644 index 1596c562e8..0000000000 --- a/grunt/config/jsx/debug.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "debug": true, - "constants": { - "__DEV__": true - } -} diff --git a/grunt/config/jsx/jsx.js b/grunt/config/jsx/jsx.js index b8a049da92..d1602f6f91 100644 --- a/grunt/config/jsx/jsx.js +++ b/grunt/config/jsx/jsx.js @@ -1,12 +1,24 @@ 'use strict'; +var grunt = require('grunt'); + var rootIDs = [ "React" ]; +var getDebugConfig = function() { + return { + "debug": true, + "constants": { + "__VERSION__": grunt.config.data.pkg.version, + "__DEV__": true + } + }; +}; + var debug = { rootIDs: rootIDs, - configFile: "grunt/config/jsx/debug.json", + getConfig: getDebugConfig, sourceDir: "src", outputDir: "build/modules" }; @@ -15,7 +27,7 @@ var jasmine = { rootIDs: [ "all" ], - configFile: debug.configFile, + getConfig: getDebugConfig, sourceDir: "vendor/jasmine", outputDir: "build/jasmine" }; @@ -25,18 +37,37 @@ var test = { "test/all.js", "**/__tests__/*.js" ]), - configFile: "grunt/config/jsx/test.json", + getConfig: function() { + return { + "debug": true, + "mocking": true, + "constants": { + "__VERSION__": grunt.config.data.pkg.version, + "__DEV__": true + } + }; + }, sourceDir: "src", outputDir: "build/modules" }; + var release = { rootIDs: rootIDs, - configFile: "grunt/config/jsx/release.json", + getConfig: function() { + return { + "debug": false, + "constants": { + "__VERSION__": grunt.config.data.pkg.version, + "__DEV__": false + } + }; + }, sourceDir: "src", outputDir: "build/modules" }; + module.exports = { debug: debug, jasmine: jasmine, diff --git a/grunt/config/jsx/release.json b/grunt/config/jsx/release.json deleted file mode 100644 index 1dd48f20fd..0000000000 --- a/grunt/config/jsx/release.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "debug": false, - "constants": { - "__DEV__": false - } -} diff --git a/grunt/config/jsx/test.json b/grunt/config/jsx/test.json deleted file mode 100644 index e897023aab..0000000000 --- a/grunt/config/jsx/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "debug": true, - "mocking": true, - "constants": { - "__DEV__": true - } -} diff --git a/grunt/tasks/jsx.js b/grunt/tasks/jsx.js index 290816711f..62bcecff70 100644 --- a/grunt/tasks/jsx.js +++ b/grunt/tasks/jsx.js @@ -24,7 +24,7 @@ module.exports = function() { }); args.push.apply(args, rootIDs); - args.push("--config", config.configFile); + args.push("--config" /* from stdin */); var child = spawn({ cmd: "bin/jsx", @@ -38,6 +38,9 @@ module.exports = function() { } }); + child.stdin.write(JSON.stringify(config.getConfig())); + child.stdin.end(); + child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); }; diff --git a/src/.jshintrc b/src/.jshintrc index 60ff8d05c2..f098432e6d 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -19,6 +19,7 @@ "unused": "vars", "globals": { + "__VERSION__": false, "__DEV__": false, "require": false, "module": false, diff --git a/src/core/React.js b/src/core/React.js index 1d7d9c3a0e..bee85668e9 100644 --- a/src/core/React.js +++ b/src/core/React.js @@ -30,6 +30,7 @@ var ReactDefaultInjection = require('ReactDefaultInjection'); ReactDefaultInjection.inject(); var React = { + version: __VERSION__, DOM: ReactDOM, PropTypes: ReactPropTypes, initializeTouchEvents: function(shouldUseTouch) {