This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
179 lines (171 loc) · 5.76 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict'
require('pkginfo')(module)
function versionIndexTemplate(path) {
return {
options: {
data: {
path: path
}
},
files: {
'doc/generated/tutorials/VersionIndex.md': ['doc/generator/VersionIndex.md.tpl'],
}
}
}
function branchDocumentationTasks(target) {
const version = exports.version,
name = exports.name
target = target || version
const path = `doc/generated/versions/${target}`
return {
jsdoc: {
src: ['*.js', 'lib/'],
options: {
configure: 'doc/generator/jsdoc.json',
recurse: true,
encoding: 'utf8',
destination: path,
package: 'package.json',
template : 'node_modules/ink-docstrap/template',
readme: 'README.md',
tutorials: 'doc/generated/tutorials/'
}
},
copy: {
cwd: `${path}/${name}/${target}`,
expand: true,
src: '**',
dest: path,
},
clean: [`${path}/${name}/`],
push: {
options: {
base: 'doc/generated',
add: true,
message: `Generated on <%= grunt.template.today('yyyy-mm-dd HH:MM') %> (doc: ${target} pkg: ${version})`,
},
src: ['**']
}
}
}
module.exports = function(grunt) {
const docTasksCurrent = branchDocumentationTasks(),
docTasksMaster = branchDocumentationTasks('master')
grunt.loadNpmTasks('grunt-mocha-test')
grunt.loadNpmTasks('grunt-jsdoc')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-gh-pages')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-template')
grunt.initConfig({
pkg: exports,
template: {
'index-root': versionIndexTemplate('./'),
'index-version': versionIndexTemplate('../../')
},
clean: {
'doc-all': ['doc/generated'],
'doc-tutorials': ['doc/generated/tutorials'],
'doc-master': docTasksMaster.clean,
'doc-current-version': docTasksCurrent.clean
},
copy: {
'doc-master': docTasksMaster.copy,
'doc-current-version': docTasksCurrent.copy,
'doc-index': {
cwd: 'doc/tutorials',
expand: true,
src: ['*.md', 'tutorials.json'],
dest: 'doc/generated/tutorials/',
}
},
jsdoc: {
master: docTasksMaster.jsdoc,
'current-version': docTasksCurrent.jsdoc,
index: {
src: ['doc/generator/index-placeholder.jsdoc'],
options: {
configure: 'doc/generator/jsdoc.json',
recurse: false,
encoding: 'utf8',
destination: 'doc/generated',
template : 'node_modules/ink-docstrap/template',
readme: 'doc/generated/tutorials/VersionIndex.md',
tutorials: 'doc/generated/tutorials/'
}
}
},
'gh-pages': {
master: docTasksMaster.push,
'current-version': docTasksCurrent.push
},
mochaTest: {
options: {
reporter: 'spec',
// Clear the require cache, since we enable/disable integrations via require.
clearRequireCache: true
},
unit: {
options: {
require: () => {
delete global._ZB_INTEGRATION_TEST
}
},
src: ['test/**/*.js']
},
integration: {
options: {
require: () => {
global._ZB_INTEGRATION_TEST = true
}
},
src: ['test/**/*.js']
}
}
})
grunt.registerTask('doc:index', [
// Remove all generated files.
'clean:doc-all',
// Render the version index template for the root (no relative links).
// This has the beneficial side effect of creating the doc target
// directory, `doc/generated` and `doc/generated/tutorials`.
'template:index-root',
// Copy the tutorials and their config file into `doc/generated/tutorials`.
'copy:doc-index',
// Generate documentation for an empty project (`index-placeholder.jsdoc`)
// using the version index template as the README. This makes a decent
// landing page without having to manually write any markup or menus.
// Laziness trumps elegance.
'jsdoc:index',
// Re-render the version index template (it's no longer needed for the
// landing page generation) with relative links that can be used by the
// per-version documentation.
'template:index-version'
])
grunt.registerTask('doc:master', [
'doc:index',
'jsdoc:master',
'copy:doc-master',
'clean:doc-master',
'clean:doc-tutorials'
])
grunt.registerTask('doc:current-version', [
'doc:index',
'jsdoc:current-version',
'copy:doc-current-version',
'clean:doc-current-version',
'clean:doc-tutorials'
])
grunt.registerTask('doc:master:push', [
'doc:master',
'gh-pages:master',
'clean:doc-all'
])
grunt.registerTask('doc:current-version:push', [
'doc:current-version',
'gh-pages:current-version',
'clean:doc-all'
])
grunt.registerTask('test:unit', 'mochaTest:unit')
grunt.registerTask('test:integration', 'mochaTest:integration')
}