js-build-tools 3.0.4 → 4.0.1

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 (213) hide show
  1. package/README.md +166 -426
  2. package/babel.config.js +1 -1
  3. package/dist/build.js +33 -34
  4. package/dist/build.min.js +1 -1
  5. package/dist/bundle.js +14 -9
  6. package/dist/bundle.min.js +1 -1
  7. package/dist/bundleLint.js +15 -11
  8. package/dist/bundleLint.min.js +1 -1
  9. package/dist/bundleMinify.js +11 -5
  10. package/dist/bundleMinify.min.js +1 -1
  11. package/dist/compileReadme.js +7 -10
  12. package/dist/compileReadme.min.js +1 -1
  13. package/dist/copyFonts.js +11 -5
  14. package/dist/copyFonts.min.js +1 -1
  15. package/dist/default.js +13 -9
  16. package/dist/default.min.js +1 -1
  17. package/dist/dist.js +7 -4
  18. package/dist/dist.min.js +1 -1
  19. package/dist/distLint.js +15 -11
  20. package/dist/distLint.min.js +1 -1
  21. package/dist/distMinify.js +11 -5
  22. package/dist/distMinify.min.js +1 -1
  23. package/dist/images.js +7 -4
  24. package/dist/images.min.js +1 -1
  25. package/dist/partials/addToReadme.js +16 -11
  26. package/dist/partials/beginWatcher.js +11 -7
  27. package/dist/partials/clean.js +11 -5
  28. package/dist/partials/copyFor.js +7 -7
  29. package/dist/partials/distFor.js +21 -11
  30. package/dist/partials/distForSrc.js +9 -3
  31. package/dist/partials/distSeries.js +17 -13
  32. package/dist/partials/imagesFor.js +16 -17
  33. package/dist/partials/minifyFor.js +12 -11
  34. package/dist/partials/readmeTemplate.js +13 -9
  35. package/dist/partials/removeDirectory.js +7 -7
  36. package/dist/partials/runOnChange.js +18 -16
  37. package/dist/partials/sassFor.js +19 -12
  38. package/dist/partials/tsFor.js +17 -14
  39. package/dist/partials.js +101 -39
  40. package/dist/partials.min.js +1 -1
  41. package/dist/sass.js +7 -4
  42. package/dist/sass.min.js +1 -1
  43. package/dist/test-helpers/setUp.js +50 -47
  44. package/dist/testFull.js +12 -7
  45. package/dist/testFull.min.js +1 -1
  46. package/dist/testHelpers.js +9 -13
  47. package/dist/testHelpers.min.js +1 -1
  48. package/dist/testQuick.js +12 -7
  49. package/dist/testQuick.min.js +1 -1
  50. package/dist/typeScript.js +6 -4
  51. package/dist/typeScript.min.js +1 -1
  52. package/dist/utilities/dotGet.js +14 -12
  53. package/dist/utilities/dotNotate.js +10 -8
  54. package/dist/utilities/dotSet.js +13 -11
  55. package/dist/utilities/isObject.js +5 -1
  56. package/dist/utilities/strAfter.js +11 -7
  57. package/dist/utilities/strBefore.js +11 -7
  58. package/dist/watchFull.js +7 -7
  59. package/dist/watchFull.min.js +1 -1
  60. package/dist/watchTest.js +13 -9
  61. package/dist/watchTest.min.js +1 -1
  62. package/functions/{build.js → build.mjs} +14 -16
  63. package/functions/{build.test.js → build.test.mjs} +9 -8
  64. package/functions/{bundle.js → bundle.mjs} +5 -7
  65. package/functions/{bundle.test.js → bundle.test.mjs} +5 -4
  66. package/functions/{bundleLint.js → bundleLint.mjs} +4 -6
  67. package/functions/{bundleLint.test.js → bundleLint.test.mjs} +5 -4
  68. package/functions/bundleMinify.mjs +9 -0
  69. package/functions/bundleMinify.test.mjs +15 -0
  70. package/functions/compileReadme.mjs +9 -0
  71. package/functions/{compileReadme.test.js → compileReadme.test.mjs} +4 -4
  72. package/functions/copyFonts.mjs +9 -0
  73. package/functions/{copyFonts.test.js → copyFonts.test.mjs} +4 -3
  74. package/functions/default.mjs +12 -0
  75. package/functions/{default.test.js → default.test.mjs} +8 -7
  76. package/functions/{dist.js → dist.mjs} +2 -4
  77. package/functions/{dist.test.js → dist.test.mjs} +4 -3
  78. package/functions/{distLint.js → distLint.mjs} +4 -6
  79. package/functions/{distLint.test.js → distLint.test.mjs} +5 -4
  80. package/functions/distMinify.mjs +9 -0
  81. package/functions/distMinify.test.mjs +15 -0
  82. package/functions/{images.js → images.mjs} +2 -4
  83. package/functions/{images.test.js → images.test.mjs} +4 -3
  84. package/functions/partials/{addToReadme.js → addToReadme.mjs} +5 -7
  85. package/functions/partials/{addToReadme.test.js → addToReadme.test.mjs} +4 -3
  86. package/functions/partials/beginWatcher.mjs +9 -0
  87. package/functions/partials/{beginWatcher.test.js → beginWatcher.test.mjs} +4 -3
  88. package/functions/partials/clean.mjs +13 -0
  89. package/functions/partials/{clean.test.js → clean.test.mjs} +4 -3
  90. package/functions/partials/{copyFor.js → copyFor.mjs} +2 -4
  91. package/functions/partials/{copyFor.test.js → copyFor.test.mjs} +4 -3
  92. package/functions/partials/distFor.mjs +22 -0
  93. package/functions/partials/{distFor.test.js → distFor.test.mjs} +49 -8
  94. package/functions/partials/{distForSrc.js → distForSrc.mjs} +2 -4
  95. package/functions/partials/{distForSrc.test.js → distForSrc.test.mjs} +3 -2
  96. package/functions/partials/{distSeries.js → distSeries.mjs} +6 -8
  97. package/functions/partials/{distSeries.test.js → distSeries.test.mjs} +7 -6
  98. package/functions/partials/{imagesFor.js → imagesFor.mjs} +5 -13
  99. package/functions/partials/{imagesFor.test.js → imagesFor.test.mjs} +4 -3
  100. package/functions/partials/minifyFor.mjs +15 -0
  101. package/functions/partials/{minifyFor.test.js → minifyFor.test.mjs} +5 -4
  102. package/functions/partials/readmeTemplate.mjs +12 -0
  103. package/functions/partials/{readmeTemplate.test.js → readmeTemplate.test.mjs} +4 -3
  104. package/functions/partials/{removeDirectory.js → removeDirectory.mjs} +2 -4
  105. package/functions/partials/{removeDirectory.test.js → removeDirectory.test.mjs} +28 -28
  106. package/functions/partials/{runOnChange.js → runOnChange.mjs} +6 -8
  107. package/functions/partials/{runOnChange.test.js → runOnChange.test.mjs} +12 -11
  108. package/functions/partials/sassFor.mjs +22 -0
  109. package/functions/partials/{sassFor.test.js → sassFor.test.mjs} +5 -4
  110. package/functions/partials/{tsFor.js → tsFor.mjs} +4 -6
  111. package/functions/partials/{tsFor.test.js → tsFor.test.mjs} +5 -4
  112. package/functions/partials.mjs +23 -0
  113. package/functions/{partials.test.js → partials.test.mjs} +1 -1
  114. package/functions/sass.mjs +4 -0
  115. package/functions/{sass.test.js → sass.test.mjs} +4 -3
  116. package/functions/test-helpers/{setUp.js → setUp.mjs} +25 -27
  117. package/functions/test-helpers/setUp.test.mjs +19 -0
  118. package/functions/{testFull.js → testFull.mjs} +4 -6
  119. package/functions/testFull.test.mjs +17 -0
  120. package/functions/{testHelpers.js → testHelpers.mjs} +1 -6
  121. package/functions/testHelpers.test.mjs +7 -0
  122. package/functions/{testQuick.js → testQuick.mjs} +4 -6
  123. package/functions/testQuick.test.mjs +17 -0
  124. package/functions/{typeScript.js → typeScript.mjs} +2 -4
  125. package/functions/typeScript.test.mjs +11 -0
  126. package/functions/utilities/{dotGet.js → dotGet.mjs} +4 -6
  127. package/functions/utilities/{dotNotate.js → dotNotate.mjs} +2 -4
  128. package/functions/utilities/{dotSet.js → dotSet.mjs} +4 -6
  129. package/functions/utilities/{isObject.js → isObject.mjs} +1 -3
  130. package/functions/utilities/{strAfter.js → strAfter.mjs} +11 -13
  131. package/functions/utilities/{strBefore.js → strBefore.mjs} +11 -13
  132. package/functions/{watchFull.js → watchFull.mjs} +2 -4
  133. package/functions/{watchFull.test.js → watchFull.test.mjs} +8 -7
  134. package/functions/watchTest.mjs +10 -0
  135. package/functions/{watchTest.test.js → watchTest.test.mjs} +7 -6
  136. package/gulp.config.js +20 -19
  137. package/gulp.config.mjs +252 -0
  138. package/gulpfile.base.js +20 -20
  139. package/gulpfile.base.mjs +27 -0
  140. package/package.json +27 -13
  141. package/functions/bundleMinify.js +0 -11
  142. package/functions/bundleMinify.test.js +0 -14
  143. package/functions/compileReadme.js +0 -11
  144. package/functions/copyFonts.js +0 -11
  145. package/functions/default.js +0 -14
  146. package/functions/distMinify.js +0 -11
  147. package/functions/distMinify.test.js +0 -14
  148. package/functions/partials/beginWatcher.js +0 -11
  149. package/functions/partials/clean.js +0 -15
  150. package/functions/partials/distFor.js +0 -17
  151. package/functions/partials/minifyFor.js +0 -15
  152. package/functions/partials/readmeTemplate.js +0 -14
  153. package/functions/partials/sassFor.js +0 -21
  154. package/functions/partials.js +0 -40
  155. package/functions/sass.js +0 -6
  156. package/functions/test-helpers/setUp.test.js +0 -18
  157. package/functions/testFull.test.js +0 -16
  158. package/functions/testHelpers.test.js +0 -7
  159. package/functions/testQuick.test.js +0 -16
  160. package/functions/typeScript.test.js +0 -10
  161. package/functions/watchTest.js +0 -12
  162. package/vendor/array-union/index.js +0 -31
  163. package/vendor/easy-transform-stream/index.js +0 -54
  164. package/vendor/globby/gitignore.js +0 -96
  165. package/vendor/globby/index.js +0 -191
  166. package/vendor/globby/node_modules/slash/index.js +0 -16
  167. package/vendor/globby/stream-utils.js +0 -58
  168. package/vendor/globby/to-path.js +0 -20
  169. package/vendor/gulp-imagemin/index.js +0 -124
  170. package/vendor/gulp-imagemin/node_modules/chalk/source/index.js +0 -265
  171. package/vendor/gulp-imagemin/node_modules/chalk/source/utilities.js +0 -36
  172. package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -217
  173. package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/supports-color/index.js +0 -154
  174. package/vendor/gulp-plugin-extras/index.js +0 -42
  175. package/vendor/gulp-plugin-extras/node_modules/chalk/source/index.js +0 -265
  176. package/vendor/gulp-plugin-extras/node_modules/chalk/source/utilities.js +0 -36
  177. package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -217
  178. package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/supports-color/index.js +0 -154
  179. package/vendor/gulp-plugin-extras/plugin-error.js +0 -145
  180. package/vendor/ignore/index.js +0 -468
  181. package/vendor/imagemin/index.js +0 -90
  182. package/vendor/imagemin-gifsicle/index.js +0 -33
  183. package/vendor/imagemin-mozjpeg/index.js +0 -100
  184. package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +0 -260
  185. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/command.js +0 -47
  186. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/error.js +0 -102
  187. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +0 -123
  188. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/promise.js +0 -47
  189. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stdio.js +0 -50
  190. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +0 -124
  191. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/core.js +0 -238
  192. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/main.js +0 -89
  193. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/realtime.js +0 -24
  194. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/signals.js +0 -44
  195. package/vendor/imagemin-mozjpeg/node_modules/is-stream/index.js +0 -25
  196. package/vendor/imagemin-mozjpeg/node_modules/mimic-fn/index.js +0 -70
  197. package/vendor/imagemin-mozjpeg/node_modules/npm-run-path/index.js +0 -52
  198. package/vendor/imagemin-mozjpeg/node_modules/onetime/index.js +0 -43
  199. package/vendor/imagemin-mozjpeg/node_modules/path-key/index.js +0 -20
  200. package/vendor/imagemin-mozjpeg/node_modules/strip-final-newline/index.js +0 -17
  201. package/vendor/imagemin-optipng/index.js +0 -44
  202. package/vendor/imagemin-svgo/index.js +0 -27
  203. package/vendor/is-jpg/index.js +0 -12
  204. package/vendor/junk/index.js +0 -49
  205. package/vendor/mozjpeg/index.js +0 -9
  206. package/vendor/mozjpeg/lib/index.js +0 -18
  207. package/vendor/mozjpeg/package.json +0 -49
  208. package/vendor/mozjpeg/vendor/cjpeg +0 -0
  209. package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
  210. package/vendor/p-pipe/index.js +0 -22
  211. package/vendor/plur/index.js +0 -32
  212. package/vendor/pretty-bytes/index.js +0 -71
  213. package/vendor/slash/index.js +0 -12
