Replace `pump` with `all`

This commit is contained in:
Christopher C. Wells 2022-10-22 14:19:06 -07:00 committed by Christopher Charbonneau Wells
parent 0a09fce38d
commit cba4a2babd
3 changed files with 111 additions and 155 deletions

View File

@ -1,12 +1,12 @@
const gulp = require('gulp'); const gulp = require('gulp');
const all = require('gulp-all');
const concat = require('gulp-concat'); const concat = require('gulp-concat');
const del = require('del'); const del = require('del');
const es = require('child_process').execSync; const es = require('child_process').execSync;
const flatten = require('gulp-flatten'); const flatten = require('gulp-flatten');
const fontello = require('gulp-fontello'); const fontello = require('gulp-fontello');
const minify = require('gulp-minify'); const minify = require('gulp-minify');
const pump = require('pump');
const removeSourcemaps = require('gulp-remove-sourcemaps'); const removeSourcemaps = require('gulp-remove-sourcemaps');
const sass = require('gulp-sass')(require('sass')); const sass = require('gulp-sass')(require('sass'));
const sassGlob = require('gulp-sass-glob'); const sassGlob = require('gulp-sass-glob');
@ -16,15 +16,26 @@ const spawn = require('child_process').spawn;
const config = require('./gulpfile.config.js'); const config = require('./gulpfile.config.js');
/** /**
* Support functions for Gulp tasks. * Spawns a command for pipenv.
*
* @param command
* Command and arguments.
*
* @returns {Promise<unknown>}
*
* @private
*/ */
function _runInPipenv(command) {
function _runInPipenv(command, cb) {
command.unshift('run'); command.unshift('run');
command = command.concat(process.argv.splice(3)); command = command.concat(process.argv.splice(3));
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', function (code) { return new Promise((resolve, reject) => {
if (code) process.exit(code); spawn('pipenv', command, { stdio: 'inherit' })
cb(); .on('exit', function (code) {
if (code) {
reject();
}
resolve();
});
}); });
} }
@ -93,144 +104,93 @@ function coverage(cb) {
/** /**
* Builds the documentation site locally. * Builds the documentation site locally.
*
* @param cb
*/ */
function docsBuild(cb) { function docsBuild() {
_runInPipenv(['mkdocs', 'build'], cb); return _runInPipenv(['mkdocs', 'build']);
} }
/** /**
* Deploys the documentation site to GitHub Pages. * Deploys the documentation site to GitHub Pages.
*
* @param cb
*/ */
function docsDeploy(cb) { function docsDeploy() {
_runInPipenv(['mkdocs', 'gh-deploy'], cb); return _runInPipenv(['mkdocs', 'gh-deploy']);
} }
/** /**
* Serves the documentation site, watching for changes. * Serves the documentation site, watching for changes.
*
* @param cb
*/ */
function docsWatch(cb) { function docsWatch() {
_runInPipenv(['mkdocs', 'serve'], cb); return _runInPipenv(['mkdocs', 'serve']);
} }
/** /**
* Builds and copies "extra" static files to configured paths. * Builds and copies "extra" static files to configured paths.
*
* @param cb
*/ */
function extras(cb) { function extras() {
pump([ return all(
gulp.src(config.extrasConfig.fonts.files), gulp.src(config.extrasConfig.fonts.files)
gulp.dest(config.extrasConfig.fonts.dest) .pipe(gulp.dest(config.extrasConfig.fonts.dest)),
], cb); gulp.src(config.extrasConfig.images.files)
.pipe(flatten({ subPath: 3 }))
pump([ .pipe(gulp.dest(config.extrasConfig.images.dest)),
gulp.src(config.extrasConfig.images.files), gulp.src(config.extrasConfig.logo.files)
flatten({ subPath: 3 }), .pipe(flatten({ subPath: 3 }))
gulp.dest(config.extrasConfig.images.dest) .pipe(gulp.dest(config.extrasConfig.logo.dest)),
], cb); gulp.src(config.extrasConfig.root.files)
.pipe(gulp.dest(config.extrasConfig.root.dest))
pump([ );
gulp.src(config.extrasConfig.logo.files),
flatten({ subPath: 3 }),
gulp.dest(config.extrasConfig.logo.dest)
], cb);
pump([
gulp.src(config.extrasConfig.root.files),
gulp.dest(config.extrasConfig.root.dest)
], cb);
} }
/** /**
* Runs Black formatting on Python code. * Runs Black formatting on Python code.
*
* @param cb
*/ */
function format(cb) { function format() {
_runInPipenv(['black', '.'], cb); return _runInPipenv(['black', '.']);
} }
/** /**
* Runs linting on Python and SASS code. * Runs linting on Python and SASS code.
*
* @param cb
*/ */
function lint(cb) { function lint() {
_runInPipenv(['black', '.', '--check', '--diff', '--color'], cb); return all(
_runInPipenv(['black', '.', '--check', '--diff', '--color']),
pump([ gulp.src(config.watchConfig.stylesGlob)
gulp.src(config.watchConfig.stylesGlob), .pipe(styleLint({
styleLint({ reporters: [{ formatter: 'string', console: true }]
reporters: [ }))
{ formatter: 'string', console: true } );
]
})
], cb);
} }
/** /**
* Builds and copies JavaScript static files to configured paths. * Builds and copies JavaScript static files to configured paths.
*
* @param cb
*/ */
function scripts(cb) { function scripts() {
const minifyOptions = { const streams = [];
const types = ['vendor', 'graph', 'app', 'tags_editor'];
types.forEach((type) => {
streams.push(
gulp.src(config.scriptsConfig[type])
.pipe(removeSourcemaps())
.pipe(concat(`${type}.js`))
.pipe(minify({
ext: { min:'.js' }, ext: { min:'.js' },
noSource: true, noSource: true,
}; }))
.pipe(gulp.dest(config.scriptsConfig.dest))
pump([ );
gulp.src(config.scriptsConfig.vendor), })
removeSourcemaps(), return all(streams);
concat('vendor.js'),
minify(minifyOptions),
gulp.dest(config.scriptsConfig.dest)
], cb);
pump([
gulp.src(config.scriptsConfig.graph),
removeSourcemaps(),
concat('graph.js'),
minify(minifyOptions),
gulp.dest(config.scriptsConfig.dest)
], cb);
pump([
gulp.src(config.scriptsConfig.app),
removeSourcemaps(),
concat('app.js'),
minify(minifyOptions),
gulp.dest(config.scriptsConfig.dest)
], cb);
pump([
gulp.src(config.scriptsConfig.tags_editor),
removeSourcemaps(),
concat('tags_editor.js'),
minify(minifyOptions),
gulp.dest(config.scriptsConfig.dest)
], cb);
} }
/** /**
* Builds and copies CSS static files to configured paths. * Builds and copies CSS static files to configured paths.
*
* @param cb
*/ */
function styles(cb) { function styles() {
pump([ return gulp.src(config.stylesConfig.app)
gulp.src(config.stylesConfig.app), .pipe(sassGlob({ignorePaths: config.stylesConfig.ignore}))
sassGlob({ignorePaths: config.stylesConfig.ignore}), .pipe(sass().on('error', sass.logError))
sass().on('error', sass.logError), .pipe(concat('app.css'))
concat('app.css'), .pipe(gulp.dest(config.stylesConfig.dest));
gulp.dest(config.stylesConfig.dest)
], cb);
} }
/** /**
@ -271,12 +231,10 @@ function test(cb) {
/** /**
* Updates glyphs font data from Fontello. * Updates glyphs font data from Fontello.
*/ */
function updateglyphs(cb) { function updateGlyphs() {
pump([ return gulp.src(config.glyphFontConfig.configFile)
gulp.src(config.glyphFontConfig.configFile), .pipe(fontello({ assetsOnly: false }))
fontello({ assetsOnly: false }), .pipe(gulp.dest(config.glyphFontConfig.dest));
gulp.dest(config.glyphFontConfig.dest)
], cb);
} }
/** /**
@ -311,32 +269,32 @@ gulp.task('collectstatic', function(cb) {
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb); spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
}); });
gulp.task('compilemessages', function(cb) { gulp.task('compilemessages', () => {
_runInPipenv(['python', 'manage.py', 'compilemessages'], cb); return _runInPipenv(['python', 'manage.py', 'compilemessages']);
}); });
gulp.task('createcachetable', function(cb) { gulp.task('createcachetable', () => {
_runInPipenv(['python', 'manage.py', 'createcachetable'], cb); return _runInPipenv(['python', 'manage.py', 'createcachetable']);
}); });
gulp.task('fake', function(cb) { gulp.task('fake', () => {
_runInPipenv(['python', 'manage.py', 'fake'], cb); return _runInPipenv(['python', 'manage.py', 'fake']);
}); });
gulp.task('migrate', function(cb) { gulp.task('migrate', () => {
_runInPipenv(['python', 'manage.py', 'migrate'], cb); return _runInPipenv(['python', 'manage.py', 'migrate']);
}); });
gulp.task('makemessages', function(cb) { gulp.task('makemessages', () => {
_runInPipenv(['python', 'manage.py', 'makemessages'], cb); return _runInPipenv(['python', 'manage.py', 'makemessages']);
}); });
gulp.task('makemigrations', function(cb) { gulp.task('makemigrations', () => {
_runInPipenv(['python', 'manage.py', 'makemigrations'], cb); return _runInPipenv(['python', 'manage.py', 'makemigrations']);
}); });
gulp.task('reset', function(cb) { gulp.task('reset', () => {
_runInPipenv(['python', 'manage.py', 'reset', '--no-input'], cb); return _runInPipenv(['python', 'manage.py', 'reset', '--no-input']);
}); });
gulp.task('runserver', function(cb) { gulp.task('runserver', function(cb) {
@ -368,8 +326,8 @@ gulp.task('runserver', function(cb) {
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb); spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
}); });
gulp.task('generateschema', function(cb) { gulp.task('generateschema', () => {
_runInPipenv([ return _runInPipenv([
'python', 'python',
'manage.py', 'manage.py',
'generateschema', 'generateschema',
@ -377,7 +335,7 @@ gulp.task('generateschema', function(cb) {
'Baby Buddy API', 'Baby Buddy API',
'--file', '--file',
'openapi-schema.yml' 'openapi-schema.yml'
], cb); ]);
}); });
/** /**
@ -406,7 +364,7 @@ gulp.task('styles', styles);
gulp.task('test', test); gulp.task('test', test);
gulp.task('updateglyphs', updateglyphs); gulp.task('updateglyphs', updateGlyphs);
gulp.task('watch', watch); gulp.task('watch', watch);

40
package-lock.json generated
View File

@ -14,6 +14,7 @@
"bootstrap": "^4.6.2", "bootstrap": "^4.6.2",
"del": "^6.1.1", "del": "^6.1.1",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-all": "^1.1.0",
"gulp-concat": "^2.6.1", "gulp-concat": "^2.6.1",
"gulp-csso": "^4.0.1", "gulp-csso": "^4.0.1",
"gulp-flatten": "^0.4.0", "gulp-flatten": "^0.4.0",
@ -31,7 +32,6 @@
"plotly.js": "^2.15.1", "plotly.js": "^2.15.1",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"pulltorefreshjs": "^0.1.22", "pulltorefreshjs": "^0.1.22",
"pump": "^3.0.0",
"sass": "^1.55.0", "sass": "^1.55.0",
"stylelint": "^14.13.0", "stylelint": "^14.13.0",
"stylelint-config-recommended-scss": "^7.0.0", "stylelint-config-recommended-scss": "^7.0.0",
@ -3581,6 +3581,15 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/gulp-all": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/gulp-all/-/gulp-all-1.1.0.tgz",
"integrity": "sha512-sOCQlBFKAhv+oifpkH8yq3802bi6uylfI254LzGyZo36lthWExYqcmItfQGpY+m81T28hJpXLvOLYyy9zetVgA==",
"dev": true,
"dependencies": {
"stream-exhaust": "^1.0.1"
}
},
"node_modules/gulp-cli": { "node_modules/gulp-cli": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz", "resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz",
@ -6824,16 +6833,6 @@
"integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==", "integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==",
"dev": true "dev": true
}, },
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dev": true,
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/pumpify": { "node_modules/pumpify": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz", "resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz",
@ -12761,6 +12760,15 @@
"vinyl-fs": "^3.0.0" "vinyl-fs": "^3.0.0"
} }
}, },
"gulp-all": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/gulp-all/-/gulp-all-1.1.0.tgz",
"integrity": "sha512-sOCQlBFKAhv+oifpkH8yq3802bi6uylfI254LzGyZo36lthWExYqcmItfQGpY+m81T28hJpXLvOLYyy9zetVgA==",
"dev": true,
"requires": {
"stream-exhaust": "^1.0.1"
}
},
"gulp-cli": { "gulp-cli": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz", "resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz",
@ -15334,16 +15342,6 @@
"integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==", "integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==",
"dev": true "dev": true
}, },
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dev": true,
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"pumpify": { "pumpify": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz", "resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz",

View File

@ -11,6 +11,7 @@
"bootstrap": "^4.6.2", "bootstrap": "^4.6.2",
"del": "^6.1.1", "del": "^6.1.1",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-all": "^1.1.0",
"gulp-concat": "^2.6.1", "gulp-concat": "^2.6.1",
"gulp-csso": "^4.0.1", "gulp-csso": "^4.0.1",
"gulp-flatten": "^0.4.0", "gulp-flatten": "^0.4.0",
@ -28,7 +29,6 @@
"plotly.js": "^2.15.1", "plotly.js": "^2.15.1",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"pulltorefreshjs": "^0.1.22", "pulltorefreshjs": "^0.1.22",
"pump": "^3.0.0",
"sass": "^1.55.0", "sass": "^1.55.0",
"stylelint": "^14.13.0", "stylelint": "^14.13.0",
"stylelint-config-recommended-scss": "^7.0.0", "stylelint-config-recommended-scss": "^7.0.0",