forked from GoogleChrome/workbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
95 lines (77 loc) · 2.1 KB
/
docs.js
File metadata and controls
95 lines (77 loc) · 2.1 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
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const fs = require('fs-extra');
const path = require('path');
const gulp = require('gulp');
const getNpmCmd = require('./utils/get-npm-cmd');
const spawn = require('./utils/spawn-promise-wrapper');
const logHelper = require('../infra/utils/log-helper');
const DOCS_DIRECTORY = path.join(__dirname, '..', 'docs');
gulp.task('docs:clean', () => {
return fs.remove(DOCS_DIRECTORY);
});
const getJSDocFunc = (debug) => {
return () => {
logHelper.log(`Building docs...`);
const queryString = [
`projectRoot=/`,
`basepath=/`,
`productName=Workbox`,
].join('&');
const params = [
'run', 'local-jsdoc', '--',
'-c', path.join(__dirname, '..', 'jsdoc.conf'),
'-d', DOCS_DIRECTORY,
];
if (!global.cliOptions.pretty) {
logHelper.warn(`
These docs will look ugly, but they will more accurately match what
is shown on developers.google.com.
You can view a friendlier UI by running
'gulp docs --pretty'
`);
params.push(
'--template', path.join(
__dirname, '..', 'infra', 'templates', 'reference-docs', 'jsdoc'
),
'--query', queryString,
);
}
if (debug) {
params.push('--debug');
}
return spawn(getNpmCmd(), params, {
cwd: path.join(__dirname, '..'),
})
.then(() => {
logHelper.log(`Docs built successfully`);
})
.catch((err) => {
logHelper.error(`Docs failed to build: `, err);
throw err;
});
};
};
gulp.task('docs:build-debug', gulp.series([
'docs:clean',
getJSDocFunc(true),
]));
gulp.task('docs:build', gulp.series([
'docs:clean',
getJSDocFunc(false),
]));
gulp.task('docs:watch', () => {
const watcher = gulp.watch('packages/**/*',
gulp.series(['docs:build']));
watcher.on('error', (err) => {
logHelper.error(`Docs failed to build: `, err);
});
});
gulp.task('docs', gulp.series([
'docs:build',
'docs:watch',
]));