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 5, 2018
1 parent f18813b commit 517b7ff
Show file tree
Hide file tree
Showing 51 changed files with 71 additions and 4,179 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
6 changes: 6 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ website/node_modules

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

website/versioned_docs/*
!website/versioned_docs/.gitkeep

website/versioned_sidebars/*
!website/versioned_sidebars/.gitkeep
48 changes: 48 additions & 0 deletions website/gatherDocs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env node
const fs = require("fs-extra");
const git = require("nodegit");
const execSync = require('child_process').execSync;
const versions = require("./versions");

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

const sidebars = [];

(async function () {
console.log("Cleanup versioned docs");
await fs.emptyDir("./versioned_docs");
await fs.emptyDir("./versioned_sidebars");

for (let version of versions) {
const tempDir = fs.mkdtempSync('detox');
console.log("Clone repository into tmp directory");
const repo = await git.Clone("https://github.com/wix/detox.git", 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 517b7ff

Please sign in to comment.