@@ -1,16 +1,14 @@
1
- const browserify = require('browserify')
2
- const { dest } = require('gulp')
3
- const gulpConfig = require('../gulp.config.js')
4
- const source = require('vinyl-source-stream')
1
+ import browserify from 'browserify'
2
+ import { dest } from 'gulp'
3
+ import * as gulpConfig from '../gulp.config.mjs'
4
+ import source from 'vinyl-source-stream'
5
5
 
6
6
  /**
7
7
  * Starting at the distribution entry point, bundle all the files into a single file and store them in the specified output directory.
8
8
  * @memberOf module:js-build-tools
9
9
  * @returns {stream.Stream}
10
10
  */
11
- const bundle = () => browserify(gulpConfig.get('dist.main'))
11
+ export const bundle = () => browserify(gulpConfig.get('dist.main'))
12
12
  .bundle()
13
13
  .pipe(source(`${gulpConfig.get('browser.name')}.js`))
14
14
  .pipe(dest(gulpConfig.get('browser.to')))
15
-
16
- module.exports = bundle
@@ -1,9 +1,10 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { bundle } from './bundle.mjs'
4
+ import { countMatches } from 'test-filesystem'
5
+
3
6
  setUp.setDefaults('test-bundle')
4
7
  const gulpConfig = setUp.gulpConfig
