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');
|
2016-10-28 20:27:33 +00:00
|
|
|
var Feed = require('feed');
|
2015-02-12 04:26:43 +00:00
|
|
|
|
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
|
|
|
|
2016-10-28 20:27:33 +00:00
|
|
|
// Generate RSS Feeds
|
|
|
|
queue = queue.then(function() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var targetFile = 'build/react-native/blog/feed.xml';
|
|
|
|
|
|
|
|
var basePath = 'https://facebook.github.io/react-native/';
|
|
|
|
var blogPath = basePath + 'blog/';
|
|
|
|
|
|
|
|
var metadataBlog = JSON.parse(fs.readFileSync('server/metadata-blog.json'));
|
|
|
|
var latestPost = metadataBlog.files[0];
|
|
|
|
var feed = new Feed({
|
|
|
|
title: 'React Native Blog',
|
|
|
|
description: 'The best place to stay up-to-date with the latest React Native news and events.',
|
|
|
|
id: blogPath,
|
|
|
|
link: blogPath,
|
|
|
|
image: basePath + 'img/header_logo.png',
|
|
|
|
copyright: 'Copyright © ' + new Date().getFullYear() + ' Facebook Inc.',
|
|
|
|
updated: new Date(latestPost.publishedAt),
|
|
|
|
});
|
|
|
|
|
|
|
|
metadataBlog.files.forEach(function(post) {
|
|
|
|
var url = blogPath + post.path;
|
|
|
|
feed.addItem({
|
|
|
|
title: post.title,
|
|
|
|
id: url,
|
|
|
|
link: url,
|
|
|
|
date: new Date(post.publishedAt),
|
|
|
|
author: [{
|
|
|
|
name: post.author,
|
|
|
|
link: post.authorURL
|
|
|
|
}],
|
2016-11-02 12:31:52 +00:00
|
|
|
description: post.excerpt,
|
2016-10-28 20:27:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
mkdirp.sync(targetFile.replace(new RegExp('/[^/]*$'), ''));
|
|
|
|
fs.writeFileSync(targetFile, feed.render('atom-1.0'));
|
|
|
|
console.log('Generated RSS feed')
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Generate HTML for each non-source code JS file
|
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
|
|
|
});
|
|
|
|
});
|