js-build-tools 1.2.3 → 2.1.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 (140) hide show
  1. package/README.md +573 -250
  2. package/dist/build.js +22 -15
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +11 -8
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/bundleLint.js +17 -13
  7. package/dist/bundleLint.min.js +1 -1
  8. package/dist/bundleMinify.js +8 -12
  9. package/dist/bundleMinify.min.js +1 -1
  10. package/dist/compileReadme.js +8 -6
  11. package/dist/compileReadme.min.js +1 -1
  12. package/dist/default.js +12 -7
  13. package/dist/default.min.js +1 -1
  14. package/dist/dist.js +6 -2
  15. package/dist/dist.min.js +1 -1
  16. package/dist/distLint.js +15 -12
  17. package/dist/distLint.min.js +1 -1
  18. package/dist/distMinify.js +7 -12
  19. package/dist/distMinify.min.js +1 -1
  20. package/dist/partials/addToReadme.js +25 -0
  21. package/dist/partials/beginWatcher.js +16 -0
  22. package/dist/partials/clean.js +21 -0
  23. package/dist/partials/distFor.js +23 -0
  24. package/dist/partials/distForSrc.js +16 -0
  25. package/dist/partials/distSeries.js +31 -0
  26. package/dist/partials/minifyFor.js +21 -0
  27. package/dist/partials/readmeTemplate.js +18 -0
  28. package/dist/partials/runOnChange.js +63 -0
  29. package/dist/partials/tsFor.js +24 -0
  30. package/dist/partials.js +33 -0
  31. package/dist/partials.min.js +1 -0
  32. package/dist/test-helpers/circularObject.js +50 -0
  33. package/dist/test-helpers/countMatches.js +16 -0
  34. package/dist/test-helpers/deepReferenceObject.js +20 -0
  35. package/dist/test-helpers/domItem.js +33 -0
  36. package/dist/test-helpers/jsonDom.js +20 -0
  37. package/dist/test-helpers/linkedList.js +23 -0
  38. package/dist/test-helpers/logObject.js +24 -0
  39. package/dist/test-helpers/multiReferenceObject.js +20 -0
  40. package/dist/test-helpers/nodeTree.js +28 -0
  41. package/dist/test-helpers/setUp.js +127 -0
  42. package/dist/testFull.js +16 -5
  43. package/dist/testFull.min.js +1 -1
  44. package/dist/testHelpers.js +29 -194
  45. package/dist/testHelpers.min.js +1 -1
  46. package/dist/testQuick.js +18 -7
  47. package/dist/testQuick.min.js +1 -1
  48. package/dist/typeScript.js +14 -0
  49. package/dist/typeScript.min.js +1 -0
  50. package/dist/watchFull.js +9 -16
  51. package/dist/watchFull.min.js +1 -1
  52. package/dist/watchTest.js +11 -9
  53. package/dist/watchTest.min.js +1 -1
  54. package/functions/build.js +8 -5
  55. package/functions/build.test.js +59 -0
  56. package/functions/bundle.js +6 -4
  57. package/functions/bundle.test.js +68 -0
  58. package/functions/bundleLint.js +5 -3
  59. package/functions/bundleLint.test.js +61 -0
  60. package/functions/bundleMinify.js +4 -7
  61. package/functions/bundleMinify.test.js +14 -0
  62. package/functions/compileReadme.js +3 -2
  63. package/functions/compileReadme.test.js +18 -0
  64. package/functions/default.js +5 -2
  65. package/functions/default.test.js +32 -0
  66. package/functions/dist.js +3 -1
  67. package/functions/dist.test.js +43 -0
  68. package/functions/distLint.js +4 -2
  69. package/functions/distLint.test.js +58 -0
  70. package/functions/distMinify.js +4 -7
  71. package/functions/distMinify.test.js +14 -0
  72. package/functions/partials/addToReadme.js +20 -0
  73. package/functions/partials/addToReadme.test.js +28 -0
  74. package/functions/partials/beginWatcher.js +12 -0
  75. package/functions/partials/beginWatcher.test.js +18 -0
  76. package/functions/partials/clean.js +14 -0
  77. package/functions/partials/clean.test.js +20 -0
  78. package/functions/partials/distFor.js +18 -0
  79. package/functions/partials/distFor.test.js +125 -0
  80. package/functions/partials/distForSrc.js +14 -0
  81. package/functions/partials/distForSrc.test.js +17 -0
  82. package/functions/partials/distSeries.js +21 -0
  83. package/functions/partials/distSeries.test.js +33 -0
  84. package/functions/partials/minifyFor.js +16 -0
  85. package/functions/partials/minifyFor.test.js +48 -0
  86. package/functions/partials/readmeTemplate.js +15 -0
  87. package/functions/partials/readmeTemplate.test.js +33 -0
  88. package/functions/partials/runOnChange.js +57 -0
  89. package/functions/partials/runOnChange.test.js +93 -0
  90. package/functions/partials/tsFor.js +21 -0
  91. package/functions/partials/tsFor.test.js +44 -0
  92. package/functions/partials.js +32 -0
  93. package/functions/partials.test.js +7 -0
  94. package/functions/test-helpers/circularObject.js +28 -0
  95. package/functions/test-helpers/circularObject.test.js +14 -0
  96. package/functions/test-helpers/countMatches.js +11 -0
  97. package/functions/test-helpers/countMatches.test.js +9 -0
  98. package/functions/test-helpers/deepReferenceObject.js +25 -0
  99. package/functions/test-helpers/deepReferenceObject.test.js +7 -0
  100. package/functions/test-helpers/domItem.js +31 -0
  101. package/functions/test-helpers/domItem.test.js +12 -0
  102. package/functions/test-helpers/jsonDom.js +16 -0
  103. package/functions/test-helpers/jsonDom.test.js +12 -0
  104. package/functions/test-helpers/linkedList.js +10 -0
  105. package/functions/test-helpers/linkedList.test.js +22 -0
  106. package/functions/test-helpers/logObject.js +18 -0
  107. package/functions/test-helpers/logObject.test.js +20 -0
  108. package/functions/test-helpers/multiReferenceObject.js +25 -0
  109. package/functions/test-helpers/multiReferenceObject.test.js +14 -0
  110. package/functions/test-helpers/nodeTree.js +11 -0
  111. package/functions/test-helpers/nodeTree.test.js +18 -0
  112. package/functions/test-helpers/setUp.js +67 -0
  113. package/functions/test-helpers/setUp.test.js +18 -0
  114. package/functions/testFull.js +13 -3
  115. package/functions/testFull.test.js +16 -0
  116. package/functions/testHelpers.js +27 -137
  117. package/functions/testHelpers.test.js +3 -96
  118. package/functions/testQuick.js +12 -2
  119. package/functions/testQuick.test.js +16 -0
  120. package/functions/typeScript.js +11 -0
  121. package/functions/typeScript.test.js +10 -0
  122. package/functions/watchFull.js +6 -12
  123. package/functions/watchFull.test.js +40 -0
  124. package/functions/watchTest.js +4 -2
  125. package/functions/watchTest.test.js +48 -0
  126. package/gulp.config.js +161 -16
  127. package/gulpfile.base.js +9 -0
  128. package/package.json +1 -1
  129. package/dist/addToReadme.js +0 -22
  130. package/dist/addToReadme.min.js +0 -1
  131. package/dist/clean.js +0 -11
  132. package/dist/clean.min.js +0 -1
  133. package/dist/distFor.js +0 -21
  134. package/dist/distFor.min.js +0 -1
  135. package/dist/readmeTemplate.js +0 -15
  136. package/dist/readmeTemplate.min.js +0 -1
  137. package/functions/addToReadme.js +0 -17
  138. package/functions/clean.js +0 -10
  139. package/functions/distFor.js +0 -15
  140. package/functions/readmeTemplate.js +0 -13
