Skip to content

Commit

Permalink
fix(v1): v1 deploy preview should be available (#3517)
Browse files Browse the repository at this point in the history
* v1 deploy preview

* Add /v1-migrated deployment
  • Loading branch information
slorber authored Oct 2, 2020
1 parent 83db07e commit e670473
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ packages/docusaurus-theme-bootstrap/lib/
packages/docusaurus-migrate/lib/

website/netlifyDeployPreview
!website/netlifyDeployPreview/index.html
!website/netlifyDeployPreview/_redirects

website-1.x-migrated
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@
"test:v1Migration:migrate": "rimraf website-1.x-migrated && docusaurus-migrate migrate ./website-1.x ./website-1.x-migrated && sed -i -- 's/docusaurus-1-website/docusaurus-1-website-migrated/g;' website-1.x-migrated/package.json",
"test:v1Migration:start": "yarn workspace docusaurus-1-website-migrated start",
"test:v1Migration:build": "yarn workspace docusaurus-1-website-migrated build",
"test:baseUrl": "yarn build:v2:baseUrl && yarn serve:v2:baseUrl"
"test:baseUrl": "yarn build:v2:baseUrl && yarn serve:v2:baseUrl",
"netlify:deployPreview:v1": "yarn netlify:deployPreview:v1:setDeployPreviewVersions && yarn netlify:deployPreview:v1:build && yarn netlify:deployPreview:v1:moveBuild",
"netlify:deployPreview:v1:setDeployPreviewVersions": "yarn node -e 'require(\"./website-1.x/netlifyUtils\").setDeployPreviewVersions()'",
"netlify:deployPreview:v1:build": "BASE_URL=/v1/ yarn build:v1",
"netlify:deployPreview:v1:moveBuild": "mv website-1.x/build/docusaurus website/netlifyDeployPreview/v1",
"netlify:deployPreview:v1-migrated": "yarn test:v1Migration:migrate && yarn netlify:deployPreview:v1-migrated:setBaseUrl && yarn netlify:deployPreview:v1-migrated:build",
"netlify:deployPreview:v1-migrated:setBaseUrl": "sed -i -e 's,\"baseUrl\": \"/\",\"baseUrl\": \"/v1-migrated/\",g' ./website-1.x-migrated/docusaurus.config.js",
"netlify:deployPreview:v1-migrated:build": "yarn workspace docusaurus-1-website-migrated build --out-dir=../website/netlifyDeployPreview/v1-migrated"
},
"devDependencies": {
"@babel/cli": "^7.9.0",
Expand Down
14 changes: 13 additions & 1 deletion website-1.x/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,16 @@ const languages = [
tag: 'zh-TW',
},
];
module.exports = languages;

const onlyEnglish = [
{
enabled: true,
name: 'English',
tag: 'en',
},
];

// We want deploy previews to be fast
module.exports = require('./netlifyUtils').isDeployPreview
? onlyEnglish
: languages;
46 changes: 46 additions & 0 deletions website-1.x/netlifyUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.
*/

const fs = require('fs');
const path = require('path');

// This is useful to speed up v1 deployment in Netlify PR deploy previews
//
// Command to test locally:
// NETLIFY=true CONTEXT=deploy-preview yarn build:v1
// or
// NETLIFY=true CONTEXT=deploy-preview yarn netlify:deployPreview:v1
//
// See Netlify env variables here: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
const isDeployPreview =
process.env.NETLIFY === 'true' && process.env.CONTEXT === 'deploy-preview';
if (isDeployPreview) {
console.log('Docusaurus v1 running as a Netlify deploy preview');
}
exports.isDeployPreview = isDeployPreview;

// On netlify deploy previews, we don't deploy all versions to make deploy preview faster
function updateDeployPreviewVersions(versions) {
const newVersions = [versions[0], versions[versions.length - 1]];
console.log(
'Netlify deploy previews will only deploy a subset of available versions: ' +
newVersions.join(' - '),
);
return newVersions;
}

