2022-02-21 17:49:36 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
|
|
|
|
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');
|
2022-10-21 03:30:31 +00:00
|
|
|
const minify = require('gulp-minify');
|
2022-02-21 17:49:36 +00:00
|
|
|
const pump = require('pump');
|
|
|
|
const removeSourcemaps = require('gulp-remove-sourcemaps');
|
|
|
|
const sass = require('gulp-sass')(require('sass'));
|
|
|
|
const sassGlob = require('gulp-sass-glob');
|
2022-05-22 20:29:32 +00:00
|
|
|
const styleLint = require('@ronilaukkarinen/gulp-stylelint');
|
2022-02-21 17:49:36 +00:00
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
|
|
|
|
const config = require('./gulpfile.config.js');
|
2018-07-15 17:12:55 +00:00
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Support functions for Gulp tasks.
|
|
|
|
*/
|
|
|
|
|
2021-12-22 16:29:32 +00:00
|
|
|
function _runInPipenv(command, cb) {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Deletes local static files.
|
|
|
|
*
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
function clean() {
|
|
|
|
return del([
|
|
|
|
'**/static',
|
|
|
|
'static'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs coverage operations.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function coverage(cb) {
|
2020-08-16 21:03:50 +00:00
|
|
|
// Erase any previous coverage results.
|
|
|
|
es('pipenv run coverage erase', {stdio: 'inherit'});
|
|
|
|
|
|
|
|
// Run tests with coverage.
|
2020-01-28 03:58:50 +00:00
|
|
|
spawn(
|
|
|
|
'pipenv',
|
|
|
|
[
|
|
|
|
'run',
|
|
|
|
'coverage',
|
|
|
|
'run',
|
|
|
|
'manage.py',
|
2020-07-23 04:56:29 +00:00
|
|
|
'test',
|
2021-06-22 03:52:47 +00:00
|
|
|
'--settings=babybuddy.settings.test',
|
2020-08-13 03:12:20 +00:00
|
|
|
'--parallel',
|
2020-07-23 04:56:29 +00:00
|
|
|
'--exclude-tag',
|
|
|
|
'isolate'
|
2020-01-28 03:58:50 +00:00
|
|
|
],
|
|
|
|
{
|
|
|
|
stdio: 'inherit'
|
|
|
|
}
|
2021-05-04 13:22:14 +00:00
|
|
|
).on('exit', function(code) {
|
2020-08-16 21:03:50 +00:00
|
|
|
// Run isolated tests with coverage.
|
2021-05-04 13:22:14 +00:00
|
|
|
if (code === 0) {
|
|
|
|
try {
|
|
|
|
config.testsConfig.isolated.forEach(function (test_name) {
|
|
|
|
es(
|
2022-06-03 03:21:16 +00:00
|
|
|
'pipenv run coverage run manage.py test --settings=babybuddy.settings.test ' + test_name,
|
2021-05-04 13:22:14 +00:00
|
|
|
{stdio: 'inherit'}
|
|
|
|
);
|
|
|
|
})
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
cb();
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Combine coverage results.
|
|
|
|
es('pipenv run coverage combine', {stdio: 'inherit'});
|
|
|
|
}
|
2020-08-16 21:03:50 +00:00
|
|
|
|
2020-07-27 03:02:51 +00:00
|
|
|
cb();
|
2021-05-04 13:22:14 +00:00
|
|
|
process.exit(code)
|
2020-07-27 03:02:51 +00:00
|
|
|
});
|
2020-01-28 03:58:50 +00:00
|
|
|
}
|
2018-07-15 17:12:55 +00:00
|
|
|
|
2021-12-22 16:32:53 +00:00
|
|
|
/**
|
|
|
|
* Builds the documentation site locally.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function docsBuild(cb) {
|
|
|
|
_runInPipenv(['mkdocs', 'build'], cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deploys the documentation site to GitHub Pages.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function docsDeploy(cb) {
|
|
|
|
_runInPipenv(['mkdocs', 'gh-deploy'], cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serves the documentation site, watching for changes.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function docsWatch(cb) {
|
|
|
|
_runInPipenv(['mkdocs', 'serve'], cb);
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Builds and copies "extra" static files to configured paths.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
2018-07-15 17:12:55 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-02-10 00:03:31 +00:00
|
|
|
/**
|
|
|
|
* Runs Black formatting on Python code.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function format(cb) {
|
|
|
|
_runInPipenv(['black', '.'], cb);
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Runs linting on Python and SASS code.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
2018-07-15 17:12:55 +00:00
|
|
|
function lint(cb) {
|
2022-02-10 00:03:31 +00:00
|
|
|
_runInPipenv(['black', '.', '--check', '--diff', '--color'], cb);
|
2018-07-15 17:12:55 +00:00
|
|
|
|
|
|
|
pump([
|
|
|
|
gulp.src(config.watchConfig.stylesGlob),
|
2019-11-09 14:37:31 +00:00
|
|
|
styleLint({
|
|
|
|
reporters: [
|
|
|
|
{ formatter: 'string', console: true }
|
|
|
|
]
|
|
|
|
})
|
2018-07-15 17:12:55 +00:00
|
|
|
], cb);
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Builds and copies JavaScript static files to configured paths.
|
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
|
|
|
function scripts(cb) {
|
|
|
|
pump([
|
|
|
|
gulp.src(config.scriptsConfig.vendor),
|
2022-02-21 17:46:35 +00:00
|
|
|
removeSourcemaps(),
|
2022-10-21 03:30:31 +00:00
|
|
|
minify(),
|
2020-01-28 03:58:50 +00:00
|
|
|
concat('vendor.js'),
|
|
|
|
gulp.dest(config.scriptsConfig.dest)
|
|
|
|
], cb);
|
|
|
|
|
|
|
|
pump([
|
|
|
|
gulp.src(config.scriptsConfig.graph),
|
2022-02-21 17:46:35 +00:00
|
|
|
removeSourcemaps(),
|
2022-10-21 13:30:20 +00:00
|
|
|
minify(),
|
2020-01-28 03:58:50 +00:00
|
|
|
concat('graph.js'),
|
|
|
|
gulp.dest(config.scriptsConfig.dest)
|
|
|
|
], cb);
|
|
|
|
|
|
|
|
pump([
|
|
|
|
gulp.src(config.scriptsConfig.app),
|
2022-02-21 17:46:35 +00:00
|
|
|
removeSourcemaps(),
|
2022-10-21 13:30:20 +00:00
|
|
|
minify(),
|
2020-01-28 03:58:50 +00:00
|
|
|
concat('app.js'),
|
|
|
|
gulp.dest(config.scriptsConfig.dest)
|
2022-02-22 18:40:27 +00:00
|
|
|
], cb);
|
|
|
|
|
|
|
|
pump([
|
|
|
|
gulp.src(config.scriptsConfig.tags_editor),
|
2022-10-21 13:30:20 +00:00
|
|
|
minify(),
|
2022-02-22 18:40:27 +00:00
|
|
|
concat('tags_editor.js'),
|
|
|
|
gulp.dest(config.scriptsConfig.dest)
|
2020-01-28 03:58:50 +00:00
|
|
|
], cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-23 04:56:29 +00:00
|
|
|
* Runs all tests _not_ tagged "isolate".
|
2020-01-28 03:58:50 +00:00
|
|
|
*
|
|
|
|
* @param cb
|
|
|
|
*/
|
2018-07-15 17:12:55 +00:00
|
|
|
function test(cb) {
|
2022-02-21 17:49:36 +00:00
|
|
|
let command = [
|
2020-07-23 04:56:29 +00:00
|
|
|
'run',
|
|
|
|
'python',
|
|
|
|
'manage.py',
|
|
|
|
'test',
|
2021-06-22 03:47:57 +00:00
|
|
|
'--settings=babybuddy.settings.test',
|
2020-08-13 03:00:03 +00:00
|
|
|
'--parallel',
|
2020-07-23 04:56:29 +00:00
|
|
|
'--exclude-tag',
|
|
|
|
'isolate'
|
|
|
|
];
|
2018-07-15 17:12:55 +00:00
|
|
|
command = command.concat(process.argv.splice(3));
|
2021-05-04 13:02:44 +00:00
|
|
|
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', function(code) {
|
|
|
|
if (code === 0) {
|
|
|
|
// Run isolated tests.
|
|
|
|
config.testsConfig.isolated.forEach(function(test_name) {
|
|
|
|
try {
|
2022-07-30 21:22:34 +00:00
|
|
|
es('pipenv run python manage.py test --settings=babybuddy.settings.test ' + test_name, {stdio: 'inherit'});
|
2021-05-04 13:02:44 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2021-05-04 13:22:14 +00:00
|
|
|
cb();
|
2021-05-04 13:02:44 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-07-27 03:02:51 +00:00
|
|
|
cb();
|
2021-05-04 13:02:44 +00:00
|
|
|
process.exit(code);
|
2020-07-27 03:02:51 +00:00
|
|
|
});
|
2018-07-15 17:12:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 03:33:25 +00:00
|
|
|
/**
|
|
|
|
* Updates glyphs font data from Fontello.
|
|
|
|
*/
|
|
|
|
function updateglyphs(cb) {
|
|
|
|
pump([
|
2021-12-22 16:29:32 +00:00
|
|
|
gulp.src(config.glyphFontConfig.configFile),
|
2021-09-04 03:33:25 +00:00
|
|
|
fontello({ assetsOnly: false }),
|
2021-12-22 16:29:32 +00:00
|
|
|
gulp.dest(config.glyphFontConfig.dest)
|
2021-09-04 03:33:25 +00:00
|
|
|
], cb);
|
|
|
|
}
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Watches for changes in configured files.
|
|
|
|
*/
|
|
|
|
function watch() {
|
|
|
|
gulp.watch(config.watchConfig.scriptsGlob, scripts);
|
|
|
|
gulp.watch(config.watchConfig.stylesGlob, styles);
|
2018-07-15 17:12:55 +00:00
|
|
|
}
|
2020-01-28 03:58:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Django management command passthroughs.
|
|
|
|
*/
|
2018-07-15 17:12:55 +00:00
|
|
|
|
|
|
|
gulp.task('collectstatic', function(cb) {
|
2022-02-21 17:49:36 +00:00
|
|
|
let command = ['run', 'python', 'manage.py', 'collectstatic'];
|
2018-10-12 02:30:11 +00:00
|
|
|
|
|
|
|
/* Use base settings if no settings parameter is supplied. */
|
2022-02-21 17:49:36 +00:00
|
|
|
const parameters = process.argv.splice(3);
|
|
|
|
let noSettings = true;
|
|
|
|
for (let i = 0; i < parameters.length; i++) {
|
2018-10-12 02:30:11 +00:00
|
|
|
if (parameters[i].substring(0, 10) === '--settings') {
|
|
|
|
noSettings = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (noSettings) {
|
|
|
|
parameters.push('--settings=babybuddy.settings.base');
|
|
|
|
}
|
|
|
|
|
|
|
|
command = command.concat(parameters);
|
2018-07-15 17:12:55 +00:00
|
|
|
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
|
|
|
|
});
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('compilemessages', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'compilemessages'], cb);
|
2018-07-15 17:12:55 +00:00
|
|
|
});
|
|
|
|
|
2020-01-29 04:45:37 +00:00
|
|
|
gulp.task('createcachetable', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'createcachetable'], cb);
|
2020-01-29 04:45:37 +00:00
|
|
|
});
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('fake', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'fake'], cb);
|
2018-07-15 17:12:55 +00:00
|
|
|
});
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('migrate', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'migrate'], cb);
|
2018-07-15 17:12:55 +00:00
|
|
|
});
|
|
|
|
|
2019-04-14 03:50:36 +00:00
|
|
|
gulp.task('makemessages', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'makemessages'], cb);
|
2019-04-14 03:50:36 +00:00
|
|
|
});
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('makemigrations', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'makemigrations'], cb);
|
2019-04-14 03:50:36 +00:00
|
|
|
});
|
|
|
|
|
2018-07-15 17:12:55 +00:00
|
|
|
gulp.task('reset', function(cb) {
|
2021-12-22 16:29:32 +00:00
|
|
|
_runInPipenv(['python', 'manage.py', 'reset', '--no-input'], cb);
|
2018-07-15 17:12:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('runserver', function(cb) {
|
2022-02-21 17:49:36 +00:00
|
|
|
let command = ['run', 'python', 'manage.py', 'runserver'];
|
2020-01-27 16:52:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process any parameters. Any arguments found here will be removed from
|
|
|
|
* the parameters list so other parameters continue to be passed to the
|
|
|
|
* command.
|
|
|
|
**/
|
2022-02-21 17:49:36 +00:00
|
|
|
const parameters = process.argv.splice(2);
|
|
|
|
for (let i = 0; i < parameters.length; i++) {
|
2020-01-27 16:52:42 +00:00
|
|
|
/* May be included because this is the default gulp command. */
|
|
|
|
if (parameters[i] === 'runserver') {
|
|
|
|
delete parameters[i];
|
|
|
|
}
|
|
|
|
/* "--ip" parameter to set the server IP address. */
|
|
|
|
else if (parameters[i] === '--ip') {
|
|
|
|
command.push(parameters[i+1]);
|
|
|
|
delete parameters[i];
|
|
|
|
delete parameters[i+1];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add parameters to command, removing empty values. */
|
|
|
|
command = command.concat(parameters.filter(String));
|
|
|
|
|
2018-07-15 17:12:55 +00:00
|
|
|
spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb);
|
|
|
|
});
|
|
|
|
|
2022-01-13 00:11:07 +00:00
|
|
|
gulp.task('generateschema', function(cb) {
|
|
|
|
_runInPipenv([
|
|
|
|
'python',
|
|
|
|
'manage.py',
|
|
|
|
'generateschema',
|
|
|
|
'--title',
|
|
|
|
'Baby Buddy API',
|
|
|
|
'--file',
|
|
|
|
'openapi-schema.yml'
|
|
|
|
], cb);
|
|
|
|
});
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
/**
|
|
|
|
* Gulp commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gulp.task('clean', clean);
|
|
|
|
|
|
|
|
gulp.task('coverage', coverage);
|
|
|
|
|
2021-12-22 16:32:53 +00:00
|
|
|
gulp.task('docs:build', docsBuild);
|
|
|
|
|
|
|
|
gulp.task('docs:deploy', docsDeploy);
|
|
|
|
|
|
|
|
gulp.task('docs:watch', docsWatch);
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('extras', extras);
|
|
|
|
|
2022-02-10 00:03:31 +00:00
|
|
|
gulp.task('format', format);
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('lint', lint);
|
|
|
|
|
|
|
|
gulp.task('scripts', scripts);
|
|
|
|
|
|
|
|
gulp.task('styles', styles);
|
|
|
|
|
|
|
|
gulp.task('test', test);
|
|
|
|
|
2021-09-04 03:33:25 +00:00
|
|
|
gulp.task('updateglyphs', updateglyphs);
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('watch', watch);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gulp compound commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gulp.task('build', gulp.parallel('extras', 'scripts', 'styles'));
|
|
|
|
|
2020-01-28 03:48:28 +00:00
|
|
|
gulp.task('updatestatic', gulp.series('lint', 'clean', 'build', 'collectstatic'));
|
|
|
|
|
2020-01-28 03:58:50 +00:00
|
|
|
gulp.task('default', gulp.series('build', gulp.parallel('watch', 'runserver')));
|