@@ -1,142 +1,32 @@
1
1
  /**
2
- * Log out an object in a nicely formatted way.
3
- * @param {Object} object
4
- * @param {string} [label='logging']
2
+ * An assortment of objects that can be used in tests and some functions to help debug and write tests.
3
+ * @file
4
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
5
+ * @version 2.0.0
6
+ * @module testHelpers
7
+ * @memberOf module:js-build-tools
5
8
  */
6
- export const logObject = (object, label = 'logging') => {
7
- if (typeof require === 'undefined') {
8
- console.log(label, object)
9
- return
10
- }
11
- console.log(label, require('util').inspect(object, false, null, true))
12
- }
13
-
14
- /**
15
- * Multilayered node tree-like structure with parent references
16
- * @type {Object.<string, string|Object|Array>}
17
- */
18
- export const circularObject = { name: 'root', parent: {}, body: {}, head: {}, children: [] }
19
- circularObject.children = [
20
- { name: 'body', parent: {}, children: [] },
21
- { name: 'head', parent: {}, children: [] }
22
- ]
23
- circularObject.body = circularObject.children[0]
24
- circularObject.head = circularObject.children[1]
25
- circularObject.body.parent = circularObject
26
- circularObject.head.parent = circularObject
27
- circularObject.body.children = [
28
- { name: 'body child one', parent: {}, children: [] },
29
- { name: 'body child two', parent: {}, children: [] }
30
- ]
31
- circularObject.body.children[0].parent = circularObject.body
32
- circularObject.body.children[1].parent = circularObject.body
33
- circularObject.head.children = [
34
- { name: 'head child one', parent: {}, children: [] },
35
- { name: 'head child two', parent: {}, children: [] }
36
- ]
37
- circularObject.head.children[0].parent = circularObject.head
38
- circularObject.head.children[1].parent = circularObject.head
39
-
40
- /**
41
- * Sample object with deep references.
42
- * @type {Object.<string, string|number|Object>}
43
- */
44
- export const deepReferenceObject = {
45
- object1: {
46
- name: 'someName',
47
- object2: {
48
- age: 12,
49
- array1: [
50
- 'someString',
51
- 'anotherString'
52
- ]
53
- },
54
- array2: [
55
- 89,
56
- 32
57
- ]
58
- },
59
- title: 'Some Title',
60
- item: 45
61
- }
62
-
63
- /**
64
- * Sample LinkedList for testing circular references.
65
- * @type {Object.<string, string|Object>}
66
- */
67
- export const linkedList = { name: 'one', prev: null, next: null }
68
- linkedList.next = { name: 'two', prev: linkedList, next: null }
69
- linkedList.next.next = { name: 'three', prev: linkedList.next, next: null }
70
9
 
