js-build-tools 6.0.0 → 6.2.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 (67) hide show
  1. package/README.md +134 -27
  2. package/dist/build.js +9 -3
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +4 -3
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/bundleMinify.js +2 -1
  7. package/dist/bundleMinify.min.js +1 -1
  8. package/dist/copyFiles.js +47 -0
  9. package/dist/copyFiles.min.js +1 -0
  10. package/dist/copyFonts.js +2 -1
  11. package/dist/copyFonts.min.js +1 -1
  12. package/dist/default.js +2 -1
  13. package/dist/default.min.js +1 -1
  14. package/dist/distMinify.js +2 -1
  15. package/dist/distMinify.min.js +1 -1
  16. package/dist/jsdocDocs.js +15 -0
  17. package/dist/jsdocDocs.min.js +1 -0
  18. package/dist/partials/addToReadme.js +3 -2
  19. package/dist/partials/beginWatcher.js +2 -1
  20. package/dist/partials/clean.js +2 -1
  21. package/dist/partials/copyFor.js +10 -2
  22. package/dist/partials/distFor.js +2 -1
  23. package/dist/partials/distForSrc.js +2 -1
  24. package/dist/partials/distSeries.js +2 -1
  25. package/dist/partials/imagesFor.js +2 -1
  26. package/dist/partials/jsdocDocsFor.js +155 -0
  27. package/dist/partials/neostandardLint.js +31 -12
  28. package/dist/partials/readmeTemplate.js +2 -1
  29. package/dist/partials/runOnChange.js +2 -1
  30. package/dist/partials/sassFor.js +2 -1
  31. package/dist/partials/tsFor.js +2 -1
  32. package/dist/partials/typeDocsFor.js +2 -1
  33. package/dist/sourceLint.js +4 -2
  34. package/dist/sourceLint.min.js +1 -1
  35. package/dist/test-helpers/neostandardLintWithRealNeostandard.js +5 -3
  36. package/dist/test-helpers/setUp.js +2 -1
  37. package/dist/testFull.js +2 -1
  38. package/dist/testFull.min.js +1 -1
  39. package/dist/testHelpers.js +2 -1
  40. package/dist/testHelpers.min.js +1 -1
  41. package/dist/testQuick.js +2 -1
  42. package/dist/testQuick.min.js +1 -1
  43. package/dist/utilities/dotNotate.js +3 -1
  44. package/dist/utilities/getBundleConfigs.js +3 -2
  45. package/dist/watchTest.js +2 -1
  46. package/dist/watchTest.min.js +1 -1
  47. package/functions/build.mjs +7 -2
  48. package/functions/build.test.mjs +50 -1
  49. package/functions/bundle.mjs +2 -2
  50. package/functions/copyFiles.mjs +32 -0
  51. package/functions/copyFiles.test.mjs +78 -0
  52. package/functions/jsdocDocs.mjs +10 -0
  53. package/functions/partials/addToReadme.mjs +1 -1
  54. package/functions/partials/copyFor.mjs +4 -1
  55. package/functions/partials/jsdocDocsFor.mjs +132 -0
  56. package/functions/partials/jsdocDocsFor.test.mjs +101 -0
  57. package/functions/partials/neostandardLint.mjs +19 -7
  58. package/functions/partials/neostandardLint.test.mjs +9 -1
  59. package/functions/sourceLint.mjs +1 -1
  60. package/functions/sourceLint.test.mjs +24 -0
  61. package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +7 -5
  62. package/functions/utilities/dotNotate.mjs +3 -1
  63. package/functions/utilities/dotNotate.test.mjs +34 -0
  64. package/functions/utilities/getBundleConfigs.mjs +1 -1
  65. package/gulp.config.mjs +42 -5
  66. package/gulpfile.base.mjs +2 -0
  67. package/package.json +11 -1
