This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
caldwell-59/gulpfile.js
Nikolaos Karaolidis 10495003c1 Fix gulpfile
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
2024-10-27 11:19:18 +00:00

89 lines
2.3 KiB
JavaScript

const { series, parallel, watch, src, dest } = require('gulp');
const pump = require('pump');
const order = require('ordered-read-streams');
const livereload = require('gulp-livereload');
const postcss = require('gulp-postcss');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const zip = require('gulp-zip');
const easyimport = require('postcss-easy-import');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const serve = (done) => {
livereload.listen();
done();
}
const hbs = (done) => {
pump([
src(['*.hbs', 'partials/**/*.hbs']),
livereload()
], done);
}
const css = (variant) => (done) => {
pump([
src(`assets/css/${variant}/main.css`, { sourcemaps: true }),
postcss([
easyimport,
autoprefixer(),
cssnano()
]),
dest(`assets/dist/${variant}/`, { sourcemaps: '.' }),
livereload()
], done);
}
const js = (variant) => (done) => {
const sources = [
src(`node_modules/@tryghost/shared-theme-assets/assets/js/v1/lib/**/*.js`),
src(`node_modules/@tryghost/shared-theme-assets/assets/js/v1/main.js`),
src(`assets/js/common/*.js`),
src(`assets/js/${variant}/main.js`)
];
pump([
order(sources, { sourcemaps: true }),
concat(`main.min.js`),
uglify(),
dest(`assets/dist/${variant}/`, { sourcemaps: '.' }),
livereload()
], done);
}
const allCss = parallel(css('text'), css('image'));
const allJs = parallel(js('text'), js('image'));
const zipper = (done) => {
const filename = require('./package.json').name + '.zip';
pump([
src([
'**',
'!node_modules',
'!node_modules/**',
'!dist',
'!dist/**',
'!yarn-error.log',
'!yarn.lock',
"!gulpfile.js"
]),
zip(filename),
dest('dist/')
], done);
}
const hbsWatcher = () => watch(['*.hbs', 'partials/**/*.hbs'], hbs);
const cssWatcher = () => watch('assets/css/**/*.css', allCss);
const jsWatcher = () => watch('assets/js/**/*.js', allJs);
const watcher = parallel(hbsWatcher, cssWatcher, jsWatcher);
const build = series(allCss, allJs);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = series(build, serve, watcher);