Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: fix version display #582

Merged
merged 10 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ matrix:

# Website
- language: node_js
addons:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed by nodegit

apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++-4.9-dev
env:
- NAME='Website - master'
node_js: 8
Expand Down
7 changes: 7 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ website/node_modules

website/i18n/*
!website/i18n/en.json

versioned_docs/*
!versioned_docs/.gitkeep

versioned_sidebars/*
!versioned_sidebars/.gitkeep
versions.json
114 changes: 114 additions & 0 deletions website/gatherDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env node
const fs = require("fs-extra");
const git = require("nodegit");
const execSync = require("child_process").execSync;
const { major, lt } = require("semver");
const REPO_URL = "https://github.com/wix/detox.git";

async function getVersions() {
const tmp = fs.mkdtempSync("detox-versions");
const repo = await git.Clone(REPO_URL, tmp);
const tags = await git.Tag.list(repo);

const semverTags = tags
.filter(tag => !tag.includes("@"))
.filter(tag => tag.split(".").length === 3 && major(tag) >= 7)
.sort()
.reverse();
await fs.remove(tmp);
return semverTags;
}

const sidebars = [];

async function cleanupExistingVersions() {
console.log("Cleanup versioned docs");
await fs.remove("./versions.json");
await fs.emptyDir("./versioned_docs");
await fs.emptyDir("./versioned_sidebars");
}

// https://stackoverflow.com/questions/29569913/switch-branch-tag-with-nodegit?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
function checkOutTag(repo, tag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, utm_source will provide false data for trackers next time someone opens this link ;p
JK, but the query string can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll get rid of that and see if I can get a better permalink

return git.Reference
.dwim(repo, "refs/tags/" + tag)
.then(function (ref) {
return ref.peel(git.Object.TYPE.COMMIT);
})
.then(function (ref) {
return repo.getCommit(ref);
})
.then(function (commit) {
return git.Checkout
.tree(repo, commit, { checkoutStrategy: git.Checkout.STRATEGY.FORCE })
.then(function () {
return repo.setHeadDetached(commit, repo.defaultSignature,
"Checkout: HEAD " + commit.id());
})
});
}

async function checkoutVersion(repo, version) {
console.log("Checking out version", version);
repo.cleanup();
await checkOutTag(repo, version);
}

function fixMarkdownForPre7_3_4_versions(tempDir) {
// We need to do this as we forgot the header in this one file, but added git tags with it included
console.log("Temporary fix for Guide.DebuggingInXcode");
const header =
"---\nid: Guide.DebuggingInXcode\ntitle: Debugging in Xcode During Detox Tests\n---";
execSync(
`echo "${header}" | cat - Guide.DebuggingInXcode.md > /tmp/out && mv /tmp/out Guide.DebuggingInXcode.md`,
{
cwd: tempDir + "/docs"
}
);
}

function generateAndCopyDocusaurusVersion(tempDir, version) {
console.log("Generating versioned doc for", version);
execSync(
`npm install && rm versions.json && rm -rf {versioned_docs,versioned_sidebars} && npm run version ${version}`,
{ cwd: tempDir + "/website" }
);

console.log("Copy versioned doc");
fs.copySync(
`${tempDir}/website/versioned_docs/version-${version}`,
`./versioned_docs/version-${version}`
);

console.log("Copy sidebar into versioned_sidebars");
fs.copyFileSync(
`${tempDir}/website/versioned_sidebars/version-${version}-sidebars.json`,
`./versioned_sidebars/version-${version}-sidebars.json`
);
}

async function cleanUp(tempDir) {
console.log("Cleanup temporary clone");
await fs.remove(tempDir);
}

(async function() {
const versions = await getVersions();
await cleanupExistingVersions();

fs.writeFileSync("./versions.json", JSON.stringify(versions), "utf8");
const tempDir = fs.mkdtempSync("detox-documentation-generation");
const repo = await git.Clone(REPO_URL, tempDir);

for (let version of versions) {
console.log("Clone repository into tmp directory");
await checkoutVersion(repo, version);
if (lt(version, "7.3.4")) {
fixMarkdownForPre7_3_4_versions(tempDir);
}
generateAndCopyDocusaurusVersion(tempDir, version);
repo.cleanup(tempDir);
console.log(`Done with ${version}\n\n`);
}
await cleanUp(tempDir);
})();
2 changes: 1 addition & 1 deletion website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"APIRef.TestLifecycle": "Test Lifecycle",
"APIRef.waitFor": "Manual Synchronization Using `waitFor`",
"Guide.Contributing": "Contributing",
"Guide.DebuggingInXcode": "Debugging Apps in Xcode During a Test",
"Guide.DebuggingInXcode": "Debugging in Xcode During Detox Tests",
"Guide.DevelopingWhileWritingTests": "Developing Your App While Writing Tests",
"Guide.Jest": "Jest",
"Guide.Migration": "Migration Guide",
Expand Down
9 changes: 8 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
"examples": "docusaurus-examples",
"start": "docusaurus-start",
"build": "docusaurus-build",
"prepublish-gh-pages": "npm run gatherDocs",
"publish-gh-pages": "docusaurus-publish",
"write-translations": "docusaurus-write-translations",
"version": "docusaurus-version",
"rename-version": "docusaurus-rename-version"
"rename-version": "docusaurus-rename-version",
"gatherDocs": "node ./gatherDocs"
},
"devDependencies": {
"docusaurus": "^1.0.4"
},
"dependencies": {
"fs-extra": "^5.0.0",
"nodegit": "^0.21.0",
"semver": "^5.5.0"
}
}
83 changes: 83 additions & 0 deletions website/pages/en/versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const React = require('react');

const CompLibrary = require('../../core/CompLibrary');
const Container = CompLibrary.Container;
const GridBlock = CompLibrary.GridBlock;

const CWD = process.cwd();

const siteConfig = require(CWD + '/siteConfig.js');
const versions = require(CWD + '/versions.json');
const githubReleaseUrl = version => `https://github.com/wix/detox/releases/tag/${version}`;
const documentationTarget = "Introduction.GettingStarted.html"

function VersionLinks({version, isLatest = false}) {
const expandedVersion = version.replace('.X', '.0.0')
const isMaster = version === "master";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get what the final result will be. Will site show exact version (i.e. 7.3.5) or 7.0.0 throughout links ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Video shows 7.X, 6.X and master. what am I missing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Video is old, but you can run it locally. Just do cd website/ && npm install && npm run gatherDocs && npm start and you can see the site


const docIdentifier = isMaster ? "next/" : (isLatest ? "" : version + "/");

return (
<tr key={version}>
<th>{version}</th>
<td>
<a href={`docs/${docIdentifier}${documentationTarget}`}>Documentation</a>
</td>
<td>
<a href={isMaster ? "https://github.com/wix/detox" : githubReleaseUrl(expandedVersion)}>Release Notes</a>
</td>
</tr>
)
}

class Versions extends React.Component {
render() {
const latestVersion = versions[0];
return (
<div className="docMainWrapper wrapper">
<Container className="mainContainer versionsContainer">
<div className="post">
<header className="postHeader">
<h2>{siteConfig.title + ' Versions'}</h2>
</header>
<a name="latest" />
<h3>Current version (Stable)</h3>
<table className="versions">
<tbody>
<VersionLinks version={latestVersion} isLatest />
</tbody>
</table>
<p>
This is the version that is configured automatically when you
first install this project.
</p>
<a name="rc" />
<h3>Pre-release versions</h3>
<table className="versions">
<tbody>
<VersionLinks version="master" />
</tbody>
</table>
<p>Other text describing this section.</p>
<a name="archive" />
<h3>Past Versions</h3>
<table className="versions">
<tbody>
{versions
.filter(version => version !== latestVersion)
.map(version => <VersionLinks version={version} />)
}
</tbody>
</table>
<p>
You can find past versions of this project{' '}
<a href="https://github.com/wix/detox/releases"> on GitHub </a>.
</p>
</div>
</Container>
</div>
);
}
}

module.exports = Versions;
110 changes: 0 additions & 110 deletions website/versioned_docs/version-6.X/APIRef.ActionsOnElement.md

This file was deleted.

Loading