@@ -0,0 +1,34 @@
1
+ import { dotNotate } from './dotNotate.mjs'
2
+
3
+ describe('dotNotate', () => {
4
+ test('flattens a nested object into dot-notation leaves', () => {
5
+ expect(dotNotate({ a: { b: 'c', d: { e: 'f' } } })).toEqual({ 'a.b': 'c', 'a.d.e': 'f' })
6
+ })
7
+
8
+ test('flattens a non-empty array into index-numbered leaves, same as a plain object', () => {
9
+ expect(dotNotate({ a: ['x', 'y'] })).toEqual({ 'a.0': 'x', 'a.1': 'y' })
10
+ })
11
+
12
+ test('keeps a primitive value (including null) as its own leaf, unflattened', () => {
13
+ expect(dotNotate({ a: 1, b: 'two', c: null })).toEqual({ a: 1, b: 'two', c: null })
14
+ })
15
+
16
+ test('keeps an empty object as a leaf value, rather than silently dropping its key', () => {
17
+ expect(dotNotate({ a: {}, b: 'c' })).toEqual({ a: {}, b: 'c' })
18
+ })
19
+
20
+ test('keeps an empty array as a leaf value, rather than silently dropping its key', () => {
21
+ expect(dotNotate({ a: [], b: 'c' })).toEqual({ a: [], b: 'c' })
22
+ })
23
+
24
+ test('keeps an empty object/array as a leaf even nested inside other objects', () => {
25
+ expect(dotNotate({ a: { b: [], c: {} } })).toEqual({ 'a.b': [], 'a.c': {} })
26
+ })
27
+
28
+ test('retains a matching key as a whole object instead of flattening into it', () => {
29
+ expect(dotNotate({ a: { b: 'c' }, options: { fix: true } }, ['options'])).toEqual({
30
+ 'a.b': 'c',
31
+ options: { fix: true }
32
+ })
33
+ })
34
+ })
@@ -16,7 +16,7 @@ export const getBundleConfigs = () => {
16
16
  ignore: gulpConfig.get('browser.ignore'),
17
17
  exclude: gulpConfig.get('browser.exclude')
18
18
  }