5
- const bundle = require('./bundle')
6
- const { countMatches } = require('test-filesystem')
7
8
 
8
9
  const file1Contents = 'function file1 () {\n' +
9
10
  ' console.log(\'Hello from file1\')\n' +
@@ -1,18 +1,16 @@
1
- const { dest, src } = require('gulp')
2
- const gulpConfig = require('../gulp.config.js')
3
- const standard = require('gulp-standard')
1
+ import { dest, src } from 'gulp'
2
+ import * as gulpConfig from '../gulp.config.mjs'
3
+ import standard from 'gulp-standard'
4
4
 
5
5
  /**
6
6
  * Applies Standard code style linting to bundled file.
7
7
  * @memberOf module:js-build-tools
8
8
  * @returns {stream.Stream}
9
9
  */
10
- const bundleLint = () => src(`${gulpConfig.get('browser.to')}/${gulpConfig.get('browser.name')}.js`)
10
+ export const bundleLint = () => src(`${gulpConfig.get('browser.to')}/${gulpConfig.get('browser.name')}.js`)
11
11
  .pipe(standard({ fix: true }))
12
12
  .pipe(standard.reporter('default', {
13
13
  fix: true,
14
14
  quiet: true
15
15
  }))
16
16
  .pipe(dest(gulpConfig.get('browser.to')))
