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/gulp.config.mjs
CHANGED
|
@@ -1,340 +1,344 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Modify these configurations to match your project specifications.
|
|
3
|
-
* @file
|
|
4
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
5
|
-
* @version 3.0.0
|
|
6
|
-
* @module gulpConfig
|
|
7
|
-
* @memberOf module:js-build-tools
|
|
8
|
-
*/
|
|
9
|
-
import { fileExists } from 'test-filesystem'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A setting that may be an array of strings or a string only.
|
|
13
|
-
* @typedef {Array<string>|string} module:gulpConfig~ArrayableSetting
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* A setting that may be true or false.
|
|
17
|
-
* @typedef {boolean} module:gulpConfig~BooleanSetting
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* A setting that may be flag 'false' or provide a number
|
|
21
|
-
* @typedef {false|number} module:gulpConfig~FlagNumberSetting
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* A setting that may be flag 'false' or provide a StringSetting
|
|
25
|
-
* @typedef {false|StringSetting} module:gulpConfig~FlagStringSetting
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* An object of boolean settings used as flags.
|
|
29
|
-
* @typedef {Object<string, BooleanSetting>} module:gulpConfig~FlagsSetting
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Configure cli options for running Jest.
|
|
33
|
-
* @typedef {FlagsSetting} module:gulpConfig~JestTestFlags
|
|
34
|
-
* @property {BooleanSetting} clearCache
|
|
35
|
-
* @property {BooleanSetting} debug
|
|
36
|
-
* @property {BooleanSetting} ignoreProjects:
|
|
37
|
-
* @property {BooleanSetting} json
|
|
38
|
-
* @property {BooleanSetting} selectProjects
|
|
39
|
-
* @property {BooleanSetting} showConfig
|
|
40
|
-
* @property {BooleanSetting} useStderr
|
|
41
|
-
* @property {BooleanSetting} watch
|
|
42
|
-
* @property {BooleanSetting} watchAll
|
|
43
|
-
*/
|
|
44
|
-
/**
|
|
45
|
-
* A setting that may only be a string.
|
|
46
|
-
* @typedef {string} module:gulpConfig~StringSetting
|
|
47
|
-
*/
|
|
48
|
-
/**
|
|
49
|
-
* Any single configuration option is a Setting.
|
|
50
|
-
* @typedef {ArrayableSetting|BooleanSetting|FlagNumberSetting|FlagsSetting|StringSetting} Setting
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* One copy-files entry: a glob (or array of globs) to copy, and where to copy it.
|
|
54
|
-
* @typedef {Object} module:gulpConfig~CopyFilesEntry
|
|
55
|
-
* @property {ArrayableSetting} from - The glob pattern(s) of files to copy.
|
|
56
|
-
* @property {StringSetting} to - The directory to copy them into.
|
|
57
|
-
* @property {FlagStringSetting} base - Optional base for gulp's own src(pattern, {base}), to preserve a glob's
|
|
58
|
-
* own subdirectory structure in the destination instead of flattening it. false (the default) uses gulp's own
|
|
59
|
-
* default base behaviour.
|
|
60
|
-
*/
|
|
61
|
-
/**
|
|
62
|
-
* Configurations for building the browser files.
|
|
63
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~BrowserConfig
|
|
64
|
-
* @property {BooleanSetting} enabled - 'true' to generate browser bundled files; 'false' for node environment only
|
|
65
|
-
* @property {StringSetting} from - The search pattern used for retrieving compiled distribution files.
|
|
66
|
-
* @property {StringSetting} name - The name to use for the browser-bundled output file (.js will be appended).
|
|
67
|
-
* @property {StringSetting} to - The output directory for browser-bundled files.
|
|
68
|
-
* @property {ArrayableSetting} ignore - Module names or file paths which resolve to an empty object ({}) in the
|
|
69
|
-
* bundle instead of their real contents. For a dependency which is only reached because it is the default value of
|
|
70
|
-
* an option you always override (for example a selector engine's default DOM adapter, when you always pass your
|
|
71
|
-
* own), this keeps it (and anything only it requires) out of the bundle, as long as your code never actually reaches
|
|
72
|
-
* the real module by not overriding that option. See browserify's b.ignore(file).
|
|
73
|
-
* @property {ArrayableSetting} exclude - Module names or file paths left out of the bundle entirely; requiring one at
|
|
74
|
-
* runtime throws unless something else provides it (for example a script tag loading it separately). See
|
|
75
|
-
* browserify's b.exclude(file).
|
|
76
|
-
* @property {Array<module:gulpConfig~AdditionalBundleConfig>} bundles - Additional bundles to produce alongside the
|
|
77
|
-
* primary one (name/dist.main/ignore/exclude above) - for example a render-only variant built from a different
|
|
78
|
-
* entry point than the full bundle. Empty by default: a project that never sets this gets exactly the one bundle it
|
|
79
|
-
* always did.
|
|
80
|
-
*/
|
|
81
|
-
/**
|
|
82
|
-
* One additional bundle - everything but `name` falls back to the primary bundle's own value when omitted, so an
|
|
83
|
-
* additional bundle only has to specify what's actually different about it.
|
|
84
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~AdditionalBundleConfig
|
|
85
|
-
* @property {StringSetting} name - The name for this bundle's output file and standalone export - must be unique
|
|
86
|
-
* among all of a project's bundles.
|
|
87
|
-
* @property {StringSetting} [main] - This bundle's own entry point. Falls back to dist.main when omitted.
|
|
88
|
-
* @property {ArrayableSetting} [ignore] - This bundle's own ignore list. Falls back to browser.ignore when omitted.
|
|
89
|
-
* @property {ArrayableSetting} [exclude] - This bundle's own exclude list. Falls back to browser.exclude when omitted.
|
|
90
|
-
*/
|
|
91
|
-
/**
|
|
92
|
-
* Configurations for building the node distribution files.
|
|
93
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~DistConfig
|
|
94
|
-
* @property {StringSetting} from - The search pattern used for gathering source files for distribution.
|
|
95
|
-
* @property {StringSetting} main - Name of the entry the distribution file.
|
|
96
|
-
* @property {StringSetting} to - The output directory for the distribution files.
|
|
97
|
-
*/
|
|
98
|
-
/**
|
|
99
|
-
* Configurations for copying the font files.
|
|
100
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~FontConfig
|
|
101
|
-
* @property {BooleanSetting} enabled - Toggle copy directory of fonts on.
|
|
102
|
-
* @property {StringSetting} from - Path to search for fonts.
|
|
103
|
-
* @property {StringSetting} to - Path to output fonts.
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
|
-
* Configurations to minify and copy the images.
|
|
107
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~ImageConfig
|
|
108
|
-
* @property {BooleanSetting} enabled - Toggle image minify and copy process.
|
|
109
|
-
* @property {StringSetting} from - Path to search for images.
|
|
110
|
-
* @property {FlagNumberSetting} jpegQuality - The JPEG quality (0 to 100) mozjpeg compresses to. False (the
|
|
111
|
-
* default) keeps mozjpeg's own default, 75. Raise it (85 is usually indistinguishable from the original) when 75
|
|
112
|
-
* visibly bands smooth gradients.
|
|
113
|
-
* @property {StringSetting} to - Path to output images.
|
|
114
|
-
*/
|
|
115
|
-
/**
|
|
116
|
-
* Configurations for linting (see {@link module:partials.neostandardLint}).
|
|
117
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~LintConfig
|
|
118
|
-
* @property {Object<string, *>} rules - ESLint rule overrides layered on top of neostandard's own config, scoped
|
|
119
|
-
* to the same files neostandard itself lints. For a rule that is wrong for your project specifically (for example
|
|
120
|
-
* a test fixture that deliberately contains text neostandard mistakes for a real syntax problem), rather than
|
|
121
|
-
* something to fix in your code. Empty by default: a project that never sets this gets exactly neostandard's own
|
|
122
|
-
* rules, unchanged. Keyed and valued exactly as ESLint's own `rules` object - see
|
|
123
|
-
* https://eslint.org/docs/latest/use/configure/rules.
|
|
124
|
-
*/
|
|
125
|
-
/**
|
|
126
|
-
* Configurations to compile and generate the Readme file.
|
|
127
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~ReadmeConfig
|
|
128
|
-
* @property {StringSetting} file - The name of the output documentation markdown file.
|
|
129
|
-
* @property {StringSetting} from - Location of files to use for compiling documentation into the readme.
|
|
130
|
-
* @property {ArrayableSetting} fromEsm - Additional `.mjs` files to document alongside `from`, converted on the
|
|
131
|
-
* fly since the readme generator only recognizes `.js` files - see 'Configure including ESM files in the
|
|
132
|
-
* generated readme'. Empty by default: a project that never sets this gets exactly the readme it always did.
|
|
133
|
-
* @property {ArrayableSetting} options - Options for formatting the output readme.
|
|
134
|
-
* @property {StringSetting} template - The file which will be pre-fixed to your README.md output.
|
|
135
|
-
* @property {StringSetting} to - The directory to output the readme file in.
|
|
136
|
-
*/
|
|
137
|
-
/**
|
|
138
|
-
* Configurations for generating the HTML documentation of a project's own source, with either TypeDoc (real
|
|
139
|
-
* TypeScript types) or jsdoc (a modern theme over jsdoc's own classic default) - see docs.method.
|
|
140
|
-
* @typedef {Object<string, Setting>} module:gulpConfig~DocsConfig
|
|
141
|
-
* @property {
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @property {
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @property {
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @property {StringSetting}
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
* @
|
|
170
|
-
* @property {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @property {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
*
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
*
|
|
185
|
-
* @
|
|
186
|
-
* @property {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
* @
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @property {
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @property {
|
|
200
|
-
* @property {
|
|
201
|
-
* @property {
|
|
202
|
-
* @property {
|
|
203
|
-
* @property {
|
|
204
|
-
* @property {
|
|
205
|
-
* @property {
|
|
206
|
-
* @property {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
import {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
*
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
*
|
|
339
|
-
|
|
340
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Modify these configurations to match your project specifications.
|
|
3
|
+
* @file
|
|
4
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
5
|
+
* @version 3.0.0
|
|
6
|
+
* @module gulpConfig
|
|
7
|
+
* @memberOf module:js-build-tools
|
|
8
|
+
*/
|
|
9
|
+
import { fileExists } from 'test-filesystem'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A setting that may be an array of strings or a string only.
|
|
13
|
+
* @typedef {Array<string>|string} module:gulpConfig~ArrayableSetting
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* A setting that may be true or false.
|
|
17
|
+
* @typedef {boolean} module:gulpConfig~BooleanSetting
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* A setting that may be flag 'false' or provide a number
|
|
21
|
+
* @typedef {false|number} module:gulpConfig~FlagNumberSetting
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* A setting that may be flag 'false' or provide a StringSetting
|
|
25
|
+
* @typedef {false|StringSetting} module:gulpConfig~FlagStringSetting
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* An object of boolean settings used as flags.
|
|
29
|
+
* @typedef {Object<string, BooleanSetting>} module:gulpConfig~FlagsSetting
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Configure cli options for running Jest.
|
|
33
|
+
* @typedef {FlagsSetting} module:gulpConfig~JestTestFlags
|
|
34
|
+
* @property {BooleanSetting} clearCache
|
|
35
|
+
* @property {BooleanSetting} debug
|
|
36
|
+
* @property {BooleanSetting} ignoreProjects:
|
|
37
|
+
* @property {BooleanSetting} json
|
|
38
|
+
* @property {BooleanSetting} selectProjects
|
|
39
|
+
* @property {BooleanSetting} showConfig
|
|
40
|
+
* @property {BooleanSetting} useStderr
|
|
41
|
+
* @property {BooleanSetting} watch
|
|
42
|
+
* @property {BooleanSetting} watchAll
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* A setting that may only be a string.
|
|
46
|
+
* @typedef {string} module:gulpConfig~StringSetting
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Any single configuration option is a Setting.
|
|
50
|
+
* @typedef {ArrayableSetting|BooleanSetting|FlagNumberSetting|FlagsSetting|StringSetting} Setting
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* One copy-files entry: a glob (or array of globs) to copy, and where to copy it.
|
|
54
|
+
* @typedef {Object} module:gulpConfig~CopyFilesEntry
|
|
55
|
+
* @property {ArrayableSetting} from - The glob pattern(s) of files to copy.
|
|
56
|
+
* @property {StringSetting} to - The directory to copy them into.
|
|
57
|
+
* @property {FlagStringSetting} base - Optional base for gulp's own src(pattern, {base}), to preserve a glob's
|
|
58
|
+
* own subdirectory structure in the destination instead of flattening it. false (the default) uses gulp's own
|
|
59
|
+
* default base behaviour.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Configurations for building the browser files.
|
|
63
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~BrowserConfig
|
|
64
|
+
* @property {BooleanSetting} enabled - 'true' to generate browser bundled files; 'false' for node environment only
|
|
65
|
+
* @property {StringSetting} from - The search pattern used for retrieving compiled distribution files.
|
|
66
|
+
* @property {StringSetting} name - The name to use for the browser-bundled output file (.js will be appended).
|
|
67
|
+
* @property {StringSetting} to - The output directory for browser-bundled files.
|
|
68
|
+
* @property {ArrayableSetting} ignore - Module names or file paths which resolve to an empty object ({}) in the
|
|
69
|
+
* bundle instead of their real contents. For a dependency which is only reached because it is the default value of
|
|
70
|
+
* an option you always override (for example a selector engine's default DOM adapter, when you always pass your
|
|
71
|
+
* own), this keeps it (and anything only it requires) out of the bundle, as long as your code never actually reaches
|
|
72
|
+
* the real module by not overriding that option. See browserify's b.ignore(file).
|
|
73
|
+
* @property {ArrayableSetting} exclude - Module names or file paths left out of the bundle entirely; requiring one at
|
|
74
|
+
* runtime throws unless something else provides it (for example a script tag loading it separately). See
|
|
75
|
+
* browserify's b.exclude(file).
|
|
76
|
+
* @property {Array<module:gulpConfig~AdditionalBundleConfig>} bundles - Additional bundles to produce alongside the
|
|
77
|
+
* primary one (name/dist.main/ignore/exclude above) - for example a render-only variant built from a different
|
|
78
|
+
* entry point than the full bundle. Empty by default: a project that never sets this gets exactly the one bundle it
|
|
79
|
+
* always did.
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* One additional bundle - everything but `name` falls back to the primary bundle's own value when omitted, so an
|
|
83
|
+
* additional bundle only has to specify what's actually different about it.
|
|
84
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~AdditionalBundleConfig
|
|
85
|
+
* @property {StringSetting} name - The name for this bundle's output file and standalone export - must be unique
|
|
86
|
+
* among all of a project's bundles.
|
|
87
|
+
* @property {StringSetting} [main] - This bundle's own entry point. Falls back to dist.main when omitted.
|
|
88
|
+
* @property {ArrayableSetting} [ignore] - This bundle's own ignore list. Falls back to browser.ignore when omitted.
|
|
89
|
+
* @property {ArrayableSetting} [exclude] - This bundle's own exclude list. Falls back to browser.exclude when omitted.
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Configurations for building the node distribution files.
|
|
93
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~DistConfig
|
|
94
|
+
* @property {StringSetting} from - The search pattern used for gathering source files for distribution.
|
|
95
|
+
* @property {StringSetting} main - Name of the entry the distribution file.
|
|
96
|
+
* @property {StringSetting} to - The output directory for the distribution files.
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* Configurations for copying the font files.
|
|
100
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~FontConfig
|
|
101
|
+
* @property {BooleanSetting} enabled - Toggle copy directory of fonts on.
|
|
102
|
+
* @property {StringSetting} from - Path to search for fonts.
|
|
103
|
+
* @property {StringSetting} to - Path to output fonts.
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* Configurations to minify and copy the images.
|
|
107
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~ImageConfig
|
|
108
|
+
* @property {BooleanSetting} enabled - Toggle image minify and copy process.
|
|
109
|
+
* @property {StringSetting} from - Path to search for images.
|
|
110
|
+
* @property {FlagNumberSetting} jpegQuality - The JPEG quality (0 to 100) mozjpeg compresses to. False (the
|
|
111
|
+
* default) keeps mozjpeg's own default, 75. Raise it (85 is usually indistinguishable from the original) when 75
|
|
112
|
+
* visibly bands smooth gradients.
|
|
113
|
+
* @property {StringSetting} to - Path to output images.
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* Configurations for linting (see {@link module:partials.neostandardLint}).
|
|
117
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~LintConfig
|
|
118
|
+
* @property {Object<string, *>} rules - ESLint rule overrides layered on top of neostandard's own config, scoped
|
|
119
|
+
* to the same files neostandard itself lints. For a rule that is wrong for your project specifically (for example
|
|
120
|
+
* a test fixture that deliberately contains text neostandard mistakes for a real syntax problem), rather than
|
|
121
|
+
* something to fix in your code. Empty by default: a project that never sets this gets exactly neostandard's own
|
|
122
|
+
* rules, unchanged. Keyed and valued exactly as ESLint's own `rules` object - see
|
|
123
|
+
* https://eslint.org/docs/latest/use/configure/rules.
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Configurations to compile and generate the Readme file.
|
|
127
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~ReadmeConfig
|
|
128
|
+
* @property {StringSetting} file - The name of the output documentation markdown file.
|
|
129
|
+
* @property {StringSetting} from - Location of files to use for compiling documentation into the readme.
|
|
130
|
+
* @property {ArrayableSetting} fromEsm - Additional `.mjs` files to document alongside `from`, converted on the
|
|
131
|
+
* fly since the readme generator only recognizes `.js` files - see 'Configure including ESM files in the
|
|
132
|
+
* generated readme'. Empty by default: a project that never sets this gets exactly the readme it always did.
|
|
133
|
+
* @property {ArrayableSetting} options - Options for formatting the output readme.
|
|
134
|
+
* @property {StringSetting} template - The file which will be pre-fixed to your README.md output.
|
|
135
|
+
* @property {StringSetting} to - The directory to output the readme file in.
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Configurations for generating the HTML documentation of a project's own source, with either TypeDoc (real
|
|
139
|
+
* TypeScript types) or jsdoc (a modern theme over jsdoc's own classic default) - see docs.method.
|
|
140
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~DocsConfig
|
|
141
|
+
* @property {FlagStringSetting} basePath - The path the documentation is served from, such as '/projects/my-lib/docs/'
|
|
142
|
+
* (jsdoc with clean-jsdoc-theme 5.x only). The theme's links start at the site root, so documentation served below it
|
|
143
|
+
* needs this. False (the default) serves it from the site root.
|
|
144
|
+
* @property {BooleanSetting} enabled - Toggle generating the documentation from the source. When it is on the
|
|
145
|
+
* build does this instead of generating the readme from the jsdoc comments of the compiled files.
|
|
146
|
+
* @property {ArrayableSetting} from - The directory holding the source, each folder in it becomes a module (TypeDoc) or
|
|
147
|
+
* is scanned recursively (jsdoc). jsdoc also takes a list of directories and files.
|
|
148
|
+
* @property {FlagStringSetting} gitRevision - The git revision TypeDoc's "Defined in" source links point to (TypeDoc
|
|
149
|
+
* only). False (the default) is TypeDoc's own: the current commit, which changes every page on every commit. A
|
|
150
|
+
* branch name such as 'main' keeps the pages unchanged until the documentation itself changes; '{branch}' is the
|
|
151
|
+
* branch being built.
|
|
152
|
+
* @property {BooleanSetting} inBuild - Generate the documentation as part of build (the default). Turn it off to only
|
|
153
|
+
* generate it when you run the docs task yourself (gulp docs), for example when docs.to points into another
|
|
154
|
+
* repository and you only want to publish the documentation of a release.
|
|
155
|
+
* @property {StringSetting} index - The markdown file used as the front page of the documentation.
|
|
156
|
+
* @property {StringSetting} logLevel - How much TypeDoc reports: Verbose, Info, Warn, Error or None. Not used by jsdoc.
|
|
157
|
+
* @property {FlagStringSetting} method - 'typedoc' or 'jsdoc'. False (the default) infers it from typescript.enabled -
|
|
158
|
+
* 'typedoc' when on, 'jsdoc' when off - so an existing TypeScript project's config needs no change to keep working
|
|
159
|
+
* exactly as it already does; set this explicitly to override that inference either way.
|
|
160
|
+
* @property {StringSetting} theme - The jsdoc theme package to use (only meaningful when method is 'jsdoc' - TypeDoc
|
|
161
|
+
* keeps its own default regardless). Defaults to 'clean-jsdoc-theme'.
|
|
162
|
+
* @property {StringSetting} title - The name of the documentation, defaults to the name in the package.json.
|
|
163
|
+
* @property {StringSetting} to - The directory to generate the documentation in (it is cleared first).
|
|
164
|
+
* @property {FlagStringSetting} tsconfig - The tsconfig file to read the source with (TypeDoc only), defaults to the
|
|
165
|
+
* one of typescript.config.
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* Configurations to compile and copy the sass files into css.
|
|
169
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~SassConfig
|
|
170
|
+
* @property {BooleanSetting} enabled - Toggle SASS to CSS process on.
|
|
171
|
+
* @property {StringSetting} from - The pattern for finding all sass files.
|
|
172
|
+
* @property {StringSetting} path - The directory were sass files will be stored.
|
|
173
|
+
* @property {StringSetting} to - The destination path for where generated CSS (from SASS files) should go.
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* Configurations for running the test suite.
|
|
177
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~TestConfig
|
|
178
|
+
* @property {JestTestFlags} options - Additional flags for programmatically running Jest Cli.
|
|
179
|
+
* @property {ArrayableSetting} path - The directory where Jest test files are stored.
|
|
180
|
+
* By default, stored as *.test.js adjacent to the files they are testing.
|
|
181
|
+
* @property {ArrayableSetting} watch - The search pattern for watching files for changes.
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Configurations for compiling typescript into JS files.
|
|
185
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~TsConfig
|
|
186
|
+
* @property {FlagStringSetting} config - The path the tsconfig file for running typescript or false if no ts file given.
|
|
187
|
+
* @property {BooleanSetting} enabled - Toggle usage of typescript parsing.
|
|
188
|
+
* @property {StringSetting} from - Pattern for finding the TypeScript files.
|
|
189
|
+
* @property {StringSetting} to - Directory where parsed typescript files go.
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* A set of Configurations options defined by Settings.
|
|
193
|
+
* @typedef {Object<string, Setting>} module:gulpConfig~Configurations
|
|
194
|
+
* @property {BrowserConfig} browser - Browser bundling configuration group.
|
|
195
|
+
* @property {ArrayableSetting} cleanPaths - The paths for directories to delete before build.
|
|
196
|
+
* @property {Array<CopyFilesEntry>} copyFiles - Files to copy elsewhere, run via the copyFiles task - never
|
|
197
|
+
* automatically as part of build, since what this copies is often the live, publicly-reachable version of
|
|
198
|
+
* something (e.g. a bundle), and publishing it should be a deliberate step.
|
|
199
|
+
* @property {DistConfig} dist - Distribution file generation configuration group.
|
|
200
|
+
* @property {DocsConfig} docs - Generate the documentation of a TypeScript project configuration group.
|
|
201
|
+
* @property {FontConfig} fonts - Fonts copy configuration group.
|
|
202
|
+
* @property {ImageConfig} images - Minify and copy the images configuration.
|
|
203
|
+
* @property {LintConfig} lint - Linting configuration group.
|
|
204
|
+
* @property {ReadmeConfig} readme - Build readme files configuration.
|
|
205
|
+
* @property {StringSetting} rootPath - Base directory of the project.
|
|
206
|
+
* @property {SassConfig} sass - Compile CSS from SASS configuration.
|
|
207
|
+
* @property {StringSetting} srcPath - The directory where your source files are stored (the files you manually created).
|
|
208
|
+
* @property {TestConfig} test - Run test suite configuration.
|
|
209
|
+
* @property {TsConfig} typescript - Compile from typescript configuration.
|
|
210
|
+
*/
|
|
211
|
+
import { dotGet } from './functions/utilities/dotGet.mjs'
|
|
212
|
+
import { dotSet } from './functions/utilities/dotSet.mjs'
|
|
213
|
+
import { dotNotate } from './functions/utilities/dotNotate.mjs'
|
|
214
|
+
import { readFileSync } from 'fs'
|
|
215
|
+
|
|
216
|
+
const setDefaults = {
|
|
217
|
+
browser: {
|
|
218
|
+
bundles: [],
|
|
219
|
+
enabled: true,
|
|
220
|
+
exclude: [],
|
|
221
|
+
from: 'dist/**/*.js',
|
|
222
|
+
ignore: [],
|
|
223
|
+
name: 'default',
|
|
224
|
+
to: 'browser',
|
|
225
|
+
},
|
|
226
|
+
cleanPaths: ['dist', 'browser'],
|
|
227
|
+
copyFiles: [],
|
|
228
|
+
dist: {
|
|
229
|
+
from: 'src/**/!(*.test).js',
|
|
230
|
+
main: 'dist/main',
|
|
231
|
+
to: 'dist',
|
|
232
|
+
},
|
|
233
|
+
docs: {
|
|
234
|
+
basePath: false,
|
|
235
|
+
enabled: false,
|
|
236
|
+
from: 'src',
|
|
237
|
+
gitRevision: false,
|
|
238
|
+
inBuild: true,
|
|
239
|
+
index: 'MAIN.md',
|
|
240
|
+
logLevel: 'Warn',
|
|
241
|
+
method: false,
|
|
242
|
+
theme: 'clean-jsdoc-theme',
|
|
243
|
+
title: '',
|
|
244
|
+
to: 'docs',
|
|
245
|
+
tsconfig: false,
|
|
246
|
+
},
|
|
247
|
+
fonts: {
|
|
248
|
+
enabled: false,
|
|
249
|
+
from: 'src/fonts/**/*',
|
|
250
|
+
to: 'browser/fonts',
|
|
251
|
+
},
|
|
252
|
+
images: {
|
|
253
|
+
enabled: false,
|
|
254
|
+
from: 'src/img/**/*.+(png|jpg|jpeg|gif|svg)',
|
|
255
|
+
jpegQuality: false,
|
|
256
|
+
to: 'browser/img',
|
|
257
|
+
},
|
|
258
|
+
lint: {
|
|
259
|
+
rules: {},
|
|
260
|
+
},
|
|
261
|
+
readme: {
|
|
262
|
+
file: 'README.md',
|
|
263
|
+
from: 'src/**/!(*.test).js',
|
|
264
|
+
fromEsm: [],
|
|
265
|
+
options: 'utf8',
|
|
266
|
+
template: 'MAIN.md',
|
|
267
|
+
to: './'
|
|
268
|
+
},
|
|
269
|
+
rootPath: './',
|
|
270
|
+
sass: {
|
|
271
|
+
enabled: false,
|
|
272
|
+
from: 'sass/**/*.+(scss|sass)',
|
|
273
|
+
path: 'sass',
|
|
274
|
+
to: 'browser/css',
|
|
275
|
+
},
|
|
276
|
+
srcPath: 'src',
|
|
277
|
+
test: {
|
|
278
|
+
options: {
|
|
279
|
+
clearCache: false,
|
|
280
|
+
debug: false,
|
|
281
|
+
ignoreProjects: false,
|
|
282
|
+
json: false,
|
|
283
|
+
selectProjects: false,
|
|
284
|
+
showConfig: false,
|
|
285
|
+
useStderr: false,
|
|
286
|
+
watch: false,
|
|
287
|
+
watchAll: false,
|
|
288
|
+
},
|
|
289
|
+
path: ['src'],
|
|
290
|
+
watch: 'src/**/*.js'
|
|
291
|
+
},
|
|
292
|
+
typescript: {
|
|
293
|
+
config: false,
|
|
294
|
+
enabled: false,
|
|
295
|
+
from: 'src/**/*.ts',
|
|
296
|
+
to: 'dist',
|
|
297
|
+
},
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* All the available configuration setting options for running the build.
|
|
302
|
+
* @memberOf module:gulpConfig` `
|
|
303
|
+
* @type {Configurations}
|
|
304
|
+
*/
|
|
305
|
+
let gulpConfigurations = null
|
|
306
|
+
if (fileExists(process.cwd() + '/build-tools.config.json')) {
|
|
307
|
+
gulpConfigurations = JSON.parse(readFileSync(process.cwd() + '/build-tools.config.json').toString())
|
|
308
|
+
} else {
|
|
309
|
+
if (fileExists('./build-tools.config.json')) {
|
|
310
|
+
gulpConfigurations = JSON.parse(readFileSync('./build-tools.config.json').toString())
|
|
311
|
+
} else {
|
|
312
|
+
console.warn('Missing config path, ensure you have a build-tools.config.js file in you project root')
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const notation = dotNotate(setDefaults)
|
|
317
|
+
for (let notationKey in notation) {
|
|
318
|
+
const arrayEnding = /(\.\d+)$/
|
|
319
|
+
if (arrayEnding.test(notationKey)) {
|
|
320
|
+
// ends in number a key then it must be an array; use the entire array
|
|
321
|
+
notationKey = notationKey.replace(arrayEnding, '')
|
|
322
|
+
}
|
|
323
|
+
const defaultValue = dotGet(setDefaults, notationKey)
|
|
324
|
+
const existingConfig = dotGet(gulpConfigurations, notationKey, defaultValue)
|
|
325
|
+
dotSet(gulpConfigurations, notationKey, existingConfig)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Retrieve a value from the configurations, default may be returned.
|
|
330
|
+
* @memberOf module:gulpConfig
|
|
331
|
+
* @param {string|null} path
|
|
332
|
+
* @param {*} defaultValue
|
|
333
|
+
* @returns {*|null}
|
|
334
|
+
*/
|
|
335
|
+
export const get = (path = null, defaultValue = null) => dotGet(gulpConfigurations, path, defaultValue)
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Specify a value for the configurations to use.
|
|
339
|
+
* @memberOf module:gulpConfig
|
|
340
|
+
* @param path
|
|
341
|
+
* @param value
|
|
342
|
+
* @returns {*}
|
|
343
|
+
*/
|
|
344
|
+
export const set = (path, value) => dotSet(gulpConfigurations, path, value)
|