Skip to content

Commit

Permalink
[FABN-829] Multi version docs
Browse files Browse the repository at this point in the history
Change-Id: I2d3016aa9339d40ae3958d373726dd4832f03cc4
Signed-off-by: Liam Grace <liamgrace.896@gmail.com>
  • Loading branch information
liam-grace committed Oct 29, 2018
1 parent 1973f7b commit db4c59f
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 18 deletions.
73 changes: 55 additions & 18 deletions build/tasks/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,72 @@

const gulp = require('gulp');
const jsdoc = require('gulp-jsdoc3');
const del = require('del');
const fs = require('fs-extra');
const path = require('path');
const replace = require('gulp-replace');
let currentBranch = process.env.GERRIT_BRANCH;

if (!currentBranch) {
currentBranch = 'master';
}
let docsRoot;
if (process.env.DOCS_ROOT) {
docsRoot = process.env.DOCS_ROOT;
} else {
docsRoot = './docs/gen';
}

gulp.task('clean', () => {
return del('./docs/gen/**', {force:true});
return fs.removeSync(path.join(docsRoot, currentBranch));
});

gulp.task('doc', ['clean'], () => {
gulp.src([
'docs/index.md',
'fabric-network/index.js',
'fabric-network/lib/**/*.js',
'fabric-client/index.js',
'fabric-client/lib/**/*.js',
'!fabric-client/lib/protos/**',
'!fabric-client/lib/hash.js',
'!fabric-client/lib/utils.js',
'fabric-ca-client/index.js',
'fabric-ca-client/lib/FabricCAClientImpl.js',
'fabric-ca-client/lib/AffiliationService.js',
'fabric-ca-client/lib/IdentityService.js',
], { read: false })
const docSrc = [
'docs/index.md',
'fabric-network/index.js',
'fabric-network/lib/**/*.js',
'fabric-client/index.js',
'fabric-client/lib/**/*.js',
'!fabric-client/lib/protos/**',
'!fabric-client/lib/hash.js',
'!fabric-client/lib/utils.js',
'fabric-ca-client/index.js',
'fabric-ca-client/lib/FabricCAClientImpl.js',
'fabric-ca-client/lib/AffiliationService.js',
'fabric-ca-client/lib/IdentityService.js',
];

gulp.task('jsdocs', ['clean'], () => {
gulp.src(docSrc, { read: false })
.pipe(jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: './docs/gen'
destination: path.join(docsRoot, currentBranch)
},
templates: {
systemName: 'Hyperledger Fabric SDK for node.js',
theme: 'cosmo' //cerulean, cosmo, cyborg, flatly, journal, lumen, paper, readable, sandstone, simplex, slate, spacelab, superhero, united, yeti
}
}));
});

gulp.task('docs-dev', ['docs'], () => {
gulp.watch(docSrc, ['docs']);
});


gulp.task('docs', ['jsdocs'], () => {
const relativePath = '..';
const packageJson = require(path.join(__dirname, '../..', 'package.json'));

// jsdocs produced
// if this is the master build then we need to ensure that the index.html and
// the 404.html page are properly setup and configured.
if (currentBranch === 'master') {
gulp.src('./docs/redirectTemplates/*.html')
.pipe(replace('LATEST__VERSION', packageJson.docsLatestVersion))
.pipe(replace('RELATIVE__PATH', relativePath))
.pipe(gulp.dest(docsRoot));
} else {
console.log(`Not updating or routing logic, as not master branch - it is ${currentBranch}`);
}
});
80 changes: 80 additions & 0 deletions docs/redirectTemplates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!--
Copyright 2018 IBM All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<style>
@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700");
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
body {
margin: 10em;
}
h1 {
font-size: 2em;
margin: 0.67em 0;
}
a {
color: #2780E3;
text-decoration: none;
}
a:hover,
a:focus {
color: #165ba8;
text-decoration: underline;
}
a:focus {
outline: thin dotted;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
</style>
<head>
<meta charset="utf-8">
<title>Single Page Apps for GitHub Pages</title>
<script type="text/javascript">

let l = window.location;

// firstly need to check if we are in a loop
if (!l.search.match(/redirect=true/)){
let newUrl = l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '')
+ '/LATEST__VERSION/index.html?redirect=true'

let mapping = [FILENAME__MAPPING]
let release = "LATEST__VERSION";

// look up the maping
let requestedPage = l.pathname.split('/').slice(1)[0]

// if (mapping.indexOf(requestedPage)>-1) {
// newUrl = l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '')
// +'/LATEST__VERSION/fabric-shim.' + requestedPage+'?redirect=true';
// }

console.log(newUrl);
l.replace(newUrl);
}

</script>
</head>
<body>
<h1>Sorry, a suitable documentation page can not be found</h1>
<h2>Please consult the main <a href="https://fabric-sdk-node.readthedocs.io/en/release-1.2/">Hyperledger Fabric documentation</a></h2>
</body>
</html>
16 changes: 16 additions & 0 deletions docs/redirectTemplates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
Copyright 2018 IBM All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta http-equiv="Refresh" content="0; url=RELATIVE__PATH/LATEST__VERSION/index.html">
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.3.0-snapshot",
"testFabricVersion": "master",
"testFabricThirdParty": "0.4.14",
"docsLatestVersion": "release-1.3",
"main": "index.js",
"repository": {
"type": "gerrit",
Expand Down Expand Up @@ -45,6 +46,7 @@
"gulp-eslint": "^3.0.1",
"gulp-jsdoc3": "^2.0.0",
"gulp-mocha": "^6.0.0",
"gulp-replace": "^1.0.0",
"gulp-shell": "^0.6.3",
"gulp-tape": "0.0.9",
"gulp-watch": "^5.0.0",
Expand Down

0 comments on commit db4c59f

Please sign in to comment.