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.
- package/README.md +573 -250
- package/dist/build.js +22 -15
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +11 -8
- package/dist/bundle.min.js +1 -1
- package/dist/bundleLint.js +17 -13
- package/dist/bundleLint.min.js +1 -1
- package/dist/bundleMinify.js +8 -12
- package/dist/bundleMinify.min.js +1 -1
- package/dist/compileReadme.js +8 -6
- package/dist/compileReadme.min.js +1 -1
- package/dist/default.js +12 -7
- package/dist/default.min.js +1 -1
- package/dist/dist.js +6 -2
- package/dist/dist.min.js +1 -1
- package/dist/distLint.js +15 -12
- package/dist/distLint.min.js +1 -1
- package/dist/distMinify.js +7 -12
- package/dist/distMinify.min.js +1 -1
- package/dist/partials/addToReadme.js +25 -0
- package/dist/partials/beginWatcher.js +16 -0
- package/dist/partials/clean.js +21 -0
- package/dist/partials/distFor.js +23 -0
- package/dist/partials/distForSrc.js +16 -0
- package/dist/partials/distSeries.js +31 -0
- package/dist/partials/minifyFor.js +21 -0
- package/dist/partials/readmeTemplate.js +18 -0
- package/dist/partials/runOnChange.js +63 -0
- package/dist/partials/tsFor.js +24 -0
- package/dist/partials.js +33 -0
- package/dist/partials.min.js +1 -0
- package/dist/test-helpers/circularObject.js +50 -0
- package/dist/test-helpers/countMatches.js +16 -0
- package/dist/test-helpers/deepReferenceObject.js +20 -0
- package/dist/test-helpers/domItem.js +33 -0
- package/dist/test-helpers/jsonDom.js +20 -0
- package/dist/test-helpers/linkedList.js +23 -0
- package/dist/test-helpers/logObject.js +24 -0
- package/dist/test-helpers/multiReferenceObject.js +20 -0
- package/dist/test-helpers/nodeTree.js +28 -0
- package/dist/test-helpers/setUp.js +127 -0
- package/dist/testFull.js +16 -5
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +29 -194
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +18 -7
- package/dist/testQuick.min.js +1 -1
- package/dist/typeScript.js +14 -0
- package/dist/typeScript.min.js +1 -0
- package/dist/watchFull.js +9 -16
- package/dist/watchFull.min.js +1 -1
- package/dist/watchTest.js +11 -9
- package/dist/watchTest.min.js +1 -1
- package/functions/build.js +8 -5
- package/functions/build.test.js +59 -0
- package/functions/bundle.js +6 -4
- package/functions/bundle.test.js +68 -0
- package/functions/bundleLint.js +5 -3
- package/functions/bundleLint.test.js +61 -0
- package/functions/bundleMinify.js +4 -7
- package/functions/bundleMinify.test.js +14 -0
- package/functions/compileReadme.js +3 -2
- package/functions/compileReadme.test.js +18 -0
- package/functions/default.js +5 -2
- package/functions/default.test.js +32 -0
- package/functions/dist.js +3 -1
- package/functions/dist.test.js +43 -0
- package/functions/distLint.js +4 -2
- package/functions/distLint.test.js +58 -0
- package/functions/distMinify.js +4 -7
- package/functions/distMinify.test.js +14 -0
- package/functions/partials/addToReadme.js +20 -0
- package/functions/partials/addToReadme.test.js +28 -0
- package/functions/partials/beginWatcher.js +12 -0
- package/functions/partials/beginWatcher.test.js +18 -0
- package/functions/partials/clean.js +14 -0
- package/functions/partials/clean.test.js +20 -0
- package/functions/partials/distFor.js +18 -0
- package/functions/partials/distFor.test.js +125 -0
- package/functions/partials/distForSrc.js +14 -0
- package/functions/partials/distForSrc.test.js +17 -0
- package/functions/partials/distSeries.js +21 -0
- package/functions/partials/distSeries.test.js +33 -0
- package/functions/partials/minifyFor.js +16 -0
- package/functions/partials/minifyFor.test.js +48 -0
- package/functions/partials/readmeTemplate.js +15 -0
- package/functions/partials/readmeTemplate.test.js +33 -0
- package/functions/partials/runOnChange.js +57 -0
- package/functions/partials/runOnChange.test.js +93 -0
- package/functions/partials/tsFor.js +21 -0
- package/functions/partials/tsFor.test.js +44 -0
- package/functions/partials.js +32 -0
- package/functions/partials.test.js +7 -0
- package/functions/test-helpers/circularObject.js +28 -0
- package/functions/test-helpers/circularObject.test.js +14 -0
- package/functions/test-helpers/countMatches.js +11 -0
- package/functions/test-helpers/countMatches.test.js +9 -0
- package/functions/test-helpers/deepReferenceObject.js +25 -0
- package/functions/test-helpers/deepReferenceObject.test.js +7 -0
- package/functions/test-helpers/domItem.js +31 -0
- package/functions/test-helpers/domItem.test.js +12 -0
- package/functions/test-helpers/jsonDom.js +16 -0
- package/functions/test-helpers/jsonDom.test.js +12 -0
- package/functions/test-helpers/linkedList.js +10 -0
- package/functions/test-helpers/linkedList.test.js +22 -0
- package/functions/test-helpers/logObject.js +18 -0
- package/functions/test-helpers/logObject.test.js +20 -0
- package/functions/test-helpers/multiReferenceObject.js +25 -0
- package/functions/test-helpers/multiReferenceObject.test.js +14 -0
- package/functions/test-helpers/nodeTree.js +11 -0
- package/functions/test-helpers/nodeTree.test.js +18 -0
- package/functions/test-helpers/setUp.js +67 -0
- package/functions/test-helpers/setUp.test.js +18 -0
- package/functions/testFull.js +13 -3
- package/functions/testFull.test.js +16 -0
- package/functions/testHelpers.js +27 -137
- package/functions/testHelpers.test.js +3 -96
- package/functions/testQuick.js +12 -2
- package/functions/testQuick.test.js +16 -0
- package/functions/typeScript.js +11 -0
- package/functions/typeScript.test.js +10 -0
- package/functions/watchFull.js +6 -12
- package/functions/watchFull.test.js +40 -0
- package/functions/watchTest.js +4 -2
- package/functions/watchTest.test.js +48 -0
- package/gulp.config.js +161 -16
- package/gulpfile.base.js +9 -0
- package/package.json +1 -1
- package/dist/addToReadme.js +0 -22
- package/dist/addToReadme.min.js +0 -1
- package/dist/clean.js +0 -11
- package/dist/clean.min.js +0 -1
- package/dist/distFor.js +0 -21
- package/dist/distFor.min.js +0 -1
- package/dist/readmeTemplate.js +0 -15
- package/dist/readmeTemplate.min.js +0 -1
- package/functions/addToReadme.js +0 -17
- package/functions/clean.js +0 -10
- package/functions/distFor.js +0 -15
- package/functions/readmeTemplate.js +0 -13
package/functions/distMinify.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
const { dest, src } = require('gulp')
|
|
2
1
|
const gulpConfig = require('../gulp.config.js')
|
|
3
|
-
const
|
|
4
|
-
const rename = require('gulp-rename')
|
|
2
|
+
const minifyFor = require('./partials/minifyFor')
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Creates minified versions of the dist files.
|
|
6
|
+
* @function
|
|
7
|
+
* @memberOf module:js-build-tools
|
|
8
8
|
* @returns {*}
|
|
9
9
|
*/
|
|
10
|
-
const distMinify = () =>
|
|
11
|
-
.pipe(uglify())
|
|
12
|
-
.pipe(rename({ extname: '.min.js' }))
|
|
13
|
-
.pipe(dest(gulpConfig.distPath))
|
|
10
|
+
const distMinify = () => minifyFor(gulpConfig.get('distSearch'), gulpConfig.get('distPath'))
|
|
14
11
|
|
|
15
12
|
module.exports = distMinify
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { setUp } = require('./testHelpers')
|
|
2
|
+
const gulpConfig = setUp.gulpConfig
|
|
3
|
+
const distMinify = require('./distMinify')
|
|
4
|
+
const minifyFor = require('./partials/minifyFor')
|
|
5
|
+
|
|
6
|
+
jest.mock('./partials/minifyFor', () => jest.fn(() => Promise.resolve(true)))
|
|
7
|
+
|
|
8
|
+
describe('distMinify', () => {
|
|
9
|
+
test('calls minifyFor with configurations', () => {
|
|
10
|
+
expect.assertions(1)
|
|
11
|
+
distMinify()
|
|
12
|
+
expect(minifyFor).toHaveBeenCalledWith(gulpConfig.get('distSearch'), gulpConfig.get('distPath'))
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
3
|
+
const jsdoc2md = require('jsdoc-to-markdown')
|
|
4
|
+
const { globSync } = require('glob')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
|
|
8
|
+
* @function
|
|
9
|
+
* @memberOf module:partials
|
|
10
|
+
* @param {function|null} [done=null]
|
|
11
|
+
* @returns {string|Uint8Array}
|
|
12
|
+
*/
|
|
13
|
+
const addToReadme = (done = null) => {
|
|
14
|
+
const files = globSync(gulpConfig.get('readmeSearch'))
|
|
15
|
+
const readme = jsdoc2md.renderSync({ files: files })
|
|
16
|
+
fs.appendFileSync(gulpConfig.get('readmePath') + gulpConfig.get('readmeFile'), readme, gulpConfig.get('readmeOptions'))
|
|
17
|
+
return done && done()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = addToReadme
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-add-to-readme')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
gulpConfig.set('srcSearch', 'test-temp/src/addToReadme.js')
|
|
6
|
+
const addToReadme = require('./addToReadme')
|
|
7
|
+
|
|
8
|
+
const rawContents = 'export function sayHello(name: string) {\n' +
|
|
9
|
+
' return `Hello from ${name}`;\n' +
|
|
10
|
+
'}'
|
|
11
|
+
|
|
12
|
+
beforeEach(() => setUp.beforeEach()
|
|
13
|
+
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/addToReadme.js', rawContents)))
|
|
14
|
+
|
|
15
|
+
afterEach(setUp.afterEach)
|
|
16
|
+
|
|
17
|
+
describe('addToReadme', () => {
|
|
18
|
+
test('generates the documentation', () => {
|
|
19
|
+
const readmeFilePath = gulpConfig.get('readmePath') + gulpConfig.get('readmeFile')
|
|
20
|
+
expect.assertions(2)
|
|
21
|
+
addToReadme(async () => {
|
|
22
|
+
await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
|
|
23
|
+
const readme = await fs.readFileSync(readmeFilePath)
|
|
24
|
+
// At least the documentation will have the addToReadme documentation
|
|
25
|
+
await expect(readme.includes('addToReadme')).toBeTruthy()
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
2
|
+
const { watch } = require('gulp')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a chokidar instance which watches and triggers change when the globed files are modified.
|
|
6
|
+
* @function
|
|
7
|
+
* @memberOf module:partials
|
|
8
|
+
* @returns {FSWatcher}
|
|
9
|
+
*/
|
|
10
|
+
const beginWatcher = () => watch(gulpConfig.get('watchSearch'))
|
|
11
|
+
|
|
12
|
+
module.exports = beginWatcher
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const setUp = require('../test-helpers/setUp')
|
|
2
|
+
setUp.setDefaults('test-begin-watcher')
|
|
3
|
+
const gulpConfig = setUp.gulpConfig
|
|
4
|
+
const beginWatcher = require('./beginWatcher')
|
|
5
|
+
const { EventEmitter } = require('node:events')
|
|
6
|
+
|
|
7
|
+
beforeEach(setUp.beforeEach)
|
|
8
|
+
|
|
9
|
+
afterEach(setUp.afterEach)
|
|
10
|
+
|
|
11
|
+
describe('beginWatcher', () => {
|
|
12
|
+
test('returns instance of EventEmitter / FSWatcher', () => {
|
|
13
|
+
gulpConfig.set('watchSearch', 'test-begin-watcher/*.js')
|
|
14
|
+
const fsWatcher = beginWatcher()
|
|
15
|
+
expect(fsWatcher).toBeInstanceOf(EventEmitter)
|
|
16
|
+
fsWatcher.close()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const del = require('del')
|
|
2
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Deletes all the distribution and browser files (used before create a new build).
|
|
6
|
+
* @function
|
|
7
|
+
* @memberOf module:partials
|
|
8
|
+
* @param {function} [done=null]
|
|
9
|
+
* @param {string[]} [paths=['dist/config/path', 'browser/config/path']]
|
|
10
|
+
* @returns {Promise<string[]> | *}
|
|
11
|
+
*/
|
|
12
|
+
const clean = (done = null, paths = [gulpConfig.get('distPath'), gulpConfig.get('browserPath')]) => del(paths).then(() => done && done())
|
|
13
|
+
|
|
14
|
+
module.exports = clean
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-clean')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const clean = require('./clean')
|
|
6
|
+
|
|
7
|
+
beforeEach(setUp.beforeEach)
|
|
8
|
+
|
|
9
|
+
afterEach(setUp.afterEach)
|
|
10
|
+
|
|
11
|
+
describe('clean', () => {
|
|
12
|
+
test('removes all contents of directories specified', async () => {
|
|
13
|
+
expect.assertions(2)
|
|
14
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
15
|
+
expect(fs.readdirSync(srcPath)).toBeTruthy()
|
|
16
|
+
// Run the clean script to empty the directories
|
|
17
|
+
await clean(null, [srcPath])
|
|
18
|
+
expect(fs.existsSync(srcPath)).toBeFalsy()
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const babel = require('gulp-babel')
|
|
2
|
+
const { dest, src } = require('gulp')
|
|
3
|
+
const distForSrc = require('./distForSrc')
|
|
4
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Build the distribution for a given source pattern.
|
|
8
|
+
* @function
|
|
9
|
+
* @memberOf module:partials
|
|
10
|
+
* @param {string|array} [srcPath='src/config/path/dist/for']
|
|
11
|
+
* @param {string} [destPath='dist/config/path']
|
|
12
|
+
* @returns {*}
|
|
13
|
+
*/
|
|
14
|
+
const distFor = (srcPath = distForSrc(), destPath = gulpConfig.get('distPath')) => src(srcPath)
|
|
15
|
+
.pipe(babel())
|
|
16
|
+
.pipe(dest(destPath))
|
|
17
|
+
|
|
18
|
+
module.exports = distFor
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-dist-for')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const distFor = require('./distFor')
|
|
6
|
+
const { countMatches } = require('../testHelpers')
|
|
7
|
+
const typeScript = require('../typeScript')
|
|
8
|
+
|
|
9
|
+
const rawContents = 'const babel = require(\'gulp-babel\')\n' +
|
|
10
|
+
'const { dest, src } = require(\'gulp\')\n' +
|
|
11
|
+
'const typeScript = require(\'./typeScript\')\n' +
|
|
12
|
+
'const gulpConfig = require(\'../gulp.config.js\')\n' +
|
|
13
|
+
'\n' +
|
|
14
|
+
'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
|
|
15
|
+
'\n' +
|
|
16
|
+
'const defaultSrc = useTsConfig\n' +
|
|
17
|
+
' ? gulpConfig.get(\'distSearch\')\n' +
|
|
18
|
+
' : gulpConfig.get(\'srcSearch\')\n' +
|
|
19
|
+
'\n' +
|
|
20
|
+
'const distFor = (srcPath = defaultSrc, destPath = gulpConfig.get(\'distPath\')) => {\n' +
|
|
21
|
+
' let pipedSrc = src(srcPath)\n' +
|
|
22
|
+
' if (useTsConfig) {\n' +
|
|
23
|
+
' // Add the typescript so we can compile then apply babel to those files\n' +
|
|
24
|
+
' pipedSrc = typeScript(pipedSrc)\n' +
|
|
25
|
+
' }\n' +
|
|
26
|
+
' return pipedSrc\n' +
|
|
27
|
+
' .pipe(babel())\n' +
|
|
28
|
+
' .pipe(dest(destPath))\n' +
|
|
29
|
+
'}\n' +
|
|
30
|
+
'\n' +
|
|
31
|
+
'module.exports = distFor\n'
|
|
32
|
+
|
|
33
|
+
const rawTsContents = '// @ts-ignore\n' +
|
|
34
|
+
'import gulpConfig from \'../gulp.config.js\'\n' +
|
|
35
|
+
'// @ts-ignore\n' +
|
|
36
|
+
'import typeScript from \'./typeScript.js\'\n' +
|
|
37
|
+
'// @ts-ignore\n' +
|
|
38
|
+
'import {dest, src} from \'gulp\'\n' +
|
|
39
|
+
'// @ts-ignore\n' +
|
|
40
|
+
'import babel from \'gulp-babel\'\n' +
|
|
41
|
+
'\n' +
|
|
42
|
+
'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
|
|
43
|
+
'\n' +
|
|
44
|
+
'const defaultSrc: string | Array<any> = useTsConfig\n' +
|
|
45
|
+
' ? gulpConfig.get(\'distSearch\')\n' +
|
|
46
|
+
' : gulpConfig.get(\'srcSearch\')\n' +
|
|
47
|
+
'\n' +
|
|
48
|
+
'// @ts-ignore\n' +
|
|
49
|
+
'const distFor = (srcPath: string | Array<any> = defaultSrc, destPath: string = gulpConfig.get(\'distPath\')): import(\'readable-stream\').Stream => {\n' +
|
|
50
|
+
' let pipedSrc = src(srcPath)\n' +
|
|
51
|
+
' if (useTsConfig) {\n' +
|
|
52
|
+
' // Add the typescript so we can compile then apply babel to those files\n' +
|
|
53
|
+
' pipedSrc = typeScript(pipedSrc)\n' +
|
|
54
|
+
' }\n' +
|
|
55
|
+
' return pipedSrc\n' +
|
|
56
|
+
' .pipe(babel())\n' +
|
|
57
|
+
' .pipe(dest(destPath))\n' +
|
|
58
|
+
'}\n' +
|
|
59
|
+
'\n' +
|
|
60
|
+
'export default distFor\n'
|
|
61
|
+
|
|
62
|
+
beforeEach(setUp.beforeEach)
|
|
63
|
+
|
|
64
|
+
afterEach(setUp.afterEach)
|
|
65
|
+
|
|
66
|
+
describe('distFor', () => {
|
|
67
|
+
test('copies the src directory and babelifies it into the dist directory', done => {
|
|
68
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
69
|
+
const srcFile = `${srcPath}/distFor.js`
|
|
70
|
+
fs.writeFileSync(srcFile, rawContents)
|
|
71
|
+
expect.assertions(7)
|
|
72
|
+
const oldContents = fs.readFileSync(srcFile).toString()
|
|
73
|
+
expect(countMatches(oldContents, 'const ')).toEqual(7)
|
|
74
|
+
const distPath = gulpConfig.get('distPath')
|
|
75
|
+
distFor(srcFile)
|
|
76
|
+
.on('finish', () => {
|
|
77
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
78
|
+
const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
|
|
79
|
+
expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
|
|
80
|
+
// If the below assertion fails it is because 'const' no longer is replaced with 'var'
|
|
81
|
+
// To fix, change `.browserslistrc` set `> 0.24%` to a lower number. For example, last fix changed from `> 0.25%`
|
|
82
|
+
expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
|
|
83
|
+
expect(countMatches(babelifiedContents, 'var ')).toEqual(10)
|
|
84
|
+
expect(countMatches(babelifiedContents, 'function')).toEqual(1)
|
|
85
|
+
expect(countMatches(babelifiedContents, 'arguments')).toEqual(6)
|
|
86
|
+
done()
|
|
87
|
+
})
|
|
88
|
+
.on('error', error => {
|
|
89
|
+
console.error('Encountered error', error)
|
|
90
|
+
done()
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('can process typescript before babel', done => {
|
|
95
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
96
|
+
const srcFile = `${srcPath}/distFor.ts`
|
|
97
|
+
fs.writeFileSync(srcFile, rawTsContents)
|
|
98
|
+
expect.assertions(7)
|
|
99
|
+
const oldContents = fs.readFileSync(srcFile).toString()
|
|
100
|
+
expect(countMatches(oldContents, 'const ')).toEqual(3)
|
|
101
|
+
const distPath = gulpConfig.get('distPath')
|
|
102
|
+
typeScript()
|
|
103
|
+
.on('finish', () => {
|
|
104
|
+
distFor()
|
|
105
|
+
.on('finish', () => {
|
|
106
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
107
|
+
const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
|
|
108
|
+
expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
|
|
109
|
+
expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
|
|
110
|
+
expect(countMatches(babelifiedContents, 'var ')).toEqual(8)
|
|
111
|
+
expect(countMatches(babelifiedContents, 'function')).toEqual(1)
|
|
112
|
+
expect(countMatches(babelifiedContents, 'Object.defineProperty(exports, "__esModule", { value: true })')).toEqual(1)
|
|
113
|
+
done()
|
|
114
|
+
})
|
|
115
|
+
.on('error', error => {
|
|
116
|
+
console.error('Encountered error with distFor', error)
|
|
117
|
+
done()
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
.on('error', error => {
|
|
121
|
+
console.error('Encountered error with typeScript', error)
|
|
122
|
+
done()
|
|
123
|
+
})
|
|
124
|
+
}, 30000)
|
|
125
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const gulpConfig = require('../../gulp.config')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retrieve the correct distFor search path based on TS Config.
|
|
5
|
+
* @function
|
|
6
|
+
* @memberOf module:partials
|
|
7
|
+
* @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
const distForSrc = (useTs = gulpConfig.get('useTsConfig')) => useTs
|
|
11
|
+
? gulpConfig.get('distSearch')
|
|
12
|
+
: gulpConfig.get('srcSearch')
|
|
13
|
+
|
|
14
|
+
module.exports = distForSrc
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const setUp = require('../test-helpers/setUp')
|
|
2
|
+
const gulpConfig = setUp.gulpConfig
|
|
3
|
+
const distForSrc = require('./distForSrc')
|
|
4
|
+
|
|
5
|
+
describe('distForSrc', () => {
|
|
6
|
+
test('useTsConfig as false returns srcSearch', () => {
|
|
7
|
+
expect.assertions(1)
|
|
8
|
+
gulpConfig.set('useTsConfig', false)
|
|
9
|
+
expect(distForSrc()).toBe(gulpConfig.get('srcSearch'))
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('useTsConfig as true returns distSearch', () => {
|
|
13
|
+
expect.assertions(1)
|
|
14
|
+
gulpConfig.set('useTsConfig', true)
|
|
15
|
+
expect(distForSrc()).toBe(gulpConfig.get('distSearch'))
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
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')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* When using TypeScript, ensure that we process the ts first then run babel (dist)
|
|
9
|
+
* @function
|
|
10
|
+
* @memberOf module:partials
|
|
11
|
+
* @param {string} [srcPath='src/config/path/dist/for']
|
|
12
|
+
* @param {string} [distFinalPath='dist/config/path']
|
|
13
|
+
* @param {string} [tsSearch='ts/search/config/path']
|
|
14
|
+
* @returns {Function}
|
|
15
|
+
*/
|
|
16
|
+
const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('distPath'), tsSearch = gulpConfig.get('tsSearch')) =>
|
|
17
|
+
gulpConfig.get('useTsConfig')
|
|
18
|
+
? series(() => tsFor(tsSearch, distFinalPath), () => distFor(srcPath, distFinalPath))
|
|
19
|
+
: () => distFor(srcPath, distFinalPath)
|
|
20
|
+
|
|
21
|
+
module.exports = distSeries
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const setUp = require('../test-helpers/setUp')
|
|
2
|
+
const gulpConfig = setUp.gulpConfig
|
|
3
|
+
const distSeries = require('./distSeries')
|
|
4
|
+
const tsFor = require('./tsFor')
|
|
5
|
+
const distFor = require('./distFor')
|
|
6
|
+
|
|
7
|
+
const genericFunction = () => Promise.resolve(true)
|
|
8
|
+
|
|
9
|
+
jest.mock('./distFor', () => jest.fn(genericFunction))
|
|
10
|
+
jest.mock('./tsFor', () => jest.fn(genericFunction))
|
|
11
|
+
|
|
12
|
+
describe('distSeries', () => {
|
|
13
|
+
test('when not using ts config only returns runnable distFor', done => {
|
|
14
|
+
gulpConfig.set('useTsConfig', false)
|
|
15
|
+
expect.assertions(1)
|
|
16
|
+
distSeries()()
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
expect(distFor).toHaveBeenCalledWith(gulpConfig.get('srcSearch'), gulpConfig.get('distPath'))
|
|
19
|
+
done()
|
|
20
|
+
}, 500)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('when using ts config returns runnable series of tsFor and distFor', done => {
|
|
24
|
+
gulpConfig.set('useTsConfig', true)
|
|
25
|
+
expect.assertions(2)
|
|
26
|
+
distSeries()()
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
expect(tsFor).toHaveBeenCalledWith(gulpConfig.get('tsSearch'), gulpConfig.get('distPath'))
|
|
29
|
+
expect(distFor).toHaveBeenCalledWith(gulpConfig.get('distSearch'), gulpConfig.get('distPath'))
|
|
30
|
+
done()
|
|
31
|
+
}, 500)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { dest, src } = require('gulp')
|
|
2
|
+
const { default: uglify } = require('gulp-uglify-es')
|
|
3
|
+
const rename = require('gulp-rename')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Minify files and rename the output with '.min' extension.
|
|
7
|
+
* @function
|
|
8
|
+
* @memberOf module:partials
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
const minifyFor = (srcSearch, destination) => src(srcSearch)
|
|
12
|
+
.pipe(uglify())
|
|
13
|
+
.pipe(rename({ extname: '.min.js' }))
|
|
14
|
+
.pipe(dest(destination))
|
|
15
|
+
|
|
16
|
+
module.exports = minifyFor
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-minify-for')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const minifyFor = require('./minifyFor')
|
|
6
|
+
const { countMatches } = require('../testHelpers')
|
|
7
|
+
|
|
8
|
+
const rawContents = 'const { dest, src } = require(\'gulp\')\n' +
|
|
9
|
+
'const { default: uglify } = require(\'gulp-uglify-es\')\n' +
|
|
10
|
+
'const rename = require(\'gulp-rename\')\n' +
|
|
11
|
+
'\n' +
|
|
12
|
+
'/**\n' +
|
|
13
|
+
' * Minify files and rename the output with \'.min\' extension.\n' +
|
|
14
|
+
' * @returns {*}\n' +
|
|
15
|
+
' */\n' +
|
|
16
|
+
'const minifyFor = (srcSearch, destination) => src(srcSearch)\n' +
|
|
17
|
+
' .pipe(uglify())\n' +
|
|
18
|
+
' .pipe(rename({ extname: \'.min.js\' }))\n' +
|
|
19
|
+
' .pipe(dest(destination))\n' +
|
|
20
|
+
'\n' +
|
|
21
|
+
'module.exports = minifyFor\n'
|
|
22
|
+
|
|
23
|
+
beforeEach(() => setUp.beforeEach()
|
|
24
|
+
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/minifyFor.js', rawContents)))
|
|
25
|
+
|
|
26
|
+
afterEach(setUp.afterEach)
|
|
27
|
+
|
|
28
|
+
describe('minifyFor', () => {
|
|
29
|
+
test('copies the src directory and minifies it into the dist directory with min extension', done => {
|
|
30
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
31
|
+
const filePath = `${srcPath}/minifyFor.js`
|
|
32
|
+
const expectedFilePath = `${srcPath}/minifyFor.min.js`
|
|
33
|
+
expect.assertions(3)
|
|
34
|
+
const oldContents = fs.readFileSync(filePath).toString()
|
|
35
|
+
expect(countMatches(oldContents, '\n')).toBe(14)
|
|
36
|
+
minifyFor(filePath, srcPath)
|
|
37
|
+
.on('finish', () => {
|
|
38
|
+
expect(fs.existsSync(expectedFilePath)).toBeTruthy()
|
|
39
|
+
const minifiedContents = fs.readFileSync(expectedFilePath).toString()
|
|
40
|
+
expect(countMatches(minifiedContents, '\n')).toBe(0)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
.on('error', error => {
|
|
44
|
+
console.error('Encountered error', error)
|
|
45
|
+
done()
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { dest, src } = require('gulp')
|
|
2
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
3
|
+
const rename = require('gulp-rename')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copy a readme template into the README.md file.
|
|
7
|
+
* @function
|
|
8
|
+
* @memberOf module:partials
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
const readmeTemplate = () => src(gulpConfig.get('readmeTemplate'))
|
|
12
|
+
.pipe(rename(gulpConfig.get('readmeFile')))
|
|
13
|
+
.pipe(dest(gulpConfig.get('readmePath')))
|
|
14
|
+
|
|
15
|
+
module.exports = readmeTemplate
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-readme-template')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const readmeTemplate = require('./readmeTemplate')
|
|
6
|
+
|
|
7
|
+
const mainMd = 'MAIN.md'
|
|
8
|
+
const mainTestPath = gulpConfig.get('readmeTemplate')
|
|
9
|
+
|
|
10
|
+
beforeEach(() => setUp.beforeEach()
|
|
11
|
+
.then(() => fs.copyFileSync(mainMd, mainTestPath)))
|
|
12
|
+
|
|
13
|
+
afterEach(setUp.afterEach)
|
|
14
|
+
|
|
15
|
+
describe('readmeTemplate', () => {
|
|
16
|
+
test('copies the main contents into the new README.md', done => {
|
|
17
|
+
const readmeFilePath = gulpConfig.get('readmePath') + gulpConfig.get('readmeFile')
|
|
18
|
+
const mainContents = fs.readFileSync(mainTestPath)
|
|
19
|
+
expect.assertions(2)
|
|
20
|
+
readmeTemplate()
|
|
21
|
+
.on('finish', async () => {
|
|
22
|
+
await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
|
|
23
|
+
const readme = await fs.readFileSync(readmeFilePath)
|
|
24
|
+
// Confirm that the contents for MAIN.md are copied to README.md
|
|
25
|
+
await expect(readme).toEqual(mainContents)
|
|
26
|
+
done()
|
|
27
|
+
})
|
|
28
|
+
.on('error', error => {
|
|
29
|
+
console.error('Encountered error', error)
|
|
30
|
+
done()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
2
|
+
const bundle = require('../bundle')
|
|
3
|
+
const distSeries = require('./distSeries')
|
|
4
|
+
const { parallel, series } = require('gulp')
|
|
5
|
+
const testQuick = require('../testQuick')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Run this function when the watched files are modified.
|
|
9
|
+
* 1. Find the sub-folders within src path
|
|
10
|
+
* 2. Maintain the folders, but use distPath for base
|
|
11
|
+
* 3. Remove base folder and return dist path with correct sub-folders
|
|
12
|
+
* @example
|
|
13
|
+
* // Configured paths
|
|
14
|
+
* distPath = 'dist'
|
|
15
|
+
* srcPath = 'functions'
|
|
16
|
+
*
|
|
17
|
+
* // Path parameter
|
|
18
|
+
* path = 'functions/some/path/file.js'
|
|
19
|
+
*
|
|
20
|
+
* // Generated regex using configured srcPath
|
|
21
|
+
* pathRegex = '/^functions(.*\/).+\.js$/i'
|
|
22
|
+
*
|
|
23
|
+
* // Replace value using the configured distPath
|
|
24
|
+
* replacePath = 'dist$1'
|
|
25
|
+
*
|
|
26
|
+
* // The resulting replaced path for the destination folder
|
|
27
|
+
* distPathResult = 'dist/some/path/'
|
|
28
|
+
* @function
|
|
29
|
+
* @memberOf module:partials
|
|
30
|
+
* @param {string} path
|
|
31
|
+
* @returns {stream.Stream}
|
|
32
|
+
*/
|
|
33
|
+
const runOnChange = path => {
|
|
34
|
+
const useTs = gulpConfig.get('useTsConfig')
|
|
35
|
+
const distPath = gulpConfig.get('distPath')
|
|
36
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
37
|
+
/**
|
|
38
|
+
* 1. The original path comes in from src and is a .ts
|
|
39
|
+
* 2. Discover the outgoing dist path where that file should go
|
|
40
|
+
* 3. Use the path and dist in tsFor
|
|
41
|
+
* 4. Take the original path, convert to full file path in dist
|
|
42
|
+
* 5. Use the dist path found previously in #2
|
|
43
|
+
* 6. Use the full dist path and the dist outgoing path in distFor
|
|
44
|
+
*/
|
|
45
|
+
const pathRegex = new RegExp(`^${srcPath}(.*\\/)(.+)\\.(js|ts)$`, 'i')
|
|
46
|
+
const distPathResult = path.replace(pathRegex, `${distPath}$1`)
|
|
47
|
+
let distSrcPath = path
|
|
48
|
+
if (useTs) {
|
|
49
|
+
distSrcPath = path.replace(pathRegex, `${distPath}$1$2.js`)
|
|
50
|
+
}
|
|
51
|
+
const runSeries = distSeries(distSrcPath, distPathResult, path)
|
|
52
|
+
return gulpConfig.get('nodeOnly')
|
|
53
|
+
? series(testQuick, runSeries)()
|
|
54
|
+
: parallel(testQuick, series(runSeries, bundle))()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = runOnChange
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('../test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-run-on-change')
|
|
4
|
+
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const bundle = require('../bundle')
|
|
6
|
+
const distFor = require('./distFor')
|
|
7
|
+
const runOnChange = require('./runOnChange')
|
|
8
|
+
const tsFor = require('./tsFor')
|
|
9
|
+
const testQuick = require('../testQuick')
|
|
10
|
+
|
|
11
|
+
const genericFunction = () => Promise.resolve(true)
|
|
12
|
+
|
|
13
|
+
jest.mock('../bundle', () => jest.fn(genericFunction))
|
|
14
|
+
jest.mock('./distFor', () => jest.fn(genericFunction))
|
|
15
|
+
jest.mock('./tsFor', () => jest.fn(genericFunction))
|
|
16
|
+
jest.mock('../testQuick', () => jest.fn(genericFunction))
|
|
17
|
+
|
|
18
|
+
const rawContents = 'export function sayHello(name: string) {\n' +
|
|
19
|
+
' return `Hello from ${name}`;\n' +
|
|
20
|
+
'}'
|
|
21
|
+
|
|
22
|
+
const distPath = gulpConfig.get('distPath') + '/'
|
|
23
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
24
|
+
const srcFile = `${srcPath}/runOnChange.js`
|
|
25
|
+
const srcTsFile = `${srcPath}/runOnChange.ts`
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
return setUp.beforeEach()
|
|
29
|
+
.then(() => fs.writeFileSync(srcTsFile, rawContents))
|
|
30
|
+
.then(() => fs.writeFileSync(srcFile, rawContents))
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.clearAllMocks()
|
|
36
|
+
return setUp.afterEach()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe('runOnChange', () => {
|
|
40
|
+
test('runs testQuick and distFor for nodeOnly true and useTs false', done => {
|
|
41
|
+
gulpConfig.set('nodeOnly', true)
|
|
42
|
+
gulpConfig.set('useTsConfig', false)
|
|
43
|
+
expect.assertions(2)
|
|
44
|
+
runOnChange(srcFile)
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
expect(testQuick).toHaveBeenCalled()
|
|
47
|
+
expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
|
|
48
|
+
done()
|
|
49
|
+
}, 500)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('runs testQuick and distFor for nodeOnly true and tsFor for useTs true', done => {
|
|
53
|
+
gulpConfig.set('nodeOnly', true)
|
|
54
|
+
gulpConfig.set('useTsConfig', true)
|
|
55
|
+
const distSrcPath = distPath + 'runOnChange.js'
|
|
56
|
+
expect.assertions(3)
|
|
57
|
+
runOnChange(srcTsFile)
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
expect(testQuick).toHaveBeenCalled()
|
|
60
|
+
expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
|
|
61
|
+
expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
|
|
62
|
+
done()
|
|
63
|
+
}, 500)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('runs testQuick and distFor then bundle for nodeOnly false and useTs false', done => {
|
|
67
|
+
gulpConfig.set('nodeOnly', false)
|
|
68
|
+
gulpConfig.set('useTsConfig', false)
|
|
69
|
+
expect.assertions(3)
|
|
70
|
+
runOnChange(srcFile)
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
expect(testQuick).toHaveBeenCalled()
|
|
73
|
+
expect(distFor).toHaveBeenCalledWith(srcFile, distPath)
|
|
74
|
+
expect(bundle).toHaveBeenCalled()
|
|
75
|
+
done()
|
|
76
|
+
}, 500)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('runs testQuick and distFor then bundle for nodeOnly false and tsFor for useTs true', done => {
|
|
80
|
+
gulpConfig.set('nodeOnly', false)
|
|
81
|
+
gulpConfig.set('useTsConfig', true)
|
|
82
|
+
const distSrcPath = distPath + 'runOnChange.js'
|
|
83
|
+
expect.assertions(4)
|
|
84
|
+
runOnChange(srcTsFile)
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
expect(testQuick).toHaveBeenCalled()
|
|
87
|
+
expect(tsFor).toHaveBeenCalledWith(srcTsFile, distPath)
|
|
88
|
+
expect(distFor).toHaveBeenCalledWith(distSrcPath, distPath)
|
|
89
|
+
expect(bundle).toHaveBeenCalled()
|
|
90
|
+
done()
|
|
91
|
+
}, 500)
|
|
92
|
+
})
|
|
93
|
+
})
|