17
-
18
- module.exports = bundleLint
@@ -1,9 +1,10 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { bundleLint } from './bundleLint.mjs'
4
+ import { countMatches } from 'test-filesystem'
5
+
3
6
  setUp.setDefaults('test-bundle-lint')
4
7
  const gulpConfig = setUp.gulpConfig
5
- const bundleLint = require('./bundleLint')
6
- const { countMatches } = require('test-filesystem')
7
8
 
8
9
  const lintableContents = 'const gulpConfig = require("../gulp.config.js");\n' +
9
10
  'const { dest, src } = require("gulp");\n' +
@@ -0,0 +1,9 @@
1
+ import * as gulpConfig from '../gulp.config.mjs'
2
+ import { minifyFor } from './partials/minifyFor.mjs'
3
+
4
+ /**
5
+ * Creates the minified bundle file.
6
+ * @memberOf module:js-build-tools
7
+ * @returns {*}
8
+ */
9
+ export const bundleMinify = () => minifyFor(`${gulpConfig.get('browser.to')}/${gulpConfig.get('browser.name')}.js`, gulpConfig.get('browser.to'))
@@ -0,0 +1,15 @@
1
+ import { testHelpers } from './testHelpers.mjs'
2
+ import { bundleMinify } from './bundleMinify.mjs'
3
+ import { minifyFor } from './partials/minifyFor.mjs'
4
+
5
+ const gulpConfig = testHelpers.gulpConfig
6
+
7
+ jest.mock('./partials/minifyFor.mjs', () => ({ minifyFor: jest.fn(() => Promise.resolve(true)) }))
8
+
9
+ describe('bundleMinify', () => {
10
+ test('calls minifyFor with configurations', () => {
11
+ expect.assertions(1)
12
+ bundleMinify()
13
+ expect(minifyFor).toHaveBeenCalledWith(`${gulpConfig.get('browser.to')}/${gulpConfig.get('browser.name')}.js`, gulpConfig.get('browser.to'))
14
+ })
15
+ })
@@ -0,0 +1,9 @@
1
+ import { addToReadme, readmeTemplate } from './partials.mjs'
2
+ import { series } from 'gulp'
3
+
4
+ /**
5
+ * Generate the README.md file based off of the template, then append the generated documentation.
6
+ * @memberOf module:js-build-tools
7
+ * @returns {stream.Stream}
8
+ */
9
+ export const compileReadme = series(readmeTemplate, addToReadme)
@@ -1,9 +1,9 @@
1
- const compileReadme = require('./compileReadme')
2
- const { addToReadme, readmeTemplate} = require('./partials')
1
+ import { compileReadme } from './compileReadme.mjs'
2
+ import { addToReadme, readmeTemplate } from './partials.mjs'
3
3
 
4
4
  const genericFunction = () => Promise.resolve(true)
5
- jest.mock('./partials/addToReadme', () => jest.fn(genericFunction))
6
- jest.mock('./partials/readmeTemplate', () => jest.fn(genericFunction))
5
+ jest.mock('./partials/addToReadme.mjs', () => ({ addToReadme: jest.fn(genericFunction) }))
6
+ jest.mock('./partials/readmeTemplate.mjs', () => ({ readmeTemplate: jest.fn(genericFunction) }))
7
7
 