71
- /**
72
- * Sample of jsonDom object containing empty nested array and objects
73
- */
74
- export const jsonDom = {
75
- tagName: 'div',
76
- attributes: { style: {}, className: 'column' },
77
- element: null,
78
- eventListeners: {},
79
- parentItem: {},
80
- children: [],
81
- axis: 'x'
82
- }
83
-
84
- /**
85
- * Sample of domItem child with nested child and optional details
86
- */
87
- export const domItem = [
88
- {
89
- attributes: { className: 'row', style: {} },
90
- axis: 'y',
91
- children: [
92
- {
93
- attributes: { style: {} },
94
- axis: 'x',
95
- children: [],
96
- element: {},
97
- eventListeners: {},
98
- hasShip: false,
99
- isHit: false,
100
- parentItem: {},
101
- point: {},
102
- tagName: 'div'
103
- }
104
- ],
105
- element: null,
106
- eventListeners: {},
107
- parentItem: {},
108
- tagName: 'div'
109
- }
110
- ]
10
+ const circularObject = require('./test-helpers/circularObject')
11
+ const countMatches = require('./test-helpers/countMatches')
12
+ const deepReferenceObject = require('./test-helpers/deepReferenceObject')
13
+ const domItem = require('./test-helpers/domItem')
14
+ const jsonDom = require('./test-helpers/jsonDom')
15
+ const linkedList = require('./test-helpers/linkedList')
16
+ const logObject = require('./test-helpers/logObject')
17
+ const multiReferenceObject = require('./test-helpers/multiReferenceObject')
18
+ const nodeTree = require('./test-helpers/nodeTree')
19
+ const setUp = require('./test-helpers/setUp')
111
20
 