19
- const additional = gulpConfig.get('browser.bundles') || []
19
+ const additional = gulpConfig.get('browser.bundles')
20
20
  return [
21
21
  primary,
22
22
  ...additional.map((bundleConfig) => ({
package/gulp.config.mjs CHANGED
@@ -45,6 +45,15 @@ import { fileExists } from 'test-filesystem'
45
45
  * Any single configuration option is a Setting.
46
46
  * @typedef {ArrayableSetting|BooleanSetting|FlagsSetting|StringSetting} Setting
47
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
+ */
48
57
  /**
49
58
  * Configurations for building the browser files.
50
59
  * @typedef {Object<string, Setting>} module:gulpConfig~BrowserConfig
@@ -96,6 +105,16 @@ import { fileExists } from 'test-filesystem'
96
105
  * @property {StringSetting} from - Path to search for images.
97
106
  * @property {StringSetting} to - Path to output images.
98
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
+ */
99
118
  /**
100
119
  * Configurations to compile and generate the Readme file.
101
120
  * @typedef {Object<string, Setting>} module:gulpConfig~ReadmeConfig
@@ -109,16 +128,24 @@ import { fileExists } from 'test-filesystem'
109
128
  * @property {StringSetting} to - The directory to output the readme file in.
110
129
  */
111
130
  /**
112
- * Configurations for generating the HTML documentation of a TypeScript project (with TypeDoc, from the source).
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.
113
133
  * @typedef {Object<string, Setting>} module:gulpConfig~DocsConfig
114
- * @property {BooleanSetting} enabled - Toggle generating the documentation from the TypeScript source. When it is on the
134
+ * @property {BooleanSetting} enabled - Toggle generating the documentation from the source. When it is on the
115
135
  * build does this instead of generating the readme from the jsdoc comments of the compiled files.
116
- * @property {StringSetting} from - The directory holding the TypeScript source, each folder in it becomes a module.
136
+ * @property {StringSetting} from - The directory holding the source, each folder in it becomes a module (TypeDoc) or
137
+ * is scanned recursively (jsdoc).
117
138
  * @property {StringSetting} index - The markdown file used as the front page of the documentation.
118
- * @property {StringSetting} logLevel - How much TypeDoc reports: Verbose, Info, Warn, Error or None.
139
+ * @property {StringSetting} logLevel - How much TypeDoc reports: Verbose, Info, Warn, Error or None. Not used by jsdoc.
140
+ * @property {FlagStringSetting} method - 'typedoc' or 'jsdoc'. False (the default) infers it from typescript.enabled -
141
+ * 'typedoc' when on, 'jsdoc' when off - so an existing TypeScript project's config needs no change to keep working
142
+ * exactly as it already does; set this explicitly to override that inference either way.
143
+ * @property {StringSetting} theme - The jsdoc theme package to use (only meaningful when method is 'jsdoc' - TypeDoc
144
+ * keeps its own default regardless). Defaults to 'clean-jsdoc-theme'.
119
145
  * @property {StringSetting} title - The name of the documentation, defaults to the name in the package.json.
120
146
  * @property {StringSetting} to - The directory to generate the documentation in (it is cleared first).
121
- * @property {FlagStringSetting} tsconfig - The tsconfig file to read the source with, defaults to the one of typescript.config.
147
+ * @property {FlagStringSetting} tsconfig - The tsconfig file to read the source with (TypeDoc only), defaults to the
148
+ * one of typescript.config.
122
149
  */
123
150
  /**
124
151
  * Configurations to compile and copy the sass files into css.
@@ -149,10 +176,14 @@ import { fileExists } from 'test-filesystem'
149
176
  * @typedef {Object<string, Setting>} module:gulpConfig~Configurations
150
177
  * @property {BrowserConfig} browser - Browser bundling configuration group.
151
178
  * @property {ArrayableSetting} cleanPaths - The paths for directories to delete before build.
179
+ * @property {Array<CopyFilesEntry>} copyFiles - Files to copy elsewhere, run via the copyFiles task - never
180
+ * automatically as part of build, since what this copies is often the live, publicly-reachable version of
181
+ * something (e.g. a bundle), and publishing it should be a deliberate step.
152
182
  * @property {DistConfig} dist - Distribution file generation configuration group.
153
183
  * @property {DocsConfig} docs - Generate the documentation of a TypeScript project configuration group.
154
184
  * @property {FontConfig} fonts - Fonts copy configuration group.
155
185
  * @property {ImageConfig} images - Minify and copy the images configuration.
186
+ * @property {LintConfig} lint - Linting configuration group.
156
187
  * @property {ReadmeConfig} readme - Build readme files configuration.
157
188
  * @property {StringSetting} rootPath - Base directory of the project.
158
189
  * @property {SassConfig} sass - Compile CSS from SASS configuration.
@@ -176,6 +207,7 @@ const setDefaults = {
176
207
  to: 'browser',
177
208
  },
178
209
  cleanPaths: ['dist', 'browser'],
210
+ copyFiles: [],
179
211
  dist: {
180
212
  from: 'src/**/!(*.test).js',
181
213
  main: 'dist/main',
@@ -186,6 +218,8 @@ const setDefaults = {
186
218
  from: 'src',
187
219
  index: 'MAIN.md',
188
220
  logLevel: 'Warn',
221
+ method: false,
222
+ theme: 'clean-jsdoc-theme',
189
223
  title: '',
190
224
  to: 'docs',
191
225
  tsconfig: false,
@@ -200,6 +234,9 @@ const setDefaults = {
200
234
  from: 'src/img/**/*.+(png|jpg|jpeg|gif|svg)',
201
235
  to: 'browser/img',
202
236
  },
237
+ lint: {
238
+ rules: {},
239
+ },
203
240
  readme: {
204
241
  file: 'README.md',
205
242
  from: 'src/**/!(*.test).js',
package/gulpfile.base.mjs CHANGED
@@ -9,12 +9,14 @@ export { build } from './functions/build.mjs'
9
9
  export { bundle } from './functions/bundle.mjs'
10
10
  export { bundleMinify } from './functions/bundleMinify.mjs'
11
11
  export { compileReadme as readme } from './functions/compileReadme.mjs'
12
+ export { copyFiles } from './functions/copyFiles.mjs'
12
13
  export { copyFonts } from './functions/copyFonts.mjs'
13
14
  export { defaultCmd } from './functions/default.mjs'
14
15
  export { dist } from './functions/dist.mjs'
15
16
  export { distMinify } from './functions/distMinify.mjs'
16
17
  export * as gulpConfig from './gulp.config.mjs'
17
18
  export { images } from './functions/images.mjs'
19
+ export { jsdocDocs } from './functions/jsdocDocs.mjs'
18
20
  export * as partials from './functions/partials.mjs'
19
21
  export { sass } from './functions/sass.mjs'
20
22
  export { sourceLint } from './functions/sourceLint.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "exports": {
@@ -79,14 +79,22 @@
79
79
  "vinyl-source-stream": "^2.0.0"
80
80
  },
81
81
  "peerDependencies": {
82
+ "clean-jsdoc-theme": ">=4.0.0",
82
83
  "gulp-imagemin": ">=9.0.0",
84
+ "jsdoc": ">=4.0.0",
83
85
  "typedoc": ">=0.28.0",
84
86
  "typescript": ">=5.0.0 <7.0.0"
85
87
  },
86
88
  "peerDependenciesMeta": {
89
+ "clean-jsdoc-theme": {
90
+ "optional": true
91
+ },
87
92
  "gulp-imagemin": {
88
93
  "optional": true
89
94
  },
95
+ "jsdoc": {
96
+ "optional": true
97
+ },
90
98
  "typedoc": {
91
99
  "optional": true
92
100
  },
@@ -106,7 +114,9 @@
106
114
  ],
107
115
  "funding": "https://www.paypal.com/donate/?business=LRYR6SZRWKXVY&no_recurring=0&item_name=Let%27s+build+together+today+to+simplify+our+jobs+tomorrow.&currency_code=CAD",
108
116
  "devDependencies": {
117
+ "clean-jsdoc-theme": "^5.2.0",
109
118
  "gulp-imagemin": "github:jheagle/gulp-imagemin#common-js-compatibility",
119
+ "jsdoc": "^4.0.5",
110
120
  "typedoc": "^0.28.20",
111
121
  "typescript": "^6.0.3"
112
122
  },