8
8
  describe('compileReadme', () => {
9
9
  test('calls readmeTemplate and addToReadme', done => {
@@ -0,0 +1,9 @@
1
+ import { copyFor } from './partials/copyFor.mjs'
2
+ import * as gulpConfig from '../gulp.config.mjs'
3
+
4
+ /**
5
+ * Move the font files into the browser directory.
6
+ * @memberOf module:js-build-tools
7
+ * @return {stream.Stream}
8
+ */
9
+ export const copyFonts = () => copyFor(gulpConfig.get('fonts.from'), gulpConfig.get('fonts.to'))
@@ -1,8 +1,9 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { copyFonts } from './copyFonts.mjs'
4
+
3
5
  setUp.setDefaults('test-copy-fonts')
4
6
  const gulpConfig = setUp.gulpConfig
5
- const copyFonts = require('./copyFonts')
6
7
 
7
8
  const fontContent = 'comic sans'
8
9
 
@@ -0,0 +1,12 @@
1
+ import { dist } from './dist.mjs'
2
+ import { bundle } from './bundle.mjs'
3
+ import * as gulpConfig from '../gulp.config.mjs'
4
+ import { series } from 'gulp'
5
+
6
+ /**
7
+ * Recommended as the default task, runs the simple dist and bundle tasks.
8
+ * @memberOf module:js-build-tools
9
+ * @param {function} [done=null]
10
+ * @returns {stream.Stream}
11
+ */
12
+ export const defaultCmd = (done = null) => gulpConfig.get('browser.enabled') ? series(dist, bundle)(done) : series(dist)(done)
@@ -1,12 +1,13 @@
1
- const { setUp } = require('./testHelpers')
2
- const gulpConfig = setUp.gulpConfig
3
- const bundle = require('./bundle')
4
- const dist = require('./dist')
5
- const defaultCmd = require('./default')
1
+ import { testHelpers } from './testHelpers.mjs'
2
+ import { bundle } from './bundle.mjs'
3
+ import { dist } from './dist.mjs'
4
+ import { defaultCmd } from './default.mjs'
5
+
6
+ const gulpConfig = testHelpers.gulpConfig
6
7
 
7
8
  const genericFunction = () => Promise.resolve(true)
8
- jest.mock('./bundle', () => jest.fn(genericFunction))
9
- jest.mock('./dist', () => jest.fn(genericFunction))
9
+ jest.mock('./bundle.mjs', () => ({ bundle: jest.fn(genericFunction) }))
10
+ jest.mock('./dist.mjs', () => ({ dist: jest.fn(genericFunction) }))
10
11
 
11
12
  describe('distMinify', () => {
12
13
  test('calls dist for nodeOnly true', done => {
@@ -1,10 +1,8 @@
1
- const distFor = require('./partials/distFor.js')
1
+ import { distFor } from './partials/distFor.mjs'
2
2
 
3
3
  /**
4
4
  * Simplified distribution tasks which will use arguments from distFor.
5
5
  * @memberOf module:js-build-tools
6
6
  * @returns {*}
7
7
  */
8
- const dist = () => distFor()
9
-
10
- module.exports = dist
8
+ export const dist = () => distFor()
@@ -1,8 +1,9 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { dist } from './dist.mjs'
4
+
3
5
  setUp.setDefaults('test-dist')
4
6
  const gulpConfig = setUp.gulpConfig
5
- const dist = require('./dist')
6
7
 
7
8
  const rawContents = 'const distFor = require(\'./distFor.js\')\n' +
8
9
  '\n' +
@@ -1,18 +1,16 @@
1
- const gulpConfig = require('../gulp.config.js')
2
- const { dest, src } = require('gulp')
3
- const standard = require('gulp-standard')
1
+ import * as gulpConfig from '../gulp.config.mjs'
2
+ import { dest, src } from 'gulp'
3
+ import standard from 'gulp-standard'
4
4
 
5
5
  /**
6
6
  * Applies Standard code style linting to distribution files.
7
7
  * @memberOf module:js-build-tools
8
8
  * @returns {*}
9
9
  */
10
- const distLint = () => src(gulpConfig.get('browser.from'))
10
+ export const distLint = () => src(gulpConfig.get('browser.from'))
11
11
  .pipe(standard({ fix: true }))
12
12
  .pipe(standard.reporter('default', {
13
13
  fix: true,
14
14
  quiet: true
15
15
  }))
16
16
  .pipe(dest(gulpConfig.get('dist.to')))
17
-
18
- module.exports = distLint
@@ -1,9 +1,10 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { distLint } from './distLint.mjs'
4
+ import { countMatches } from 'test-filesystem'
5
+
3
6
  setUp.setDefaults('test-dist-lint')
4
7
  const gulpConfig = setUp.gulpConfig
5
- const distLint = require('./distLint')
6
- const { countMatches } = require('test-filesystem')
7
8
 
8
9
  const lintableContents = 'const gulpConfig = require("../gulp.config.js");\n' +
9
10
  'const { dest, src } = require("gulp");\n' +
@@ -0,0 +1,9 @@
1
+ import * as gulpConfig from '../gulp.config.mjs'
2
+ import { minifyFor } from './partials/minifyFor.mjs'
3
+
4
+ /**
5
+ * Creates minified versions of the dist files.
6
+ * @memberOf module:js-build-tools
7
+ * @returns {*}
8
+ */
9
+ export const distMinify = () => minifyFor(gulpConfig.get('browser.from'), gulpConfig.get('dist.to'))
@@ -0,0 +1,15 @@
1
+ import { testHelpers } from './testHelpers.mjs'
2
+ import { distMinify } from './distMinify.mjs'
3
+ import { minifyFor } from './partials/minifyFor.mjs'
4
+
5
+ const gulpConfig = testHelpers.gulpConfig
6
+
7
+ jest.mock('./partials/minifyFor.mjs', () => ({ minifyFor: jest.fn(() => Promise.resolve(true)) }))
8
+
9
+ describe('distMinify', () => {
10
+ test('calls minifyFor with configurations', () => {
11
+ expect.assertions(1)
12
+ distMinify()
13
+ expect(minifyFor).toHaveBeenCalledWith(gulpConfig.get('browser.from'), gulpConfig.get('dist.to'))
14
+ })
15
+ })
@@ -1,10 +1,8 @@
1
- const imagesFor = require('./partials/imagesFor.js')
1
+ import { imagesFor } from './partials/imagesFor.mjs'
2
2
 
3
3
  /**
4
4
  * Move and optimize the images into the browser folder using configured settings.
5
5
  * @memberOf module:js-build-tools
6
6
  * @return {stream.Stream}
7
7
  */
8
- const images = () => imagesFor()
9
-
10
- module.exports = images
8
+ export const images = () => imagesFor()
@@ -1,8 +1,9 @@
1
- const fs = require('fs')
2
- const setUp = require('./test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from './test-helpers/setUp.mjs'
3
+ import { images } from './images.mjs'
4
+
3
5
  setUp.setDefaults('test-images')
4
6
  const gulpConfig = setUp.gulpConfig
5
- const images = require('./images')
6
7
 
7
8
  const imageContents = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' +
8
9
  '<!-- Created with Inkscape (http://www.inkscape.org/) -->\n' +
@@ -1,7 +1,7 @@
1
- const fs = require('fs')
2
- const gulpConfig = require('../../gulp.config.js')
3
- const jsdoc2md = require('jsdoc-to-markdown')
4
- const { globSync } = require('glob')
1
+ import fs from 'fs'
2
+ import * as gulpConfig from '../../gulp.config.mjs'
3
+ import jsdoc2md from 'jsdoc-to-markdown'
4
+ import { globSync } from 'glob'
5
5
 
6
6
  /**
7
7
  * Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
@@ -9,10 +9,8 @@ const { globSync } = require('glob')
9
9
  * @memberOf module:partials
10
10
  * @returns {string|Uint8Array}
11
11
  */
12
- const addToReadme = () => jsdoc2md
12
+ export const addToReadme = () => jsdoc2md
13
13
  .render({ files: globSync(gulpConfig.get('readme.from')) })
14
14
  .then(
15
15
  readme => fs.appendFileSync(gulpConfig.get('readme.to') + gulpConfig.get('readme.file'), readme, gulpConfig.get('readmeOptions'))
16
16
  )
17
-
18
- module.exports = addToReadme
@@ -1,9 +1,10 @@
1
- const fs = require('fs')
2
- const setUp = require('../test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from '../test-helpers/setUp.mjs'
3
+ import { addToReadme } from './addToReadme.mjs'
4
+
3
5
  setUp.setDefaults('test-add-to-readme')
4
6
  const gulpConfig = setUp.gulpConfig
5
7
  gulpConfig.set('dist.from', 'test-temp/src/addToReadme.js')
6
- const addToReadme = require('./addToReadme')
7
8
 
8
9
  const rawContents = '/**\n' +
9
10
  ' * Say hello with a given name.\n' +
@@ -0,0 +1,9 @@
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+ import { watch } from 'gulp'
3
+
4
+ /**
5
+ * Create a chokidar instance which watches and triggers change when the globed files are modified.
6
+ * @memberOf module:partials
7
+ * @returns {FSWatcher}
8
+ */
9
+ export const beginWatcher = () => watch(gulpConfig.get('test.watch'))
@@ -1,8 +1,9 @@
1
- const setUp = require('../test-helpers/setUp')
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { beginWatcher } from './beginWatcher.mjs'
3
+ import { EventEmitter } from 'node:events'
4
+
2
5
  setUp.setDefaults('test-begin-watcher')
3
6
  const gulpConfig = setUp.gulpConfig
4
- const beginWatcher = require('./beginWatcher')
5
- const { EventEmitter } = require('node:events')
6
7
 
7
8
  beforeEach(setUp.beforeEach)
8
9
 
@@ -0,0 +1,13 @@
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+ import { removeDirectory } from './removeDirectory.mjs'
3
+
4
+ /**
5
+ * Deletes all the distribution and browser files (used before create a new build).
6
+ * Configure array of directories to remove with 'cleanPaths'.
7
+ * @memberOf module:partials
8
+ * @returns {Promise<string[]> | *}
9
+ */
10
+ export const clean = () => gulpConfig.get('cleanPaths').reduce(
11
+ (promise, path) => promise.then(() => removeDirectory(path)),
12
+ Promise.resolve()
13
+ )
@@ -1,10 +1,11 @@
1
- const fs = require('fs')
2
- const setUp = require('../test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from '../test-helpers/setUp.mjs'
3
+ import { clean } from './clean.mjs'
4
+
3
5
  setUp.setDefaults('test-clean')
4
6
  const gulpConfig = setUp.gulpConfig
5
7
  const srcPath = gulpConfig.get('srcPath')
6
8
  gulpConfig.set('cleanPaths', [srcPath])
7
- const clean = require('./clean')
8
9
 
9
10
  beforeEach(setUp.beforeEach)
10
11
 
@@ -1,4 +1,4 @@
1
- const { dest, src } = require('gulp')
1
+ import { dest, src } from 'gulp'
2
2
 
3
3
  /**
4
4
  * Copy some files to a different location.
@@ -7,7 +7,5 @@ const { dest, src } = require('gulp')
7
7
  * @param {string} destPath
8
8
  * @returns {stream.Stream}
9
9
  */
10
- const copyFor = (srcPath, destPath) => src(srcPath)
10
+ export const copyFor = (srcPath, destPath) => src(srcPath)
11
11
  .pipe(dest(destPath))
12
-
13
- module.exports = copyFor
@@ -1,8 +1,9 @@
1
- const fs = require('fs')
2
- const setUp = require('../test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from '../test-helpers/setUp.mjs'
3
+ import { copyFor } from './copyFor.mjs'
4
+
3
5
  setUp.setDefaults('test-copy-for')
4
6
  const gulpConfig = setUp.gulpConfig
5
- const copyFor = require('./copyFor')
6
7
 
7
8
  const fileContents = 'some file contents'
8
9
 
@@ -0,0 +1,22 @@
1
+ import babel from 'gulp-babel'
2
+ import { dest, src } from 'gulp'
3
+ import { distForSrc } from './distForSrc.mjs'
4
+ import * as gulpConfig from '../../gulp.config.mjs'
5
+ import through from 'through2'
6
+
7
+ /**
8
+ * Build the distribution for a given source pattern.
9
+ * @memberOf module:partials
10
+ * @param {string|array} [srcPath='src/config/path/dist/for']
11
+ * @param {string} [destPath='dist/config/path']
12
+ * @returns {stream.Stream}
13
+ */
14
+ export const distFor = (srcPath = distForSrc(), destPath = gulpConfig.get('dist.to')) => src(srcPath)
15
+ .pipe(babel())
16
+ .pipe(through.obj(function (file, enc, callback) {
17
+ const regex = /\.mjs(['"]\s*\))/gi
18
+ file.contents = Buffer.from(file.contents.toString().replaceAll(regex, '.js$1'))
19
+ this.push(file)
20
+ callback()
21
+ }))
22
+ .pipe(dest(destPath))
@@ -1,10 +1,11 @@
1
- const fs = require('fs')
2
- const setUp = require('../test-helpers/setUp')
1
+ import fs from 'fs'
2
+ import * as setUp from '../test-helpers/setUp.mjs'
3
+ import { distFor } from './distFor.mjs'
4
+ import { countMatches, fileExists } from 'test-filesystem'
5
+ import { tsFor } from './tsFor.mjs'
6
+
3
7
  setUp.setDefaults('test-dist-for')
4
8
  const gulpConfig = setUp.gulpConfig
5
- const distFor = require('./distFor')
6
- const { countMatches } = require('test-filesystem')
7
- const typeScript = require('../typeScript')
8
9
 
9
10
  const rawContents = 'const babel = require(\'gulp-babel\')\n' +
10
11
  'const { dest, src } = require(\'gulp\')\n' +
@@ -59,6 +60,23 @@ const rawTsContents = '// @ts-ignore\n' +
59
60
  '\n' +
60
61
  'export default distFor\n'
61
62
 
63
+ const rawMjsContents = 'import babel from \'gulp-babel\'\n' +
64
+ 'import { dest, src } from \'gulp\'\n' +
65
+ 'import { distForSrc } from \'./distForSrc.mjs\'\n' +
66
+ 'import * as gulpConfig from \'../../gulp.config.mjs\'\n' +
67
+ '\n' +
68
+ '/**\n' +
69
+ ' * Build the distribution for a given source pattern.\n' +
70
+ ' * @memberOf module:partials\n' +
71
+ ' * @param {string|array} [srcPath=\'src/config/path/dist/for\']\n' +
72
+ ' * @param {string} [destPath=\'dist/config/path\']\n' +
73
+ ' * @returns {stream.Stream}\n' +
74
+ ' */\n' +
75
+ 'export const distFor = (srcPath = distForSrc(), destPath = gulpConfig.get(\'dist.to\')) => src(srcPath)\n' +
76
+ ' .pipe(babel())\n' +
77
+ ' .pipe((result) => console.log(result) || result)\n' +
78
+ ' .pipe(dest(destPath))\n'
79
+
62
80
  beforeEach(setUp.beforeEach)
63
81
 
64
82
  afterEach(setUp.afterEach)
@@ -74,7 +92,7 @@ describe('distFor', () => {
74
92
  const distPath = gulpConfig.get('dist.to')
75
93
  distFor(srcFile)
76
94
  .on('finish', () => {
77
- expect(fs.existsSync(distPath)).toBeTruthy()
95
+ expect(fileExists(distPath)).toBeTruthy()
78
96
  const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
79
97
  expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
80
98
  /* There used to be a nice check here where `const` and `let` would be swapped to `var`, but that no longer
@@ -100,10 +118,12 @@ describe('distFor', () => {
100
118
  const oldContents = fs.readFileSync(srcFile).toString()
101
119
  expect(countMatches(oldContents, 'const ')).toEqual(3)
102
120
  const distPath = gulpConfig.get('dist.to')
103
- typeScript(() => {
121
+ const tsFrom = gulpConfig.get('typescript.from')
122
+ const tsTo = gulpConfig.get('typescript.to')
123
+ tsFor(tsFrom, tsTo)(() => {
104
124
  distFor()
105
125
  .on('finish', () => {
106
- expect(fs.existsSync(distPath)).toBeTruthy()
126
+ expect(fileExists(distPath)).toBeTruthy()
107
127
  const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
108
128
  expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
109
129
  expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
@@ -118,4 +138,25 @@ describe('distFor', () => {
118
138
  })
119
139
  })
120
140
  }, 60000)
141
+
142
+ test('converts .mjs file extension to .js', done => {
143
+ const srcPath = gulpConfig.get('srcPath')
144
+ const srcFile = `${srcPath}/distFor.mjs`
145
+ fs.writeFileSync(srcFile, rawMjsContents)
146
+ // expect.assertions(5)
147
+ const oldContents = fs.readFileSync(srcFile).toString()
148
+ expect(countMatches(oldContents, '.mjs')).toEqual(2)
149
+ const distPath = gulpConfig.get('dist.to')
150
+ distFor(srcFile)
151
+ .on('finish', () => {
152
+ expect(fileExists(distPath)).toBeTruthy()
153
+ const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
154
+ expect(countMatches(babelifiedContents, '.js')).toEqual(3)
155
+ done()
156
+ })
157
+ .on('error', error => {
158
+ console.error('Encountered error', error)
159
+ done()
160
+ })
161
+ }, 5000)
121
162
  })
@@ -1,4 +1,4 @@
1
- const gulpConfig = require('../../gulp.config')
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
2
 
3
3
  /**
4
4
  * Retrieve the correct distFor search path based on TS Config.
@@ -6,8 +6,6 @@ const gulpConfig = require('../../gulp.config')
6
6
  * @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
7
7
  * @returns {string}
8
8
  */
9
- const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs
9
+ export const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs
10
10
  ? gulpConfig.get('browser.from')
11
11
  : gulpConfig.get('dist.from')
12
-
13
- module.exports = distForSrc
@@ -1,6 +1,7 @@
1
- const setUp = require('../test-helpers/setUp')
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { distForSrc } from './distForSrc.mjs'
3
+
2
4
  const gulpConfig = setUp.gulpConfig
3
- const distForSrc = require('./distForSrc')
4
5
 
5
6
  describe('distForSrc', () => {
6
7
  test('typescript.enabled as false returns srcSearch', () => {
@@ -1,8 +1,8 @@
1
- const gulpConfig = require('../../gulp.config')
2
- const distFor = require('./distFor')
3
- const distForSrc = require('./distForSrc')
4
- const { series } = require('gulp')
5
- const tsFor = require('./tsFor')
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+ import { distFor } from './distFor.mjs'
3
+ import { distForSrc } from './distForSrc.mjs'
4
+ import { series } from 'gulp'
5
+ import { tsFor } from './tsFor.mjs'
6
6
 
7
7
  /**
8
8
  * When using TypeScript, ensure that we process the ts first then run babel (dist)
@@ -12,12 +12,10 @@ const tsFor = require('./tsFor')
12
12
  * @param {string} [tsSearch='ts/search/config/path']
13
13
  * @returns {function(null=): stream.Stream}
14
14
  */
15
- const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
15
+ export const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
16
16
  const typescript = tsFor(tsSearch, distFinalPath)
17
17
  const dist = () => distFor(srcPath, distFinalPath)
18
18
  return gulpConfig.get('typescript.enabled')
19
19
  ? series(typescript, dist)
20
20
  : dist
21
21
  }
22
-
23
- module.exports = distSeries
@@ -1,13 +1,14 @@
1
- const setUp = require('../test-helpers/setUp')
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { distSeries } from './distSeries.mjs'
3
+ import { tsFor } from './tsFor.mjs'
4
+ import { distFor } from './distFor.mjs'
5
+
2
6
  const gulpConfig = setUp.gulpConfig
3
- const distSeries = require('./distSeries')
4
- const tsFor = require('./tsFor')
5
- const distFor = require('./distFor')
6
7
 
7
8
  const genericFunction = () => Promise.resolve(true)
8
9
 
9
- jest.mock('./distFor', () => jest.fn(genericFunction))
10
- jest.mock('./tsFor', () => jest.fn(() => genericFunction))
10
+ jest.mock('./distFor.mjs', () => ({ distFor: jest.fn(genericFunction) }))
11
+ jest.mock('./tsFor.mjs', () => ({ tsFor: jest.fn(() => genericFunction) }))
11
12
 
12
13
  describe('distSeries', () => {
13
14
  test('when not using ts config only returns runnable distFor', done => {