forked from Azure/azure-sdk-for-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntfile.js
135 lines (120 loc) · 4.23 KB
/
gruntfile.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// Copyright (c) Microsoft and contributors. 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.
//
module.exports = function(grunt) {
var glob = require('glob');
var _ = require('underscore');
var path = require('path');
var fs = require('fs');
var util = require('util');
var jsdocOptions = {
destination: 'docs',
template: 'node_modules/minami',
configure: 'jsdocs/jsdoc.conf.json',
};
var servicePackages = glob.sync('lib/**/package.json', {ignore: 'lib/services/webSiteManagement2/package.json'});
var runtimePackages = glob.sync('runtime/**/package.json', {ignore: 'runtime/**/test/package.json'});
var packages = servicePackages.concat(runtimePackages);
var sources = _.map(packages, function(pack) {
return _.map(['/**/*.js', '/package.json', '/README.md'], function(i) {
return path.dirname(pack) + i;
});
});
var modifyDefaultConfig = function(confName, jsdocOptions, mutatorFn){
var confPath = path.join("jsdocs", confName);
if(fs.existsSync(confPath)){
fs.unlinkSync(confPath);
}
var defaultConf = JSON.parse(fs.readFileSync(jsdocOptions.configure));
fs.writeFileSync(confPath, JSON.stringify(mutatorFn(defaultConf)));
return confPath;
}
var jsdocConfig = {};
_.each(sources, function(source) {
var examplesPath = path.join(path.dirname(source[1]), 'examples');
var docOptions = _.clone(jsdocOptions);
if(fs.existsSync(examplesPath)) {
docOptions.tutorials = examplesPath;
}
docOptions.configure = modifyDefaultConfig('child.conf.json', docOptions, function(config){
config.templates.repoUrl = JSON.parse(fs.readFileSync('package.json')).repository.url;
config.templates.childPackage = true;
return config;
});
jsdocConfig[JSON.parse(fs.readFileSync(source[1])).name] = {
src: source,
options: docOptions
};
});
var packageVersions = {};
_.each(sources, function(source) {
var pack = JSON.parse(fs.readFileSync(source[1]));
packageVersions[pack.name] = pack;
});
var docOptions = _.clone(jsdocOptions);
docOptions.tutorials = 'examples';
docOptions.configure = modifyDefaultConfig('main.conf.json', docOptions, function(config){
config.templates.repoUrl = JSON.parse(fs.readFileSync('package.json')).repository.url;
config.templates.packages = packageVersions;
return config;
});
jsdocConfig['azure'] = {
src: ['lib/azure.js', 'README.md'],
options: docOptions
};
var packagesLatestSymlinkMapping = Object.keys(packageVersions).map(function(name){
if (!packageVersions[name].version) packageVersions[name].version = '0.0.1';
return {src: path.join('docs', name, packageVersions[name].version), dest: path.join('docs', name, 'latest')};
});
symlinkConfig = {
options: { overwrite: true },
expanded: {files: packagesLatestSymlinkMapping}
}
//init stuff
grunt.initConfig({
packageVersions: packageVersions,
jsdoc: jsdocConfig,
symlink: symlinkConfig,
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
keepalive: true
},
server: {
options: {
base: './docs',
}
}
},
'gh-pages': {
options: {
base: 'docs',
branch: 'gh-pages',
message: '[Auto-generated] Updated documentations',
add: true
},
src: '**/*'
}
});
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-symlink');
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.registerTask('publishdocs', ['gh-pages']);
grunt.registerTask('genDocs', ['jsdoc', 'symlink']);
};