112
- /**
113
- * Sample of object containing multiple references.
114
- * @type {Object.<string, string|number|Object>}
115
- */
116
- export const multiReferenceObject = {
117
- object1: {
118
- name: 'someName'
119
- },
120
- object2: {
121
- age: 12
122
- },
123
- array1: [
124
- 'someString',
125
- 'anotherString'
126
- ],
127
- array2: [
128
- 89,
129
- 32
130
- ],
131
- title: 'Some Title',
132
- item: 45
21
+ module.exports = {
22
+ circularObject,
23
+ countMatches,
24
+ deepReferenceObject,
25
+ domItem,
26
+ jsonDom,
27
+ linkedList,
28
+ logObject,
29
+ multiReferenceObject,
30
+ nodeTree,
31
+ setUp,
133
32
  }
134
-
135
- /**
136
- * Sample NodeTree for testing circular references and arrays.
137
- * @type {Object.<string, string|Object|Array>}
138
- */
139
- export const nodeTree = { name: 'one', parent: null, children: [] }
140
- nodeTree.children[0] = { name: 'child one', parent: nodeTree, children: [] }
141
- nodeTree.children[1] = { name: 'child two', parent: nodeTree, children: [] }
142
- nodeTree.children[0].children[0] = { name: 'grandchild one', parent: nodeTree.children[0], children: [] }
@@ -1,100 +1,7 @@
1
- const {
2
- circularObject,
3
- deepReferenceObject,
4
- domItem,
5
- jsonDom,
6
- linkedList,
7
- logObject,
8
- multiReferenceObject,
9
- nodeTree
10
- } = require('./testHelpers.js')
11
- const util = require('util')
1
+ const testHelpers = require('./testHelpers')
12
2
 
13
3
  describe('testHelpers', () => {
14
- test('can nicely output objects with logObject', () => {
15
- const logSpy = jest.spyOn(console, 'log')
16
- const inspectSpy = jest.spyOn(util, 'inspect')
17
- const someObject = { one: 1, two: 2, three: 3 }
18
- logObject(someObject, 'someObject')
19
- expect(inspectSpy).toHaveBeenCalledWith(someObject, false, null, true)
20
- expect(logSpy).toHaveBeenCalledWith('someObject', util.inspect(someObject, false, null, true))
21
- })
22
-
23
- test('has sample circular object', () => {
24
- expect(circularObject.body.parent).toBe(circularObject)
25
- expect(circularObject.body.children[0].parent).toBe(circularObject.body)
26
- expect(circularObject.body.children[1].parent).toBe(circularObject.body)
27
- expect(circularObject.children[0]).toBe(circularObject.body)
28
- expect(circularObject.head.parent).toBe(circularObject)
29
- expect(circularObject.head.children[0].parent).toBe(circularObject.head)
30
- expect(circularObject.head.children[1].parent).toBe(circularObject.head)
31
- expect(circularObject.children[1]).toBe(circularObject.head)
32
- })
33
-
34
- test('has sample deep reference object', () => {
35
- expect(deepReferenceObject).toHaveProperty('object1.object2.array1')
36
- })
37
-
38
- test('has sample domItem object', () => {
39
- expect(domItem[0]).toHaveProperty('attributes')
40
- expect(domItem[0]).toHaveProperty('children')
41
- expect(domItem[0]).toHaveProperty('element')
42
- expect(domItem[0]).toHaveProperty('eventListeners')
43
- expect(domItem[0]).toHaveProperty('parentItem')
44
- expect(domItem[0]).toHaveProperty('tagName')
45
- })
46
-
47
- test('has sample jsonDom object', () => {
48
- expect(jsonDom).toHaveProperty('attributes')
49
- expect(jsonDom).toHaveProperty('children')
50
- expect(jsonDom).toHaveProperty('element')
51
- expect(jsonDom).toHaveProperty('eventListeners')
52
- expect(jsonDom).toHaveProperty('parentItem')
53
- expect(jsonDom).toHaveProperty('tagName')
54
- })
55
-
56
- test('has sample linkedList object', () => {
57
- expect(linkedList.name).toBe('one')
58
- expect(linkedList).toHaveProperty('prev')
59
- expect(linkedList.prev).toBeNull()
60
-
61
- expect(linkedList).toHaveProperty('next')
62
- expect(linkedList.next.name).toBe('two')
63
- expect(linkedList).toHaveProperty('next.prev')
64
- expect(linkedList.next.prev).toBe(linkedList)
65
-
66
- expect(linkedList).toHaveProperty('next.next')
67
- expect(linkedList.next.next.name).toBe('three')
68
- expect(linkedList).toHaveProperty('next.prev')
69
- expect(linkedList.next.next.prev).toBe(linkedList.next)
70
-
71
- expect(linkedList).toHaveProperty('next.next.next')
72
- expect(linkedList.next.next.next).toBeNull()
73
- })
74
-
75
- test('has sample multiReferenceObject object', () => {
76
- expect(multiReferenceObject).toHaveProperty('object1.name')
77
- expect(multiReferenceObject).toHaveProperty('object2.age')
78
- expect(multiReferenceObject).toHaveProperty('array1.0')
79
- expect(multiReferenceObject).toHaveProperty('array1.1')
80
- expect(multiReferenceObject).toHaveProperty('array2.0')
81
- expect(multiReferenceObject).toHaveProperty('array2.1')
82
- expect(multiReferenceObject).toHaveProperty('title')
83
- expect(multiReferenceObject).toHaveProperty('item')
84
- })
85
-
86
- test('has sample nodeTree object', () => {
87
- expect(nodeTree.name).toBe('one')
88
- expect(nodeTree.parent).toBeNull()
89
- expect(nodeTree.children.length).toBe(2)
90
- expect(nodeTree.children[0].name).toBe('child one')
91
- expect(nodeTree.children[0].parent).toBe(nodeTree)
92
- expect(nodeTree.children[0].children.length).toBe(1)
93
- expect(nodeTree.children[0].children[0].name).toBe('grandchild one')
94
- expect(nodeTree.children[0].children[0].parent).toBe(nodeTree.children[0])
95
- expect(nodeTree.children[0].children[0].children.length).toBe(0)
96
- expect(nodeTree.children[1].name).toBe('child two')
97
- expect(nodeTree.children[1].parent).toBe(nodeTree)
98
- expect(nodeTree.children[1].children.length).toBe(0)
4
+ test('is object with all helper exports', () => {
5
+ expect(Object.keys(testHelpers).length).toBe(10)
99
6
  })
100
7
  })
@@ -1,10 +1,20 @@
1
1
  const gulpConfig = require('../gulp.config.js')
2
- const { runCLI: jest } = require('jest')
2
+ const { runCLI } = require('jest')
3
3
 
4
4
  /**
5
5
  * Run the Jest tests for files which have been modified (based on git status).
6
+ * @function
7
+ * @memberOf module:js-build-tools
8
+ * @param {function} [done=null]
9
+ * @param {Array.<string>|string} [testPath='path/config/test/files']
6
10
  * @returns {Promise<*>}
7
11
  */
8
- const testQuick = async () => await jest({ onlyChanged: true }, gulpConfig.testPath)
12
+ const testQuick = (done = null, testPath = gulpConfig.get('testPath')) => {
13
+ if (!Array.isArray(testPath)) {
14
+ // The testPath must be an array of strings
15
+ testPath = [testPath]
16
+ }
17
+ return runCLI({ onlyChanged: true }, testPath)
18
+ }
9
19
 
10
20
  module.exports = testQuick
@@ -0,0 +1,16 @@
1
+ const { setUp } = require('./testHelpers')
2
+ const gulpConfig = setUp.gulpConfig
3
+ const { runCLI } = require('jest')
4
+ const testQuick = require('./testQuick')
5
+
6
+ jest.mock('jest', () => ({
7
+ 'runCLI': jest.fn(() => Promise.resolve(true))
8
+ }))
9
+
10
+ describe('testQuick', () => {
11
+ test('runs the jest CLI with onlyChanged option', () => {
12
+ expect.assertions(1)
13
+ testQuick()
14
+ expect(runCLI).toHaveBeenCalledWith({ onlyChanged: true }, [gulpConfig.get('testPath')])
15
+ })
16
+ })
@@ -0,0 +1,11 @@
1
+ const tsFor = require('./partials/tsFor')
2
+
3
+ /**
4
+ * Simplified typescript task using tsFor.
5
+ * @function
6
+ * @memberOf module:js-build-tools
7
+ * @returns {stream.Stream}
8
+ */
9
+ const typeScript = () => tsFor()
10
+
11
+ module.exports = typeScript
@@ -0,0 +1,10 @@
1
+ const typeScript = require('./typeScript')
2
+ const tsFor = require('./partials/tsFor')
3
+ jest.mock('./partials/tsFor', () => jest.fn())
4
+
5
+ describe('typeScript', () => {
6
+ test('calls tsFor with no parameters', () => {
7
+ typeScript()
8
+ expect(tsFor).toHaveBeenCalled()
9
+ })
10
+ })
@@ -1,18 +1,12 @@
1
- const bundle = require('./bundle')
2
- const distFor = require('./distFor')
3
- const gulpConfig = require('../gulp.config.js')
4
- const { parallel, series, watch } = require('gulp')
5
- const testQuick = require('./testQuick')
1
+ const { beginWatcher, runOnChange } = require('./partials')
6
2
 
7
3
  /**
8
4
  * Watch for changes and run the distribution for the changed files, then bundle and test the changed files.
9
- * @returns {*}
5
+ * @function
6
+ * @memberOf module:js-build-tools
7
+ * @returns {FSWatcher}
10
8
  */
11
- const watchFull = () => watch(gulpConfig.watchSearch)
12
- .on('change', path => {
13
- const pathRegex = new RegExp(`^${gulpConfig.srcPath}(.*\\/).+\\.js$`, 'i')
14
- const distForPath = () => distFor(path, path.replace(pathRegex, `${gulpConfig.distPath}$1`))
15
- return parallel(testQuick, series(distForPath, bundle))()
16
- })
9
+ const watchFull = () => beginWatcher()
10
+ .on('change', runOnChange)
17
11
 
18
12
  module.exports = watchFull
@@ -0,0 +1,40 @@
1
+ const fs = require('fs')
2
+ const setUp = require('./test-helpers/setUp')
3
+ setUp.setDefaults('test-watch-full')
4
+ const gulpConfig = setUp.gulpConfig
5
+ const watchFull = require('./watchFull')
6
+ const beginWatcher = require('./partials/beginWatcher')
7
+ const runOnChange = require('./partials/runOnChange')
8
+
9
+ jest.mock('./partials/beginWatcher', () => jest.fn(() => ({ on: (event, fn) => fn() })))
10
+ jest.mock('./partials/runOnChange', () => jest.fn())
11
+
12
+ const rawContents = 'const { beginWatcher, runOnChange } = require(\'./partials\')\n' +
13
+ '\n' +
14
+ '/**\n' +
15
+ ' * Watch for changes and run the distribution for the changed files, then bundle and test the changed files.\n' +
16
+ ' * @function\n' +
17
+ ' * @memberOf module:js-build-tools\n' +
18
+ ' * @returns {FSWatcher}\n' +
19
+ ' */\n' +
20
+ 'const watchFull = () => beginWatcher()\n' +
21
+ ' .on(\'change\', runOnChange)\n' +
22
+ '\n' +
23
+ 'module.exports = watchFull\n'
24
+
25
+ beforeEach(setUp.beforeEach)
26
+
27
+ afterEach(setUp.afterEach)
28
+
29
+ describe('watchFull', () => {
30
+ test('should call beginWatcher and runOnChange for change event', () => {
31
+ const srcPath = gulpConfig.get('srcPath')
32
+ gulpConfig.set('watchSearch', `${srcPath}/*.js`)
33
+ const srcFile = `${srcPath}/watchFull.js`
34
+ fs.writeFileSync(srcFile, rawContents)
35
+ expect.assertions(2)
36
+ watchFull()
37
+ expect(beginWatcher).toHaveBeenCalled()
38
+ expect(runOnChange).toHaveBeenCalled()
39
+ })
40
+ })
@@ -1,11 +1,13 @@
1
1
  const gulpConfig = require('../gulp.config.js')
2
- const { series, watch } = require('gulp')
2
+ const { watch } = require('gulp')
3
3
  const testQuick = require('./testQuick')
4
4
 
5
5
  /**
6
6
  * Watch for changes and run the tests.
7
+ * @function
8
+ * @memberOf module:js-build-tools
7
9
  * @returns {*}
8
10
  */
9
- const watchTest = () => watch(gulpConfig.watchSearch, { ignoreInitial: false }, series(testQuick))
11
+ const watchTest = () => watch(gulpConfig.get('watchSearch'), { ignoreInitial: false }, testQuick)
10
12
 
11
13
  module.exports = watchTest
@@ -0,0 +1,48 @@
1
+ const setUp = require('./test-helpers/setUp')
2
+ setUp.setDefaults('test-watch-test')
3
+ const gulpConfig = setUp.gulpConfig
4
+ gulpConfig.set('watchSearch', 'test-begin-watcher/*.js')
5
+ const watchTest = require('./watchTest')
6
+ const { EventEmitter } = require('node:events')
7
+ const fs = require('fs')
8
+ const testQuick = require('./testQuick')
9
+
10
+ jest.mock('./testQuick', () => jest.fn(() => Promise.resolve(true)))
11
+
12
+ const rawContents = 'const gulpConfig = require(\'../gulp.config.js\')\n' +
13
+ 'const { watch } = require(\'gulp\')\n' +
14
+ 'const testQuick = require(\'./testQuick\')\n' +
15
+ '\n' +
16
+ '/**\n' +
17
+ ' * Watch for changes and run the tests.\n' +
18
+ ' * @function\n' +
19
+ ' * @memberOf module:js-build-tools\n' +
20
+ ' * @returns {*}\n' +
21
+ ' */\n' +
22
+ 'const watchTest = () => watch(gulpConfig.get(\'watchSearch\'), { ignoreInitial: false }, testQuick)\n' +
23
+ '\n' +
24
+ 'module.exports = watchTest\n'
25
+
26
+ const filePath = gulpConfig.get('srcPath') + '/watchTest.js'
27
+
28
+ beforeEach(() => setUp.beforeEach()
29
+ .then(
30
+ () => fs.writeFileSync(filePath, rawContents)
31
+ )
32
+ )
33
+
34
+ afterEach(setUp.afterEach)
35
+
36
+ describe('watchTest', () => {
37
+ test('returns instance of EventEmitter / FSWatcher and calls testQuick on change', done => {
38
+ expect.assertions(2)
39
+ const fsWatcher = watchTest()
40
+ expect(fsWatcher).toBeInstanceOf(EventEmitter)
41
+ fsWatcher.emit('change')
42
+ setTimeout(() => {
43
+ expect(testQuick).toHaveBeenCalled()
44
+ done()
45
+ }, 500)
46
+ fsWatcher.close()
47
+ })
48
+ })
package/gulp.config.js CHANGED
@@ -1,30 +1,175 @@
1
- const defaultConfig = (config, path, defaultValue) => {
1
+ /**
2
+ * Modify these configurations to match your project specifications.
3
+ * @file
4
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
5
+ * @version 2.0.0
6
+ * @module gulpConfig
7
+ * @memberOf module:js-build-tools
8
+ */
9
+
10
+ /**
11
+ * Retrieve a value from an object with the path (key), return a given default if the key is not found.
12
+ * @memberOf module:gulpConfig
13
+ * @param {Object<string, *>} [config=[]]
14
+ * @param {string|null} [path=null]
15
+ * @param {*} [defaultValue=null]
16
+ * @returns {*|null}
17
+ */
18
+ const defaultConfig = (config = {}, path = null, defaultValue = null) => {
19
+ if (!path) {
20
+ return config
21
+ }
2
22
  if (typeof config[path] === 'undefined') {
3
23
  return defaultValue
4
24
  }
5
25
  return config[path]
6
26
  }
7
- let parentConfig = {}
27
+
28
+ /**
29
+ * A setting that may be an array of strings or a string only.
30
+ * @typedef {Array<string>|string} module:gulpConfig~ArrayableSetting
31
+ */
32
+
33
+ /**
34
+ * A setting that may be true or false.
35
+ * @typedef {boolean} module:gulpConfig~BooleanSetting
36
+ */
37
+
38
+ /**
39
+ * A setting that may be flag 'false' or provide a StringSetting
40
+ * @typedef {false|StringSetting} module:gulpConfig~FlagStringSetting
41
+ */
42
+
43
+ /**
44
+ * An object of boolean settings used as flags.
45
+ * @typedef {Object<string, BooleanSetting>} module:gulpConfig~FlagsSetting
46
+ */
47
+
48
+ /**
49
+ * Configure cli options for running Jest.
50
+ * @typedef {FlagsSetting} module:gulpConfig~JestTestFlags
51
+ * @property {BooleanSetting} clearCache
52
+ * @property {BooleanSetting} debug
53
+ * @property {BooleanSetting} ignoreProjects:
54
+ * @property {BooleanSetting} json
55
+ * @property {BooleanSetting} selectProjects
56
+ * @property {BooleanSetting} showConfig
57
+ * @property {BooleanSetting} useStderr
58
+ * @property {BooleanSetting} watch
59
+ * @property {BooleanSetting} watchAll
60
+ */
61
+
62
+ /**
63
+ * A setting that may only be a string.
64
+ * @typedef {string} module:gulpConfig~StringSetting
65
+ */
66
+
67
+ /**
68
+ * Any single configuration option is a Setting.
69
+ * @typedef {ArrayableSetting|BooleanSetting|FlagsSetting|StringSetting} Setting
70
+ */
71
+
72
+ /**
73
+ * A set of Configurations options defined by Settings.
74
+ * @typedef {Object<string, Setting>} module:gulpConfig~Configurations
75
+ * @property {StringSetting} browserName
76
+ * @property {StringSetting} browserPath
77
+ * @property {StringSetting} distMain
78
+ * @property {StringSetting} distPath
79
+ * @property {ArrayableSetting} distSearch
80
+ * @property {BooleanSetting} nodeOnly
81
+ * @property {StringSetting} readmeTemplate
82
+ * @property {ArrayableSetting} readmeOptions
83
+ * @property {StringSetting} readmeFile
84
+ * @property {StringSetting} readmePath
85
+ * @property {ArrayableSetting} readmeSearch
86
+ * @property {StringSetting} rootPath
87
+ * @property {StringSetting} srcPath
88
+ * @property {ArrayableSetting} srcSearch
89
+ * @property {JestTestFlags} testOptions
90
+ * @property {ArrayableSetting} testPath
91
+ * @property {FlagStringSetting} useTsConfig
92
+ * @property {ArrayableSetting} watchSearch
93
+ */
94
+
95
+ /**
96
+ * All the available configuration setting options for running the build.
97
+ * @memberOf module:gulpConfig` `
98
+ * @type {Configurations}
99
+ */
100
+ let gulpConfigurations = {}
8
101
  try {
9
- parentConfig = require('../../build-tools.config.js')
102
+ gulpConfigurations = require('../../build-tools.config.js')
10
103
  } catch (isUndefined) {
11
104
  try {
12
- parentConfig = require('./build-tools.config.js')
13
- console.info('Missing main project config, using default path')
105
+ // Missing main project config, using default path
106
+ gulpConfigurations = require('./build-tools.config.js')
14
107
  } catch (stillUndefined) {
15
108
  console.warn('Missing config path, ensure you have a build-tools.config.js file in you project root')
16
109
  }
17
110
  }
111
+
112
+ const setDefaults = {
113
+ browserName: 'default',
114
+ browserPath: 'browser',
115
+ distMain: 'dist/main',
116
+ distPath: 'dist',
117
+ distSearch: 'dist/**/*.js',
118
+ nodeOnly: false,
119
+ readmeTemplate: 'MAIN.md',
120
+ readmeOptions: 'utf8',
121
+ readmeFile: 'README.md',
122
+ readmePath: './',
123
+ readmeSearch: 'src/**/!(*.test).js',
124
+ rootPath: './',
125
+ srcPath: 'src',
126
+ srcSearch: 'src/**/!(*.test).js',
127
+ testOptions: {
128
+ clearCache: false,
129
+ debug: false,
130
+ ignoreProjects: false,
131
+ json: false,
132
+ selectProjects: false,
133
+ showConfig: false,
134
+ useStderr: false,
135
+ watch: false,
136
+ watchAll: false,
137
+ },
138
+ testPath: ['src'],
139
+ tsSearch: 'src/**/*.ts',
140
+ useTsConfig: false,
141
+ watchSearch: 'src/**/*.js'
142
+ }
143
+
144
+ Object.keys(setDefaults).forEach(parentKey => {
145
+ gulpConfigurations[parentKey] = defaultConfig(gulpConfigurations, parentKey, setDefaults[parentKey])
146
+ })
147
+
148
+ /**
149
+ * Retrieve a value from teh configurations, default may be returned.
150
+ * @function
151
+ * @memberOf module:gulpConfig
152
+ * @param {string|null} path
153
+ * @param {*} defaultValue
154
+ * @returns {*|null}
155
+ */
156
+ const get = (path = null, defaultValue = null) => defaultConfig(gulpConfigurations, path, defaultValue)
157
+
158
+ /**
159
+ * Specify a value for the configurations to use.
160
+ * @function
161
+ * @memberOf module:gulpConfig
162
+ * @param path
163
+ * @param value
164
+ * @returns {*}
165
+ */
166
+ const set = (path, value) => {
167
+ gulpConfigurations[path] = value
168
+ return value
169
+ }
170
+
18
171
  module.exports = {
19
- browserName: defaultConfig(parentConfig, 'browserName', 'default'),
20
- browserPath: defaultConfig(parentConfig, 'browserPath', 'browser'),
21
- distMain: defaultConfig(parentConfig, 'distMain', 'dist/main'),
22
- distPath: defaultConfig(parentConfig, 'distPath', 'dist'),
23
- distSearch: defaultConfig(parentConfig, 'distSearch', 'dist/**/*.js'),
24
- nodeOnly: defaultConfig(parentConfig, 'nodeOnly', false),
25
- readmeTemplate: defaultConfig(parentConfig, 'readmeTemplate', 'MAIN.md'),
26
- srcPath: defaultConfig(parentConfig, 'srcPath', 'src'),
27
- srcSearch: defaultConfig(parentConfig, 'srcSearch', 'src/**/!(*.test).js'),
28
- testPath: defaultConfig(parentConfig, 'testPath', ['src']),
29
- watchSearch: defaultConfig(parentConfig, 'watchSearch', 'src/**/*.js'),
172
+ defaultConfig,
173
+ get,
174
+ set
30
175
  }
package/gulpfile.base.js CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Export these functions to your own project in order to customize your build pipeline.
3
+ * @file
4
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
5
+ * @version 2.0.0
6
+ * @module js-build-tools
7
+ */
8
+
9
+ const gulpConfig = require('./gulp.config.js')
1
10
  const build = require('./functions/build.js')
2
11
  const compileReadme = require('./functions/compileReadme.js')
3
12
  const defaultCmd = require('./functions/default.js')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "1.2.3",
3
+ "version": "2.1.0",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "scripts": {