js-build-tools 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,100 +1,353 @@
1
- # js-build-tools
2
- Centralize the build process for node.js and JS projects into a single tool suite.
3
-
4
- ### Goals
5
- Using this tool suite, you can:
6
- * Create formatted distribution files to be used in a node / commonjs environment.
7
- * Bundle your distribution files to be used in a browser environment.
8
- * Run tests and watch for changes.
9
- * Generate jsdoc readme files.
10
-
11
- ## Installation
12
- In your project's root directory, run: `npm install --save-dev gulp js-build-tools`
13
- (or `yarn add --dev gulp js-build-tools` if you use Yarn).
14
-
15
- It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead of `node_modules/.bin/gulp`.
16
-
17
- ## Configuration
18
- In your project's root directory, create a `build-tools.config.js` file. This can contain any of the following (values provided are the defaults):
19
- ```
20
- module.exports = {
21
- // The name to use for the browser-bundled output file (.js will be appended).
22
- browserName: 'my-package',
23
-
24
- // The output directory for browser-bundled files.
25
- browserPath: 'browser',
26
-
27
- // The name of entry the distribution file.
28
- distMain: 'dist/main',
29
-
30
- // The output directory for the distribution files.
31
- distPath: 'dist',
32
-
33
- // The search pattern used for retrieving compiled distribution files.
34
- distSearch: 'dist/**/*.js',
35
-
36
- // The file which will be pre-fixed to your README.md output.
37
- readmeTemplate: 'MAIN.md',
38
-
39
- // The directory where your source files are stored (the files you manually created).
40
- srcPath: 'src',
41
-
42
- // The search pattern used for gathering source files for distribution.
43
- srcSearch: 'src/**/!(*.test).js',
44
-
45
- // The directory where Jest test files are stored.
46
- // By default stored as *.test.js adjacent with the files they are testing).
47
- testPath: 'src',
48
-
49
- // The search pattern for watching files for changes.
50
- watchSearch: 'src/**/*.js',
51
- }
52
- ```
53
-
54
- ### Create your local gulpfile.js
55
- In your project's root directory, create a `gulpfile.js` file, in here you can require any of the functions you need. For example:
56
- ```
57
- // Your local gulpfile.js
58
- const { build, defaultCmd, readme, testFull, testQuick, watchFull, watchTest } = require('js-build-tools')
59
-
60
- // Everything you export will be created as a gulp task.
61
- // You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
62
- // You can list your available tasks by running `gulp --tasks`.
63
- exports.build = build
64
- exports.default = defaultCmd
65
- exports.readme = readme
66
- exports.testFull = testFull
67
- exports.testQuick = testQuick
68
- exports.watchFull = watchFull
69
- exports.watchTest = watchTest
70
- ```
71
-
72
- Verify your tasks are available by running `gulp --tasks`.
73
-
74
- ### Configure Babel
75
- Depending on how you wrote your test files, Jest may require some Babel configuration.
76
- Create a `babel.config.js` file in the root directory of your project.
77
- You can then use the recommended configuration by requiring the babel.config.js file into your own configuration file.
78
- Example:
79
- ```
80
- const babelConfig = require('js-build-tools/babel.config')
81
- // You may add additional configuration here. Example: babelConfig.presets.push('@babel/preset-env')
82
- module.exports = babelConfig
83
- ```
84
-
85
- ### Configure Scripts
86
- In your package.json file, add the following scripts:
87
- ```
88
- "scripts": {
89
- "build": "gulp build",
90
- "dev": "gulp",
91
- "readme": "gulp readme",
92
- "test": "gulp testFull",
93
- "test:quick": "gulp testQuick",
94
- "watch": "gulp watchFull",
95
- "watch:test": "gulp watchTest"
96
- },
97
- ```
98
-
99
- ## Usage
100
- Run any of the above commands with `gulp` or `npm run`.
1
+ # js-build-tools
2
+ Centralize the build process for node.js and JS projects into a single tool suite.
3
+
4
+ ### Goals
5
+ Using this tool suite, you can:
6
+ * Create formatted distribution files to be used in a node / commonjs environment.
7
+ * Bundle your distribution files to be used in a browser environment.
8
+ * Run tests and watch for changes.
9
+ * Generate jsdoc readme files.
10
+
11
+ ## Installation
12
+ In your project's root directory, run: `npm install --save-dev gulp js-build-tools`
13
+ (or `yarn add --dev gulp js-build-tools` if you use Yarn).
14
+
15
+ It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead of `node_modules/.bin/gulp`.
16
+
17
+ ## Configuration
18
+ In your project's root directory, create a `build-tools.config.js` file. This can contain any of the following (values provided are the defaults):
19
+ ```
20
+ module.exports = {
21
+ // The name to use for the browser-bundled output file (.js will be appended).
22
+ browserName: 'my-package',
23
+
24
+ // The output directory for browser-bundled files.
25
+ browserPath: 'browser',
26
+
27
+ // The name of entry the distribution file.
28
+ distMain: 'dist/main',
29
+
30
+ // The output directory for the distribution files.
31
+ distPath: 'dist',
32
+
33
+ // The search pattern used for retrieving compiled distribution files.
34
+ distSearch: 'dist/**/*.js',
35
+
36
+ // The file which will be pre-fixed to your README.md output.
37
+ readmeTemplate: 'MAIN.md',
38
+
39
+ // The directory where your source files are stored (the files you manually created).
40
+ srcPath: 'src',
41
+
42
+ // The search pattern used for gathering source files for distribution.
43
+ srcSearch: 'src/**/!(*.test).js',
44
+
45
+ // The directory where Jest test files are stored.
46
+ // By default stored as *.test.js adjacent with the files they are testing).
47
+ testPath: 'src',
48
+
49
+ // The search pattern for watching files for changes.
50
+ watchSearch: 'src/**/*.js',
51
+ }
52
+ ```
53
+
54
+ ### Create your local gulpfile.js
55
+ In your project's root directory, create a `gulpfile.js` file, in here you can require any of the functions you need. For example:
56
+ ```
57
+ // Your local gulpfile.js
58
+ const { build, defaultCmd, readme, testFull, testQuick, watchFull, watchTest } = require('js-build-tools')
59
+
60
+ // Everything you export will be created as a gulp task.
61
+ // You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
62
+ // You can list your available tasks by running `gulp --tasks`.
63
+ exports.build = build
64
+ exports.default = defaultCmd
65
+ exports.readme = readme
66
+ exports.testFull = testFull
67
+ exports.testQuick = testQuick
68
+ exports.watchFull = watchFull
69
+ exports.watchTest = watchTest
70
+ ```
71
+
72
+ Verify your tasks are available by running `gulp --tasks`.
73
+
74
+ ### Configure Babel
75
+ Depending on how you wrote your test files, Jest may require some Babel configuration.
76
+ Create a `babel.config.js` file in the root directory of your project.
77
+ You can then use the recommended configuration by requiring the babel.config.js file into your own configuration file.
78
+ Example:
79
+ ```
80
+ const babelConfig = require('js-build-tools/babel.config')
81
+ // You may add additional configuration here. Example: babelConfig.presets.push('@babel/preset-env')
82
+ module.exports = babelConfig
83
+ ```
84
+
85
+ ### Configure Scripts
86
+ In your package.json file, add the following scripts:
87
+ ```
88
+ "scripts": {
89
+ "build": "gulp build",
90
+ "dev": "gulp",
91
+ "readme": "gulp readme",
92
+ "test": "gulp testFull",
93
+ "test:quick": "gulp testQuick",
94
+ "watch": "gulp watchFull",
95
+ "watch:test": "gulp watchTest"
96
+ },
97
+ ```
98
+
99
+ ## Usage
100
+ Run any of the above commands with `gulp` or `npm run`.
101
+
102
+
103
+ # Available functions documentation
104
+
105
+ ## Constants
106
+
107
+ <dl>
108
+ <dt><a href="#build">build</a></dt>
109
+ <dd><p>Runs several processes to build and validate the project.
110
+ Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.</p>
111
+ </dd>
112
+ <dt><a href="#compileReadme">compileReadme</a></dt>
113
+ <dd><p>Generate the README.md file based off of the template, then append the generated documentation.</p>
114
+ </dd>
115
+ <dt><a href="#defaultCmd">defaultCmd</a></dt>
116
+ <dd><p>Recommended as the default task, runs the simple dist and bundle tasks.</p>
117
+ </dd>
118
+ <dt><a href="#logObject">logObject</a></dt>
119
+ <dd><p>Log out an object in a nicely formatted way.</p>
120
+ </dd>
121
+ <dt><a href="#circularObject">circularObject</a> : <code>Object.&lt;string, (string|Object|Array)&gt;</code></dt>
122
+ <dd><p>Multilayered node tree-like structure with parent references</p>
123
+ </dd>
124
+ <dt><a href="#deepReferenceObject">deepReferenceObject</a> : <code>Object.&lt;string, (string|number|Object)&gt;</code></dt>
125
+ <dd><p>Sample object with deep references.</p>
126
+ </dd>
127
+ <dt><a href="#linkedList">linkedList</a> : <code>Object.&lt;string, (string|Object)&gt;</code></dt>
128
+ <dd><p>Sample LinkedList for testing circular references.</p>
129
+ </dd>
130
+ <dt><a href="#jsonDom">jsonDom</a></dt>
131
+ <dd><p>Sample of jsonDom object containing empty nested array and objects</p>
132
+ </dd>
133
+ <dt><a href="#domItem">domItem</a></dt>
134
+ <dd><p>Sample of domItem child with nested child and optional details</p>
135
+ </dd>
136
+ <dt><a href="#multiReferenceObject">multiReferenceObject</a> : <code>Object.&lt;string, (string|number|Object)&gt;</code></dt>
137
+ <dd><p>Sample of object containing multiple references.</p>
138
+ </dd>
139
+ <dt><a href="#nodeTree">nodeTree</a> : <code>Object.&lt;string, (string|Object|Array)&gt;</code></dt>
140
+ <dd><p>Sample NodeTree for testing circular references and arrays.</p>
141
+ </dd>
142
+ </dl>
143
+
144
+ ## Functions
145
+
146
+ <dl>
147
+ <dt><a href="#addToReadme">addToReadme()</a> ⇒ <code>string</code> | <code>Uint8Array</code></dt>
148
+ <dd><p>Appends all the jsdoc comments to the readme file. Assumes empty or templated file.</p>
149
+ </dd>
150
+ <dt><a href="#bundle">bundle()</a> ⇒ <code>*</code></dt>
151
+ <dd><p>Starting at the distribution entry point, bundle all the files into a single file and store them in the specified output directory.</p>
152
+ </dd>
153
+ <dt><a href="#bundleLint">bundleLint()</a> ⇒ <code>*</code></dt>
154
+ <dd><p>Applies Standard code style linting to bundled file.</p>
155
+ </dd>
156
+ <dt><a href="#bundleMinify">bundleMinify()</a> ⇒ <code>*</code></dt>
157
+ <dd><p>Creates the minified bundle file.</p>
158
+ </dd>
159
+ <dt><a href="#clean">clean()</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> | <code>*</code></dt>
160
+ <dd><p>Deletes all the distribution and browser files (used before create a new build).</p>
161
+ </dd>
162
+ <dt><a href="#dist">dist()</a> ⇒ <code>*</code></dt>
163
+ <dd><p>Simplified distribution tasks which will use arguments from distFor.</p>
164
+ </dd>
165
+ <dt><a href="#distFor">distFor(srcPath, destPath)</a> ⇒ <code>*</code></dt>
166
+ <dd><p>Build the distribution for a given source pattern.</p>
167
+ </dd>
168
+ <dt><a href="#distLint">distLint()</a> ⇒ <code>*</code></dt>
169
+ <dd><p>Applies Standard code style linting to distribution files.</p>
170
+ </dd>
171
+ <dt><a href="#distMinify">distMinify()</a> ⇒ <code>*</code></dt>
172
+ <dd><p>Creates minified versions of the dist files.</p>
173
+ </dd>
174
+ <dt><a href="#readmeTemplate">readmeTemplate()</a> ⇒ <code>*</code></dt>
175
+ <dd><p>Copy a readme template into the README.md file.</p>
176
+ </dd>
177
+ <dt><a href="#testFull">testFull()</a> ⇒ <code>Promise.&lt;*&gt;</code></dt>
178
+ <dd><p>Run all tests with jest.</p>
179
+ </dd>
180
+ <dt><a href="#testQuick">testQuick()</a> ⇒ <code>Promise.&lt;*&gt;</code></dt>
181
+ <dd><p>Run the Jest tests for files which have been modified (based on git status).</p>
182
+ </dd>
183
+ <dt><a href="#watchFull">watchFull()</a> ⇒ <code>*</code></dt>
184
+ <dd><p>Watch for changes and run the distribution for the changed files, then bundle and test the changed files.</p>
185
+ </dd>
186
+ <dt><a href="#watchTest">watchTest()</a> ⇒ <code>*</code></dt>
187
+ <dd><p>Watch for changes and run the tests.</p>
188
+ </dd>
189
+ </dl>
190
+
191
+ <a name="build"></a>
192
+
193
+ ## build
194
+ Runs several processes to build and validate the project.
195
+ Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
196
+
197
+ **Kind**: global constant
198
+ <a name="compileReadme"></a>
199
+
200
+ ## compileReadme
201
+ Generate the README.md file based off of the template, then append the generated documentation.
202
+
203
+ **Kind**: global constant
204
+ <a name="defaultCmd"></a>
205
+
206
+ ## defaultCmd
207
+ Recommended as the default task, runs the simple dist and bundle tasks.
208
+
209
+ **Kind**: global constant
210
+ <a name="logObject"></a>
211
+
212
+ ## logObject
213
+ Log out an object in a nicely formatted way.
214
+
215
+ **Kind**: global constant
216
+
217
+ | Param | Type | Default |
218
+ | --- | --- | --- |
219
+ | object | <code>Object</code> | |
220
+ | [label] | <code>string</code> | <code>&quot;&#x27;logging&#x27;&quot;</code> |
221
+
222
+ <a name="circularObject"></a>
223
+
224
+ ## circularObject : <code>Object.&lt;string, (string\|Object\|Array)&gt;</code>
225
+ Multilayered node tree-like structure with parent references
226
+
227
+ **Kind**: global constant
228
+ <a name="deepReferenceObject"></a>
229
+
230
+ ## deepReferenceObject : <code>Object.&lt;string, (string\|number\|Object)&gt;</code>
231
+ Sample object with deep references.
232
+
233
+ **Kind**: global constant
234
+ <a name="linkedList"></a>
235
+
236
+ ## linkedList : <code>Object.&lt;string, (string\|Object)&gt;</code>
237
+ Sample LinkedList for testing circular references.
238
+
239
+ **Kind**: global constant
240
+ <a name="jsonDom"></a>
241
+
242
+ ## jsonDom
243
+ Sample of jsonDom object containing empty nested array and objects
244
+
245
+ **Kind**: global constant
246
+ <a name="domItem"></a>
247
+
248
+ ## domItem
249
+ Sample of domItem child with nested child and optional details
250
+
251
+ **Kind**: global constant
252
+ <a name="multiReferenceObject"></a>
253
+
254
+ ## multiReferenceObject : <code>Object.&lt;string, (string\|number\|Object)&gt;</code>
255
+ Sample of object containing multiple references.
256
+
257
+ **Kind**: global constant
258
+ <a name="nodeTree"></a>
259
+
260
+ ## nodeTree : <code>Object.&lt;string, (string\|Object\|Array)&gt;</code>
261
+ Sample NodeTree for testing circular references and arrays.
262
+
263
+ **Kind**: global constant
264
+ <a name="addToReadme"></a>
265
+
266
+ ## addToReadme() ⇒ <code>string</code> \| <code>Uint8Array</code>
267
+ Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
268
+
269
+ **Kind**: global function
270
+ <a name="bundle"></a>
271
+
272
+ ## bundle() ⇒ <code>\*</code>
273
+ Starting at the distribution entry point, bundle all the files into a single file and store them in the specified output directory.
274
+
275
+ **Kind**: global function
276
+ <a name="bundleLint"></a>
277
+
278
+ ## bundleLint() ⇒ <code>\*</code>
279
+ Applies Standard code style linting to bundled file.
280
+
281
+ **Kind**: global function
282
+ <a name="bundleMinify"></a>
283
+
284
+ ## bundleMinify() ⇒ <code>\*</code>
285
+ Creates the minified bundle file.
286
+
287
+ **Kind**: global function
288
+ <a name="clean"></a>
289
+
290
+ ## clean() ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>\*</code>
291
+ Deletes all the distribution and browser files (used before create a new build).
292
+
293
+ **Kind**: global function
294
+ <a name="dist"></a>
295
+
296
+ ## dist() ⇒ <code>\*</code>
297
+ Simplified distribution tasks which will use arguments from distFor.
298
+
299
+ **Kind**: global function
300
+ <a name="distFor"></a>
301
+
302
+ ## distFor(srcPath, destPath) ⇒ <code>\*</code>
303
+ Build the distribution for a given source pattern.
304
+
305
+ **Kind**: global function
306
+
307
+ | Param | Type |
308
+ | --- | --- |
309
+ | srcPath | <code>string</code> \| <code>array</code> |
310
+ | destPath | <code>string</code> |
311
+
312
+ <a name="distLint"></a>
313
+
314
+ ## distLint() ⇒ <code>\*</code>
315
+ Applies Standard code style linting to distribution files.
316
+
317
+ **Kind**: global function
318
+ <a name="distMinify"></a>
319
+
320
+ ## distMinify() ⇒ <code>\*</code>
321
+ Creates minified versions of the dist files.
322
+
323
+ **Kind**: global function
324
+ <a name="readmeTemplate"></a>
325
+
326
+ ## readmeTemplate() ⇒ <code>\*</code>
327
+ Copy a readme template into the README.md file.
328
+
329
+ **Kind**: global function
330
+ <a name="testFull"></a>
331
+
332
+ ## testFull() ⇒ <code>Promise.&lt;\*&gt;</code>
333
+ Run all tests with jest.
334
+
335
+ **Kind**: global function
336
+ <a name="testQuick"></a>
337
+
338
+ ## testQuick() ⇒ <code>Promise.&lt;\*&gt;</code>
339
+ Run the Jest tests for files which have been modified (based on git status).
340
+
341
+ **Kind**: global function
342
+ <a name="watchFull"></a>
343
+
344
+ ## watchFull() ⇒ <code>\*</code>
345
+ Watch for changes and run the distribution for the changed files, then bundle and test the changed files.
346
+
347
+ **Kind**: global function
348
+ <a name="watchTest"></a>
349
+
350
+ ## watchTest() ⇒ <code>\*</code>
351
+ Watch for changes and run the tests.
352
+
353
+ **Kind**: global function
package/babel.config.js CHANGED
@@ -1,4 +1,7 @@
1
1
  module.exports = {
2
+ plugins: [
3
+ '@babel/plugin-proposal-throw-expressions'
4
+ ],
2
5
  presets: [
3
6
  ['@babel/preset-env', {
4
7
  useBuiltIns: 'usage',
@@ -6,7 +6,7 @@ const { src } = require('gulp')
6
6
 
7
7
  /**
8
8
  * Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
9
- * @returns {*}
9
+ * @returns {string|Uint8Array}
10
10
  */
11
11
  const addToReadme = () => src(gulpConfig.srcSearch)
12
12
  .pipe(filenames('readme'))
@@ -7,6 +7,7 @@ const dist = require('./dist')
7
7
  const distLint = require('./distLint')
8
8
  const distMinify = require('./distMinify')
9
9
  const { parallel, series } = require('gulp')
10
+ const gulpConfig = require('../gulp.config.js')
10
11
  const testFull = require('./testFull')
11
12
 
12
13
  /**
@@ -14,7 +15,9 @@ const testFull = require('./testFull')
14
15
  * Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
15
16
  */
16
17
  const build = parallel(
17
- series(clean, dist, parallel(distLint, distMinify), bundle, parallel(bundleLint, bundleMinify)),
18
+ gulpConfig.nodeOnly
19
+ ? series(clean, dist, parallel(distLint, distMinify))
20
+ : series(clean, dist, parallel(distLint, distMinify), bundle, parallel(bundleLint, bundleMinify)),
18
21
  compileReadme,
19
22
  testFull
20
23
  )
@@ -1,10 +1,11 @@
1
1
  const { series } = require('gulp')
2
2
  const dist = require('./dist')
3
3
  const bundle = require('./bundle')
4
+ const gulpConfig = require('../gulp.config')
4
5
 
5
6
  /**
6
7
  * Recommended as the default task, runs the simple dist and bundle tasks.
7
8
  */
8
- const defaultCmd = series(dist, bundle)
9
+ const defaultCmd = gulpConfig.nodeOnly ? series(dist) : series(dist, bundle)
9
10
 
10
11
  module.exports = defaultCmd
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Log out an object in a nicely formatted way.
3
+ * @param {Object} object
4
+ * @param {string} [label='logging']
5
+ */
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
+
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
+ ]
111
+
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
133
+ }
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: [] }
@@ -0,0 +1,100 @@
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')
12
+
13
+ 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)
99
+ })
100
+ })
package/gulp.config.js CHANGED
@@ -1,16 +1,27 @@
1
- const parentConfig = require('../../build-tools.config.js')
2
1
  const defaultConfig = (config, path, defaultValue) => {
3
2
  if (typeof config[path] === 'undefined') {
4
3
  return defaultValue
5
4
  }
6
5
  return config[path]
7
6
  }
