-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 9 commits
5668269
b06bc48
bf25220
cc2b436
056027f
87e4019
a0d2cd3
cade110
52dab87
70e8de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
})(); |
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Video shows 7.X, 6.X and master. what am I missing ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Video is old, but you can run it locally. Just do |
||
|
||
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; |
This file was deleted.
There was a problem hiding this comment.
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