2015-03-23 17:55:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-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.
|
|
|
|
*/
|
2015-02-12 04:26:43 +00:00
|
|
|
|
|
|
|
var request = require('request');
|
|
|
|
var glob = require('glob');
|
|
|
|
var fs = require('fs.extra');
|
|
|
|
var mkdirp = require('mkdirp');
|
|
|
|
var server = require('./server.js');
|
|
|
|
|
2015-03-16 02:32:59 +00:00
|
|
|
require('./convert.js')();
|
2015-03-16 02:54:14 +00:00
|
|
|
server.noconvert = true;
|
2015-03-16 02:32:59 +00:00
|
|
|
|
2015-02-12 04:26:43 +00:00
|
|
|
// Sadly, our setup fatals when doing multiple concurrent requests
|
|
|
|
// I don't have the time to dig into why, it's easier to just serialize
|
|
|
|
// requests.
|
|
|
|
var queue = (function() {
|
|
|
|
var is_executing = false;
|
|
|
|
var queue = [];
|
|
|
|
function push(fn) {
|
|
|
|
queue.push(fn);
|
|
|
|
execute();
|
|
|
|
}
|
|
|
|
function execute() {
|
|
|
|
if (is_executing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (queue.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var fn = queue.shift();
|
|
|
|
is_executing = true;
|
|
|
|
fn(function() {
|
|
|
|
is_executing = false;
|
2015-02-12 22:43:41 +00:00
|
|
|
execute();
|
2015-02-12 04:26:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return {push: push};
|
|
|
|
})();
|
|
|
|
|
|
|
|
glob('src/**/*.*', function(er, files) {
|
|
|
|
files.forEach(function(file) {
|
|
|
|
var targetFile = file.replace(/^src/, 'build');
|
|
|
|
|
|
|
|
if (file.match(/\.js$/)) {
|
|
|
|
targetFile = targetFile.replace(/\.js$/, '.html');
|
|
|
|
queue.push(function(cb) {
|
|
|
|
request('http://localhost:8079/' + targetFile.replace(/^build\//, ''), function(error, response, body) {
|
|
|
|
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
|
|
|
fs.writeFileSync(targetFile, body);
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
queue.push(function(cb) {
|
|
|
|
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
|
|
|
fs.copy(file, targetFile, cb);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
queue.push(function(cb) {
|
|
|
|
server.close();
|
|
|
|
console.log('It is live at: http://facebook.github.io/react-native/')
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|