7
+ let parentConfig = {}
8
+ try {
9
+ parentConfig = require('../../build-tools.config.js')
10
+ } catch (isUndefined) {
11
+ try {
12
+ parentConfig = require('./build-tools.config.js')
13
+ console.info('Missing main project config, using default path')
14
+ } catch (stillUndefined) {
15
+ console.warn('Missing config path, ensure you have a build-tools.config.js file in you project root')
16
+ }
17
+ }
8
18
  module.exports = {
9
19
  browserName: defaultConfig(parentConfig, 'browserName', 'default'),
10
20
  browserPath: defaultConfig(parentConfig, 'browserPath', 'browser'),
11
21
  distMain: defaultConfig(parentConfig, 'distMain', 'dist/main'),
12
22
  distPath: defaultConfig(parentConfig, 'distPath', 'dist'),
13
23
  distSearch: defaultConfig(parentConfig, 'distSearch', 'dist/**/*.js'),
24
+ nodeOnly: defaultConfig(parentConfig, 'nodeOnly', false),
14
25
  readmeTemplate: defaultConfig(parentConfig, 'readmeTemplate', 'MAIN.md'),
15
26
  srcPath: defaultConfig(parentConfig, 'srcPath', 'src'),
16
27
  srcSearch: defaultConfig(parentConfig, 'srcSearch', 'src/**/!(*.test).js'),
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "scripts": {
7
- "resolutions": "npx npm-force-resolutions"
7
+ "build": "gulp build",
8
+ "dev": "gulp",
9
+ "htmldocs": "jsdoc -R MAIN.md -c ./.jsdoc.conf.js -d docs",
10
+ "readme": "gulp readme",
11
+ "resolutions": "npx npm-force-resolutions",
12
+ "test": "gulp testFull",
13
+ "test:quick": "gulp testQuick",
14
+ "watch": "gulp watchFull",
15
+ "watch:test": "gulp watchTest"
8
16
  },
9
17
  "repository": "github:jheagle/js-build-tools",
10
18
  "keywords": [
@@ -25,31 +33,26 @@
25
33
  ]
26
34
  },
