diff --git a/gulp/modules/plumber.js b/gulp/modules/plumber.mjs similarity index 83% rename from gulp/modules/plumber.js rename to gulp/modules/plumber.mjs index cbb5dc9..c6f3073 100644 --- a/gulp/modules/plumber.js +++ b/gulp/modules/plumber.mjs @@ -1,4 +1,4 @@ -const plumber = require('gulp-plumber'); +import plumber from 'gulp-plumber'; // const notify = require('gulp-notify'); // function catchErrors(errTitle) { @@ -11,7 +11,7 @@ const plumber = require('gulp-plumber'); // }); // } -function catchErrors() { +export function catchErrors() { return plumber({ errorHandler: function (err) { // Logs error in console @@ -20,6 +20,5 @@ function catchErrors() { this.emit('end'); } }); -} -module.exports = catchErrors; \ No newline at end of file +} \ No newline at end of file diff --git a/gulp/tasks/clean.js b/gulp/tasks/clean.js deleted file mode 100644 index 667f6a3..0000000 --- a/gulp/tasks/clean.js +++ /dev/null @@ -1,9 +0,0 @@ -const config = require('../config'); -const del = require('del'); - -// Clean output folders -function clean() { - return del([config.dev + '**', config.rep + '**', config.dpl + '**']); -} - -module.exports = clean; \ No newline at end of file diff --git a/gulp/tasks/clean.mjs b/gulp/tasks/clean.mjs new file mode 100644 index 0000000..d3635b1 --- /dev/null +++ b/gulp/tasks/clean.mjs @@ -0,0 +1,8 @@ +import config from '../config.js'; +import { deleteAsync } from 'del'; + +// Clean output folders +export function clean() { + return deleteAsync([config.dev + '**', config.rep + '**', config.dpl + '**']); + +} \ No newline at end of file diff --git a/gulp/tasks/sync.js b/gulp/tasks/sync.mjs similarity index 59% rename from gulp/tasks/sync.js rename to gulp/tasks/sync.mjs index 5f65a4f..1e70304 100644 --- a/gulp/tasks/sync.js +++ b/gulp/tasks/sync.mjs @@ -1,16 +1,17 @@ -const config = require('../config'); +import config from '../config.js'; // const browserSync = require('browser-sync'), server = browserSync.create(); -const server = require('browser-sync').create(); +import browserSync from 'browser-sync' +const server = browserSync.create(); // Automagically reload browsers -function reload(done) { +export function reload(done) { server.reload; done(); } // Serve files to the browser -function serve(done) { +export function serve(done) { server.init({ index: config.index, open: false, @@ -19,8 +20,3 @@ function serve(done) { done(); } - -module.exports = { - serve: serve, - reload: reload -}; \ No newline at end of file diff --git a/gulp/tasks/validate.js b/gulp/tasks/validate.js deleted file mode 100644 index 0293245..0000000 --- a/gulp/tasks/validate.js +++ /dev/null @@ -1,13 +0,0 @@ -const { src } = require('gulp'); -const config = require('../config'); -const plumber = require('../modules/plumber'); -const htmlValidator = require('gulp-w3c-html-validator'); - -function validate() { - return src(config.dev + '**/*.html') - .pipe(plumber()) - .pipe(htmlValidator()) - .pipe(htmlValidator.reporter()); -} - -module.exports = validate; \ No newline at end of file diff --git a/gulp/tasks/validate.mjs b/gulp/tasks/validate.mjs new file mode 100644 index 0000000..3e63ac9 --- /dev/null +++ b/gulp/tasks/validate.mjs @@ -0,0 +1,14 @@ +import gulp from 'gulp'; +const { src } = gulp; +import config from '../config.js'; +import plumber from '../modules/plumber.mjs'; +import htmlValidator from 'gulp-w3c-html-validator'; + +function validate() { + return src(config.dev + '**/*.html') + .pipe(plumber()) + .pipe(htmlValidator()) + .pipe(htmlValidator.reporter()); +} + +module.exports = validate; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.mjs similarity index 84% rename from gulpfile.js rename to gulpfile.mjs index f6cbecd..fd0ac5c 100644 --- a/gulpfile.js +++ b/gulpfile.mjs @@ -2,43 +2,45 @@ // const hippie = require('hippie/hippie'); // Setup project -const config = require('./gulp/config'); +import config from './gulp/config.js'; -const hello = require('./gulp/tasks/hello'); -const plumber = require('./gulp/modules/plumber'); -const { serve, reload } = require('./gulp/tasks/sync'); -const clean = require('./gulp/tasks/clean'); +import hello from './gulp/tasks/hello.js'; +import { catchErrors } from './gulp/modules/plumber.mjs'; +import { serve, reload } from './gulp/tasks/sync.mjs'; +import { clean } from './gulp/tasks/clean.mjs'; // const validate = require("./gulp/tasks/validate"); // Gulp requirements -const { watch, series, parallel } = require('gulp'); -const { src, dest } = require('gulp'); +import gulp from 'gulp'; +const { watch, series, parallel, src, dest } = gulp; -const fs = require('fs'); +import fs from 'node:fs'; -const nunjucksRender = require('gulp-nunjucks-render'); +import nunjucksRender from 'gulp-nunjucks-render'; // const nunjucks = require('gulp-nunjucks'); -const data = require('gulp-data'); -const jsonConcat = require('gulp-json-concat'); -const sass = require('gulp-sass')(require('sass')); -const autoprefixer = require('gulp-autoprefixer'); -const sassLint = require('gulp-sass-lint'); -const rename = require('gulp-rename'); -const cleanCss = require('gulp-clean-css'); -const pump = require('pump'); -const cached = require('gulp-cached'); +import data from 'gulp-data'; +import jsonConcat from 'gulp-json-concat'; +import dartSass from 'sass'; +import gulpSass from 'gulp-sass'; +const sass = gulpSass(dartSass); +import autoprefixer from 'gulp-autoprefixer'; +import sassLint from 'gulp-sass-lint'; +import rename from 'gulp-rename'; +import cleanCss from 'gulp-clean-css'; +import pump from 'pump'; +import cached from 'gulp-cached'; // const remember = require('gulp-remember'); // const concat = require('gulp-concat'); -const uglify = require('gulp-uglify'); -const jshint = require('gulp-jshint'); -const gulpIf = require('gulp-if'); -const changed = require('gulp-changed'); -const merge = require('merge-stream'); -const spritesmith = require('gulp.spritesmith'); +import uglify from 'gulp-uglify'; +import jshint from 'gulp-jshint'; +import gulpIf from 'gulp-if'; +import changed from 'gulp-changed'; +import merge from 'merge-stream'; +import spritesmith from 'gulp.spritesmith'; // const babel = require('gulp-babel'); // const buffer = require('vinyl-buffer'); // const imagemin = require('gulp-imagemin'); -const useref = require('gulp-useref'); +import useref from 'gulp-useref'; // Data variables const input = { @@ -86,7 +88,7 @@ if (config.demo === true) { // Concatenate JSON files function json() { return src(config.frontendData) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(jsonConcat('db.json', function (data) { return new Buffer.from(JSON.stringify(data)); })) @@ -115,7 +117,7 @@ function getDataForTemplates() { // Transpile HTML function nunjucks() { return src(input.screens) - .pipe(plumber()) + .pipe(catchErrors()) // TODO only add data to pipe for necessary files .pipe(data(getDataForTemplates)) .pipe(nunjucksRender({ @@ -131,7 +133,7 @@ function nunjucks() { // This is for the looks function style() { return src(input.style) - .pipe(plumber()) + .pipe(catchErrors()) // .pipe(sass.sync({ .pipe(sass({ includePaths: [input.vendor + '/**/*.s+(a|c)ss'] @@ -152,7 +154,7 @@ function styleLint() { } let file = fs.createWriteStream(config.rep + 'sass-lint.html'); let stream = src(input.style) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(sassLint({ configFile: '.sasslintrc', files: { @@ -175,7 +177,7 @@ function code(cb) { sourcemaps: true, allowEmpty: true }), - plumber(), + catchErrors(), // cache('code'), // babel({ presets: ['@babel/env'] }), // concat(config.hippie.jsFile + 'main.js'), @@ -192,7 +194,7 @@ function code(cb) { // Linting function codeLint() { return src(input.code, { allowEmpty: true }) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(jshint()) .pipe(jshint.reporter('jshint-stylish')) .pipe(jshint.reporter('fail', { @@ -204,7 +206,7 @@ function codeLint() { // Fonts function fonts() { return src(input.fonts) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(dest(output.fonts)); } @@ -212,13 +214,13 @@ function fonts() { function art() { // Move favicons to the root folder let favicons = src(input.art.favicons) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(changed(output.art)) .pipe(dest(config.dev)); // Move images to the root folder let images = src(input.art.images) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(changed(output.art)) .pipe(dest(output.art)); @@ -227,7 +229,7 @@ function art() { // function art() { // // Move favicons and images to the root folder // return src(input.art.favicons) -// .pipe(plumber()) +// .pipe(catchErrors()) // .pipe(changed(config.dev)) // .pipe(dest(config.dev)) // .pipe(src(input.art.images)) @@ -239,7 +241,7 @@ function art() { function sprites() { // Assemble sprites let sprites = src(input.art.sprites) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(changed(output.art)) .pipe(spritesmith({ imgName: 'sprite.png', @@ -262,7 +264,7 @@ function sprites() { // Gather dependencies for tools function vendor() { return src(input.vendor) - .pipe(plumber()) + .pipe(catchErrors()) .pipe(dest(output.vendor)); }