From 7a66e17bf8530acc57c7ad405cf87466516da187 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Thu, 26 Jan 2023 16:56:50 +0100 Subject: [PATCH] ci: Build static assets for production --- .gitignore | 2 ++ deploy.php | 14 ++++++++++++++ gulpfile.js | 29 +++++++++++++++++++++++++++++ package.json | 12 ++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 gulpfile.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index ca98c103..8324505d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ pub .vscode *.css.map deployment-report.json +package-lock.json build/ +node_modules/ diff --git a/deploy.php b/deploy.php index 5d04ac59..0402462e 100644 --- a/deploy.php +++ b/deploy.php @@ -44,6 +44,18 @@ run('ln -s docs/_build/html pub'); }); +# Install NPM packages from package.json +task('npm:prepare', static function () { + run('npm install'); +}); + +# Build static assets for production using gulp +task('assets:compile', static function () { + run('ls -l ./docs/_static/css'); + run('whoami'); + run('npx gulp buildProd'); +}); + # HMV configuration for when this is running in a docker task('deploy:hmv_docker', static function () use (&$DOCKER_HOST, &$DOCKER_WEBROOT) { if (test('[ -f /etc/hypernode/is_docker ]')) { @@ -68,6 +80,8 @@ }); $configuration = new Configuration(); +$configuration->addBuildTask('npm:prepare'); +$configuration->addBuildTask('assets:compile'); $configuration->addBuildTask('python:venv:create'); $configuration->addBuildTask('python:venv:requirements'); $configuration->addBuildTask('python:build_documentation'); diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 00000000..372b807f --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,29 @@ +const { series } = require('gulp'); +const cleanCSS = require('gulp-clean-css'); +const gulp = require('gulp'); +const sass = require('gulp-sass')(require('sass')); +const sourcemaps = require('gulp-sourcemaps'); +const terser = require('gulp-terser'); + +function cssCompile() { + return gulp.src('./docs/_static/scss/*.scss') + .pipe(sourcemaps.init()) + .pipe(sass.sync().on('error', sass.logError)) + .pipe(sourcemaps.write()) + .pipe(gulp.dest('./docs/_static/css')); +} + +function cssMinify() { + return gulp.src('./docs/_static/css/*.css') + .pipe(cleanCSS()) + .pipe(gulp.dest('./docs/_static/css')); +} + +function jsMinify() { + return gulp.src('./docs/_static/js/*.js') + .pipe(terser()) + .pipe(gulp.dest('./docs/_static/js')); +} + +exports.default = series(cssCompile); +exports.buildProd = series(cssCompile, cssMinify, jsMinify); diff --git a/package.json b/package.json new file mode 100644 index 00000000..94d3dbe3 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "devDependencies": { + "clean-css": "^5.3.2", + "gulp": "^4.0.2", + "gulp-clean-css": "^4.3.0", + "gulp-sass": "^5.1.0", + "gulp-sourcemaps": "^3.0.0", + "gulp-terser": "^2.1.0", + "sass": "^1.57.1", + "terser": "^5.16.1" + } +}