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