Skip to content

Commit

Permalink
Reduce versions to build on Netlify (#757)
Browse files Browse the repository at this point in the history
* Reduce versions to build on Netlify

* Remove imagebackground and safeareaview from 0.5

* Keep 0.46 and 0.50
  • Loading branch information
charpeni authored and cpojer committed Feb 8, 2019
1 parent 5fe4532 commit 2281c8a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]
base = "website"
publish = "website/build/react-native"
command = "sed -i -e \"s|const baseUrl .*|const baseUrl = '/';|g\" siteConfig.js && yarn install && yarn build"
command = "sed -i -e \"s|const baseUrl .*|const baseUrl = '/';|g\" siteConfig.js && yarn install && node netlify-reduce-versions && yarn build"
48 changes: 48 additions & 0 deletions website/netlify-reduce-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* During the build process, we build a complete website for each version
* which is 9.2 MB / version.
*
* On Netlify, our deploy preview infrastructure, we have to upload every
* changed file. Each time we cut a new version or making multiple changes
* we're facing timeout errors from Netlify trying to upload megabytes of HTML
* file.
*
* This script makes sure we're not deploying unnecessary versions on Netlify.
*
* We only need 0.5 which is the first draft of each doc, and the recent ones.
*/

const fs = require('fs-extra');
const versions = require('./versions.json');

const filterWantedVersions = version =>
+version === 0.5 ||
((version.length > 3 && +version >= 0.56) ||
+version === 0.46 ||
version === '0.50');

fs.writeFileSync(
'./versions.json',
JSON.stringify(versions.filter(filterWantedVersions))
);

fs.readdirSync('./versioned_docs').map(directory => {
if (!filterWantedVersions(directory.replace('version-', ''))) {
fs.removeSync(`./versioned_docs/${directory}`);
}
});

fs.readdirSync('./versioned_sidebars').map(directory => {
const match = /version-(\d.\d\d?)-sidebars.json/g.exec(directory);

if (match && !filterWantedVersions(match[1])) {
fs.removeSync(`./versioned_sidebars/${directory}`);
}
});

0 comments on commit 2281c8a

Please sign in to comment.