forked from hyperledger/fabric-chaincode-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
102 lines (87 loc) · 2.9 KB
/
docs.js
File metadata and controls
102 lines (87 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable no-console */
const gulp = require('gulp');
const jsdoc = require('gulp-jsdoc3');
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', function() {
return fs.removeSync(path.join(docsRoot, currentBranch));
});
const docSrc = [
'docs/README.md',
'fabric-shim/lib/chaincode.js',
'fabric-shim/lib/stub.js',
'fabric-shim/lib/iterators.js',
'fabric-contract-api/lib/**/*.js'
];
gulp.task('schema-docs', () => {
return gulp.src('fabric-contract-api/schema/contract-schema.json')
.pipe(gulp.dest(path.join(docsRoot, currentBranch)));
});
gulp.task('jsdocs', ['clean'], function (cb) {
gulp.src(docSrc, {read: false}).pipe(jsdoc({
opts: {
tutorials: './docs/tutorials',
destination: path.join(docsRoot, currentBranch)
},
templates: {
systemName: 'Hyperledger Fabric Node.js Contract and Shim',
theme: 'cosmo'
},
}, cb)
);
});
gulp.task('docs-dev', ['docs'], function() {
gulp.watch(docSrc, ['docs']);
});
// for the rare occurance where something needs to be bootsrap in the docs ahead of a release
gulp.task('bootstrap', function() {
gulp.src('./docs/bootstrap/**/*').pipe(gulp.dest(docsRoot));
});
gulp.task('docs', ['jsdocs', 'schema-docs', 'bootstrap'], () => {
const relativePath = '.';
const packageJson = require(path.join(__dirname, '..', 'package.json'));
let mapping = ['ClientIdentity',
'ChaincodeFromContract',
'CommonIterator',
'ChaincodeInterface',
'ChaincodeStub',
'HistoryQueryIterator',
'ChaincodeStub.SignedProposal',
'Shim',
'Meta',
'StateQueryIterator'
];
mapping = mapping.map((e) => {
return `'${e}.html'`;
});
// 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.
// also copies the
if (currentBranch === 'master') {
const pathToReleasedSchema = path.resolve(docsRoot, packageJson.docsLatestVersion, 'contract-schema.json');
return gulp.src(['./docs/redirectTemplates/*.html', pathToReleasedSchema])
.pipe(replace('LATEST__VERSION', packageJson.docsLatestVersion))
.pipe(replace('FILENAME__MAPPING', mapping.join(',')))
.pipe(replace('RELATIVE__PATH', relativePath))
.pipe(gulp.dest(docsRoot));
} else {
console.log(`Not updating or routing logic, as not master branch - it is ${currentBranch}`);
}
});