Skip to content

Commit

Permalink
Gather doc versions from git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Mar 7, 2018
1 parent f18813b commit 74e6108
Show file tree
Hide file tree
Showing 51 changed files with 88 additions and 4,181 deletions.
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:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++-4.9-dev
env:
- NAME='Website - master'
node_js: 8
Expand Down
1 change: 1 addition & 0 deletions scripts/publish-website.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ else
echo "machine github.com login $GIT_USER password $GIT_TOKEN" > ~/.netrc;
cd website;
npm install;
npm run gatherDocs
GIT_USER=$GIT_USER CURRENT_BRANCH=master npm run publish-gh-pages;
fi
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
68 changes: 68 additions & 0 deletions website/gatherDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env node
const fs = require("fs-extra");
const git = require("nodegit");
const execSync = require('child_process').execSync;
const REPO_URL = "https://github.com/wix/detox.git"

// From https://gist.github.com/joerx/3296d972735adc5b4ec1
function clearRequireCache() {
Object.keys(require.cache).forEach(function (key) {
delete require.cache[key];
});
}

function getMajorVersion(tag) {
return parseInt(tag.split('.')[0], 10)
}

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

const semverTags = tags
.filter(tag => tag.split('.').length === 3 && getMajorVersion(tag) >= 6)
.sort()
.reverse();
await fs.remove(tmp);
return semverTags;
}

const sidebars = [];

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

fs.writeFileSync("./versions.json", JSON.stringify(versions), "utf8");
for (let version of versions) {
const tempDir = fs.mkdtempSync('detox');
console.log("Clone repository into tmp directory");
const repo = await git.Clone(REPO_URL, tempDir);

console.log("Checking out version", version);
await repo.checkoutBranch(version);

console.log("Generating versioned doc for", version)
execSync(`npm install && 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");
clearRequireCache();
sidebars[version] = require(`./${tempDir}/website/sidebars`);

sidebars[version][`version-${version}-docs`] = sidebars[version].docs;
delete sidebars[version].docs;

fs.writeFileSync(`./versioned_sidebars/version-${version}-sidebars.json`, JSON.stringify(sidebars[version]), "utf8");

console.log("Cleanup temporary clone");
await fs.remove(tempDir);
}
})();

7 changes: 6 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"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"
}
}
Empty file added website/versioned_docs/.gitkeep
Empty file.
110 changes: 0 additions & 110 deletions website/versioned_docs/version-6.X/APIRef.ActionsOnElement.md

This file was deleted.

84 changes: 0 additions & 84 deletions website/versioned_docs/version-6.X/APIRef.Artifacts.md

This file was deleted.

Loading

0 comments on commit 74e6108

Please sign in to comment.