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
@@ -1,34 +1,34 @@
1
- import { access, rm } from 'node:fs/promises'
2
- import { setTimeout as sleep } from 'node:timers/promises'
3
-
4
- const attempts = 4
5
-
6
- const exists = dirPath => access(dirPath).then(() => true, () => false)
7
-
8
- /**
9
- * Delete a directory and everything in it, resolving only once it is really gone.
10
- *
11
- * A single rm can leave a directory behind - most often when something is still writing into it (a build task, a
12
- * watcher, a dev server) or has it briefly locked (EBUSY/EPERM/ENOTEMPTY) - which silently leaves stale output for
13
- * the next build. So: Node's own retry-with-back-off handles the transient errors, then the directory is checked and
14
- * removed again if it was recreated, and a clear error is raised rather than carrying on with stale output.
15
- * @memberOf module:partials
16
- * @param {string} dirPath
17
- * @returns {Promise<string>} Resolves with dirPath once the directory no longer exists (or already didn't).
18
- * @throws {Error} If the directory still exists after several attempts.
19
- */
20
- export const removeDirectory = async dirPath => {
21
- for (let attempt = 1; attempt <= attempts; attempt++) {
22
- await rm(dirPath, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
23
- if (!await exists(dirPath)) {
24
- return dirPath
25
- }
26
- if (attempt < attempts) {
27
- await sleep(200 * attempt)
28
- }
29
- }
30
- throw new Error(
31
- `Unable to remove "${dirPath}" - it was recreated or is locked. Stop anything that has it open or is writing ` +
32
- 'into it (watchers, dev servers, editors, other build tasks) and try again.'
33
- )
34
- }
1
+ import { access, rm } from 'node:fs/promises'
2
+ import { setTimeout as sleep } from 'node:timers/promises'
3
+
4
+ const attempts = 4
5
+
6
+ const exists = dirPath => access(dirPath).then(() => true, () => false)
7
+
8
+ /**
9
+ * Delete a directory and everything in it, resolving only once it is really gone.
10
+ *
11
+ * A single rm can leave a directory behind - most often when something is still writing into it (a build task, a
12
+ * watcher, a dev server) or has it briefly locked (EBUSY/EPERM/ENOTEMPTY) - which silently leaves stale output for
13
+ * the next build. So: Node's own retry-with-back-off handles the transient errors, then the directory is checked and
14
+ * removed again if it was recreated, and a clear error is raised rather than carrying on with stale output.
15
+ * @memberOf module:partials
16
+ * @param {string} dirPath
17
+ * @returns {Promise<string>} Resolves with dirPath once the directory no longer exists (or already didn't).
18
+ * @throws {Error} If the directory still exists after several attempts.
19
+ */
20
+ export const removeDirectory = async dirPath => {
21
+ for (let attempt = 1; attempt <= attempts; attempt++) {
22
+ await rm(dirPath, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 })
23
+ if (!await exists(dirPath)) {
24
+ return dirPath
25
+ }
26
+ if (attempt < attempts) {
27
+ await sleep(200 * attempt)
28
+ }
29
+ }
30
+ throw new Error(
31
+ `Unable to remove "${dirPath}" - it was recreated or is locked. Stop anything that has it open or is writing ` +
32
+ 'into it (watchers, dev servers, editors, other build tasks) and try again.'
33
+ )
34
+ }
@@ -1,72 +1,72 @@
1
- import fs from 'fs'
2
- import { rm } from 'node:fs/promises'
3
- import { removeDirectory } from './removeDirectory.mjs'
4
-
5
- // Wrap rm so tests can simulate something recreating the directory while (or right after) it is deleted.
6
- jest.mock('node:fs/promises', () => {
7
- const actual = jest.requireActual('node:fs/promises')
8
- return { ...actual, rm: jest.fn(actual.rm) }
9
- })
10
- const { rm: realRm } = jest.requireActual('node:fs/promises')
11
-
12
- const dirPath = 'remove-directory'
13
- const recreateAfterRemoving = async (target, options) => {
14
- await realRm(target, options)
15
- fs.mkdirSync(target)
16
- }
17
-
18
- afterEach(() => {
19
- rm.mockReset()
20
- rm.mockImplementation(realRm)
21
- fs.rmSync(dirPath, { recursive: true, force: true })
22
- })
23
-
24
- describe('removeDirectory', () => {
25
- test('able to delete the remove-directory', async () => {
26
- const dirPath = 'remove-directory'
27
- fs.mkdirSync(dirPath)
28
- expect(fs.existsSync(dirPath)).toBeTruthy()
29
- await removeDirectory(dirPath)
30
- expect(fs.existsSync(dirPath)).toBeFalsy()
31
- })
32
-
33
- test('able to delete directory with sub-directories', async () => {
34
- const dirPath = 'remove-directory'
35
- fs.mkdirSync(dirPath)
36
- const subDir = `${dirPath}/sub`
37
- fs.mkdirSync(subDir)
38
- expect(fs.existsSync(subDir)).toBeTruthy()
39
- await removeDirectory(dirPath)
40
- expect(fs.existsSync(subDir)).toBeFalsy()
41
- })
42
-
43
- test('ends cleanly if directory does not exist', async () => {
44
- const dirPath = 'remove-directory'
45
- expect(fs.existsSync(dirPath)).toBeFalsy()
46
- expect(await removeDirectory(dirPath)).toBe(dirPath)
47
- })
48
-
49
- test('removes with force and Node\'s built-in retry-with-back-off for busy or locked directories', async () => {
50
- expect.assertions(1)
51
- fs.mkdirSync(dirPath)
52
- await removeDirectory(dirPath)
53
- expect(rm).toHaveBeenCalledWith(dirPath, expect.objectContaining({ recursive: true, force: true, maxRetries: 5 }))
54
- })
55
-
56
- test('removes the directory again when something recreates it right after the first removal', async () => {
57
- expect.assertions(2)
58
- fs.mkdirSync(dirPath)
59
- rm.mockImplementationOnce(recreateAfterRemoving)
60
- await removeDirectory(dirPath)
61
- expect(fs.existsSync(dirPath)).toBeFalsy()
62
- expect(rm).toHaveBeenCalledTimes(2)
63
- })
64
-
65
- test('fails with a clear error instead of leaving stale output when the directory keeps coming back', async () => {
66
- expect.assertions(2)
67
- fs.mkdirSync(dirPath)
68
- rm.mockImplementation(recreateAfterRemoving)
69
- await expect(removeDirectory(dirPath)).rejects.toThrow(/Unable to remove "remove-directory" - it was recreated or is locked/)
70
- expect(rm).toHaveBeenCalledTimes(4)
71
- })
72
- })
1
+ import fs from 'fs'
2
+ import { rm } from 'node:fs/promises'
3
+ import { removeDirectory } from './removeDirectory.mjs'
4
+
5
+ // Wrap rm so tests can simulate something recreating the directory while (or right after) it is deleted.
6
+ jest.mock('node:fs/promises', () => {
7
+ const actual = jest.requireActual('node:fs/promises')
8
+ return { ...actual, rm: jest.fn(actual.rm) }
9
+ })
10
+ const { rm: realRm } = jest.requireActual('node:fs/promises')
11
+
12
+ const dirPath = 'remove-directory'
13
+ const recreateAfterRemoving = async (target, options) => {
14
+ await realRm(target, options)
15
+ fs.mkdirSync(target)
16
+ }
17
+
18
+ afterEach(() => {
19
+ rm.mockReset()
20
+ rm.mockImplementation(realRm)
21
+ fs.rmSync(dirPath, { recursive: true, force: true })
22
+ })
23
+
24
+ describe('removeDirectory', () => {
25
+ test('able to delete the remove-directory', async () => {
26
+ const dirPath = 'remove-directory'
27
+ fs.mkdirSync(dirPath)
28
+ expect(fs.existsSync(dirPath)).toBeTruthy()
29
+ await removeDirectory(dirPath)
30
+ expect(fs.existsSync(dirPath)).toBeFalsy()
31
+ })
32
+
33
+ test('able to delete directory with sub-directories', async () => {
34
+ const dirPath = 'remove-directory'
35
+ fs.mkdirSync(dirPath)
36
+ const subDir = `${dirPath}/sub`
37
+ fs.mkdirSync(subDir)
38
+ expect(fs.existsSync(subDir)).toBeTruthy()
39
+ await removeDirectory(dirPath)
40
+ expect(fs.existsSync(subDir)).toBeFalsy()
41
+ })
42
+
43
+ test('ends cleanly if directory does not exist', async () => {
44
+ const dirPath = 'remove-directory'
45
+ expect(fs.existsSync(dirPath)).toBeFalsy()
46
+ expect(await removeDirectory(dirPath)).toBe(dirPath)
47
+ })
48
+
49
+ test('removes with force and Node\'s built-in retry-with-back-off for busy or locked directories', async () => {
50
+ expect.assertions(1)
51
+ fs.mkdirSync(dirPath)
52
+ await removeDirectory(dirPath)
53
+ expect(rm).toHaveBeenCalledWith(dirPath, expect.objectContaining({ recursive: true, force: true, maxRetries: 5 }))
54
+ })
55
+
56
+ test('removes the directory again when something recreates it right after the first removal', async () => {
57
+ expect.assertions(2)
58
+ fs.mkdirSync(dirPath)
59
+ rm.mockImplementationOnce(recreateAfterRemoving)
60
+ await removeDirectory(dirPath)
61
+ expect(fs.existsSync(dirPath)).toBeFalsy()
62
+ expect(rm).toHaveBeenCalledTimes(2)
63
+ })
64
+
65
+ test('fails with a clear error instead of leaving stale output when the directory keeps coming back', async () => {
66
+ expect.assertions(2)
67
+ fs.mkdirSync(dirPath)
68
+ rm.mockImplementation(recreateAfterRemoving)
69
+ await expect(removeDirectory(dirPath)).rejects.toThrow(/Unable to remove "remove-directory" - it was recreated or is locked/)
70
+ expect(rm).toHaveBeenCalledTimes(4)
71
+ })
72
+ })
@@ -1,10 +1,10 @@
1
- import * as gulpConfig from '../../gulp.config.mjs'
2
-
3
- /**
4
- * Pick which engine generates the HTML documentation: docs.method picks it explicitly; left unset (false, the
5
- * default), it's inferred from typescript.enabled - every existing TypeScript project's config, which never
6
- * sets method, keeps producing TypeDoc output exactly as it always has.
7
- * @memberOf module:partials
8
- * @returns {'typedoc'|'jsdoc'}
9
- */
10
- export const resolveDocsMethod = () => gulpConfig.get('docs.method') || (gulpConfig.get('typescript.enabled') ? 'typedoc' : 'jsdoc')
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+
3
+ /**
4
+ * Pick which engine generates the HTML documentation: docs.method picks it explicitly; left unset (false, the
5
+ * default), it's inferred from typescript.enabled - every existing TypeScript project's config, which never
6
+ * sets method, keeps producing TypeDoc output exactly as it always has.
7
+ * @memberOf module:partials
8
+ * @returns {'typedoc'|'jsdoc'}
9
+ */
10
+ export const resolveDocsMethod = () => gulpConfig.get('docs.method') || (gulpConfig.get('typescript.enabled') ? 'typedoc' : 'jsdoc')
@@ -1,33 +1,33 @@
1
- import * as setUp from '../test-helpers/setUp.mjs'
2
- import { resolveDocsMethod } from './resolveDocsMethod.mjs'
3
-
4
- setUp.setDefaults('test-resolve-docs-method')
5
- const gulpConfig = setUp.gulpConfig
6
-
7
- beforeEach(setUp.beforeEach)
8
-
9
- afterEach(setUp.afterEach)
10
-
11
- describe('resolveDocsMethod', () => {
12
- test('infers jsdoc when typescript.enabled is false and docs.method is unset', () => {
13
- gulpConfig.set('typescript.enabled', false)
14
- gulpConfig.set('docs.method', false)
15
- expect(resolveDocsMethod()).toBe('jsdoc')
16
- })
17
-
18
- test('infers typedoc when typescript.enabled is true and docs.method is unset', () => {
19
- gulpConfig.set('typescript.enabled', true)
20
- gulpConfig.set('docs.method', false)
21
- expect(resolveDocsMethod()).toBe('typedoc')
22
- })
23
-
24
- test('docs.method overrides the typescript.enabled inference either way', () => {
25
- gulpConfig.set('typescript.enabled', true)
26
- gulpConfig.set('docs.method', 'jsdoc')
27
- expect(resolveDocsMethod()).toBe('jsdoc')
28
-
29
- gulpConfig.set('typescript.enabled', false)
30
- gulpConfig.set('docs.method', 'typedoc')
31
- expect(resolveDocsMethod()).toBe('typedoc')
32
- })
33
- })
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { resolveDocsMethod } from './resolveDocsMethod.mjs'
3
+
4
+ setUp.setDefaults('test-resolve-docs-method')
5
+ const gulpConfig = setUp.gulpConfig
6
+
7
+ beforeEach(setUp.beforeEach)
8
+
9
+ afterEach(setUp.afterEach)
10
+
11
+ describe('resolveDocsMethod', () => {
12
+ test('infers jsdoc when typescript.enabled is false and docs.method is unset', () => {
13
+ gulpConfig.set('typescript.enabled', false)
14
+ gulpConfig.set('docs.method', false)
15
+ expect(resolveDocsMethod()).toBe('jsdoc')
16
+ })
17
+
18
+ test('infers typedoc when typescript.enabled is true and docs.method is unset', () => {
19
+ gulpConfig.set('typescript.enabled', true)
20
+ gulpConfig.set('docs.method', false)
21
+ expect(resolveDocsMethod()).toBe('typedoc')
22
+ })
23
+
24
+ test('docs.method overrides the typescript.enabled inference either way', () => {
25
+ gulpConfig.set('typescript.enabled', true)
26
+ gulpConfig.set('docs.method', 'jsdoc')
27
+ expect(resolveDocsMethod()).toBe('jsdoc')
28
+
29
+ gulpConfig.set('typescript.enabled', false)
30
+ gulpConfig.set('docs.method', 'typedoc')
31
+ expect(resolveDocsMethod()).toBe('typedoc')
32
+ })
33
+ })
@@ -1,54 +1,54 @@
1
- import * as gulpConfig from '../../gulp.config.mjs'
2
- import { bundle } from '../bundle.mjs'
3
- import { distSeries } from './distSeries.mjs'
4
- import { parallel, series } from 'gulp'
5
- import { testQuick } from '../testQuick.mjs'
6
-
7
- /**
8
- * Run this function when the watched files are modified.
9
- * 1. Find the sub-folders within src path
10
- * 2. Maintain the folders, but use distPath for base
11
- * 3. Remove base folder and return dist path with correct sub-folders
12
- * @example
13
- * // Configured paths
14
- * distPath = 'dist'
15
- * srcPath = 'functions'
16
- *
17
- * // Path parameter
18
- * path = 'functions/some/path/file.js'
19
- *
20
- * // Generated regex using configured srcPath
21
- * pathRegex = '/^functions(.*\/).+\.js$/i'
22
- *
23
- * // Replace value using the configured distPath
24
- * replacePath = 'dist$1'
25
- *
26
- * // The resulting replaced path for the destination folder
27
- * distPathResult = 'dist/some/path/'
28
- * @memberOf module:partials
29
- * @param {string} path
30
- * @returns {stream.Stream}
31
- */
32
- export const runOnChange = path => {
33
- const useTs = gulpConfig.get('typescript.enabled')
34
- const distPath = gulpConfig.get('dist.to')
35
- const srcPath = gulpConfig.get('srcPath')
36
- /**
37
- * 1. The original path comes in from src and is a .ts
38
- * 2. Discover the outgoing dist path where that file should go
39
- * 3. Use the path and dist in tsFor
40
- * 4. Take the original path, convert to full file path in dist
41
- * 5. Use the dist path found previously in #2
42
- * 6. Use the full dist path and the dist outgoing path in distFor
43
- */
44
- const pathRegex = new RegExp(`^${srcPath}(.*\\/)(.+)\\.(js|ts)$`, 'i')
45
- const distPathResult = path.replace(pathRegex, `${distPath}$1`)
46
- let distSrcPath = path
47
- if (useTs) {
48
- distSrcPath = path.replace(pathRegex, `${distPath}$1$2.js`)
49
- }
50
- const runSeries = distSeries(distSrcPath, distPathResult, path)
51
- return gulpConfig.get('browser.enabled')
52
- ? parallel(testQuick, series(runSeries, bundle))()
53
- : series(testQuick, runSeries)()
54
- }
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+ import { bundle } from '../bundle.mjs'
3
+ import { distSeries } from './distSeries.mjs'
4
+ import { parallel, series } from 'gulp'
5
+ import { testQuick } from '../testQuick.mjs'
6
+
7
+ /**
8
+ * Run this function when the watched files are modified.
9
+ * 1. Find the sub-folders within src path
10
+ * 2. Maintain the folders, but use distPath for base
11
+ * 3. Remove base folder and return dist path with correct sub-folders
12
+ * @example
13
+ * // Configured paths
14
+ * distPath = 'dist'
15
+ * srcPath = 'functions'
16
+ *
17
+ * // Path parameter
18
+ * path = 'functions/some/path/file.js'
19
+ *
20
+ * // Generated regex using configured srcPath
21
+ * pathRegex = '/^functions(.*\/).+\.js$/i'
22
+ *
23
+ * // Replace value using the configured distPath
24
+ * replacePath = 'dist$1'
25
+ *
26
+ * // The resulting replaced path for the destination folder
27
+ * distPathResult = 'dist/some/path/'
28
+ * @memberOf module:partials
29
+ * @param {string} path
30
+ * @returns {stream.Stream}
31
+ */
32
+ export const runOnChange = path => {
33
+ const useTs = gulpConfig.get('typescript.enabled')
34
+ const distPath = gulpConfig.get('dist.to')
35
+ const srcPath = gulpConfig.get('srcPath')
36
+ /**
37
+ * 1. The original path comes in from src and is a .ts
38
+ * 2. Discover the outgoing dist path where that file should go
39
+ * 3. Use the path and dist in tsFor
40
+ * 4. Take the original path, convert to full file path in dist
41
+ * 5. Use the dist path found previously in #2
42
+ * 6. Use the full dist path and the dist outgoing path in distFor
43
+ */
44
+ const pathRegex = new RegExp(`^${srcPath}(.*\\/)(.+)\\.(js|ts)$`, 'i')
45
+ const distPathResult = path.replace(pathRegex, `${distPath}$1`)
46
+ let distSrcPath = path
47
+ if (useTs) {
48
+ distSrcPath = path.replace(pathRegex, `${distPath}$1$2.js`)
49
+ }
50
+ const runSeries = distSeries(distSrcPath, distPathResult, path)
51
+ return gulpConfig.get('browser.enabled')
52
+ ? parallel(testQuick, series(runSeries, bundle))()
53
+ : series(testQuick, runSeries)()
54
+ }
@@ -1,95 +1,95 @@
1
- /* eslint-disable no-template-curly-in-string -- fixture source code, the ${...} is meant to stay literal */
2
- import fs from 'fs'
3
- import * as setUp from '../test-helpers/setUp.mjs'
4
- import { bundle } from '../bundle.mjs'
5
- import { distFor } from './distFor.mjs'
6
- import { runOnChange } from './runOnChange.mjs'
7
- import { tsFor } from './tsFor.mjs'
8
- import { testQuick } from '../testQuick.mjs'
9
-
10
- setUp.setDefaults('test-run-on-change')
11
- const gulpConfig = setUp.gulpConfig
12
-
13
- const genericFunction = () => Promise.resolve(true)
14
-
15
- jest.mock('../bundle.mjs', () => ({ bundle: jest.fn(genericFunction) }))
16
- jest.mock('./distFor.mjs', () => ({ distFor: jest.fn(genericFunction) }))
17
- jest.mock('./tsFor.mjs', () => ({ tsFor: jest.fn(() => genericFunction) }))
18
- jest.mock('../testQuick.mjs', () => ({ testQuick: jest.fn(genericFunction) }))
19
-
20
- const rawContents = 'export function sayHello(name: string) {\n' +
21
- ' return `Hello from ${name}`;\n' +
22
- '}'
23
-
24
- const distPath = gulpConfig.get('dist.to') + '/'
25
- const srcPath = gulpConfig.get('srcPath')
26
- const srcFile = `${srcPath}/runOnChange.js`
27
- const srcTsFile = `${srcPath}/runOnChange.ts`
28
-
29
- beforeEach(() => {
30
- return setUp.beforeEach()
31
- .then(() => fs.writeFileSync(srcTsFile, rawContents))
32
- .then(() => fs.writeFileSync(srcFile, rawContents))
33
- }
34
- )
35
-
36
- afterEach(() => {
37
- jest.clearAllMocks()
38
- return setUp.afterEach()
39
- })
40
-
41
- describe('runOnChange', () => {
42
- test('runs testQuick and distFor for nodeOnly true and useTs false', done => {
43
- gulpConfig.set('browser.enabled', false)
44
- gulpConfig.set('typescript.enabled', false)
45
- expect.assertions(2)
46
- runOnChange(srcFile)
47
- setTimeout(() => {
48
- expect(testQuick).toHaveBeenCalled()
49
- expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
50
- done()
51
- }, 500)
52
- })
53
-
54
- test('runs testQuick and distFor for nodeOnly true and tsFor for useTs true', done => {
55
- gulpConfig.set('browser.enabled', false)
56
- gulpConfig.set('typescript.enabled', true)
57
- const distSrcPath = distPath + 'runOnChange.js'
58
- expect.assertions(3)
59
- runOnChange(srcTsFile)
60
- setTimeout(() => {
61
- expect(testQuick).toHaveBeenCalled()
62
- expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
63
- expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
64
- done()
65
- }, 500)
66
- })
67
-
68
- test('runs testQuick and distFor then bundle for nodeOnly false and useTs false', done => {
69
- gulpConfig.set('browser.enabled', true)
70
- gulpConfig.set('typescript.enabled', false)
71
- expect.assertions(3)
72
- runOnChange(srcFile)
73
- setTimeout(() => {
74
- expect(testQuick).toHaveBeenCalled()
75
- expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
76
- expect(bundle).toHaveBeenCalled()
77
- done()
78
- }, 500)
79
- })
80
-
81
- test('runs testQuick and distFor then bundle for nodeOnly false and tsFor for useTs true', done => {
82
- gulpConfig.set('browser.enabled', true)
83
- gulpConfig.set('typescript.enabled', true)
84
- const distSrcPath = distPath + 'runOnChange.js'
85
- expect.assertions(4)
86
- runOnChange(srcTsFile)
87
- setTimeout(() => {
88
- expect(testQuick).toHaveBeenCalled()
89
- expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
90
- expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
91
- expect(bundle).toHaveBeenCalled()
92
- done()
93
- }, 500)
94
- })
95
- })
1
+ /* eslint-disable no-template-curly-in-string -- fixture source code, the ${...} is meant to stay literal */
2
+ import fs from 'fs'
3
+ import * as setUp from '../test-helpers/setUp.mjs'
4
+ import { bundle } from '../bundle.mjs'
5
+ import { distFor } from './distFor.mjs'
6
+ import { runOnChange } from './runOnChange.mjs'
7
+ import { tsFor } from './tsFor.mjs'
8
+ import { testQuick } from '../testQuick.mjs'
9
+
10
+ setUp.setDefaults('test-run-on-change')
11
+ const gulpConfig = setUp.gulpConfig
12
+
13
+ const genericFunction = () => Promise.resolve(true)
14
+
15
+ jest.mock('../bundle.mjs', () => ({ bundle: jest.fn(genericFunction) }))
16
+ jest.mock('./distFor.mjs', () => ({ distFor: jest.fn(genericFunction) }))
17
+ jest.mock('./tsFor.mjs', () => ({ tsFor: jest.fn(() => genericFunction) }))
18
+ jest.mock('../testQuick.mjs', () => ({ testQuick: jest.fn(genericFunction) }))
19
+
20
+ const rawContents = 'export function sayHello(name: string) {\n' +
21
+ ' return `Hello from ${name}`;\n' +
22
+ '}'
23
+
24
+ const distPath = gulpConfig.get('dist.to') + '/'
25
+ const srcPath = gulpConfig.get('srcPath')
26
+ const srcFile = `${srcPath}/runOnChange.js`
27
+ const srcTsFile = `${srcPath}/runOnChange.ts`
28
+
29
+ beforeEach(() => {
30
+ return setUp.beforeEach()
31
+ .then(() => fs.writeFileSync(srcTsFile, rawContents))
32
+ .then(() => fs.writeFileSync(srcFile, rawContents))
33
+ }
34
+ )
35
+
36
+ afterEach(() => {
37
+ jest.clearAllMocks()
38
+ return setUp.afterEach()
39
+ })
40
+
41
+ describe('runOnChange', () => {
42
+ test('runs testQuick and distFor for nodeOnly true and useTs false', done => {
43
+ gulpConfig.set('browser.enabled', false)
44
+ gulpConfig.set('typescript.enabled', false)
45
+ expect.assertions(2)
46
+ runOnChange(srcFile)
47
+ setTimeout(() => {
48
+ expect(testQuick).toHaveBeenCalled()
49
+ expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
50
+ done()
51
+ }, 500)
52
+ })
53
+
54
+ test('runs testQuick and distFor for nodeOnly true and tsFor for useTs true', done => {
55
+ gulpConfig.set('browser.enabled', false)
56
+ gulpConfig.set('typescript.enabled', true)
57
+ const distSrcPath = distPath + 'runOnChange.js'
58
+ expect.assertions(3)
59
+ runOnChange(srcTsFile)
60
+ setTimeout(() => {
61
+ expect(testQuick).toHaveBeenCalled()
62
+ expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
63
+ expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
64
+ done()
65
+ }, 500)
66
+ })
67
+
68
+ test('runs testQuick and distFor then bundle for nodeOnly false and useTs false', done => {
69
+ gulpConfig.set('browser.enabled', true)
70
+ gulpConfig.set('typescript.enabled', false)
71
+ expect.assertions(3)
72
+ runOnChange(srcFile)
73
+ setTimeout(() => {
74
+ expect(testQuick).toHaveBeenCalled()
75
+ expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
76
+ expect(bundle).toHaveBeenCalled()
77
+ done()
78
+ }, 500)
79
+ })
80
+
81
+ test('runs testQuick and distFor then bundle for nodeOnly false and tsFor for useTs true', done => {
82
+ gulpConfig.set('browser.enabled', true)
83
+ gulpConfig.set('typescript.enabled', true)
84
+ const distSrcPath = distPath + 'runOnChange.js'
85
+ expect.assertions(4)
86
+ runOnChange(srcTsFile)
87
+ setTimeout(() => {
88
+ expect(testQuick).toHaveBeenCalled()
89
+ expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
90
+ expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
91
+ expect(bundle).toHaveBeenCalled()
92
+ done()
93
+ }, 500)
94
+ })
95
+ })
@@ -1,25 +1,25 @@
1
- import { dest, src } from 'gulp'
2
- import * as gulpConfig from '../../gulp.config.mjs'
3
- import autoprefixer from 'autoprefixer'
4
- import cssnano from 'cssnano'
5
- import postcss from 'gulp-postcss'
6
- import rename from 'gulp-rename'
7
- import * as sass from 'sass'
8
- import { default as gulpSass } from 'gulp-sass'
9
-
10
- const runSass = gulpSass(sass)
11
-
12
- /**
13
- * Build the CSS for a given source pattern.
14
- * @memberOf module:partials
15
- * @param {string|array} [srcSearch='src/config/path/sass/for']
16
- * @param {string} [cssPath='css/config/path']
17
- * @returns {stream.Stream}
18
- */
19
- export const sassFor = (srcSearch = gulpConfig.get('sass.from'), cssPath = gulpConfig.get('sass.to')) => src(srcSearch)
20
- .pipe(runSass().on('error', runSass.logError)) // Passes it through a gulp-sass, log errors to console
21
- .pipe(dest(cssPath))
22
- // add: false - the old gulp-cssnano only ever removed obsolete vendor prefixes, never added any; keep that.
23
- .pipe(postcss([autoprefixer({ add: false }), cssnano()]))
24
- .pipe(rename({ extname: '.min.css' }))
25
- .pipe(dest(cssPath))
1
+ import { dest, src } from 'gulp'
2
+ import * as gulpConfig from '../../gulp.config.mjs'
3
+ import autoprefixer from 'autoprefixer'
4
+ import cssnano from 'cssnano'
5
+ import postcss from 'gulp-postcss'
6
+ import rename from 'gulp-rename'
7
+ import * as sass from 'sass'
8
+ import { default as gulpSass } from 'gulp-sass'
9
+
10
+ const runSass = gulpSass(sass)
11
+
12
+ /**
13
+ * Build the CSS for a given source pattern.
14
+ * @memberOf module:partials
15
+ * @param {string|array} [srcSearch='src/config/path/sass/for']
16
+ * @param {string} [cssPath='css/config/path']
17
+ * @returns {stream.Stream}
18
+ */
19
+ export const sassFor = (srcSearch = gulpConfig.get('sass.from'), cssPath = gulpConfig.get('sass.to')) => src(srcSearch)
20
+ .pipe(runSass().on('error', runSass.logError)) // Passes it through a gulp-sass, log errors to console
21
+ .pipe(dest(cssPath))
22
+ // add: false - the old gulp-cssnano only ever removed obsolete vendor prefixes, never added any; keep that.
23
+ .pipe(postcss([autoprefixer({ add: false }), cssnano()]))
24
+ .pipe(rename({ extname: '.min.css' }))
25
+ .pipe(dest(cssPath))