js-build-tools 1.0.5 → 1.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 (45) hide show
  1. package/README.md +353 -100
  2. package/babel.config.js +3 -0
  3. package/dist/addToReadme.js +38 -0
  4. package/dist/addToReadme.min.js +1 -0
  5. package/dist/build.js +32 -0
  6. package/dist/build.min.js +1 -0
  7. package/dist/bundle.js +20 -0
  8. package/dist/bundle.min.js +1 -0
  9. package/dist/bundleLint.js +26 -0
  10. package/dist/bundleLint.min.js +1 -0
  11. package/dist/bundleMinify.js +26 -0
  12. package/dist/bundleMinify.min.js +1 -0
  13. package/dist/clean.js +15 -0
  14. package/dist/clean.min.js +1 -0
  15. package/dist/compileReadme.js +14 -0
  16. package/dist/compileReadme.min.js +1 -0
  17. package/dist/default.js +16 -0
  18. package/dist/default.min.js +1 -0
  19. package/dist/dist.js +13 -0
  20. package/dist/dist.min.js +1 -0
  21. package/dist/distFor.js +23 -0
  22. package/dist/distFor.min.js +1 -0
  23. package/dist/distLint.js +24 -0
  24. package/dist/distLint.min.js +1 -0
  25. package/dist/distMinify.js +24 -0
  26. package/dist/distMinify.min.js +1 -0
  27. package/dist/readmeTemplate.js +19 -0
  28. package/dist/readmeTemplate.min.js +1 -0
  29. package/dist/testFull.js +85 -0
  30. package/dist/testFull.min.js +1 -0
  31. package/dist/testHelpers.js +203 -0
  32. package/dist/testHelpers.min.js +1 -0
  33. package/dist/testQuick.js +87 -0
  34. package/dist/testQuick.min.js +1 -0
  35. package/dist/watchFull.js +42 -0
  36. package/dist/watchFull.min.js +1 -0
  37. package/dist/watchTest.js +21 -0
  38. package/dist/watchTest.min.js +1 -0
  39. package/functions/addToReadme.js +1 -1
  40. package/functions/build.js +4 -1
  41. package/functions/default.js +2 -1
  42. package/functions/testHelpers.js +142 -0
  43. package/functions/testHelpers.test.js +100 -0
  44. package/gulp.config.js +12 -1
  45. package/package.json +18 -14
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ require('core-js/modules/es.regexp.constructor.js')
4
+
5
+ require('core-js/modules/es.regexp.exec.js')
6
+
7
+ require('core-js/modules/es.regexp.sticky.js')
8
+
9
+ require('core-js/modules/es.regexp.to-string.js')
10
+
11
+ require('core-js/modules/es.string.replace.js')
12
+
13
+ var bundle = require('./bundle')
14
+
15
+ var distFor = require('./distFor')
16
+
17
+ var gulpConfig = require('../gulp.config.js')
18
+
19
+ var _require = require('gulp')
20
+ var parallel = _require.parallel
21
+ var series = _require.series
22
+ var watch = _require.watch
23
+
24
+ var testQuick = require('./testQuick')
25
+ /**
26
+ * Watch for changes and run the distribution for the changed files, then bundle and test the changed files.
27
+ * @returns {*}
28
+ */
29
+
30
+ var watchFull = function watchFull () {
31
+ return watch(gulpConfig.watchSearch).on('change', function (path) {
32
+ var pathRegex = new RegExp('^'.concat(gulpConfig.srcPath, '(.*\\/).+\\.js$'), 'i')
33
+
34
+ var distForPath = function distForPath () {
35
+ return distFor(path, path.replace(pathRegex, ''.concat(gulpConfig.distPath, '$1')))
36
+ }
37
+
38
+ return parallel(testQuick, series(distForPath, bundle))()
39
+ })
40
+ }
41
+
42
+ module.exports = watchFull
@@ -0,0 +1 @@
1
+ "use strict";require("core-js/modules/es.regexp.constructor.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.sticky.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.string.replace.js");var bundle=require("./bundle"),distFor=require("./distFor"),gulpConfig=require("../gulp.config.js"),_require=require("gulp"),parallel=_require.parallel,series=_require.series,watch=_require.watch,testQuick=require("./testQuick"),watchFull=function(){return watch(gulpConfig.watchSearch).on("change",(function(e){var r=new RegExp("^".concat(gulpConfig.srcPath,"(.*\\/).+\\.js$"),"i");return parallel(testQuick,series((function(){return distFor(e,e.replace(r,"".concat(gulpConfig.distPath,"$1")))}),bundle))()}))};module.exports=watchFull;
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ var gulpConfig = require('../gulp.config.js')
4
+
5
+ var _require = require('gulp')
6
+ var series = _require.series
7
+ var watch = _require.watch
8
+
9
+ var testQuick = require('./testQuick')
10
+ /**
11
+ * Watch for changes and run the tests.
12
+ * @returns {*}
13
+ */
14
+
15
+ var watchTest = function watchTest () {
16
+ return watch(gulpConfig.watchSearch, {
17
+ ignoreInitial: false
18
+ }, series(testQuick))
19
+ }
20
+
21
+ module.exports = watchTest
@@ -0,0 +1 @@
1
+ "use strict";var gulpConfig=require("../gulp.config.js"),_require=require("gulp"),series=_require.series,watch=_require.watch,testQuick=require("./testQuick"),watchTest=function(){return watch(gulpConfig.watchSearch,{ignoreInitial:!1},series(testQuick))};module.exports=watchTest;
@@ -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.1.0",
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,33 +33,29 @@
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",
58
+ "dist",
55
59
  "functions",
56
60
  "gulpfile.base.js",
57
61
  "gulp.config.js"