js-build-tools 6.6.0 → 6.8.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 +768 -701
- 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/cacheFiles.js +121 -0
- 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 +155 -93
- package/dist/partials/jsdocDocsFor.js +64 -51
- 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 +264 -264
- package/dist/partials.js +183 -176
- package/dist/partials.min.js +1 -1
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/setUp.js +6 -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 +760 -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 +140 -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/cacheFiles.mjs +114 -0
- package/functions/partials/cacheFiles.test.mjs +151 -0
- 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 +147 -83
- package/functions/partials/imagesFor.test.mjs +311 -287
- 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 -231
- package/functions/partials/typeDocsFor.test.mjs +263 -263
- package/functions/partials.mjs +32 -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/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +102 -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 +349 -340
- 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
- package/dist/test-helpers/isolateGulpCache.js +0 -25
- package/functions/test-helpers/isolateGulpCache.mjs +0 -16
|
@@ -1,83 +1,147 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
.
|
|
83
|
-
|
|
1
|
+
import { existsSync, readFileSync } from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { cacheFiles } from './cacheFiles.mjs'
|
|
4
|
+
import { requirePeer } from './loadPeer.mjs'
|
|
5
|
+
import { dest, src } from 'gulp'
|
|
6
|
+
import * as gulpConfig from '../../gulp.config.mjs'
|
|
7
|
+
|
|
8
|
+
const installHint = 'Add it to your project with: npm install --save-dev github:jheagle/gulp-imagemin#common-js-compatibility ' +
|
|
9
|
+
'(the CommonJS-compatible fork - upstream gulp-imagemin is ESM-only and cannot be require()d by this package\'s CommonJS build).'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
13
|
+
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
14
|
+
* consuming project's own directory rather than from this package.
|
|
15
|
+
* @memberOf module:partials
|
|
16
|
+
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
17
|
+
* @returns {Function} The gulp-imagemin plugin factory.
|
|
18
|
+
* @throws {Error} With install instructions when gulp-imagemin is missing or is the ESM-only upstream release.
|
|
19
|
+
*/
|
|
20
|
+
export const loadImagemin = (projectPath = process.cwd()) => {
|
|
21
|
+
const loaded = requirePeer('gulp-imagemin', {
|
|
22
|
+
task: 'images',
|
|
23
|
+
installHint,
|
|
24
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
25
|
+
projectPath
|
|
26
|
+
})
|
|
27
|
+
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Load the plugins `gulp-imagemin` exports by name (gifsicle, mozjpeg, optipng and svgo), each a promise of a plugin
|
|
32
|
+
* factory, for when they need options of their own (see images.jpegQuality). Resolved like {@link loadImagemin}.
|
|
33
|
+
* @memberOf module:partials
|
|
34
|
+
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
35
|
+
* @returns {Object<string, Promise<Function>>} The plugin factories, by name.
|
|
36
|
+
*/
|
|
37
|
+
export const loadImageminPlugins = (projectPath = process.cwd()) => requirePeer('gulp-imagemin', {
|
|
38
|
+
task: 'images',
|
|
39
|
+
installHint,
|
|
40
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
41
|
+
projectPath
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// The plugins imagemin runs when it isn't given any, in its own order
|
|
45
|
+
const defaultPluginNames = ['gifsicle', 'mozjpeg', 'optipng', 'svgo']
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The plugins imagemin uses by default, with mozjpeg set to the given JPEG quality instead of its own default (75).
|
|
49
|
+
* @memberOf module:partials
|
|
50
|
+
* @param {number} jpegQuality - The mozjpeg quality, 0 to 100.
|
|
51
|
+
* @param {Object<string, Promise<Function>>} [plugins=loadImageminPlugins()] - The plugin factories, by name.
|
|
52
|
+
* @returns {Array<Promise<Function>>} The plugins, in imagemin's default order.
|
|
53
|
+
*/
|
|
54
|
+
export const imageminPlugins = (jpegQuality, plugins = loadImageminPlugins()) => defaultPluginNames.map(
|
|
55
|
+
name => Promise.resolve(plugins[name]).then(makePlugin => name === 'mozjpeg' ? makePlugin({ quality: jpegQuality }) : makePlugin())
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
// The packages that decide imagemin's output: the wrapper and imagemin, then each plugin with the engine it runs
|
|
59
|
+
const imageminPackages = [
|
|
60
|
+
['gulp-imagemin'],
|
|
61
|
+
['imagemin'],
|
|
62
|
+
['imagemin-gifsicle', 'gifsicle'],
|
|
63
|
+
['imagemin-mozjpeg', 'mozjpeg'],
|
|
64
|
+
['imagemin-optipng', 'optipng-bin'],
|
|
65
|
+
['imagemin-svgo', 'svgo']
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Find an installed package the way Node does, from a directory up through each node_modules folder. Reads the
|
|
70
|
+
* package.json directly, so it also works for ESM-only packages that don't export it.
|
|
71
|
+
* @private
|
|
72
|
+
* @param {string} name
|
|
73
|
+
* @param {string} fromDirectory
|
|
74
|
+
* @returns {{directory: string, version: string}|undefined}
|
|
75
|
+
*/
|
|
76
|
+
const findPackage = (name, fromDirectory) => {
|
|
77
|
+
for (let directory = path.resolve(fromDirectory); ; directory = path.dirname(directory)) {
|
|
78
|
+
const file = path.join(directory, 'node_modules', name, 'package.json')
|
|
79
|
+
if (existsSync(file)) {
|
|
80
|
+
return { directory: path.dirname(file), version: JSON.parse(readFileSync(file, 'utf8')).version }
|
|
81
|
+
}
|
|
82
|
+
if (directory === path.dirname(directory)) {
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The installed versions of the packages that decide imagemin's output, so the image cache stops using results made
|
|
90
|
+
* by older versions after an upgrade (see images.cacheDir).
|
|
91
|
+
* @memberOf module:partials
|
|
92
|
+
* @param {string} [projectPath=process.cwd()] - The project directory gulp-imagemin is installed in.
|
|
93
|
+
* @returns {Object<string, string>} Each package's version by name; a package that isn't installed is left out.
|
|
94
|
+
*/
|
|
95
|
+
export const imageminVersions = (projectPath = process.cwd()) => {
|
|
96
|
+
const gulpImagemin = findPackage('gulp-imagemin', projectPath)
|
|
97
|
+
const versions = {}
|
|
98
|
+
if (!gulpImagemin) {
|
|
99
|
+
return versions
|
|
100
|
+
}
|
|
101
|
+
for (const [wrapper, engine] of imageminPackages) {
|
|
102
|
+
const found = findPackage(wrapper, gulpImagemin.directory)
|
|
103
|
+
if (found) {
|
|
104
|
+
versions[wrapper] = found.version
|
|
105
|
+
const engineFound = engine && findPackage(engine, found.directory)
|
|
106
|
+
if (engineFound) {
|
|
107
|
+
versions[engine] = engineFound.version
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return versions
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Move and optimize images into the browser directory.
|
|
116
|
+
* @memberOf module:partials
|
|
117
|
+
* @param {string|array} [imageSrc=src/images/pattern]
|
|
118
|
+
* @param {string} [imageDest=dest/image/folder]
|
|
119
|
+
* @return {stream.Stream}
|
|
120
|
+
*/
|
|
121
|
+
export const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
122
|
+
const imagemin = loadImagemin()
|
|
123
|
+
const jpegQuality = gulpConfig.get('images.jpegQuality')
|
|
124
|
+
// Left unset, imagemin runs its default plugins with their own defaults
|
|
125
|
+
const plugins = jpegQuality ? imageminPlugins(jpegQuality) : undefined
|
|
126
|
+
const options = {
|
|
127
|
+
interlaced: true,
|
|
128
|
+
silent: true,
|
|
129
|
+
verbose: false,
|
|
130
|
+
}
|
|
131
|
+
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images.
|
|
132
|
+
return src(imageSrc, { encoding: false })
|
|
133
|
+
.pipe(
|
|
134
|
+
// Only images imagemin hasn't optimized before go through it; the rest come from the cache
|
|
135
|
+
cacheFiles(
|
|
136
|
+
imagemin(plugins, options),
|
|
137
|
+
{
|
|
138
|
+
directory: gulpConfig.get('images.cacheDir'),
|
|
139
|
+
// Each quality gets results of its own
|
|
140
|
+
name: jpegQuality ? `jpeg-quality-${jpegQuality}` : 'default',
|
|
141
|
+
// A new imagemin (or plugin, or engine) version, or other options, makes new results
|
|
142
|
+
fingerprint: JSON.stringify({ options, versions: imageminVersions() })
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
.pipe(dest(imageDest))
|
|
147
|
+
}
|