exports.setDeployPreviewVersions = function () {
const versions = JSON.parse(
fs.readFileSync(path.join(__dirname, 'versions.json'), 'utf8'),
);
const newVersions = updateDeployPreviewVersions(versions);
fs.writeFileSync(
path.join(__dirname, 'versions.json'),
JSON.stringify(newVersions, null, 2),
'utf8',
);
};
2 changes: 1 addition & 1 deletion website-1.x/siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const siteConfig = {
title: 'Docusaurus',
tagline: 'Easy to Maintain Open Source Documentation Websites',
url: 'https://docusaurus.io',
baseUrl: '/',
baseUrl: process.env.BASE_URL || '/',
organizationName: 'facebook',
projectName: 'docusaurus',
cname: 'docusaurus.io',
Expand Down
2 changes: 2 additions & 0 deletions website/netlifyDeployPreview/_redirects
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/classic/* /classic/404.html 200
/bootstrap/* /bootstrap/404.html 200
/blog-only/* /blog-only/404.html 200
/v1/* /v1/404.html 200
/v1-migrated/* /v1-migrated/404.html 200
/* /classic/
17 changes: 15 additions & 2 deletions website/netlifyDeployPreview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ <h1 style="margin-top: 20px;">
<p>When in doubt, try the <a href="/classic">classic preview</a></p>
</section>
<section style="margin-top: 40px;">
<h2>Available deploy previews:</h2>
<h2>V2 deploy previews:</h2>
<ul style="margin-top: 20px;">
<li style="margin-top: 20px;">
<a href="/classic">classic</a>: the regular site
<a href="/classic">classic</a>: the regular Docusaurus v2 site
</li>
<li style="margin-top: 20px;">
<a href="/bootstrap">bootstrap</a>: the regular site with the
Expand All @@ -27,5 +27,18 @@ <h2>Available deploy previews:</h2>
</li>
</ul>
</section>

<section style="margin-top: 40px;">
<h2>V1 deploy previews:</h2>
<ul style="margin-top: 20px;">
<li style="margin-top: 20px;">
<a href="/v1">v1</a>: the legacy Docusaurus v1 site
</li>
<li style="margin-top: 20px;">
<a href="/v1-migrated">v1-migrated</a>: the legacy Docusaurus v1 site,
migrated to v2 with the migration cli
</li>
</ul>
</section>
</body>
</html>
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"start:blogOnly": "DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn start",
"build:blogOnly": "DOCUSAURUS_CONFIG='docusaurus.config-blog-only.js' yarn build",
"netlify:build:production": "yarn build",
"netlify:build:deployPreview": "yarn netlify:build:deployPreview:classic && yarn netlify:build:deployPreview:bootstrap && yarn netlify:build:deployPreview:blogOnly",
"netlify:build:deployPreview": "yarn netlify:build:deployPreview:v1:all && yarn netlify:build:deployPreview:classic && yarn netlify:build:deployPreview:bootstrap && yarn netlify:build:deployPreview:blogOnly",
"netlify:build:deployPreview:classic": "BASE_URL='/classic/' yarn build --out-dir netlifyDeployPreview/classic",
"netlify:build:deployPreview:bootstrap": "BASE_URL='/bootstrap/' DOCUSAURUS_PRESET=bootstrap DISABLE_VERSIONING=true yarn build --out-dir netlifyDeployPreview/bootstrap",
"netlify:build:deployPreview:blogOnly": "yarn build:blogOnly --out-dir netlifyDeployPreview/blog-only",
"netlify:build:deployPreview:v1:all": "yarn --cwd .. netlify:deployPreview:v1 && yarn --cwd .. netlify:deployPreview:v1-migrated",
"netlify:test": "yarn netlify:build:deployPreview && yarn netlify dev --debug"
},
"dependencies": {
Expand Down

0 comments on commit e670473

Please sign in to comment.