27
35
  "dependencies": {
28
- "@babel/core": "^7.18.6",
29
- "@babel/preset-env": "^7.18.6",
30
- "@babel/runtime-corejs3": "^7.18.6",
31
- "babel-jest": "^28.1.2",
36
+ "@babel/core": "^7.18.13",
37
+ "@babel/plugin-proposal-throw-expressions": "^7.18.6",
38
+ "@babel/preset-env": "^7.18.10",
39
+ "@babel/runtime-corejs3": "^7.18.9",
40
+ "babel-jest": "^29.0.1",
32
41
  "browserify": "^17.0.0",
33
- "core-js": "^3.23.3",
42
+ "core-js": "^3.25.0",
34
43
  "del": "^6.1.1",
35
44
  "fs": "^0.0.1-security",
36
- "glob-parent": "^5.1.2",
37
45
  "gulp": "^4.0.2",
38
46
  "gulp-babel": "^8.0.0",
39
47
  "gulp-filenames": "^4.0.1",
40
48
  "gulp-rename": "^2.0.0",
41
49
  "gulp-standard": "^14.0.0",
42
50
  "gulp-uglify-es": "^3.0.0",
43
- "jest": "^28.1.2",
51
+ "jest": "^29.0.1",
44
52
  "jsdoc-to-markdown": "^7.1.1",
45
- "lodash.template": "^4.5.0",
46
53
  "regenerator-runtime": "^0.13.9",
47
54
  "vinyl-source-stream": "^2.0.0"
48
55
  },
49
- "resolutions": {
50
- "glob-parent": "5.1.2",
51
- "lodash.template": "4.5.0"
52
- },
53
56
  "files": [
54
57
  "babel.config.js",
55
58
  "functions",