js-build-tools 6.5.0 → 6.7.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/LICENSE +674 -674
- package/README.md +762 -692
- package/babel.config.js +28 -28
- package/dist/build.js +75 -75
- package/dist/bundle.js +19 -19
- package/dist/bundleMinify.js +7 -7
- package/dist/compileReadme.js +4 -4
- package/dist/copyFiles.js +17 -17
- package/dist/copyFonts.js +4 -4
- package/dist/default.js +5 -5
- package/dist/dist.js +4 -4
- package/dist/distMinify.js +4 -4
- package/dist/docs.js +7 -7
- package/dist/images.js +4 -4
- package/dist/jsdocDocs.js +6 -6
- package/dist/lint.js +16 -16
- package/dist/partials/addToReadme.js +9 -9
- package/dist/partials/beginWatcher.js +4 -4
- package/dist/partials/clean.js +5 -5
- package/dist/partials/copyFor.js +9 -9
- package/dist/partials/distFor.js +6 -6
- package/dist/partials/distForSrc.js +5 -5
- package/dist/partials/distSeries.js +7 -7
- package/dist/partials/imagesFor.js +93 -56
- package/dist/partials/jsdocDocsFor.js +46 -46
- package/dist/partials/lintSource.js +51 -51
- package/dist/partials/loadPeer.js +99 -99
- package/dist/partials/loadPlaywright.js +14 -14
- package/dist/partials/minifyFor.js +20 -20
- package/dist/partials/neostandardLint.js +175 -175
- package/dist/partials/readmeTemplate.js +4 -4
- package/dist/partials/removeDirectory.js +11 -11
- package/dist/partials/resolveDocsMethod.js +6 -6
- package/dist/partials/runOnChange.js +31 -31
- package/dist/partials/sassFor.js +6 -6
- package/dist/partials/serveStatic.js +9 -9
- package/dist/partials/tsFor.js +32 -32
- package/dist/partials/typeDocsFor.js +57 -51
- package/dist/partials.js +176 -176
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/isolateGulpCache.js +24 -24
- package/dist/test-helpers/setUp.js +4 -4
- package/dist/testFull.js +5 -5
- package/dist/testQuick.js +5 -5
- package/dist/typeDocs.js +5 -5
- package/dist/typeScript.js +4 -4
- package/dist/utilities/convertMjsFilesForDocs.js +12 -12
- package/dist/utilities/dotGet.js +54 -54
- package/dist/utilities/dotNotate.js +79 -79
- package/dist/utilities/dotSet.js +45 -45
- package/dist/utilities/esmNamedExportsToCjs.js +15 -15
- package/dist/utilities/getBundleConfigs.js +9 -9
- package/dist/utilities/isObject.js +6 -6
- package/dist/utilities/strAfter.js +7 -7
- package/dist/utilities/strBefore.js +7 -7
- package/dist/watchFull.js +4 -4
- package/dist/watchTest.js +4 -4
- package/functions/build.mjs +72 -72
- package/functions/build.test.mjs +763 -759
- package/functions/bundle.mjs +44 -44
- package/functions/bundle.test.mjs +219 -219
- package/functions/bundleMinify.mjs +16 -16
- package/functions/bundleMinify.test.mjs +37 -37
- package/functions/compileReadme.mjs +9 -9
- package/functions/compileReadme.test.mjs +18 -18
- package/functions/copyFiles.mjs +32 -32
- package/functions/copyFiles.test.mjs +78 -78
- package/functions/copyFonts.mjs +9 -9
- package/functions/copyFonts.test.mjs +32 -32
- package/functions/default.mjs +12 -12
- package/functions/default.test.mjs +33 -33
- package/functions/dist.mjs +8 -8
- package/functions/dist.test.mjs +44 -44
- package/functions/distMinify.mjs +9 -9
- package/functions/distMinify.test.mjs +15 -15
- package/functions/docs.mjs +13 -13
- package/functions/docs.test.mjs +45 -45
- package/functions/gulpConfigEntries.test.mjs +23 -23
- package/functions/images.mjs +8 -8
- package/functions/images.test.mjs +142 -142
- package/functions/jsdocDocs.mjs +10 -10
- package/functions/jsdocEsmExports.test.mjs +24 -24
- package/functions/lint.mjs +9 -9
- package/functions/partials/addToReadme.mjs +25 -25
- package/functions/partials/addToReadme.test.mjs +34 -34
- package/functions/partials/beginWatcher.mjs +9 -9
- package/functions/partials/beginWatcher.test.mjs +19 -19
- package/functions/partials/clean.mjs +13 -13
- package/functions/partials/clean.test.mjs +22 -22
- package/functions/partials/copyFor.mjs +15 -15
- package/functions/partials/copyFor.test.mjs +53 -53
- package/functions/partials/distFor.mjs +22 -22
- package/functions/partials/distFor.test.mjs +195 -195
- package/functions/partials/distForSrc.mjs +11 -11
- package/functions/partials/distForSrc.test.mjs +18 -18
- package/functions/partials/distSeries.mjs +21 -21
- package/functions/partials/distSeries.test.mjs +34 -34
- package/functions/partials/imagesFor.mjs +83 -50
- package/functions/partials/imagesFor.test.mjs +287 -229
- package/functions/partials/jsdocDocsFor.mjs +163 -152
- package/functions/partials/jsdocDocsFor.test.mjs +182 -152
- package/functions/partials/lintSource.mjs +41 -41
- package/functions/partials/loadPeer.mjs +76 -76
- package/functions/partials/loadPeer.test.mjs +58 -58
- package/functions/partials/loadPlaywright.mjs +23 -23
- package/functions/partials/loadPlaywright.test.mjs +70 -70
- package/functions/partials/minifyFor.mjs +15 -15
- package/functions/partials/minifyFor.test.mjs +49 -49
- package/functions/partials/neostandardLint.mjs +142 -142
- package/functions/partials/neostandardLint.test.mjs +131 -131
- package/functions/partials/readmeTemplate.mjs +12 -12
- package/functions/partials/readmeTemplate.test.mjs +34 -34
- package/functions/partials/removeDirectory.mjs +34 -34
- package/functions/partials/removeDirectory.test.mjs +72 -72
- package/functions/partials/resolveDocsMethod.mjs +10 -10
- package/functions/partials/resolveDocsMethod.test.mjs +33 -33
- package/functions/partials/runOnChange.mjs +54 -54
- package/functions/partials/runOnChange.test.mjs +95 -95
- package/functions/partials/sassFor.mjs +25 -25
- package/functions/partials/sassFor.test.mjs +81 -81
- package/functions/partials/serveStatic.mjs +47 -47
- package/functions/partials/serveStatic.test.mjs +71 -71
- package/functions/partials/tsFor.mjs +92 -92
- package/functions/partials/tsFor.test.mjs +88 -88
- package/functions/partials/typeDocsFor.mjs +231 -227
- package/functions/partials/typeDocsFor.test.mjs +263 -252
- package/functions/partials.mjs +31 -31
- package/functions/partials.test.mjs +7 -7
- package/functions/sass.mjs +4 -4
- package/functions/sass.test.mjs +31 -31
- package/functions/sourceLint.mjs +13 -13
- package/functions/sourceLint.test.mjs +166 -166
- package/functions/test-helpers/isolateGulpCache.mjs +16 -16
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +100 -100
- package/functions/test-helpers/setUp.test.mjs +19 -19
- package/functions/testFull.mjs +17 -17
- package/functions/testFull.test.mjs +17 -17
- package/functions/testHelpers.mjs +10 -10
- package/functions/testHelpers.test.mjs +7 -7
- package/functions/testQuick.mjs +17 -17
- package/functions/testQuick.test.mjs +17 -17
- package/functions/typeDocs.mjs +9 -9
- package/functions/typeDocs.test.mjs +11 -11
- package/functions/typeScript.mjs +8 -8
- package/functions/typeScript.test.mjs +11 -11
- package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
- package/functions/utilities/dotGet.mjs +49 -49
- package/functions/utilities/dotNotate.mjs +73 -73
- package/functions/utilities/dotNotate.test.mjs +41 -41
- package/functions/utilities/dotSet.mjs +40 -40
- package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
- package/functions/utilities/getBundleConfigs.mjs +30 -30
- package/functions/utilities/isObject.mjs +8 -8
- package/functions/utilities/strAfter.mjs +12 -12
- package/functions/utilities/strBefore.mjs +12 -12
- package/functions/watchFull.mjs +9 -9
- package/functions/watchFull.test.mjs +41 -41
- package/functions/watchTest.mjs +10 -10
- package/functions/watchTest.test.mjs +49 -49
- package/gulp.config.js +4 -4
- package/gulp.config.mjs +344 -327
- package/gulpfile.base.js +51 -51
- package/gulpfile.base.mjs +29 -29
- package/jsdoc.base.js +16 -16
- package/jsdoc.esmExports.js +17 -17
- package/package.json +146 -145
|
@@ -1,9 +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
|
+
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,18 +1,18 @@
|
|
|
1
|
-
import { compileReadme } from './compileReadme.mjs'
|
|
2
|
-
import { addToReadme, readmeTemplate } from './partials.mjs'
|
|
3
|
-
|
|
4
|
-
const genericFunction = () => Promise.resolve(true)
|
|
5
|
-
jest.mock('./partials/addToReadme.mjs', () => ({ addToReadme: jest.fn(genericFunction) }))
|
|
6
|
-
jest.mock('./partials/readmeTemplate.mjs', () => ({ readmeTemplate: jest.fn(genericFunction) }))
|
|
7
|
-
|
|
8
|
-
describe('compileReadme', () => {
|
|
9
|
-
test('calls readmeTemplate and addToReadme', done => {
|
|
10
|
-
expect.assertions(2)
|
|
11
|
-
compileReadme()
|
|
12
|
-
setTimeout(() => {
|
|
13
|
-
expect(readmeTemplate).toHaveBeenCalled()
|
|
14
|
-
expect(addToReadme).toHaveBeenCalled()
|
|
15
|
-
done()
|
|
16
|
-
}, 500)
|
|
17
|
-
})
|
|
18
|
-
})
|
|
1
|
+
import { compileReadme } from './compileReadme.mjs'
|
|
2
|
+
import { addToReadme, readmeTemplate } from './partials.mjs'
|
|
3
|
+
|
|
4
|
+
const genericFunction = () => Promise.resolve(true)
|
|
5
|
+
jest.mock('./partials/addToReadme.mjs', () => ({ addToReadme: jest.fn(genericFunction) }))
|
|
6
|
+
jest.mock('./partials/readmeTemplate.mjs', () => ({ readmeTemplate: jest.fn(genericFunction) }))
|
|
7
|
+
|
|
8
|
+
describe('compileReadme', () => {
|
|
9
|
+
test('calls readmeTemplate and addToReadme', done => {
|
|
10
|
+
expect.assertions(2)
|
|
11
|
+
compileReadme()
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
expect(readmeTemplate).toHaveBeenCalled()
|
|
14
|
+
expect(addToReadme).toHaveBeenCalled()
|
|
15
|
+
done()
|
|
16
|
+
}, 500)
|
|
17
|
+
})
|
|
18
|
+
})
|
package/functions/copyFiles.mjs
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { copyFor } from './partials/copyFor.mjs'
|
|
2
|
-
import * as gulpConfig from '../gulp.config.mjs'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Copy files from one place to another - any number of { from, to, base? } entries, configured via copyFiles.
|
|
6
|
-
* A project with no copyFiles entries gets a task that does nothing. Meant to be run explicitly (its own script,
|
|
7
|
-
* e.g. `gulp copyFiles`), not folded into the default build - a bundle (or any other file this copies) is often
|
|
8
|
-
* the live, publicly-reachable version of something, so publishing it elsewhere should be a deliberate step, not
|
|
9
|
-
* a side effect of every routine local build.
|
|
10
|
-
*
|
|
11
|
-
* Reuses copyFor (already shared with copyFonts) rather than a fresh src()/dest() pair - that keeps its existing
|
|
12
|
-
* encoding: false fix (Gulp 5's default utf8 handling corrupts binary files such as fonts or a minified bundle)
|
|
13
|
-
* instead of silently losing it in a parallel implementation.
|
|
14
|
-
*
|
|
15
|
-
* Each entry runs as its own independent copyFor(), awaited via Promise.all rather than merged into one combined
|
|
16
|
-
* stream (mergeStream, the pattern bundle.mjs uses) - that pattern assumes every merged stream ends up at the
|
|
17
|
-
* same shared destination; here, each entry can have a genuinely different one, and merging streams that each
|
|
18
|
-
* already terminate at their own separate dest() hit a real "write after end" error in practice.
|
|
19
|
-
* @memberOf module:js-build-tools
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
*/
|
|
22
|
-
export const copyFiles = () => {
|
|
23
|
-
const copies = gulpConfig.get('copyFiles', [])
|
|
24
|
-
if (!copies.length) {
|
|
25
|
-
return Promise.resolve()
|
|
26
|
-
}
|
|
27
|
-
return Promise.all(copies.map(({ from, to, base }) => new Promise((resolve, reject) => {
|
|
28
|
-
copyFor(from, to, { base })
|
|
29
|
-
.on('finish', resolve)
|
|
30
|
-
.on('error', reject)
|
|
31
|
-
}))).then(() => {})
|
|
32
|
-
}
|
|
1
|
+
import { copyFor } from './partials/copyFor.mjs'
|
|
2
|
+
import * as gulpConfig from '../gulp.config.mjs'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copy files from one place to another - any number of { from, to, base? } entries, configured via copyFiles.
|
|
6
|
+
* A project with no copyFiles entries gets a task that does nothing. Meant to be run explicitly (its own script,
|
|
7
|
+
* e.g. `gulp copyFiles`), not folded into the default build - a bundle (or any other file this copies) is often
|
|
8
|
+
* the live, publicly-reachable version of something, so publishing it elsewhere should be a deliberate step, not
|
|
9
|
+
* a side effect of every routine local build.
|
|
10
|
+
*
|
|
11
|
+
* Reuses copyFor (already shared with copyFonts) rather than a fresh src()/dest() pair - that keeps its existing
|
|
12
|
+
* encoding: false fix (Gulp 5's default utf8 handling corrupts binary files such as fonts or a minified bundle)
|
|
13
|
+
* instead of silently losing it in a parallel implementation.
|
|
14
|
+
*
|
|
15
|
+
* Each entry runs as its own independent copyFor(), awaited via Promise.all rather than merged into one combined
|
|
16
|
+
* stream (mergeStream, the pattern bundle.mjs uses) - that pattern assumes every merged stream ends up at the
|
|
17
|
+
* same shared destination; here, each entry can have a genuinely different one, and merging streams that each
|
|
18
|
+
* already terminate at their own separate dest() hit a real "write after end" error in practice.
|
|
19
|
+
* @memberOf module:js-build-tools
|
|
20
|
+
* @returns {Promise<void>}
|
|
21
|
+
*/
|
|
22
|
+
export const copyFiles = () => {
|
|
23
|
+
const copies = gulpConfig.get('copyFiles', [])
|
|
24
|
+
if (!copies.length) {
|
|
25
|
+
return Promise.resolve()
|
|
26
|
+
}
|
|
27
|
+
return Promise.all(copies.map(({ from, to, base }) => new Promise((resolve, reject) => {
|
|
28
|
+
copyFor(from, to, { base })
|
|
29
|
+
.on('finish', resolve)
|
|
30
|
+
.on('error', reject)
|
|
31
|
+
}))).then(() => {})
|
|
32
|
+
}
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
-
import { copyFiles } from './copyFiles.mjs'
|
|
4
|
-
|
|
5
|
-
setUp.setDefaults('test-copy-files')
|
|
6
|
-
const gulpConfig = setUp.gulpConfig
|
|
7
|
-
|
|
8
|
-
beforeEach(() => setUp.beforeEach())
|
|
9
|
-
afterEach(() => {
|
|
10
|
-
gulpConfig.set('copyFiles', [])
|
|
11
|
-
return setUp.afterEach()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('copyFiles', () => {
|
|
15
|
-
test('with no entries configured, does nothing and resolves', async () => {
|
|
16
|
-
await expect(copyFiles()).resolves.toBeUndefined()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('copies a file from one place to another', async () => {
|
|
20
|
-
const sourceDir = `${gulpConfig.get('rootPath')}copy-source`
|
|
21
|
-
const destDir = `${gulpConfig.get('rootPath')}copy-dest`
|
|
22
|
-
fs.mkdirSync(sourceDir, { recursive: true })
|
|
23
|
-
fs.writeFileSync(`${sourceDir}/one.txt`, 'one file\n')
|
|
24
|
-
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/*.txt`, to: destDir }])
|
|
25
|
-
|
|
26
|
-
await copyFiles()
|
|
27
|
-
|
|
28
|
-
expect(fs.readFileSync(`${destDir}/one.txt`).toString()).toBe('one file\n')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test('copies several configured entries, each to its own destination', async () => {
|
|
32
|
-
const sourceDirA = `${gulpConfig.get('rootPath')}copy-source-a`
|
|
33
|
-
const sourceDirB = `${gulpConfig.get('rootPath')}copy-source-b`
|
|
34
|
-
const destDirA = `${gulpConfig.get('rootPath')}copy-dest-a`
|
|
35
|
-
const destDirB = `${gulpConfig.get('rootPath')}copy-dest-b`
|
|
36
|
-
fs.mkdirSync(sourceDirA, { recursive: true })
|
|
37
|
-
fs.mkdirSync(sourceDirB, { recursive: true })
|
|
38
|
-
fs.writeFileSync(`${sourceDirA}/a.txt`, 'from a\n')
|
|
39
|
-
fs.writeFileSync(`${sourceDirB}/b.txt`, 'from b\n')
|
|
40
|
-
gulpConfig.set('copyFiles', [
|
|
41
|
-
{ from: `${sourceDirA}/*.txt`, to: destDirA },
|
|
42
|
-
{ from: `${sourceDirB}/*.txt`, to: destDirB }
|
|
43
|
-
])
|
|
44
|
-
|
|
45
|
-
await copyFiles()
|
|
46
|
-
|
|
47
|
-
expect(fs.readFileSync(`${destDirA}/a.txt`).toString()).toBe('from a\n')
|
|
48
|
-
expect(fs.readFileSync(`${destDirB}/b.txt`).toString()).toBe('from b\n')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('base preserves the glob\'s own subdirectory structure in the destination', async () => {
|
|
52
|
-
const sourceDir = `${gulpConfig.get('rootPath')}copy-source-nested`
|
|
53
|
-
const destDir = `${gulpConfig.get('rootPath')}copy-dest-nested`
|
|
54
|
-
fs.mkdirSync(`${sourceDir}/inner`, { recursive: true })
|
|
55
|
-
fs.writeFileSync(`${sourceDir}/inner/deep.txt`, 'nested file\n')
|
|
56
|
-
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/**/*.txt`, to: destDir, base: sourceDir }])
|
|
57
|
-
|
|
58
|
-
await copyFiles()
|
|
59
|
-
|
|
60
|
-
expect(fs.readFileSync(`${destDir}/inner/deep.txt`).toString()).toBe('nested file\n')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
// The real bug this guards against: a fresh src()/dest() pair (what this used to do) loses copyFor.mjs's own
|
|
64
|
-
// encoding: false fix - Gulp 5's default utf8 handling corrupts binary files such as fonts or a minified
|
|
65
|
-
// bundle. Reusing copyFor instead of duplicating its logic keeps that fix automatically.
|
|
66
|
-
test('copies binary files byte for byte, including bytes above 0x7f', async () => {
|
|
67
|
-
const sourceDir = `${gulpConfig.get('rootPath')}copy-source-binary`
|
|
68
|
-
const destDir = `${gulpConfig.get('rootPath')}copy-dest-binary`
|
|
69
|
-
fs.mkdirSync(sourceDir, { recursive: true })
|
|
70
|
-
const original = Buffer.from(Array.from({ length: 512 }, (_, i) => i % 256))
|
|
71
|
-
fs.writeFileSync(`${sourceDir}/font.woff`, original)
|
|
72
|
-
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/*.woff`, to: destDir }])
|
|
73
|
-
|
|
74
|
-
await copyFiles()
|
|
75
|
-
|
|
76
|
-
expect(fs.readFileSync(`${destDir}/font.woff`).equals(original)).toBe(true)
|
|
77
|
-
})
|
|
78
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
+
import { copyFiles } from './copyFiles.mjs'
|
|
4
|
+
|
|
5
|
+
setUp.setDefaults('test-copy-files')
|
|
6
|
+
const gulpConfig = setUp.gulpConfig
|
|
7
|
+
|
|
8
|
+
beforeEach(() => setUp.beforeEach())
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
gulpConfig.set('copyFiles', [])
|
|
11
|
+
return setUp.afterEach()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('copyFiles', () => {
|
|
15
|
+
test('with no entries configured, does nothing and resolves', async () => {
|
|
16
|
+
await expect(copyFiles()).resolves.toBeUndefined()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('copies a file from one place to another', async () => {
|
|
20
|
+
const sourceDir = `${gulpConfig.get('rootPath')}copy-source`
|
|
21
|
+
const destDir = `${gulpConfig.get('rootPath')}copy-dest`
|
|
22
|
+
fs.mkdirSync(sourceDir, { recursive: true })
|
|
23
|
+
fs.writeFileSync(`${sourceDir}/one.txt`, 'one file\n')
|
|
24
|
+
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/*.txt`, to: destDir }])
|
|
25
|
+
|
|
26
|
+
await copyFiles()
|
|
27
|
+
|
|
28
|
+
expect(fs.readFileSync(`${destDir}/one.txt`).toString()).toBe('one file\n')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('copies several configured entries, each to its own destination', async () => {
|
|
32
|
+
const sourceDirA = `${gulpConfig.get('rootPath')}copy-source-a`
|
|
33
|
+
const sourceDirB = `${gulpConfig.get('rootPath')}copy-source-b`
|
|
34
|
+
const destDirA = `${gulpConfig.get('rootPath')}copy-dest-a`
|
|
35
|
+
const destDirB = `${gulpConfig.get('rootPath')}copy-dest-b`
|
|
36
|
+
fs.mkdirSync(sourceDirA, { recursive: true })
|
|
37
|
+
fs.mkdirSync(sourceDirB, { recursive: true })
|
|
38
|
+
fs.writeFileSync(`${sourceDirA}/a.txt`, 'from a\n')
|
|
39
|
+
fs.writeFileSync(`${sourceDirB}/b.txt`, 'from b\n')
|
|
40
|
+
gulpConfig.set('copyFiles', [
|
|
41
|
+
{ from: `${sourceDirA}/*.txt`, to: destDirA },
|
|
42
|
+
{ from: `${sourceDirB}/*.txt`, to: destDirB }
|
|
43
|
+
])
|
|
44
|
+
|
|
45
|
+
await copyFiles()
|
|
46
|
+
|
|
47
|
+
expect(fs.readFileSync(`${destDirA}/a.txt`).toString()).toBe('from a\n')
|
|
48
|
+
expect(fs.readFileSync(`${destDirB}/b.txt`).toString()).toBe('from b\n')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('base preserves the glob\'s own subdirectory structure in the destination', async () => {
|
|
52
|
+
const sourceDir = `${gulpConfig.get('rootPath')}copy-source-nested`
|
|
53
|
+
const destDir = `${gulpConfig.get('rootPath')}copy-dest-nested`
|
|
54
|
+
fs.mkdirSync(`${sourceDir}/inner`, { recursive: true })
|
|
55
|
+
fs.writeFileSync(`${sourceDir}/inner/deep.txt`, 'nested file\n')
|
|
56
|
+
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/**/*.txt`, to: destDir, base: sourceDir }])
|
|
57
|
+
|
|
58
|
+
await copyFiles()
|
|
59
|
+
|
|
60
|
+
expect(fs.readFileSync(`${destDir}/inner/deep.txt`).toString()).toBe('nested file\n')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// The real bug this guards against: a fresh src()/dest() pair (what this used to do) loses copyFor.mjs's own
|
|
64
|
+
// encoding: false fix - Gulp 5's default utf8 handling corrupts binary files such as fonts or a minified
|
|
65
|
+
// bundle. Reusing copyFor instead of duplicating its logic keeps that fix automatically.
|
|
66
|
+
test('copies binary files byte for byte, including bytes above 0x7f', async () => {
|
|
67
|
+
const sourceDir = `${gulpConfig.get('rootPath')}copy-source-binary`
|
|
68
|
+
const destDir = `${gulpConfig.get('rootPath')}copy-dest-binary`
|
|
69
|
+
fs.mkdirSync(sourceDir, { recursive: true })
|
|
70
|
+
const original = Buffer.from(Array.from({ length: 512 }, (_, i) => i % 256))
|
|
71
|
+
fs.writeFileSync(`${sourceDir}/font.woff`, original)
|
|
72
|
+
gulpConfig.set('copyFiles', [{ from: `${sourceDir}/*.woff`, to: destDir }])
|
|
73
|
+
|
|
74
|
+
await copyFiles()
|
|
75
|
+
|
|
76
|
+
expect(fs.readFileSync(`${destDir}/font.woff`).equals(original)).toBe(true)
|
|
77
|
+
})
|
|
78
|
+
})
|
package/functions/copyFonts.mjs
CHANGED
|
@@ -1,9 +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
|
+
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,32 +1,32 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
-
import { copyFonts } from './copyFonts.mjs'
|
|
4
|
-
|
|
5
|
-
setUp.setDefaults('test-copy-fonts')
|
|
6
|
-
const gulpConfig = setUp.gulpConfig
|
|
7
|
-
|
|
8
|
-
const fontContent = 'comic sans'
|
|
9
|
-
|
|
10
|
-
beforeEach(setUp.beforeEach)
|
|
11
|
-
|
|
12
|
-
afterEach(setUp.afterEach)
|
|
13
|
-
|
|
14
|
-
describe('copyFonts', () => {
|
|
15
|
-
test('uses the configured paths', done => {
|
|
16
|
-
const srcPath = gulpConfig.get('srcPath') + '/fonts'
|
|
17
|
-
fs.mkdirSync(srcPath, { recursive: true })
|
|
18
|
-
const fontFile = `${srcPath}/comic-sans.woff`
|
|
19
|
-
fs.writeFileSync(fontFile, fontContent)
|
|
20
|
-
const fontPath = gulpConfig.get('fonts.to')
|
|
21
|
-
expect.assertions(1)
|
|
22
|
-
copyFonts()
|
|
23
|
-
.on('finish', () => {
|
|
24
|
-
expect(fs.existsSync(fontPath)).toBeTruthy()
|
|
25
|
-
done()
|
|
26
|
-
})
|
|
27
|
-
.on('error', error => {
|
|
28
|
-
console.error('Encountered error', error)
|
|
29
|
-
done()
|
|
30
|
-
})
|
|
31
|
-
}, 10000)
|
|
32
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
+
import { copyFonts } from './copyFonts.mjs'
|
|
4
|
+
|
|
5
|
+
setUp.setDefaults('test-copy-fonts')
|
|
6
|
+
const gulpConfig = setUp.gulpConfig
|
|
7
|
+
|
|
8
|
+
const fontContent = 'comic sans'
|
|
9
|
+
|
|
10
|
+
beforeEach(setUp.beforeEach)
|
|
11
|
+
|
|
12
|
+
afterEach(setUp.afterEach)
|
|
13
|
+
|
|
14
|
+
describe('copyFonts', () => {
|
|
15
|
+
test('uses the configured paths', done => {
|
|
16
|
+
const srcPath = gulpConfig.get('srcPath') + '/fonts'
|
|
17
|
+
fs.mkdirSync(srcPath, { recursive: true })
|
|
18
|
+
const fontFile = `${srcPath}/comic-sans.woff`
|
|
19
|
+
fs.writeFileSync(fontFile, fontContent)
|
|
20
|
+
const fontPath = gulpConfig.get('fonts.to')
|
|
21
|
+
expect.assertions(1)
|
|
22
|
+
copyFonts()
|
|
23
|
+
.on('finish', () => {
|
|
24
|
+
expect(fs.existsSync(fontPath)).toBeTruthy()
|
|
25
|
+
done()
|
|
26
|
+
})
|
|
27
|
+
.on('error', error => {
|
|
28
|
+
console.error('Encountered error', error)
|
|
29
|
+
done()
|
|
30
|
+
})
|
|
31
|
+
}, 10000)
|
|
32
|
+
})
|
package/functions/default.mjs
CHANGED
|
@@ -1,12 +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
|
+
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,33 +1,33 @@
|
|
|
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
|
|
7
|
-
|
|
8
|
-
const genericFunction = () => Promise.resolve(true)
|
|
9
|
-
jest.mock('./bundle.mjs', () => ({ bundle: jest.fn(genericFunction) }))
|
|
10
|
-
jest.mock('./dist.mjs', () => ({ dist: jest.fn(genericFunction) }))
|
|
11
|
-
|
|
12
|
-
describe('distMinify', () => {
|
|
13
|
-
test('calls dist for nodeOnly true', done => {
|
|
14
|
-
gulpConfig.set('browser.enabled', false)
|
|
15
|
-
expect.assertions(1)
|
|
16
|
-
defaultCmd()
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
expect(dist).toHaveBeenCalled()
|
|
19
|
-
done()
|
|
20
|
-
}, 500)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('calls dist and bundle for nodeOnly false', done => {
|
|
24
|
-
gulpConfig.set('browser.enabled', true)
|
|
25
|
-
expect.assertions(2)
|
|
26
|
-
defaultCmd()
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
expect(dist).toHaveBeenCalled()
|
|
29
|
-
expect(bundle).toHaveBeenCalled()
|
|
30
|
-
done()
|
|
31
|
-
}, 500)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
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
|
|
7
|
+
|
|
8
|
+
const genericFunction = () => Promise.resolve(true)
|
|
9
|
+
jest.mock('./bundle.mjs', () => ({ bundle: jest.fn(genericFunction) }))
|
|
10
|
+
jest.mock('./dist.mjs', () => ({ dist: jest.fn(genericFunction) }))
|
|
11
|
+
|
|
12
|
+
describe('distMinify', () => {
|
|
13
|
+
test('calls dist for nodeOnly true', done => {
|
|
14
|
+
gulpConfig.set('browser.enabled', false)
|
|
15
|
+
expect.assertions(1)
|
|
16
|
+
defaultCmd()
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
expect(dist).toHaveBeenCalled()
|
|
19
|
+
done()
|
|
20
|
+
}, 500)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('calls dist and bundle for nodeOnly false', done => {
|
|
24
|
+
gulpConfig.set('browser.enabled', true)
|
|
25
|
+
expect.assertions(2)
|
|
26
|
+
defaultCmd()
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
expect(dist).toHaveBeenCalled()
|
|
29
|
+
expect(bundle).toHaveBeenCalled()
|
|
30
|
+
done()
|
|
31
|
+
}, 500)
|
|
32
|
+
})
|
|
33
|
+
})
|
package/functions/dist.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { distFor } from './partials/distFor.mjs'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Simplified distribution tasks which will use arguments from distFor.
|
|
5
|
-
* @memberOf module:js-build-tools
|
|
6
|
-
* @returns {*}
|
|
7
|
-
*/
|
|
8
|
-
export const dist = () => distFor()
|
|
1
|
+
import { distFor } from './partials/distFor.mjs'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simplified distribution tasks which will use arguments from distFor.
|
|
5
|
+
* @memberOf module:js-build-tools
|
|
6
|
+
* @returns {*}
|
|
7
|
+
*/
|
|
8
|
+
export const dist = () => distFor()
|
package/functions/dist.test.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
-
import { dist } from './dist.mjs'
|
|
4
|
-
|
|
5
|
-
setUp.setDefaults('test-dist')
|
|
6
|
-
const gulpConfig = setUp.gulpConfig
|
|
7
|
-
|
|
8
|
-
const rawContents = 'const distFor = require(\'./distFor.js\')\n' +
|
|
9
|
-
'\n' +
|
|
10
|
-
'/**\n' +
|
|
11
|
-
' * Simplified distribution tasks which will use arguments from distFor.\n' +
|
|
12
|
-
' * @returns {*}\n' +
|
|
13
|
-
' */\n' +
|
|
14
|
-
'const dist = () => distFor()\n' +
|
|
15
|
-
'\n' +
|
|
16
|
-
'module.exports = dist\n'
|
|
17
|
-
|
|
18
|
-
beforeEach(
|
|
19
|
-
() => setUp.beforeEach()
|
|
20
|
-
.then(
|
|
21
|
-
async () => {
|
|
22
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
23
|
-
return fs.writeFileSync(`${srcPath}/dist.js`, rawContents)
|
|
24
|
-
}
|
|
25
|
-
)
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
afterEach(setUp.afterEach)
|
|
29
|
-
|
|
30
|
-
describe('dist', () => {
|
|
31
|
-
test('uses the configured paths', done => {
|
|
32
|
-
const distPath = gulpConfig.get('dist.to')
|
|
33
|
-
expect.assertions(1)
|
|
34
|
-
dist()
|
|
35
|
-
.on('finish', () => {
|
|
36
|
-
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
37
|
-
done()
|
|
38
|
-
})
|
|
39
|
-
.on('error', error => {
|
|
40
|
-
console.error('Encountered error', error)
|
|
41
|
-
done()
|
|
42
|
-
})
|
|
43
|
-
}, 10000)
|
|
44
|
-
})
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import * as setUp from './test-helpers/setUp.mjs'
|
|
3
|
+
import { dist } from './dist.mjs'
|
|
4
|
+
|
|
5
|
+
setUp.setDefaults('test-dist')
|
|
6
|
+
const gulpConfig = setUp.gulpConfig
|
|
7
|
+
|
|
8
|
+
const rawContents = 'const distFor = require(\'./distFor.js\')\n' +
|
|
9
|
+
'\n' +
|
|
10
|
+
'/**\n' +
|
|
11
|
+
' * Simplified distribution tasks which will use arguments from distFor.\n' +
|
|
12
|
+
' * @returns {*}\n' +
|
|
13
|
+
' */\n' +
|
|
14
|
+
'const dist = () => distFor()\n' +
|
|
15
|
+
'\n' +
|
|
16
|
+
'module.exports = dist\n'
|
|
17
|
+
|
|
18
|
+
beforeEach(
|
|
19
|
+
() => setUp.beforeEach()
|
|
20
|
+
.then(
|
|
21
|
+
async () => {
|
|
22
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
23
|
+
return fs.writeFileSync(`${srcPath}/dist.js`, rawContents)
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
afterEach(setUp.afterEach)
|
|
29
|
+
|
|
30
|
+
describe('dist', () => {
|
|
31
|
+
test('uses the configured paths', done => {
|
|
32
|
+
const distPath = gulpConfig.get('dist.to')
|
|
33
|
+
expect.assertions(1)
|
|
34
|
+
dist()
|
|
35
|
+
.on('finish', () => {
|
|
36
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
37
|
+
done()
|
|
38
|
+
})
|
|
39
|
+
.on('error', error => {
|
|
40
|
+
console.error('Encountered error', error)
|
|
41
|
+
done()
|
|
42
|
+
})
|
|
43
|
+
}, 10000)
|
|
44
|
+
})
|
package/functions/distMinify.mjs
CHANGED
|
@@ -1,9 +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'))
|
|
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'))
|
|
@@ -1,15 +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
|
+
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
|
+
})
|
package/functions/docs.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { jsdocDocs } from './jsdocDocs.mjs'
|
|
2
|
-
import { resolveDocsMethod } from './partials/resolveDocsMethod.mjs'
|
|
3
|
-
import { typeDocs } from './typeDocs.mjs'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate the HTML documentation with whichever engine docs.method (or its typescript.enabled-based default)
|
|
7
|
-
* resolves to - see {@link module:partials.resolveDocsMethod}. The standalone counterpart to build's own
|
|
8
|
-
* internal branching, for running `gulp docs` directly instead of as part of a full build.
|
|
9
|
-
* @memberOf module:js-build-tools
|
|
10
|
-
* @param {Function} [done]
|
|
11
|
-
* @returns {*}
|
|
12
|
-
*/
|
|
13
|
-
export const docs = (done = null) => (resolveDocsMethod() === 'jsdoc' ? jsdocDocs : typeDocs)(done)
|
|
1
|
+
import { jsdocDocs } from './jsdocDocs.mjs'
|
|
2
|
+
import { resolveDocsMethod } from './partials/resolveDocsMethod.mjs'
|
|
3
|
+
import { typeDocs } from './typeDocs.mjs'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generate the HTML documentation with whichever engine docs.method (or its typescript.enabled-based default)
|
|
7
|
+
* resolves to - see {@link module:partials.resolveDocsMethod}. The standalone counterpart to build's own
|
|
8
|
+
* internal branching, for running `gulp docs` directly instead of as part of a full build.
|
|
9
|
+
* @memberOf module:js-build-tools
|
|
10
|
+
* @param {Function} [done]
|
|
11
|
+
* @returns {*}
|
|
12
|
+
*/
|
|
13
|
+
export const docs = (done = null) => (resolveDocsMethod() === 'jsdoc' ? jsdocDocs : typeDocs)(done)
|