js-build-tools 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -674
- package/README.md +762 -701
- package/babel.config.js +28 -28
- package/dist/build.js +75 -75
- package/dist/bundle.js +19 -19
- package/dist/bundleMinify.js +7 -7
- package/dist/compileReadme.js +4 -4
- package/dist/copyFiles.js +17 -17
- package/dist/copyFonts.js +4 -4
- package/dist/default.js +5 -5
- package/dist/dist.js +4 -4
- package/dist/distMinify.js +4 -4
- package/dist/docs.js +7 -7
- package/dist/images.js +4 -4
- package/dist/jsdocDocs.js +6 -6
- package/dist/lint.js +16 -16
- package/dist/partials/addToReadme.js +9 -9
- package/dist/partials/beginWatcher.js +4 -4
- package/dist/partials/clean.js +5 -5
- package/dist/partials/copyFor.js +9 -9
- package/dist/partials/distFor.js +6 -6
- package/dist/partials/distForSrc.js +5 -5
- package/dist/partials/distSeries.js +7 -7
- package/dist/partials/imagesFor.js +93 -93
- package/dist/partials/jsdocDocsFor.js +46 -46
- package/dist/partials/lintSource.js +51 -51
- package/dist/partials/loadPeer.js +99 -99
- package/dist/partials/loadPlaywright.js +14 -14
- package/dist/partials/minifyFor.js +20 -20
- package/dist/partials/neostandardLint.js +175 -175
- package/dist/partials/readmeTemplate.js +4 -4
- package/dist/partials/removeDirectory.js +11 -11
- package/dist/partials/resolveDocsMethod.js +6 -6
- package/dist/partials/runOnChange.js +31 -31
- package/dist/partials/sassFor.js +6 -6
- package/dist/partials/serveStatic.js +9 -9
- package/dist/partials/tsFor.js +32 -32
- package/dist/partials/typeDocsFor.js +264 -264
- package/dist/partials.js +176 -176
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/isolateGulpCache.js +24 -24
- package/dist/test-helpers/setUp.js +4 -4
- package/dist/testFull.js +5 -5
- package/dist/testQuick.js +5 -5
- package/dist/typeDocs.js +5 -5
- package/dist/typeScript.js +4 -4
- package/dist/utilities/convertMjsFilesForDocs.js +12 -12
- package/dist/utilities/dotGet.js +54 -54
- package/dist/utilities/dotNotate.js +79 -79
- package/dist/utilities/dotSet.js +45 -45
- package/dist/utilities/esmNamedExportsToCjs.js +15 -15
- package/dist/utilities/getBundleConfigs.js +9 -9
- package/dist/utilities/isObject.js +6 -6
- package/dist/utilities/strAfter.js +7 -7
- package/dist/utilities/strBefore.js +7 -7
- package/dist/watchFull.js +4 -4
- package/dist/watchTest.js +4 -4
- package/functions/build.mjs +72 -72
- package/functions/build.test.mjs +763 -759
- package/functions/bundle.mjs +44 -44
- package/functions/bundle.test.mjs +219 -219
- package/functions/bundleMinify.mjs +16 -16
- package/functions/bundleMinify.test.mjs +37 -37
- package/functions/compileReadme.mjs +9 -9
- package/functions/compileReadme.test.mjs +18 -18
- package/functions/copyFiles.mjs +32 -32
- package/functions/copyFiles.test.mjs +78 -78
- package/functions/copyFonts.mjs +9 -9
- package/functions/copyFonts.test.mjs +32 -32
- package/functions/default.mjs +12 -12
- package/functions/default.test.mjs +33 -33
- package/functions/dist.mjs +8 -8
- package/functions/dist.test.mjs +44 -44
- package/functions/distMinify.mjs +9 -9
- package/functions/distMinify.test.mjs +15 -15
- package/functions/docs.mjs +13 -13
- package/functions/docs.test.mjs +45 -45
- package/functions/gulpConfigEntries.test.mjs +23 -23
- package/functions/images.mjs +8 -8
- package/functions/images.test.mjs +142 -142
- package/functions/jsdocDocs.mjs +10 -10
- package/functions/jsdocEsmExports.test.mjs +24 -24
- package/functions/lint.mjs +9 -9
- package/functions/partials/addToReadme.mjs +25 -25
- package/functions/partials/addToReadme.test.mjs +34 -34
- package/functions/partials/beginWatcher.mjs +9 -9
- package/functions/partials/beginWatcher.test.mjs +19 -19
- package/functions/partials/clean.mjs +13 -13
- package/functions/partials/clean.test.mjs +22 -22
- package/functions/partials/copyFor.mjs +15 -15
- package/functions/partials/copyFor.test.mjs +53 -53
- package/functions/partials/distFor.mjs +22 -22
- package/functions/partials/distFor.test.mjs +195 -195
- package/functions/partials/distForSrc.mjs +11 -11
- package/functions/partials/distForSrc.test.mjs +18 -18
- package/functions/partials/distSeries.mjs +21 -21
- package/functions/partials/distSeries.test.mjs +34 -34
- package/functions/partials/imagesFor.mjs +83 -83
- package/functions/partials/imagesFor.test.mjs +287 -287
- package/functions/partials/jsdocDocsFor.mjs +163 -152
- package/functions/partials/jsdocDocsFor.test.mjs +182 -152
- package/functions/partials/lintSource.mjs +41 -41
- package/functions/partials/loadPeer.mjs +76 -76
- package/functions/partials/loadPeer.test.mjs +58 -58
- package/functions/partials/loadPlaywright.mjs +23 -23
- package/functions/partials/loadPlaywright.test.mjs +70 -70
- package/functions/partials/minifyFor.mjs +15 -15
- package/functions/partials/minifyFor.test.mjs +49 -49
- package/functions/partials/neostandardLint.mjs +142 -142
- package/functions/partials/neostandardLint.test.mjs +131 -131
- package/functions/partials/readmeTemplate.mjs +12 -12
- package/functions/partials/readmeTemplate.test.mjs +34 -34
- package/functions/partials/removeDirectory.mjs +34 -34
- package/functions/partials/removeDirectory.test.mjs +72 -72
- package/functions/partials/resolveDocsMethod.mjs +10 -10
- package/functions/partials/resolveDocsMethod.test.mjs +33 -33
- package/functions/partials/runOnChange.mjs +54 -54
- package/functions/partials/runOnChange.test.mjs +95 -95
- package/functions/partials/sassFor.mjs +25 -25
- package/functions/partials/sassFor.test.mjs +81 -81
- package/functions/partials/serveStatic.mjs +47 -47
- package/functions/partials/serveStatic.test.mjs +71 -71
- package/functions/partials/tsFor.mjs +92 -92
- package/functions/partials/tsFor.test.mjs +88 -88
- package/functions/partials/typeDocsFor.mjs +231 -231
- package/functions/partials/typeDocsFor.test.mjs +263 -263
- package/functions/partials.mjs +31 -31
- package/functions/partials.test.mjs +7 -7
- package/functions/sass.mjs +4 -4
- package/functions/sass.test.mjs +31 -31
- package/functions/sourceLint.mjs +13 -13
- package/functions/sourceLint.test.mjs +166 -166
- package/functions/test-helpers/isolateGulpCache.mjs +16 -16
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +100 -100
- package/functions/test-helpers/setUp.test.mjs +19 -19
- package/functions/testFull.mjs +17 -17
- package/functions/testFull.test.mjs +17 -17
- package/functions/testHelpers.mjs +10 -10
- package/functions/testHelpers.test.mjs +7 -7
- package/functions/testQuick.mjs +17 -17
- package/functions/testQuick.test.mjs +17 -17
- package/functions/typeDocs.mjs +9 -9
- package/functions/typeDocs.test.mjs +11 -11
- package/functions/typeScript.mjs +8 -8
- package/functions/typeScript.test.mjs +11 -11
- package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
- package/functions/utilities/dotGet.mjs +49 -49
- package/functions/utilities/dotNotate.mjs +73 -73
- package/functions/utilities/dotNotate.test.mjs +41 -41
- package/functions/utilities/dotSet.mjs +40 -40
- package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
- package/functions/utilities/getBundleConfigs.mjs +30 -30
- package/functions/utilities/isObject.mjs +8 -8
- package/functions/utilities/strAfter.mjs +12 -12
- package/functions/utilities/strBefore.mjs +12 -12
- package/functions/watchFull.mjs +9 -9
- package/functions/watchFull.test.mjs +41 -41
- package/functions/watchTest.mjs +10 -10
- package/functions/watchTest.test.mjs +49 -49
- package/gulp.config.js +4 -4
- package/gulp.config.mjs +344 -340
- package/gulpfile.base.js +51 -51
- package/gulpfile.base.mjs +29 -29
- package/jsdoc.base.js +16 -16
- package/jsdoc.esmExports.js +17 -17
- package/package.json +146 -145
package/README.md
CHANGED
|
@@ -1,691 +1,695 @@
|
|
|
1
|
-
# [js-build-tools](https://www.npmjs.com/package/js-build-tools)
|
|
2
|
-
|
|
3
|
-
Centralize the build process for Node.js, JS and TypeScript projects into a single tool suite.
|
|
4
|
-
|
|
5
|
-
### Goals
|
|
6
|
-
|
|
7
|
-
Using this tool suite, you can:
|
|
8
|
-
|
|
9
|
-
* Parse TypeScript into JS distribution files
|
|
10
|
-
* Create formatted distribution files to be used in a node / commonjs environment.
|
|
11
|
-
* Bundle your distribution files to be used in a browser environment.
|
|
12
|
-
* Run tests and watch for changes.
|
|
13
|
-
* Generate jsdoc readme files.
|
|
14
|
-
* Generate real HTML documentation straight from your source - TypeDoc for a TypeScript project (a module for
|
|
15
|
-
each of your folders), or jsdoc with a modern theme for a plain JavaScript one.
|
|
16
|
-
* Copy files (a bundle, or anything else) to another location, on demand.
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
In your project's root directory, run: `npm install --save-dev gulp js-build-tools`
|
|
21
|
-
(or `yarn add --dev gulp js-build-tools` if you use Yarn).
|
|
22
|
-
|
|
23
|
-
It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead
|
|
24
|
-
of `node_modules/.bin/gulp`.
|
|
25
|
-
|
|
26
|
-
## Configuration
|
|
27
|
-
|
|
28
|
-
In your project's root directory, create a `build-tools.config.json` file. This can contain any of the following (values
|
|
29
|
-
provided are the defaults):
|
|
30
|
-
|
|
31
|
-
```json
|
|
32
|
-
{
|
|
33
|
-
"browser": {
|
|
34
|
-
// 'true' to generate browser bundled files; 'false' for node environment only
|
|
35
|
-
"enabled": true,
|
|
36
|
-
// The name to use for the browser-bundled output file (.js will be appended).
|
|
37
|
-
"name": "my-package",
|
|
38
|
-
// The search pattern used for retrieving compiled distribution files.
|
|
39
|
-
"from": "dist/**/*.js",
|
|
40
|
-
// Module names or file paths which resolve to an empty object ({}) in the bundle instead of their real contents.
|
|
41
|
-
"ignore": [],
|
|
42
|
-
// Module names or file paths left out of the bundle entirely (requiring one at runtime throws, unless something
|
|
43
|
-
// else provides it, for example a script tag which loads it separately).
|
|
44
|
-
"exclude": [],
|
|
45
|
-
// Additional bundles to produce alongside the primary one above (see 'Configure additional browser bundles').
|
|
46
|
-
"bundles": [],
|
|
47
|
-
// The output directory for browser-bundled files.
|
|
48
|
-
"to": "browser"
|
|
49
|
-
},
|
|
50
|
-
// The paths for directories to delete before build.
|
|
51
|
-
"cleanPaths": [
|
|
52
|
-
"dist",
|
|
53
|
-
"browser"
|
|
54
|
-
],
|
|
55
|
-
"dist": {
|
|
56
|
-
// Name of the entry the distribution file.
|
|
57
|
-
"main": "dist/main",
|
|
58
|
-
// The search pattern used for gathering source files for distribution.
|
|
59
|
-
"from": "src/**/!(*.test).js",
|
|
60
|
-
// The output directory for the distribution files.
|
|
61
|
-
"to": "dist"
|
|
62
|
-
},
|
|
63
|
-
"docs": {
|
|
64
|
-
// Toggle generating the HTML documentation from the TypeScript source (see 'Configure TypeScript documentation').
|
|
65
|
-
// When on, the build does this instead of generating the readme from the jsdoc comments.
|
|
66
|
-
"enabled": false,
|
|
67
|
-
// The directory holding the TypeScript source, each folder in it becomes a module of the documentation.
|
|
68
|
-
"from": "src",
|
|
69
|
-
// The markdown file used as the front page of the documentation.
|
|
70
|
-
"index": "MAIN.md",
|
|
71
|
-
// How much TypeDoc reports: Verbose, Info, Warn, Error or None.
|
|
72
|
-
"logLevel": "Warn",
|
|
73
|
-
// The name of the documentation, defaults to the name in your package.json.
|
|
74
|
-
"title": "",
|
|
75
|
-
// The directory to generate the documentation in (it is cleared first).
|
|
76
|
-
"to": "docs",
|
|
77
|
-
// The tsconfig file to read the source with, false to use the one of 'typescript.config'.
|
|
78
|
-
"tsconfig": false
|
|
79
|
-
},
|
|
80
|
-
"fonts": {
|
|
81
|
-
// Toggle copy directory of fonts on
|
|
82
|
-
"enabled": false,
|
|
83
|
-
// Path to search for fonts
|
|
84
|
-
"from": "src/fonts/**/*",
|
|
85
|
-
// Path to output fonts
|
|
86
|
-
"to": "browser/fonts"
|
|
87
|
-
},
|
|
88
|
-
"images": {
|
|
89
|
-
// Toggle image minify and copy process
|
|
90
|
-
"enabled": false,
|
|
91
|
-
// Path to search for images
|
|
92
|
-
"from": "src/img/**/*.+(png|jpg|jpeg|gif|svg)",
|
|
93
|
-
// The JPEG quality (0 to 100) to compress to, false keeps mozjpeg's own default (75)
|
|
94
|
-
"jpegQuality": false,
|
|
95
|
-
// Path to output images
|
|
96
|
-
"to": "browser/img"
|
|
97
|
-
},
|
|
98
|
-
"readme": {
|
|
99
|
-
// The file which will be pre-fixed to your README.md output.
|
|
100
|
-
"template": "MAIN.md",
|
|
101
|
-
// Options for formatting the output readme.
|
|
102
|
-
"options": "utf8",
|
|
103
|
-
// The name of the output documentation markdown file.
|
|
104
|
-
"file": "README.md",
|
|
105
|
-
// Location of files to use for compiling documentation into the readme.
|
|
106
|
-
"from": [
|
|
107
|
-
"src/**/!(*.test).js"
|
|
108
|
-
],
|
|
109
|
-
// Additional .mjs files to document alongside 'from' (see 'Configure including ESM files in the generated
|
|
110
|
-
// readme'). Empty by default: a project that never sets this gets exactly the readme it always did.
|
|
111
|
-
"fromEsm": [],
|
|
112
|
-
// The directory to output the readme file in.
|
|
113
|
-
"to": "./"
|
|
114
|
-
},
|
|
115
|
-
// Base directory of the project.
|
|
116
|
-
"rootPath": "./",
|
|
117
|
-
"sass": {
|
|
118
|
-
// Toggle SASS to CSS process on.
|
|
119
|
-
"enabled": false,
|
|
120
|
-
// The pattern for finding all sass files.
|
|
121
|
-
"from": "sass/**/*.+(scss|sass)",
|
|
122
|
-
// The directory were sass files will be stored.
|
|
123
|
-
"path": "sass",
|
|
124
|
-
// The destination path for where generated CSS (from SASS files) should go.
|
|
125
|
-
"to": "browser/css"
|
|
126
|
-
},
|
|
127
|
-
// The directory where your source files are stored (the files you manually created).
|
|
128
|
-
"srcPath": "src",
|
|
129
|
-
"test": {
|
|
130
|
-
// Additional flags for programmatically running Jest Cli.
|
|
131
|
-
"options": null,
|
|
132
|
-
// The directory where Jest test files are stored.
|
|
133
|
-
// By default, stored as *.test.js adjacent to the files they are testing.
|
|
134
|
-
"path": [
|
|
135
|
-
"src"
|
|
136
|
-
],
|
|
137
|
-
// The search pattern for watching files for changes.
|
|
138
|
-
"watch": "src/**/*.js"
|
|
139
|
-
},
|
|
140
|
-
"typescript": {
|
|
141
|
-
// The path the tsconfig file for running typescript or false if no ts file given.
|
|
142
|
-
"config": false,
|
|
143
|
-
// Toggle usage of typescript parsing.
|
|
144
|
-
"enabled": false,
|
|
145
|
-
// Pattern for finding the TypeScript files.
|
|
146
|
-
"from": "src/**/*.ts",
|
|
147
|
-
// Directory where parsed typescript files go.
|
|
148
|
-
"to": "dist"
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Create your local gulpfile.js
|
|
154
|
-
|
|
155
|
-
In your project's root directory, create a `gulpfile.js` file, in here you can require any of the functions you need.
|
|
156
|
-
For example:
|
|
157
|
-
|
|
158
|
-
#### Common JS
|
|
159
|
-
|
|
160
|
-
```js
|
|
161
|
-
// Your local gulpfile.js
|
|
162
|
-
const {
|
|
163
|
-
build,
|
|
164
|
-
defaultCmd,
|
|
165
|
-
docs,
|
|
166
|
-
partials,
|
|
167
|
-
readme,
|
|
168
|
-
sass,
|
|
169
|
-
testFull,
|
|
170
|
-
testQuick,
|
|
171
|
-
typescript,
|
|
172
|
-
watchFull,
|
|
173
|
-
watchTest
|
|
174
|
-
} = require('js-build-tools/gulpfile.base.js')
|
|
175
|
-
|
|
176
|
-
// Everything you export will be created as a gulp task.
|
|
177
|
-
// You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
|
|
178
|
-
// You can list your available tasks by running `gulp --tasks`.
|
|
179
|
-
exports.build = build
|
|
180
|
-
exports.default = defaultCmd
|
|
181
|
-
exports.docs = docs
|
|
182
|
-
exports.readme = readme
|
|
183
|
-
exports.sass = sass
|
|
184
|
-
exports.testFull = testFull
|
|
185
|
-
exports.testQuick = testQuick
|
|
186
|
-
exports.watchFull = watchFull
|
|
187
|
-
exports.watchTest = watchTest
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
#### ES Module
|
|
191
|
-
|
|
192
|
-
```js
|
|
193
|
-
// Your local gulpfile.mjs
|
|
194
|
-
// Everything you export will be created as a gulp task.
|
|
195
|
-
export {
|
|
196
|
-
build,
|
|
197
|
-
defaultCmd,
|
|
198
|
-
docs,
|
|
199
|
-
partials,
|
|
200
|
-
readme,
|
|
201
|
-
sass,
|
|
202
|
-
testFull,
|
|
203
|
-
testQuick,
|
|
204
|
-
typescript,
|
|
205
|
-
watchFull,
|
|
206
|
-
watchTest
|
|
207
|
-
} from 'js-build-tools/gulpfile.base.mjs'
|
|
208
|
-
|
|
209
|
-
// You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
|
|
210
|
-
// You can list your available tasks by running `gulp --tasks`.
|
|
211
|
-
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Verify your tasks are available by running `gulp --tasks`.
|
|
215
|
-
|
|
216
|
-
### Configure Babel
|
|
217
|
-
|
|
218
|
-
Depending on how you wrote your test files, Jest may require some Babel configuration.
|
|
219
|
-
Create a `babel.config.js` file in the root directory of your project.
|
|
220
|
-
You can then use the recommended configuration by requiring the `babel.config.js` file into your own configuration file.
|
|
221
|
-
Example:
|
|
222
|
-
|
|
223
|
-
```js
|
|
224
|
-
const babelConfig = require('js-build-tools/babel.config')
|
|
225
|
-
// You may add additional configuration here. Example: babelConfig.presets.push('@babel/preset-env')
|
|
226
|
-
module.exports = babelConfig
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### Configure ES Modules (.mjs)
|
|
230
|
-
|
|
231
|
-
It is not recommended to use `"type": "module"` in the `package.json` to enable ES Modules.
|
|
232
|
-
This is because some dependencies still rely on common JS syntax (ex: babel, jest, jsdoc).
|
|
233
|
-
So, to use ES Modules, you can use the `.mjs` extension on your files instead.
|
|
234
|
-
There are different downsides to using the `.mjs` extension to consider.
|
|
235
|
-
The `jsdoc` generation can only read `.js` files, and the provided test runner `Jest` will need to be configured.
|
|
236
|
-
Update the test config as follows:
|
|
237
|
-
|
|
238
|
-
```json
|
|
239
|
-
{
|
|
240
|
-
"dist": {
|
|
241
|
-
// Use .mjs files for from and main
|
|
242
|
-
"main": "src/main.mjs",
|
|
243
|
-
"from": "src/**/!(*.test).mjs",
|
|
244
|
-
"to": "dist"
|
|
245
|
-
},
|
|
246
|
-
"readme": {
|
|
247
|
-
"template": "MAIN.md",
|
|
248
|
-
"options": "utf8",
|
|
249
|
-
"file": "README.md",
|
|
250
|
-
"from": [
|
|
251
|
-
// Use the dist directory files to generate the jsdocs - dist is always .js regardless of source
|
|
252
|
-
// extension, since Babel compiles .mjs source down to it, so this is enough on its own. If you instead
|
|
253
|
-
// have a handful of standalone .mjs files that never go through the normal dist compile (for example a
|
|
254
|
-
// config file read directly by the build itself), see 'Configure including ESM files in the generated
|
|
255
|
-
// readme' for readme.fromEsm instead - a lighter option than switching your whole project's dist/test
|
|
256
|
-
// config over to .mjs just to document a few files.
|
|
257
|
-
"dist/!(*.test).js"
|
|
258
|
-
],
|
|
259
|
-
"to": "./"
|
|
260
|
-
},
|
|
261
|
-
"test": {
|
|
262
|
-
"options": {
|
|
263
|
-
// The below helps to find the .mjs files (rather than default .js files)
|
|
264
|
-
"testMatch": [
|
|
265
|
-
"**/?(*.)+(spec|test).mjs?(x)"
|
|
266
|
-
]
|
|
267
|
-
},
|
|
268
|
-
"path": "functions",
|
|
269
|
-
// Include watching for .mjs files
|
|
270
|
-
"watch": "functions/**/*.[cm]?[jt]s"
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
There is an additional file you need to get Jest working, add a `jest.config.js` file.
|
|
276
|
-
While we have already added these configurations above in the "options",
|
|
277
|
-
there seems to be a bug where the "transform" does not work in that context. Add the following to your `jest.config.js`:
|
|
278
|
-
|
|
279
|
-
```js
|
|
280
|
-
module.exports = {
|
|
281
|
-
// The transform will instruct jest to run the files through babel so it can interpret them
|
|
282
|
-
transform: {
|
|
283
|
-
'^.+\\.[cm]?[jt]sx?$': 'babel-jest'
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### Configure HTML JS Documentation, full manual control (optional, advanced)
|
|
289
|
-
|
|
290
|
-
For most projects, `docs.enabled` with `docs.method: 'jsdoc'` (see 'Configure HTML documentation' below) is the
|
|
291
|
-
simpler path - no `.jsdoc.conf.js` file to maintain by hand, wired straight into `gulp build`/`gulp docs`. This
|
|
292
|
-
section is for when you want full, direct control over jsdoc's own config instead (a plugin or option this
|
|
293
|
-
project's own generated config does not expose, for example).
|
|
294
|
-
|
|
295
|
-
Create a `.jsdoc.conf.js` file and add the following:
|
|
296
|
-
|
|
297
|
-
```js
|
|
298
|
-
const jsDocBase = require('js-build-tools/jsdoc.base')
|
|
299
|
-
/* You will get a jsdoc config object with the following:
|
|
300
|
-
* {
|
|
301
|
-
* plugins: ['plugins/markdown'],
|
|
302
|
-
* source: {
|
|
303
|
-
* include: [your configured distPath],
|
|
304
|
-
* includePattern: '.+\\.js(doc|x)?$',
|
|
305
|
-
* excludePattern: '((^|\\/|\\\\)_|.+\\.test\\..*)'
|
|
306
|
-
* }
|
|
307
|
-
* }
|
|
308
|
-
* You can manipulate the properties before returning in module.exports.
|
|
309
|
-
* This searches the defined 'distPath' for building the HTML JS Documentation
|
|
310
|
-
*/
|
|
311
|
-
module.exports = jsDocBase
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Configure what the browser bundle leaves out (optional)
|
|
315
|
-
|
|
316
|
-
A dependency can be reached from your code without being needed in the browser, and bundling it can add a lot of size.
|
|
317
|
-
Two settings in `browser` handle this, both take module names or file paths (see browserify's `b.ignore(file)` and
|
|
318
|
-
`b.exclude(file)`):
|
|
319
|
-
|
|
320
|
-
```json
|
|
321
|
-
{
|
|
322
|
-
"browser": {
|
|
323
|
-
// Resolves to an empty object ({}) in the bundle instead of the real module. This suits a dependency which is only
|
|
324
|
-
// reached because it is the default value of an option you always override with your own (for example a selector
|
|
325
|
-
// engine's default DOM adapter). Anything only that module requires is left out too. Your code must never actually
|
|
326
|
-
// use the real module, so keep overriding that option.
|
|
327
|
-
"ignore": ["some-default-adapter"],
|
|
328
|
-
// Left out of the bundle entirely. Requiring it at runtime throws unless something else provides it, for example a
|
|
329
|
-
// script tag which loads it separately, so this suits a large library which the page already loads.
|
|
330
|
-
"exclude": ["a-library-the-page-loads"]
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### Configure additional browser bundles (optional)
|
|
336
|
-
|
|
337
|
-
By default a project produces exactly one browser bundle, from `dist.main`/`browser.name`/`browser.ignore`/
|
|
338
|
-
`browser.exclude` above. `browser.bundles` adds more bundles alongside it - for example a render-only variant built
|
|
339
|
-
from a different entry point than the full bundle. Each entry only needs to specify what's actually different about
|
|
340
|
-
that bundle; anything left out falls back to the primary bundle's own value:
|
|
341
|
-
|
|
342
|
-
```json
|
|
343
|
-
{
|
|
344
|
-
"browser": {
|
|
345
|
-
"bundles": [
|
|
346
|
-
{
|
|
347
|
-
// Required, and must be unique among all of a project's bundles: the name for this bundle's own output file
|
|
348
|
-
// and standalone export.
|
|
349
|
-
"name": "render-only",
|
|
350
|
-
// This bundle's own entry point. Falls back to dist.main when omitted.
|
|
351
|
-
"main": "dist/renderOnly.js",
|
|
352
|
-
// This bundle's own ignore list. Falls back to browser.ignore when omitted.
|
|
353
|
-
"ignore": [],
|
|
354
|
-
// This bundle's own exclude list. Falls back to browser.exclude when omitted.
|
|
355
|
-
"exclude": []
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
For the `gulpConfig` module's own `get`/`set` functions (read or override a resolved configuration value from your
|
|
363
|
-
own code, by the same dot-notation path a setting has in the JSON above), see the generated reference below.
|
|
364
|
-
|
|
365
|
-
### Configure including ESM files in the generated readme (optional)
|
|
366
|
-
|
|
367
|
-
The readme generator (`jsdoc-to-markdown`) only recognizes `.js` files, even though it parses real ESM `import`/
|
|
368
|
-
`export` syntax just fine once it reads one - the file extension is the only thing it filters on, not the content.
|
|
369
|
-
`readme.fromEsm` names `.mjs` files to document anyway: each one is read, rewritten (every top-level `export const`/
|
|
370
|
-
`export function`/`export class` becomes a plain declaration plus a trailing `module.exports = { ... }` - the same
|
|
371
|
-
shape `jsdoc-to-markdown` already documents cleanly, since that rewrite is exactly what this project's own
|
|
372
|
-
`gulp.config.mjs` needs it for) and written to a temp `.js` file outside your project entirely, which is cleaned up
|
|
373
|
-
again once the readme generator has read it. Other export forms (`export default`, re-exports, `export { a, b }`
|
|
374
|
-
lists) are left untouched in whatever way `jsdoc-to-markdown` already handles ESM - restructure a file to use named
|
|
375
|
-
exports if you want it documented this cleanly:
|
|
376
|
-
|
|
377
|
-
```json
|
|
378
|
-
{
|
|
379
|
-
"readme": {
|
|
380
|
-
"fromEsm": ["src/myEsmOnlyModule.mjs"]
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
### Configure copy files (optional)
|
|
386
|
-
|
|
387
|
-
Copy files (a bundle, or anything else) to another location - any number of entries, each independent. Unlike
|
|
388
|
-
every other task here, this is never run automatically as part of `gulp build` - what this copies is often the
|
|
389
|
-
live, publicly-reachable version of something, so publishing it should be a deliberate step your own script
|
|
390
|
-
opts into, not a side effect of a routine local build.
|
|
391
|
-
|
|
392
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
393
|
-
|
|
394
|
-
```json
|
|
395
|
-
{
|
|
396
|
-
"copyFiles": [
|
|
397
|
-
{
|
|
398
|
-
// The glob pattern(s) of files to copy
|
|
399
|
-
"from": "browser/**/*.js",
|
|
400
|
-
// The directory to copy them into
|
|
401
|
-
"to": "../my-other-project/vendor",
|
|
402
|
-
// Optional - preserves this glob's own subdirectory structure in the destination, instead of flattening it
|
|
403
|
-
"base": "browser"
|
|
404
|
-
}
|
|
405
|
-
]
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
If you also export `copyFiles` from your gulpfile you can run it on its own with `gulp copyFiles`, and can then
|
|
410
|
-
add your own script for it, for example `"publish:bundle": "gulp copyFiles"`.
|
|
411
|
-
|
|
412
|
-
### Configure move fonts (optional)
|
|
413
|
-
|
|
414
|
-
Be able to copy a source directory of fonts into the distribution path.
|
|
415
|
-
|
|
416
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
417
|
-
|
|
418
|
-
```json
|
|
419
|
-
{
|
|
420
|
-
"fonts": {
|
|
421
|
-
// Enable fonts process
|
|
422
|
-
"enabled": false,
|
|
423
|
-
// Search pattern to find your font files
|
|
424
|
-
"from": "src/fonts/**/*",
|
|
425
|
-
// Output directory for your font files
|
|
426
|
-
"to": "browser/fonts"
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
### Configure move and minify images (optional)
|
|
432
|
-
|
|
433
|
-
Be able to copy and reduce the file size of images into an output path.
|
|
434
|
-
|
|
435
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
436
|
-
|
|
437
|
-
```json
|
|
438
|
-
{
|
|
439
|
-
"images": {
|
|
440
|
-
// Enable image process
|
|
441
|
-
"enabled": false,
|
|
442
|
-
// Search pattern to find your images
|
|
443
|
-
"from": "src/img/**/*.+(png|jpg|jpeg|gif|svg)",
|
|
444
|
-
// The JPEG quality (0 to 100) to compress to. Left false, mozjpeg uses its own default of 75, which can
|
|
445
|
-
// visibly band smooth gradients in photos; 85 is usually indistinguishable from the original
|
|
446
|
-
"jpegQuality": false,
|
|
447
|
-
// Output directory for your images files
|
|
448
|
-
"to": "browser/img"
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
### Configure SASS (optional)
|
|
454
|
-
|
|
455
|
-
SASS support is built-in, this enables conversion of SASS files to CSS for web projects.
|
|
456
|
-
|
|
457
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
458
|
-
|
|
459
|
-
```json
|
|
460
|
-
{
|
|
461
|
-
"sass": {
|
|
462
|
-
// Enable SASS process
|
|
463
|
-
"enabled": false,
|
|
464
|
-
// Search pattern to find your SASS files (the below would be files ending in .scss or .sass in a directory called 'sass')
|
|
465
|
-
"from": "sass/**/*.+(scss|sass)",
|
|
466
|
-
// Optional but nice to add (future support), add the directory where your sass files exist
|
|
467
|
-
"path": "sass",
|
|
468
|
-
// Output directory for your compiled css files, recommend css directory within your browser output directory
|
|
469
|
-
"to": "browser/css"
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
### Configure TypeScript (optional)
|
|
475
|
-
|
|
476
|
-
Create a `tsconfig.json` file in your project root with the following:
|
|
477
|
-
|
|
478
|
-
```json
|
|
479
|
-
{
|
|
480
|
-
"include": ["src/**/*.ts"],
|
|
481
|
-
"exclude": ["src/**/*.test.*"],
|
|
482
|
-
"compilerOptions": {
|
|
483
|
-
"strict": true,
|
|
484
|
-
"target": "es2020",
|
|
485
|
-
"module": "commonjs",
|
|
486
|
-
"moduleResolution": "node10",
|
|
487
|
-
"ignoreDeprecations": "6.0",
|
|
488
|
-
"skipLibCheck": true,
|
|
489
|
-
"esModuleInterop": true,
|
|
490
|
-
"declaration": true,
|
|
491
|
-
"types": []
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
The pattern for `"include"` should match your .ts files (and leave out the tests, which can stay `.test.js` files).
|
|
497
|
-
The actual pattern used to compile comes from `build-tools.config.json` as the `'typescript.from'` setting.
|
|
498
|
-
To create the ts declaration files, you must add the `"declaration": true`. The `typescript` package is an optional peer
|
|
499
|
-
dependency, install it in your project with `npm install --save-dev typescript` (versions 5.0 up to, but not including,
|
|
500
|
-
7 are supported). When you write relative imports, leave the `.js` extension off (`import a from './a'`), because
|
|
501
|
-
they stop resolving once the target is a `.ts` file. The compile only builds `.ts` files while `typescript.enabled` is
|
|
502
|
-
on, so convert a whole library at once.
|
|
503
|
-
|
|
504
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
505
|
-
|
|
506
|
-
```json
|
|
507
|
-
{
|
|
508
|
-
"readme": {
|
|
509
|
-
// Location of files to use for compiling documentation into the readme.
|
|
510
|
-
"from": "dist/**/!(*.min).js"
|
|
511
|
-
},
|
|
512
|
-
"typescript": {
|
|
513
|
-
// The path the tsconfig file for running typescript or false if no ts file given.
|
|
514
|
-
"config": "tsconfig.json",
|
|
515
|
-
// Toggle usage of typescript parsing
|
|
516
|
-
"enabled": true,
|
|
517
|
-
// Pattern for finding the TypeScript files
|
|
518
|
-
"from": "src/**/*.ts",
|
|
519
|
-
// Directory where parsed typescript files go
|
|
520
|
-
"to": "dist"
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
The `js-to-markdown` only works on .js files, so we run the readme search on the built dist files. Also, we want to
|
|
526
|
-
register the tsconfig.json we created earlier and will alter the processes to build for TypeScript.
|
|
527
|
-
|
|
528
|
-
Update `babel.config.js` with the following:
|
|
529
|
-
|
|
530
|
-
```js
|
|
531
|
-
const babelConfig = require('js-build-tools/babel.config')
|
|
532
|
-
// This is the important line, we need to add compatibility for Jest to run tests on .ts files
|
|
533
|
-
babelConfig.presets.push('@babel/preset-typescript')
|
|
534
|
-
module.exports = babelConfig
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
### Configure HTML documentation (optional)
|
|
538
|
-
|
|
539
|
-
`jsdoc-to-markdown` (the readme generator) only reads `.js` files, so the types in your `.ts` files (and the
|
|
540
|
-
comments on them) never reach the readme it generates, and even for a plain JavaScript project a single
|
|
541
|
-
markdown readme is a thinner result than a real browsable site. Instead, `docs.enabled` generates real HTML
|
|
542
|
-
documentation straight from your source, with either engine:
|
|
543
|
-
|
|
544
|
-
* **TypeDoc** (for a TypeScript project) - every folder in your source directory becomes a module of the
|
|
545
|
-
documentation, the default export of each file (one function per file) is listed under the name of the file,
|
|
546
|
-
and everything else a file exports (for example the types in a `types.ts`) is listed as it is. Index files,
|
|
547
|
-
tests and declaration files are left out. A file which sits directly in the source directory, beside the
|
|
548
|
-
folders, is a module of its own (unless it is `index` or `main`). The first comment of a folder's `index.ts`
|
|
549
|
-
(or the header comment of such a file) describes its module. The comments on your code are the documentation,
|
|
550
|
-
and the types come from the code itself, so `@module`, `@memberOf`, `@typedef` and the `{Type}` of `@param`
|
|
551
|
-
are not needed. `typedoc` is an optional peer dependency (like `typescript`), install it in your project with
|
|
552
|
-
`npm install --save-dev typedoc` (this needs a `typescript` version it supports).
|
|
553
|
-
* **jsdoc** (for a plain JavaScript project, where TypeDoc has no real types to read) - scans your source
|
|
554
|
-
(`.js`, `.mjs` and `.cjs` files, leaving out tests and minified `.min.js` copies) recursively with jsdoc itself, rendered with a modern theme (`clean-jsdoc-theme` by default, used instead of
|
|
555
|
-
jsdoc's own classic default template) instead of the manual `.jsdoc.conf.js` setup described further below.
|
|
556
|
-
`jsdoc` and whichever theme you configure are optional peer dependencies, install them with
|
|
557
|
-
`npm install --save-dev jsdoc clean-jsdoc-theme` (or your own chosen theme package).
|
|
558
|
-
|
|
559
|
-
Add the following to the exports in your `build-tools.config.json`:
|
|
560
|
-
|
|
561
|
-
```json
|
|
562
|
-
{
|
|
563
|
-
"docs": {
|
|
564
|
-
//
|
|
565
|
-
"
|
|
566
|
-
//
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
//
|
|
571
|
-
//
|
|
572
|
-
"
|
|
573
|
-
//
|
|
574
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
//
|
|
579
|
-
|
|
580
|
-
//
|
|
581
|
-
"
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
//
|
|
588
|
-
"
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
is
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
await
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
(
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
"
|
|
676
|
-
"
|
|
677
|
-
"
|
|
678
|
-
"
|
|
679
|
-
"
|
|
680
|
-
"
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1
|
+
# [js-build-tools](https://www.npmjs.com/package/js-build-tools)
|
|
2
|
+
|
|
3
|
+
Centralize the build process for Node.js, JS and TypeScript projects into a single tool suite.
|
|
4
|
+
|
|
5
|
+
### Goals
|
|
6
|
+
|
|
7
|
+
Using this tool suite, you can:
|
|
8
|
+
|
|
9
|
+
* Parse TypeScript into JS distribution files
|
|
10
|
+
* Create formatted distribution files to be used in a node / commonjs environment.
|
|
11
|
+
* Bundle your distribution files to be used in a browser environment.
|
|
12
|
+
* Run tests and watch for changes.
|
|
13
|
+
* Generate jsdoc readme files.
|
|
14
|
+
* Generate real HTML documentation straight from your source - TypeDoc for a TypeScript project (a module for
|
|
15
|
+
each of your folders), or jsdoc with a modern theme for a plain JavaScript one.
|
|
16
|
+
* Copy files (a bundle, or anything else) to another location, on demand.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
In your project's root directory, run: `npm install --save-dev gulp js-build-tools`
|
|
21
|
+
(or `yarn add --dev gulp js-build-tools` if you use Yarn).
|
|
22
|
+
|
|
23
|
+
It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead
|
|
24
|
+
of `node_modules/.bin/gulp`.
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
|
|
28
|
+
In your project's root directory, create a `build-tools.config.json` file. This can contain any of the following (values
|
|
29
|
+
provided are the defaults):
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"browser": {
|
|
34
|
+
// 'true' to generate browser bundled files; 'false' for node environment only
|
|
35
|
+
"enabled": true,
|
|
36
|
+
// The name to use for the browser-bundled output file (.js will be appended).
|
|
37
|
+
"name": "my-package",
|
|
38
|
+
// The search pattern used for retrieving compiled distribution files.
|
|
39
|
+
"from": "dist/**/*.js",
|
|
40
|
+
// Module names or file paths which resolve to an empty object ({}) in the bundle instead of their real contents.
|
|
41
|
+
"ignore": [],
|
|
42
|
+
// Module names or file paths left out of the bundle entirely (requiring one at runtime throws, unless something
|
|
43
|
+
// else provides it, for example a script tag which loads it separately).
|
|
44
|
+
"exclude": [],
|
|
45
|
+
// Additional bundles to produce alongside the primary one above (see 'Configure additional browser bundles').
|
|
46
|
+
"bundles": [],
|
|
47
|
+
// The output directory for browser-bundled files.
|
|
48
|
+
"to": "browser"
|
|
49
|
+
},
|
|
50
|
+
// The paths for directories to delete before build.
|
|
51
|
+
"cleanPaths": [
|
|
52
|
+
"dist",
|
|
53
|
+
"browser"
|
|
54
|
+
],
|
|
55
|
+
"dist": {
|
|
56
|
+
// Name of the entry the distribution file.
|
|
57
|
+
"main": "dist/main",
|
|
58
|
+
// The search pattern used for gathering source files for distribution.
|
|
59
|
+
"from": "src/**/!(*.test).js",
|
|
60
|
+
// The output directory for the distribution files.
|
|
61
|
+
"to": "dist"
|
|
62
|
+
},
|
|
63
|
+
"docs": {
|
|
64
|
+
// Toggle generating the HTML documentation from the TypeScript source (see 'Configure TypeScript documentation').
|
|
65
|
+
// When on, the build does this instead of generating the readme from the jsdoc comments.
|
|
66
|
+
"enabled": false,
|
|
67
|
+
// The directory holding the TypeScript source, each folder in it becomes a module of the documentation.
|
|
68
|
+
"from": "src",
|
|
69
|
+
// The markdown file used as the front page of the documentation.
|
|
70
|
+
"index": "MAIN.md",
|
|
71
|
+
// How much TypeDoc reports: Verbose, Info, Warn, Error or None.
|
|
72
|
+
"logLevel": "Warn",
|
|
73
|
+
// The name of the documentation, defaults to the name in your package.json.
|
|
74
|
+
"title": "",
|
|
75
|
+
// The directory to generate the documentation in (it is cleared first).
|
|
76
|
+
"to": "docs",
|
|
77
|
+
// The tsconfig file to read the source with, false to use the one of 'typescript.config'.
|
|
78
|
+
"tsconfig": false
|
|
79
|
+
},
|
|
80
|
+
"fonts": {
|
|
81
|
+
// Toggle copy directory of fonts on
|
|
82
|
+
"enabled": false,
|
|
83
|
+
// Path to search for fonts
|
|
84
|
+
"from": "src/fonts/**/*",
|
|
85
|
+
// Path to output fonts
|
|
86
|
+
"to": "browser/fonts"
|
|
87
|
+
},
|
|
88
|
+
"images": {
|
|
89
|
+
// Toggle image minify and copy process
|
|
90
|
+
"enabled": false,
|
|
91
|
+
// Path to search for images
|
|
92
|
+
"from": "src/img/**/*.+(png|jpg|jpeg|gif|svg)",
|
|
93
|
+
// The JPEG quality (0 to 100) to compress to, false keeps mozjpeg's own default (75)
|
|
94
|
+
"jpegQuality": false,
|
|
95
|
+
// Path to output images
|
|
96
|
+
"to": "browser/img"
|
|
97
|
+
},
|
|
98
|
+
"readme": {
|
|
99
|
+
// The file which will be pre-fixed to your README.md output.
|
|
100
|
+
"template": "MAIN.md",
|
|
101
|
+
// Options for formatting the output readme.
|
|
102
|
+
"options": "utf8",
|
|
103
|
+
// The name of the output documentation markdown file.
|
|
104
|
+
"file": "README.md",
|
|
105
|
+
// Location of files to use for compiling documentation into the readme.
|
|
106
|
+
"from": [
|
|
107
|
+
"src/**/!(*.test).js"
|
|
108
|
+
],
|
|
109
|
+
// Additional .mjs files to document alongside 'from' (see 'Configure including ESM files in the generated
|
|
110
|
+
// readme'). Empty by default: a project that never sets this gets exactly the readme it always did.
|
|
111
|
+
"fromEsm": [],
|
|
112
|
+
// The directory to output the readme file in.
|
|
113
|
+
"to": "./"
|
|
114
|
+
},
|
|
115
|
+
// Base directory of the project.
|
|
116
|
+
"rootPath": "./",
|
|
117
|
+
"sass": {
|
|
118
|
+
// Toggle SASS to CSS process on.
|
|
119
|
+
"enabled": false,
|
|
120
|
+
// The pattern for finding all sass files.
|
|
121
|
+
"from": "sass/**/*.+(scss|sass)",
|
|
122
|
+
// The directory were sass files will be stored.
|
|
123
|
+
"path": "sass",
|
|
124
|
+
// The destination path for where generated CSS (from SASS files) should go.
|
|
125
|
+
"to": "browser/css"
|
|
126
|
+
},
|
|
127
|
+
// The directory where your source files are stored (the files you manually created).
|
|
128
|
+
"srcPath": "src",
|
|
129
|
+
"test": {
|
|
130
|
+
// Additional flags for programmatically running Jest Cli.
|
|
131
|
+
"options": null,
|
|
132
|
+
// The directory where Jest test files are stored.
|
|
133
|
+
// By default, stored as *.test.js adjacent to the files they are testing.
|
|
134
|
+
"path": [
|
|
135
|
+
"src"
|
|
136
|
+
],
|
|
137
|
+
// The search pattern for watching files for changes.
|
|
138
|
+
"watch": "src/**/*.js"
|
|
139
|
+
},
|
|
140
|
+
"typescript": {
|
|
141
|
+
// The path the tsconfig file for running typescript or false if no ts file given.
|
|
142
|
+
"config": false,
|
|
143
|
+
// Toggle usage of typescript parsing.
|
|
144
|
+
"enabled": false,
|
|
145
|
+
// Pattern for finding the TypeScript files.
|
|
146
|
+
"from": "src/**/*.ts",
|
|
147
|
+
// Directory where parsed typescript files go.
|
|
148
|
+
"to": "dist"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Create your local gulpfile.js
|
|
154
|
+
|
|
155
|
+
In your project's root directory, create a `gulpfile.js` file, in here you can require any of the functions you need.
|
|
156
|
+
For example:
|
|
157
|
+
|
|
158
|
+
#### Common JS
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
// Your local gulpfile.js
|
|
162
|
+
const {
|
|
163
|
+
build,
|
|
164
|
+
defaultCmd,
|
|
165
|
+
docs,
|
|
166
|
+
partials,
|
|
167
|
+
readme,
|
|
168
|
+
sass,
|
|
169
|
+
testFull,
|
|
170
|
+
testQuick,
|
|
171
|
+
typescript,
|
|
172
|
+
watchFull,
|
|
173
|
+
watchTest
|
|
174
|
+
} = require('js-build-tools/gulpfile.base.js')
|
|
175
|
+
|
|
176
|
+
// Everything you export will be created as a gulp task.
|
|
177
|
+
// You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
|
|
178
|
+
// You can list your available tasks by running `gulp --tasks`.
|
|
179
|
+
exports.build = build
|
|
180
|
+
exports.default = defaultCmd
|
|
181
|
+
exports.docs = docs
|
|
182
|
+
exports.readme = readme
|
|
183
|
+
exports.sass = sass
|
|
184
|
+
exports.testFull = testFull
|
|
185
|
+
exports.testQuick = testQuick
|
|
186
|
+
exports.watchFull = watchFull
|
|
187
|
+
exports.watchTest = watchTest
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### ES Module
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// Your local gulpfile.mjs
|
|
194
|
+
// Everything you export will be created as a gulp task.
|
|
195
|
+
export {
|
|
196
|
+
build,
|
|
197
|
+
defaultCmd,
|
|
198
|
+
docs,
|
|
199
|
+
partials,
|
|
200
|
+
readme,
|
|
201
|
+
sass,
|
|
202
|
+
testFull,
|
|
203
|
+
testQuick,
|
|
204
|
+
typescript,
|
|
205
|
+
watchFull,
|
|
206
|
+
watchTest
|
|
207
|
+
} from 'js-build-tools/gulpfile.base.mjs'
|
|
208
|
+
|
|
209
|
+
// You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
|
|
210
|
+
// You can list your available tasks by running `gulp --tasks`.
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Verify your tasks are available by running `gulp --tasks`.
|
|
215
|
+
|
|
216
|
+
### Configure Babel
|
|
217
|
+
|
|
218
|
+
Depending on how you wrote your test files, Jest may require some Babel configuration.
|
|
219
|
+
Create a `babel.config.js` file in the root directory of your project.
|
|
220
|
+
You can then use the recommended configuration by requiring the `babel.config.js` file into your own configuration file.
|
|
221
|
+
Example:
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
const babelConfig = require('js-build-tools/babel.config')
|
|
225
|
+
// You may add additional configuration here. Example: babelConfig.presets.push('@babel/preset-env')
|
|
226
|
+
module.exports = babelConfig
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Configure ES Modules (.mjs)
|
|
230
|
+
|
|
231
|
+
It is not recommended to use `"type": "module"` in the `package.json` to enable ES Modules.
|
|
232
|
+
This is because some dependencies still rely on common JS syntax (ex: babel, jest, jsdoc).
|
|
233
|
+
So, to use ES Modules, you can use the `.mjs` extension on your files instead.
|
|
234
|
+
There are different downsides to using the `.mjs` extension to consider.
|
|
235
|
+
The `jsdoc` generation can only read `.js` files, and the provided test runner `Jest` will need to be configured.
|
|
236
|
+
Update the test config as follows:
|
|
237
|
+
|
|
238
|
+
```json
|
|
239
|
+
{
|
|
240
|
+
"dist": {
|
|
241
|
+
// Use .mjs files for from and main
|
|
242
|
+
"main": "src/main.mjs",
|
|
243
|
+
"from": "src/**/!(*.test).mjs",
|
|
244
|
+
"to": "dist"
|
|
245
|
+
},
|
|
246
|
+
"readme": {
|
|
247
|
+
"template": "MAIN.md",
|
|
248
|
+
"options": "utf8",
|
|
249
|
+
"file": "README.md",
|
|
250
|
+
"from": [
|
|
251
|
+
// Use the dist directory files to generate the jsdocs - dist is always .js regardless of source
|
|
252
|
+
// extension, since Babel compiles .mjs source down to it, so this is enough on its own. If you instead
|
|
253
|
+
// have a handful of standalone .mjs files that never go through the normal dist compile (for example a
|
|
254
|
+
// config file read directly by the build itself), see 'Configure including ESM files in the generated
|
|
255
|
+
// readme' for readme.fromEsm instead - a lighter option than switching your whole project's dist/test
|
|
256
|
+
// config over to .mjs just to document a few files.
|
|
257
|
+
"dist/!(*.test).js"
|
|
258
|
+
],
|
|
259
|
+
"to": "./"
|
|
260
|
+
},
|
|
261
|
+
"test": {
|
|
262
|
+
"options": {
|
|
263
|
+
// The below helps to find the .mjs files (rather than default .js files)
|
|
264
|
+
"testMatch": [
|
|
265
|
+
"**/?(*.)+(spec|test).mjs?(x)"
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
"path": "functions",
|
|
269
|
+
// Include watching for .mjs files
|
|
270
|
+
"watch": "functions/**/*.[cm]?[jt]s"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
There is an additional file you need to get Jest working, add a `jest.config.js` file.
|
|
276
|
+
While we have already added these configurations above in the "options",
|
|
277
|
+
there seems to be a bug where the "transform" does not work in that context. Add the following to your `jest.config.js`:
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
module.exports = {
|
|
281
|
+
// The transform will instruct jest to run the files through babel so it can interpret them
|
|
282
|
+
transform: {
|
|
283
|
+
'^.+\\.[cm]?[jt]sx?$': 'babel-jest'
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Configure HTML JS Documentation, full manual control (optional, advanced)
|
|
289
|
+
|
|
290
|
+
For most projects, `docs.enabled` with `docs.method: 'jsdoc'` (see 'Configure HTML documentation' below) is the
|
|
291
|
+
simpler path - no `.jsdoc.conf.js` file to maintain by hand, wired straight into `gulp build`/`gulp docs`. This
|
|
292
|
+
section is for when you want full, direct control over jsdoc's own config instead (a plugin or option this
|
|
293
|
+
project's own generated config does not expose, for example).
|
|
294
|
+
|
|
295
|
+
Create a `.jsdoc.conf.js` file and add the following:
|
|
296
|
+
|
|
297
|
+
```js
|
|
298
|
+
const jsDocBase = require('js-build-tools/jsdoc.base')
|
|
299
|
+
/* You will get a jsdoc config object with the following:
|
|
300
|
+
* {
|
|
301
|
+
* plugins: ['plugins/markdown'],
|
|
302
|
+
* source: {
|
|
303
|
+
* include: [your configured distPath],
|
|
304
|
+
* includePattern: '.+\\.js(doc|x)?$',
|
|
305
|
+
* excludePattern: '((^|\\/|\\\\)_|.+\\.test\\..*)'
|
|
306
|
+
* }
|
|
307
|
+
* }
|
|
308
|
+
* You can manipulate the properties before returning in module.exports.
|
|
309
|
+
* This searches the defined 'distPath' for building the HTML JS Documentation
|
|
310
|
+
*/
|
|
311
|
+
module.exports = jsDocBase
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Configure what the browser bundle leaves out (optional)
|
|
315
|
+
|
|
316
|
+
A dependency can be reached from your code without being needed in the browser, and bundling it can add a lot of size.
|
|
317
|
+
Two settings in `browser` handle this, both take module names or file paths (see browserify's `b.ignore(file)` and
|
|
318
|
+
`b.exclude(file)`):
|
|
319
|
+
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"browser": {
|
|
323
|
+
// Resolves to an empty object ({}) in the bundle instead of the real module. This suits a dependency which is only
|
|
324
|
+
// reached because it is the default value of an option you always override with your own (for example a selector
|
|
325
|
+
// engine's default DOM adapter). Anything only that module requires is left out too. Your code must never actually
|
|
326
|
+
// use the real module, so keep overriding that option.
|
|
327
|
+
"ignore": ["some-default-adapter"],
|
|
328
|
+
// Left out of the bundle entirely. Requiring it at runtime throws unless something else provides it, for example a
|
|
329
|
+
// script tag which loads it separately, so this suits a large library which the page already loads.
|
|
330
|
+
"exclude": ["a-library-the-page-loads"]
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Configure additional browser bundles (optional)
|
|
336
|
+
|
|
337
|
+
By default a project produces exactly one browser bundle, from `dist.main`/`browser.name`/`browser.ignore`/
|
|
338
|
+
`browser.exclude` above. `browser.bundles` adds more bundles alongside it - for example a render-only variant built
|
|
339
|
+
from a different entry point than the full bundle. Each entry only needs to specify what's actually different about
|
|
340
|
+
that bundle; anything left out falls back to the primary bundle's own value:
|
|
341
|
+
|
|
342
|
+
```json
|
|
343
|
+
{
|
|
344
|
+
"browser": {
|
|
345
|
+
"bundles": [
|
|
346
|
+
{
|
|
347
|
+
// Required, and must be unique among all of a project's bundles: the name for this bundle's own output file
|
|
348
|
+
// and standalone export.
|
|
349
|
+
"name": "render-only",
|
|
350
|
+
// This bundle's own entry point. Falls back to dist.main when omitted.
|
|
351
|
+
"main": "dist/renderOnly.js",
|
|
352
|
+
// This bundle's own ignore list. Falls back to browser.ignore when omitted.
|
|
353
|
+
"ignore": [],
|
|
354
|
+
// This bundle's own exclude list. Falls back to browser.exclude when omitted.
|
|
355
|
+
"exclude": []
|
|
356
|
+
}
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
For the `gulpConfig` module's own `get`/`set` functions (read or override a resolved configuration value from your
|
|
363
|
+
own code, by the same dot-notation path a setting has in the JSON above), see the generated reference below.
|
|
364
|
+
|
|
365
|
+
### Configure including ESM files in the generated readme (optional)
|
|
366
|
+
|
|
367
|
+
The readme generator (`jsdoc-to-markdown`) only recognizes `.js` files, even though it parses real ESM `import`/
|
|
368
|
+
`export` syntax just fine once it reads one - the file extension is the only thing it filters on, not the content.
|
|
369
|
+
`readme.fromEsm` names `.mjs` files to document anyway: each one is read, rewritten (every top-level `export const`/
|
|
370
|
+
`export function`/`export class` becomes a plain declaration plus a trailing `module.exports = { ... }` - the same
|
|
371
|
+
shape `jsdoc-to-markdown` already documents cleanly, since that rewrite is exactly what this project's own
|
|
372
|
+
`gulp.config.mjs` needs it for) and written to a temp `.js` file outside your project entirely, which is cleaned up
|
|
373
|
+
again once the readme generator has read it. Other export forms (`export default`, re-exports, `export { a, b }`
|
|
374
|
+
lists) are left untouched in whatever way `jsdoc-to-markdown` already handles ESM - restructure a file to use named
|
|
375
|
+
exports if you want it documented this cleanly:
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"readme": {
|
|
380
|
+
"fromEsm": ["src/myEsmOnlyModule.mjs"]
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Configure copy files (optional)
|
|
386
|
+
|
|
387
|
+
Copy files (a bundle, or anything else) to another location - any number of entries, each independent. Unlike
|
|
388
|
+
every other task here, this is never run automatically as part of `gulp build` - what this copies is often the
|
|
389
|
+
live, publicly-reachable version of something, so publishing it should be a deliberate step your own script
|
|
390
|
+
opts into, not a side effect of a routine local build.
|
|
391
|
+
|
|
392
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
393
|
+
|
|
394
|
+
```json
|
|
395
|
+
{
|
|
396
|
+
"copyFiles": [
|
|
397
|
+
{
|
|
398
|
+
// The glob pattern(s) of files to copy
|
|
399
|
+
"from": "browser/**/*.js",
|
|
400
|
+
// The directory to copy them into
|
|
401
|
+
"to": "../my-other-project/vendor",
|
|
402
|
+
// Optional - preserves this glob's own subdirectory structure in the destination, instead of flattening it
|
|
403
|
+
"base": "browser"
|
|
404
|
+
}
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
If you also export `copyFiles` from your gulpfile you can run it on its own with `gulp copyFiles`, and can then
|
|
410
|
+
add your own script for it, for example `"publish:bundle": "gulp copyFiles"`.
|
|
411
|
+
|
|
412
|
+
### Configure move fonts (optional)
|
|
413
|
+
|
|
414
|
+
Be able to copy a source directory of fonts into the distribution path.
|
|
415
|
+
|
|
416
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
417
|
+
|
|
418
|
+
```json
|
|
419
|
+
{
|
|
420
|
+
"fonts": {
|
|
421
|
+
// Enable fonts process
|
|
422
|
+
"enabled": false,
|
|
423
|
+
// Search pattern to find your font files
|
|
424
|
+
"from": "src/fonts/**/*",
|
|
425
|
+
// Output directory for your font files
|
|
426
|
+
"to": "browser/fonts"
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### Configure move and minify images (optional)
|
|
432
|
+
|
|
433
|
+
Be able to copy and reduce the file size of images into an output path.
|
|
434
|
+
|
|
435
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
436
|
+
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"images": {
|
|
440
|
+
// Enable image process
|
|
441
|
+
"enabled": false,
|
|
442
|
+
// Search pattern to find your images
|
|
443
|
+
"from": "src/img/**/*.+(png|jpg|jpeg|gif|svg)",
|
|
444
|
+
// The JPEG quality (0 to 100) to compress to. Left false, mozjpeg uses its own default of 75, which can
|
|
445
|
+
// visibly band smooth gradients in photos; 85 is usually indistinguishable from the original
|
|
446
|
+
"jpegQuality": false,
|
|
447
|
+
// Output directory for your images files
|
|
448
|
+
"to": "browser/img"
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### Configure SASS (optional)
|
|
454
|
+
|
|
455
|
+
SASS support is built-in, this enables conversion of SASS files to CSS for web projects.
|
|
456
|
+
|
|
457
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
458
|
+
|
|
459
|
+
```json
|
|
460
|
+
{
|
|
461
|
+
"sass": {
|
|
462
|
+
// Enable SASS process
|
|
463
|
+
"enabled": false,
|
|
464
|
+
// Search pattern to find your SASS files (the below would be files ending in .scss or .sass in a directory called 'sass')
|
|
465
|
+
"from": "sass/**/*.+(scss|sass)",
|
|
466
|
+
// Optional but nice to add (future support), add the directory where your sass files exist
|
|
467
|
+
"path": "sass",
|
|
468
|
+
// Output directory for your compiled css files, recommend css directory within your browser output directory
|
|
469
|
+
"to": "browser/css"
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### Configure TypeScript (optional)
|
|
475
|
+
|
|
476
|
+
Create a `tsconfig.json` file in your project root with the following:
|
|
477
|
+
|
|
478
|
+
```json
|
|
479
|
+
{
|
|
480
|
+
"include": ["src/**/*.ts"],
|
|
481
|
+
"exclude": ["src/**/*.test.*"],
|
|
482
|
+
"compilerOptions": {
|
|
483
|
+
"strict": true,
|
|
484
|
+
"target": "es2020",
|
|
485
|
+
"module": "commonjs",
|
|
486
|
+
"moduleResolution": "node10",
|
|
487
|
+
"ignoreDeprecations": "6.0",
|
|
488
|
+
"skipLibCheck": true,
|
|
489
|
+
"esModuleInterop": true,
|
|
490
|
+
"declaration": true,
|
|
491
|
+
"types": []
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
The pattern for `"include"` should match your .ts files (and leave out the tests, which can stay `.test.js` files).
|
|
497
|
+
The actual pattern used to compile comes from `build-tools.config.json` as the `'typescript.from'` setting.
|
|
498
|
+
To create the ts declaration files, you must add the `"declaration": true`. The `typescript` package is an optional peer
|
|
499
|
+
dependency, install it in your project with `npm install --save-dev typescript` (versions 5.0 up to, but not including,
|
|
500
|
+
7 are supported). When you write relative imports, leave the `.js` extension off (`import a from './a'`), because
|
|
501
|
+
they stop resolving once the target is a `.ts` file. The compile only builds `.ts` files while `typescript.enabled` is
|
|
502
|
+
on, so convert a whole library at once.
|
|
503
|
+
|
|
504
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
505
|
+
|
|
506
|
+
```json
|
|
507
|
+
{
|
|
508
|
+
"readme": {
|
|
509
|
+
// Location of files to use for compiling documentation into the readme.
|
|
510
|
+
"from": "dist/**/!(*.min).js"
|
|
511
|
+
},
|
|
512
|
+
"typescript": {
|
|
513
|
+
// The path the tsconfig file for running typescript or false if no ts file given.
|
|
514
|
+
"config": "tsconfig.json",
|
|
515
|
+
// Toggle usage of typescript parsing
|
|
516
|
+
"enabled": true,
|
|
517
|
+
// Pattern for finding the TypeScript files
|
|
518
|
+
"from": "src/**/*.ts",
|
|
519
|
+
// Directory where parsed typescript files go
|
|
520
|
+
"to": "dist"
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
The `js-to-markdown` only works on .js files, so we run the readme search on the built dist files. Also, we want to
|
|
526
|
+
register the tsconfig.json we created earlier and will alter the processes to build for TypeScript.
|
|
527
|
+
|
|
528
|
+
Update `babel.config.js` with the following:
|
|
529
|
+
|
|
530
|
+
```js
|
|
531
|
+
const babelConfig = require('js-build-tools/babel.config')
|
|
532
|
+
// This is the important line, we need to add compatibility for Jest to run tests on .ts files
|
|
533
|
+
babelConfig.presets.push('@babel/preset-typescript')
|
|
534
|
+
module.exports = babelConfig
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Configure HTML documentation (optional)
|
|
538
|
+
|
|
539
|
+
`jsdoc-to-markdown` (the readme generator) only reads `.js` files, so the types in your `.ts` files (and the
|
|
540
|
+
comments on them) never reach the readme it generates, and even for a plain JavaScript project a single
|
|
541
|
+
markdown readme is a thinner result than a real browsable site. Instead, `docs.enabled` generates real HTML
|
|
542
|
+
documentation straight from your source, with either engine:
|
|
543
|
+
|
|
544
|
+
* **TypeDoc** (for a TypeScript project) - every folder in your source directory becomes a module of the
|
|
545
|
+
documentation, the default export of each file (one function per file) is listed under the name of the file,
|
|
546
|
+
and everything else a file exports (for example the types in a `types.ts`) is listed as it is. Index files,
|
|
547
|
+
tests and declaration files are left out. A file which sits directly in the source directory, beside the
|
|
548
|
+
folders, is a module of its own (unless it is `index` or `main`). The first comment of a folder's `index.ts`
|
|
549
|
+
(or the header comment of such a file) describes its module. The comments on your code are the documentation,
|
|
550
|
+
and the types come from the code itself, so `@module`, `@memberOf`, `@typedef` and the `{Type}` of `@param`
|
|
551
|
+
are not needed. `typedoc` is an optional peer dependency (like `typescript`), install it in your project with
|
|
552
|
+
`npm install --save-dev typedoc` (this needs a `typescript` version it supports).
|
|
553
|
+
* **jsdoc** (for a plain JavaScript project, where TypeDoc has no real types to read) - scans your source
|
|
554
|
+
(`.js`, `.mjs` and `.cjs` files, leaving out tests and minified `.min.js` copies) recursively with jsdoc itself, rendered with a modern theme (`clean-jsdoc-theme` by default, used instead of
|
|
555
|
+
jsdoc's own classic default template) instead of the manual `.jsdoc.conf.js` setup described further below.
|
|
556
|
+
`jsdoc` and whichever theme you configure are optional peer dependencies, install them with
|
|
557
|
+
`npm install --save-dev jsdoc clean-jsdoc-theme` (or your own chosen theme package).
|
|
558
|
+
|
|
559
|
+
Add the following to the exports in your `build-tools.config.json`:
|
|
560
|
+
|
|
561
|
+
```json
|
|
562
|
+
{
|
|
563
|
+
"docs": {
|
|
564
|
+
// jsdoc with clean-jsdoc-theme 5.x only: the path the documentation is served from, such as
|
|
565
|
+
// "/projects/my-lib/docs/". The theme's links start at the site root, so documentation served below it needs
|
|
566
|
+
// this. Left false, it is served from the site root
|
|
567
|
+
"basePath": false,
|
|
568
|
+
// Generate the documentation from the source
|
|
569
|
+
"enabled": true,
|
|
570
|
+
// The directory holding the source, each folder in it becomes a module (TypeDoc) or is scanned recursively (jsdoc).
|
|
571
|
+
// jsdoc also takes a list of directories and files, for example ["functions", "gulpfile.base.mjs"]
|
|
572
|
+
"from": "src",
|
|
573
|
+
// TypeDoc only: the git revision the "Defined in" source links point to. Left false, TypeDoc uses the current
|
|
574
|
+
// commit, so every commit changes every page; a branch name such as "main" keeps them the same until the
|
|
575
|
+
// documentation itself changes
|
|
576
|
+
"gitRevision": false,
|
|
577
|
+
// Generate the documentation as part of build (the default). Set it to false to only generate it when you run
|
|
578
|
+
// the docs task yourself (see below)
|
|
579
|
+
"inBuild": true,
|
|
580
|
+
// The markdown file used as the front page of the documentation (a short overview of your project)
|
|
581
|
+
"index": "MAIN.md",
|
|
582
|
+
// 'typedoc' or 'jsdoc'. Left out (or false), it's inferred from typescript.enabled - 'typedoc' when your
|
|
583
|
+
// project is TypeScript, 'jsdoc' when it is not - so most projects never need to set this at all. Set it
|
|
584
|
+
// explicitly to override that inference either way.
|
|
585
|
+
"method": false,
|
|
586
|
+
// Only meaningful when method is (or resolves to) 'jsdoc' - the theme package to render with. TypeDoc
|
|
587
|
+
// always keeps its own default regardless of this setting.
|
|
588
|
+
"theme": "clean-jsdoc-theme",
|
|
589
|
+
// The name of the documentation (TypeDoc's title, the theme's title for jsdoc), defaults to the package name
|
|
590
|
+
"title": "",
|
|
591
|
+
// Where the HTML is generated (the directory is cleared first)
|
|
592
|
+
"to": "docs"
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
While `docs.enabled` is on, `gulp build` generates the documentation instead of the readme, so your `README.md` stays
|
|
598
|
+
hand-written (a short overview which links to the documentation). If you also export `docs` from your gulpfile you can
|
|
599
|
+
run it on its own with `gulp docs`, and can then add the script `"docs": "gulp docs"`.
|
|
600
|
+
|
|
601
|
+
To make generating the documentation a deliberate step instead, set `docs.inBuild` to `false`: `gulp build` then
|
|
602
|
+
generates neither the documentation nor the readme, and `gulp docs` is the only thing that writes to `docs.to`. This
|
|
603
|
+
suits a `docs.to` which points into another repository (a website, say): a build on a work-in-progress branch no
|
|
604
|
+
longer rewrites the published documentation, which you regenerate when you release instead. For example with
|
|
605
|
+
release-it, in `.release-it.json`:
|
|
606
|
+
|
|
607
|
+
```json
|
|
608
|
+
{
|
|
609
|
+
"hooks": {
|
|
610
|
+
"after:bump": "npm run docs"
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Browser automation (optional)
|
|
616
|
+
|
|
617
|
+
Unlike the rest of this file, this isn't a `build-tools.config.json`-driven feature with its own task - it's a pair
|
|
618
|
+
of plain functions (`partials.loadPlaywright`/`partials.launchBrowser` and `partials.serveStatic`) for whatever your
|
|
619
|
+
own script needs a real browser for: verifying a page that only works correctly in a real browser (for example one
|
|
620
|
+
using `<script type="module">`, which no DOM-simulation library executes at all), or taking a real screenshot.
|
|
621
|
+
|
|
622
|
+
`playwright` is an optional peer dependency, install it in your project with `npm install --save-dev playwright`,
|
|
623
|
+
then fetch a real browser binary once per machine (not per project) with `npx playwright install chromium` - if
|
|
624
|
+
that fails with "Playwright does not support chromium on <your distro>", your OS is too old for the current
|
|
625
|
+
release; either upgrade it or pin an older `playwright` version known to still support it (confirmed: `1.62.1`
|
|
626
|
+
is the newest release that still installs and runs real headless Chromium on Ubuntu 20.04).
|
|
627
|
+
|
|
628
|
+
```js
|
|
629
|
+
const { launchBrowser, serveStatic } = require('js-build-tools').partials
|
|
630
|
+
|
|
631
|
+
const { server, url } = await serveStatic('browser') // serves ./browser/ over a real local HTTP server
|
|
632
|
+
const browser = await launchBrowser()
|
|
633
|
+
const page = await browser.newPage()
|
|
634
|
+
await page.goto(`${url}/index.html`)
|
|
635
|
+
await page.screenshot({ path: 'homepage.png' }) // a real screenshot, to actually look at
|
|
636
|
+
await browser.close()
|
|
637
|
+
server.close()
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
`serveStatic` exists because a page loaded directly from a `file://` path resolves any root-relative asset path
|
|
641
|
+
(`/browser/...`) against the filesystem root instead of the page's own directory - serving it over real HTTP avoids
|
|
642
|
+
that entirely, and is also the right fix for the exact same problem in a jsdom-based test.
|
|
643
|
+
|
|
644
|
+
### Configure lint rule overrides (optional)
|
|
645
|
+
|
|
646
|
+
`sourceLint` lints your real source directly (not the compiled dist/browser output) with
|
|
647
|
+
[neostandard](https://github.com/neostandard/neostandard). Occasionally a rule is wrong for your project
|
|
648
|
+
specifically, rather than something to fix in your code - for example a test which deliberately contains a string
|
|
649
|
+
of literal `${...}` text (simulating another module's real source, not a mistaken non-template string), which
|
|
650
|
+
trips neostandard's `no-template-curly-in-string` rule as a false positive. `lint.rules` layers ESLint rule
|
|
651
|
+
overrides on top of neostandard's own rules, scoped to the same files neostandard itself lints:
|
|
652
|
+
|
|
653
|
+
```json
|
|
654
|
+
{
|
|
655
|
+
"lint": {
|
|
656
|
+
// ESLint rule overrides, keyed and valued exactly as ESLint's own "rules" object.
|
|
657
|
+
"rules": {
|
|
658
|
+
"no-template-curly-in-string": "off"
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
Empty by default, so a project that never sets this gets exactly neostandard's own rules, unchanged. Prefer fixing
|
|
665
|
+
the actual code (or, for one specific line, an `eslint-disable-next-line` comment) over this when the finding is
|
|
666
|
+
real - reach for `lint.rules` only when the rule itself doesn't fit your project.
|
|
667
|
+
|
|
668
|
+
### Configure Scripts
|
|
669
|
+
|
|
670
|
+
In your `package.json` file, add the following scripts:
|
|
671
|
+
|
|
672
|
+
```json
|
|
673
|
+
{
|
|
674
|
+
"scripts": {
|
|
675
|
+
"build": "gulp build",
|
|
676
|
+
"dev": "gulp",
|
|
677
|
+
"docs": "gulp docs",
|
|
678
|
+
"publish:bundle": "gulp copyFiles",
|
|
679
|
+
"readme": "gulp readme",
|
|
680
|
+
"sass": "gulp sass",
|
|
681
|
+
"test": "gulp testFull",
|
|
682
|
+
"test:quick": "gulp testQuick",
|
|
683
|
+
"watch": "gulp watchFull",
|
|
684
|
+
"watch:test": "gulp watchTest"
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
## Usage
|
|
690
|
+
|
|
691
|
+
Run any of the above commands with `gulp` or `npm run`.
|
|
692
|
+
|
|
689
693
|
## Modules
|
|
690
694
|
|
|
691
695
|
<dl>
|
|
@@ -736,13 +740,16 @@ Simplified typescript task using tsFor.
|
|
|
736
740
|
<a name="module_js-build-tools.typeDocs"></a>
|
|
737
741
|
|
|
738
742
|
### js-build-tools.typeDocs ⇒ <code>function</code>
|
|
739
|
-
Generate the HTML documentation of a TypeScript project from its source, with the modules mirroring the source
|
|
743
|
+
Generate the HTML documentation of a TypeScript project from its source, with the modules mirroring the source
|
|
744
|
+
folders. Turn it on with docs.enabled, see [typeDocsFor](#module_partials.typeDocsFor).
|
|
740
745
|
|
|
741
746
|
**Kind**: static constant of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
742
747
|
<a name="module_js-build-tools.jsdocDocs"></a>
|
|
743
748
|
|
|
744
749
|
### js-build-tools.jsdocDocs ⇒ <code>function</code>
|
|
745
|
-
Generate the HTML documentation of a plain-JavaScript project from its source, with a modern jsdoc theme
|
|
750
|
+
Generate the HTML documentation of a plain-JavaScript project from its source, with a modern jsdoc theme
|
|
751
|
+
instead of jsdoc's own classic default. Turn it on with docs.enabled and docs.method: 'jsdoc' (the default
|
|
752
|
+
when typescript.enabled is off), see [module:partials.jsdocDocsFor](module:partials.jsdocDocsFor).
|
|
746
753
|
|
|
747
754
|
**Kind**: static constant of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
748
755
|
<a name="module_js-build-tools.compileReadme"></a>
|
|
@@ -766,25 +773,33 @@ Watch for changes and run the distribution for the changed files, then bundle an
|
|
|
766
773
|
<a name="module_js-build-tools.testQuick"></a>
|
|
767
774
|
|
|
768
775
|
### js-build-tools.testQuick() ⇒ <code>Promise.<\*></code>
|
|
769
|
-
Run the Jest tests for files which have been modified (based on git status).
|
|
776
|
+
Run the Jest tests for files which have been modified (based on git status).
|
|
777
|
+
Configure where tests are located by using 'testPath'.
|
|
770
778
|
|
|
771
779
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
772
780
|
<a name="module_js-build-tools.testFull"></a>
|
|
773
781
|
|
|
774
782
|
### js-build-tools.testFull() ⇒ <code>Promise.<\*></code>
|
|
775
|
-
Run all tests with jest.
|
|
783
|
+
Run all tests with jest.
|
|
784
|
+
Configure where tests are located by using 'testPath'.
|
|
776
785
|
|
|
777
786
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
778
787
|
<a name="module_js-build-tools.sourceLint"></a>
|
|
779
788
|
|
|
780
789
|
### js-build-tools.sourceLint() ⇒ <code>\*</code>
|
|
781
|
-
Applies neostandard linting (js-build-tools' chosen style) to the real, hand-written source - not the compiled
|
|
790
|
+
Applies neostandard linting (js-build-tools' chosen style) to the real, hand-written source - not the compiled
|
|
791
|
+
dist/browser output, which is generated and so was never going to pass a hand-authored-code style check (every
|
|
792
|
+
compiler/bundler emits its own boilerplate - import aliasing, interop headers - that only looks like a style
|
|
793
|
+
violation). Includes test files: there is no reason to hold tests to a lower style bar than the rest of the
|
|
794
|
+
source. When typescript.enabled, the real TypeScript source is linted too, with type-aware rules. Runs as part of
|
|
795
|
+
`build`, where remaining errors are reported but never fail it.
|
|
782
796
|
|
|
783
797
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
784
798
|
<a name="module_js-build-tools.lint"></a>
|
|
785
799
|
|
|
786
800
|
### js-build-tools.lint() ⇒ <code>\*</code>
|
|
787
|
-
The standalone lint command (`gulp lint`, or `npm run lint`): the same linting and fixing as sourceLint, but it
|
|
801
|
+
The standalone lint command (`gulp lint`, or `npm run lint`): the same linting and fixing as sourceLint, but it
|
|
802
|
+
fails (exits non-zero) when any errors remain that neostandard could not fix automatically.
|
|
788
803
|
|
|
789
804
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
790
805
|
<a name="module_js-build-tools.images"></a>
|
|
@@ -796,7 +811,9 @@ Move and optimize the images into the browser folder using configured settings.
|
|
|
796
811
|
<a name="module_js-build-tools.docs"></a>
|
|
797
812
|
|
|
798
813
|
### js-build-tools.docs([done]) ⇒ <code>\*</code>
|
|
799
|
-
Generate the HTML documentation with whichever engine docs.method (or its typescript.enabled-based default)
|
|
814
|
+
Generate the HTML documentation with whichever engine docs.method (or its typescript.enabled-based default)
|
|
815
|
+
resolves to - see [resolveDocsMethod](#module_partials.resolveDocsMethod). The standalone counterpart to build's own
|
|
816
|
+
internal branching, for running `gulp docs` directly instead of as part of a full build.
|
|
800
817
|
|
|
801
818
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
802
819
|
|
|
@@ -836,25 +853,58 @@ Move the font files into the browser directory.
|
|
|
836
853
|
<a name="module_js-build-tools.copyFiles"></a>
|
|
837
854
|
|
|
838
855
|
### js-build-tools.copyFiles() ⇒ <code>Promise.<void></code>
|
|
839
|
-
Copy files from one place to another - any number of { from, to, base? } entries, configured via copyFiles.
|
|
856
|
+
Copy files from one place to another - any number of { from, to, base? } entries, configured via copyFiles.
|
|
857
|
+
A project with no copyFiles entries gets a task that does nothing. Meant to be run explicitly (its own script,
|
|
858
|
+
e.g. `gulp copyFiles`), not folded into the default build - a bundle (or any other file this copies) is often
|
|
859
|
+
the live, publicly-reachable version of something, so publishing it elsewhere should be a deliberate step, not
|
|
860
|
+
a side effect of every routine local build.
|
|
861
|
+
|
|
862
|
+
Reuses copyFor (already shared with copyFonts) rather than a fresh src()/dest() pair - that keeps its existing
|
|
863
|
+
encoding: false fix (Gulp 5's default utf8 handling corrupts binary files such as fonts or a minified bundle)
|
|
864
|
+
instead of silently losing it in a parallel implementation.
|
|
865
|
+
|
|
866
|
+
Each entry runs as its own independent copyFor(), awaited via Promise.all rather than merged into one combined
|
|
867
|
+
stream (mergeStream, the pattern bundle.mjs uses) - that pattern assumes every merged stream ends up at the
|
|
868
|
+
same shared destination; here, each entry can have a genuinely different one, and merging streams that each
|
|
869
|
+
already terminate at their own separate dest() hit a real "write after end" error in practice.
|
|
840
870
|
|
|
841
871
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
842
872
|
<a name="module_js-build-tools.bundleMinify"></a>
|
|
843
873
|
|
|
844
874
|
### js-build-tools.bundleMinify() ⇒ <code>\*</code>
|
|
845
|
-
Creates the minified file for every bundle (the primary bundle, plus any additional ones from
|
|
875
|
+
Creates the minified file for every bundle (the primary bundle, plus any additional ones from
|
|
876
|
+
browser.bundles). The minify step itself never varies per bundle, so this is one shared
|
|
877
|
+
src()/dest() pipeline (inside minifyFor) fed every bundle's filename at once, rather than one
|
|
878
|
+
pipeline per bundle - gulp's src() accepts an array of paths natively.
|
|
846
879
|
|
|
847
880
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
848
881
|
<a name="module_js-build-tools.bundle"></a>
|
|
849
882
|
|
|
850
883
|
### js-build-tools.bundle() ⇒ <code>stream.Stream</code>
|
|
851
|
-
Starting at each bundle's own entry point (dist.main for the primary bundle, or its own
|
|
884
|
+
Starting at each bundle's own entry point (dist.main for the primary bundle, or its own
|
|
885
|
+
override from browser.bundles), bundle all the reachable files into a single file per bundle and
|
|
886
|
+
store them in the specified output directory. A project with no browser.bundles entries gets
|
|
887
|
+
exactly the one bundle it always did; each additional entry produces its own separate bundle
|
|
888
|
+
(for example, a render-only variant built from a different entry point than the full bundle).
|
|
889
|
+
|
|
890
|
+
A bundle's name does double duty: it names the output file (name.js) and, via browserify's
|
|
891
|
+
`standalone` option, is also the name its exports are exposed under - as a global when loaded
|
|
892
|
+
with a bare `<script>` tag, or as the module when required via CommonJS/AMD. Without this, a
|
|
893
|
+
bundle built from a real entry point (one that actually exports something) builds successfully
|
|
894
|
+
but exposes nothing a consumer can reach.
|
|
895
|
+
|
|
896
|
+
Two escape hatches from browser.config.json keep an unwanted dependency (or a dependency's dependency) out of the
|
|
897
|
+
bundle: 'ignore' replaces it with an empty object (safe when your code never actually calls into it - for example
|
|
898
|
+
a library's default option value you always override with your own) and 'exclude' leaves it out entirely (your
|
|
899
|
+
code must not require it, or provide it another way, such as a separate script tag).
|
|
852
900
|
|
|
853
901
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
854
902
|
<a name="module_js-build-tools.build"></a>
|
|
855
903
|
|
|
856
904
|
### js-build-tools.build() ⇒ <code>stream.Stream</code>
|
|
857
|
-
Runs several processes to build and validate the project.
|
|
905
|
+
Runs several processes to build and validate the project.
|
|
906
|
+
Cleans and lints the source, distributes and minifies, bundles and minifies, creates the readme, then runs the
|
|
907
|
+
tests.
|
|
858
908
|
|
|
859
909
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
860
910
|
<a name="module_gulpConfig"></a>
|
|
@@ -872,11 +922,12 @@ Modify these configurations to match your project specifications.
|
|
|
872
922
|
* _inner_
|
|
873
923
|
* [~ArrayableSetting](#module_gulpConfig..ArrayableSetting) : <code>Array.<string></code> \| <code>string</code>
|
|
874
924
|
* [~BooleanSetting](#module_gulpConfig..BooleanSetting) : <code>boolean</code>
|
|
925
|
+
* [~FlagNumberSetting](#module_gulpConfig..FlagNumberSetting) : <code>false</code> \| <code>number</code>
|
|
875
926
|
* [~FlagStringSetting](#module_gulpConfig..FlagStringSetting) : <code>false</code> \| <code>StringSetting</code>
|
|
876
927
|
* [~FlagsSetting](#module_gulpConfig..FlagsSetting) : <code>Object.<string, BooleanSetting></code>
|
|
877
928
|
* [~JestTestFlags](#module_gulpConfig..JestTestFlags) : <code>FlagsSetting</code>
|
|
878
929
|
* [~StringSetting](#module_gulpConfig..StringSetting) : <code>string</code>
|
|
879
|
-
* [~Setting](#module_gulpConfig..Setting) : <code>ArrayableSetting</code> \| <code>BooleanSetting</code> \| <code>FlagsSetting</code> \| <code>StringSetting</code>
|
|
930
|
+
* [~Setting](#module_gulpConfig..Setting) : <code>ArrayableSetting</code> \| <code>BooleanSetting</code> \| <code>FlagNumberSetting</code> \| <code>FlagsSetting</code> \| <code>StringSetting</code>
|
|
880
931
|
* [~CopyFilesEntry](#module_gulpConfig..CopyFilesEntry) : <code>Object</code>
|
|
881
932
|
* [~BrowserConfig](#module_gulpConfig..BrowserConfig) : <code>Object.<string, Setting></code>
|
|
882
933
|
* [~AdditionalBundleConfig](#module_gulpConfig..AdditionalBundleConfig) : <code>Object.<string, Setting></code>
|
|
@@ -926,6 +977,12 @@ A setting that may be an array of strings or a string only.
|
|
|
926
977
|
### gulpConfig~BooleanSetting : <code>boolean</code>
|
|
927
978
|
A setting that may be true or false.
|
|
928
979
|
|
|
980
|
+
**Kind**: inner typedef of [<code>gulpConfig</code>](#module_gulpConfig)
|
|
981
|
+
<a name="module_gulpConfig..FlagNumberSetting"></a>
|
|
982
|
+
|
|
983
|
+
### gulpConfig~FlagNumberSetting : <code>false</code> \| <code>number</code>
|
|
984
|
+
A setting that may be flag 'false' or provide a number
|
|
985
|
+
|
|
929
986
|
**Kind**: inner typedef of [<code>gulpConfig</code>](#module_gulpConfig)
|
|
930
987
|
<a name="module_gulpConfig..FlagStringSetting"></a>
|
|
931
988
|
|
|
@@ -967,7 +1024,7 @@ A setting that may only be a string.
|
|
|
967
1024
|
**Kind**: inner typedef of [<code>gulpConfig</code>](#module_gulpConfig)
|
|
968
1025
|
<a name="module_gulpConfig..Setting"></a>
|
|
969
1026
|
|
|
970
|
-
### gulpConfig~Setting : <code>ArrayableSetting</code> \| <code>BooleanSetting</code> \| <code>FlagsSetting</code> \| <code>StringSetting</code>
|
|
1027
|
+
### gulpConfig~Setting : <code>ArrayableSetting</code> \| <code>BooleanSetting</code> \| <code>FlagNumberSetting</code> \| <code>FlagsSetting</code> \| <code>StringSetting</code>
|
|
971
1028
|
Any single configuration option is a Setting.
|
|
972
1029
|
|
|
973
1030
|
**Kind**: inner typedef of [<code>gulpConfig</code>](#module_gulpConfig)
|
|
@@ -1059,6 +1116,7 @@ Configurations to minify and copy the images.
|
|
|
1059
1116
|
| --- | --- | --- |
|
|
1060
1117
|
| enabled | <code>BooleanSetting</code> | Toggle image minify and copy process. |
|
|
1061
1118
|
| from | <code>StringSetting</code> | Path to search for images. |
|
|
1119
|
+
| jpegQuality | <code>FlagNumberSetting</code> | The JPEG quality (0 to 100) mozjpeg compresses to. False (the default) keeps mozjpeg's own default, 75. Raise it (85 is usually indistinguishable from the original) when 75 visibly bands smooth gradients. |
|
|
1062
1120
|
| to | <code>StringSetting</code> | Path to output images. |
|
|
1063
1121
|
|
|
1064
1122
|
<a name="module_gulpConfig..LintConfig"></a>
|
|
@@ -1101,8 +1159,11 @@ TypeScript types) or jsdoc (a modern theme over jsdoc's own classic default) - s
|
|
|
1101
1159
|
|
|
1102
1160
|
| Name | Type | Description |
|
|
1103
1161
|
| --- | --- | --- |
|
|
1162
|
+
| basePath | <code>FlagStringSetting</code> | The path the documentation is served from, such as '/projects/my-lib/docs/' (jsdoc with clean-jsdoc-theme 5.x only). The theme's links start at the site root, so documentation served below it needs this. False (the default) serves it from the site root. |
|
|
1104
1163
|
| enabled | <code>BooleanSetting</code> | Toggle generating the documentation from the source. When it is on the build does this instead of generating the readme from the jsdoc comments of the compiled files. |
|
|
1105
1164
|
| from | <code>ArrayableSetting</code> | The directory holding the source, each folder in it becomes a module (TypeDoc) or is scanned recursively (jsdoc). jsdoc also takes a list of directories and files. |
|
|
1165
|
+
| gitRevision | <code>FlagStringSetting</code> | The git revision TypeDoc's "Defined in" source links point to (TypeDoc only). False (the default) is TypeDoc's own: the current commit, which changes every page on every commit. A branch name such as 'main' keeps the pages unchanged until the documentation itself changes; '{branch}' is the branch being built. |
|
|
1166
|
+
| inBuild | <code>BooleanSetting</code> | Generate the documentation as part of build (the default). Turn it off to only generate it when you run the docs task yourself (gulp docs), for example when docs.to points into another repository and you only want to publish the documentation of a release. |
|
|
1106
1167
|
| index | <code>StringSetting</code> | The markdown file used as the front page of the documentation. |
|
|
1107
1168
|
| logLevel | <code>StringSetting</code> | How much TypeDoc reports: Verbose, Info, Warn, Error or None. Not used by jsdoc. |
|
|
1108
1169
|
| method | <code>FlagStringSetting</code> | 'typedoc' or 'jsdoc'. False (the default) infers it from typescript.enabled - 'typedoc' when on, 'jsdoc' when off - so an existing TypeScript project's config needs no change to keep working exactly as it already does; set this explicitly to override that inference either way. |
|