Skip to content

Commit

Permalink
Move react-source gem out of project root
Browse files Browse the repository at this point in the history
Now it requires a build step. At least the confusing lib directory is
gone though.
  • Loading branch information
zpao committed Jul 22, 2014
1 parent 04e3419 commit 520c4f9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
15 changes: 6 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var releaseTasks = require('./grunt/tasks/release');
var npmReactTasks = require('./grunt/tasks/npm-react');
var npmReactToolsTasks = require('./grunt/tasks/npm-react-tools');
var versionCheckTask = require('./grunt/tasks/version-check');
var gemReactSourceTasks = require('./grunt/tasks/gem-react-source');

module.exports = function(grunt) {

Expand Down Expand Up @@ -68,6 +69,8 @@ module.exports = function(grunt) {
grunt.registerTask('npm-react:pack', npmReactTasks.packRelease);
grunt.registerTask('npm-react-tools:release', npmReactToolsTasks.buildRelease);
grunt.registerTask('npm-react-tools:pack', npmReactToolsTasks.packRelease);
grunt.registerTask('gem-react-source:release', gemReactSourceTasks.buildRelease);
grunt.registerTask('gem-react-source:pack', gemReactSourceTasks.packRelease);

grunt.registerTask('version-check', versionCheckTask);

Expand Down Expand Up @@ -96,6 +99,7 @@ module.exports = function(grunt) {
'populist:test'
]);
grunt.registerTask('build:npm-react', ['version-check', 'jsx:normal', 'npm-react:release']);
grunt.registerTask('build:gem-react-source', ['build', 'gem-react-source:release'])

grunt.registerTask('webdriver-phantomjs', webdriverPhantomJSTask);

Expand Down Expand Up @@ -238,22 +242,15 @@ module.exports = function(grunt) {
'release:setup',
'clean',
'build',
'gem:only',
'gem-react-source:release',
'gem-react-source:pack',
'release:bower',
'release:starter',
'compress',
'release:docs',
'release:msg'
]);

// `gem` task to build the react-source gem
grunt.registerTask('gem', ['build', 'gem:only']);

grunt.registerTask('gem:only', function() {
var done = this.async();
exec('gem build react-source.gemspec', done);
});

// The default task - build - to keep setup easy
grunt.registerTask('default', ['build']);
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#encoding: utf-8

require('json')
package = JSON.parse(File.read('package.json'))

# Because of build process, does not necessarily reflect directory path in the
# repository.
package = JSON.parse(File.read('../../package.json'))

gemspec = Gem::Specification.new do |s|
s.name = 'react-source'
Expand Down
61 changes: 61 additions & 0 deletions grunt/tasks/gem-react-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

var fs = require('fs');
var grunt = require('grunt');

var src = 'gem-react-source/';
var dest = 'build/gem-react-source/';
var build = dest + 'build/';
var buildFiles = [
'react.js', 'react.min.js', 'JSXTransformer.js',
'react-with-addons.js', 'react-with-addons.min.js'
];

function buildRelease() {
grunt.file.exists(dest) && grunt.file.delete(dest);

// Copy gem-react-source/**/* to build/gem-react-source
var mappings = [].concat(
grunt.file.expandMapping('**/*', dest, {cwd: src})
);
mappings.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);
}
});

// Make built source available inside npm package
grunt.file.mkdir(build);
buildFiles.forEach(function(file) {
grunt.file.copy('build/' + file, build + file);
});
}

function packRelease() {
/*jshint validthis:true */
var done = this.async();
var spawnCmd = {
cmd: 'gem',
args: ['build', 'react-source.gemspec'],
opts: {
cwd: dest
}
};
grunt.util.spawn(spawnCmd, function(err, result) {
// Gem packing does weird things to versions so 0.12.0-alpha becomes
// 0.12.0.pre.alpha. We need to get the filename printed to stdout.
var filename = result.stdout.match(/File: (.*)$/)[1];
var src = 'build/gem-react-source/' + filename;
var dest = 'build/react-source.tgz';
fs.rename(src, dest, done);
});
}

module.exports = {
buildRelease: buildRelease,
packRelease: packRelease
};
4 changes: 2 additions & 2 deletions grunt/tasks/npm-react-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function buildRelease() {

pkgFiles.map(function(file) {
if (grunt.file.isDir(file)) {
mappings = mappings.concat(grunt.file.expandMapping(file + '**/*', dest))
mappings = mappings.concat(grunt.file.expandMapping(file + '**/*', dest));
} else {
mappings.push({src: [file], dest: dest + file})
mappings.push({src: [file], dest: dest + file});
}
});

Expand Down

0 comments on commit 520c4f9

Please sign in to comment.