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.
|
|
|
|
*/
|
2016-02-11 14:16:34 +00:00
|
|
|
'use strict';
|
2015-02-12 04:26:43 +00:00
|
|
|
|
2015-04-02 00:41:02 +00:00
|
|
|
var Promise = require('bluebird');
|
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.
|
2015-04-02 00:41:02 +00:00
|
|
|
var queue = Promise.resolve();
|
2015-02-12 04:26:43 +00:00
|
|
|
|
2015-10-14 18:40:16 +00:00
|
|
|
glob('src/**/*.*', function(er, files) {
|
2015-02-12 04:26:43 +00:00
|
|
|
files.forEach(function(file) {
|
|
|
|
var targetFile = file.replace(/^src/, 'build');
|
|
|
|
|
2015-10-14 18:40:16 +00:00
|
|
|
if (file.match(/\.js$/) && !file.match(/src\/react-native\/js/)) {
|
2015-02-12 04:26:43 +00:00
|
|
|
targetFile = targetFile.replace(/\.js$/, '.html');
|
2015-04-02 00:41:02 +00:00
|
|
|
queue = queue.then(function() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
request('http://localhost:8079/' + targetFile.replace(/^build\//, ''), function(error, response, body) {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (response.statusCode != 200) {
|
2015-05-07 23:05:30 +00:00
|
|
|
reject(new Error('Status ' + response.statusCode + ':\n' + body));
|
2015-04-02 00:41:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
|
|
|
fs.writeFileSync(targetFile, body);
|
|
|
|
resolve();
|
|
|
|
});
|
2015-02-12 04:26:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2015-04-02 00:41:02 +00:00
|
|
|
queue = queue.then(function() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
|
|
|
fs.copy(file, targetFile, resolve);
|
|
|
|
});
|
2015-02-12 04:26:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-02 00:41:02 +00:00
|
|
|
queue = queue.then(function() {
|
2016-02-11 14:16:34 +00:00
|
|
|
console.log('Generated HTML files from JS');
|
2015-04-02 00:41:02 +00:00
|
|
|
}).finally(function() {
|
2015-02-12 04:26:43 +00:00
|
|
|
server.close();
|
2015-04-02 01:31:18 +00:00
|
|
|
}).catch(function(e) {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
2015-02-12 04:26:43 +00:00
|
|
|
});
|
|
|
|
});
|