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

40
package-lock.json generated
View File

@ -14,6 +14,7 @@
"bootstrap": "^4.6.2",
"del": "^6.1.1",
"gulp": "^4.0.2",
"gulp-all": "^1.1.0",
"gulp-concat": "^2.6.1",
"gulp-csso": "^4.0.1",
"gulp-flatten": "^0.4.0",
@ -31,7 +32,6 @@
"plotly.js": "^2.15.1",
"popper.js": "^1.16.1",
"pulltorefreshjs": "^0.1.22",
"pump": "^3.0.0",
"sass": "^1.55.0",
"stylelint": "^14.13.0",
"stylelint-config-recommended-scss": "^7.0.0",
@ -3581,6 +3581,15 @@
"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": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz",
@ -6824,16 +6833,6 @@
"integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==",
"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": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz",
@ -12761,6 +12760,15 @@
"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": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/gulp-cli/-/gulp-cli-2.3.0.tgz",
@ -15334,16 +15342,6 @@
"integrity": "sha512-haxNVEHnS4NCQA7NeG7TSV69z4uqy/N7nfPRuc4dPWe8H6ygUrMjdNeohE+6v0lVVX/ukSjbLYwPUGUYtFKfvQ==",
"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": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz",

View File

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