require to import

exports are not working
This commit is contained in:
Stephan Hagedorn 2022-08-11 08:41:39 +02:00
parent f7a5481fd2
commit da075e5beb
7 changed files with 69 additions and 72 deletions

View file

@ -1,4 +1,4 @@
const plumber = require('gulp-plumber'); import plumber from 'gulp-plumber';
// const notify = require('gulp-notify'); // const notify = require('gulp-notify');
// function catchErrors(errTitle) { // function catchErrors(errTitle) {
@ -11,7 +11,7 @@ const plumber = require('gulp-plumber');
// }); // });
// } // }
function catchErrors() { export function catchErrors() {
return plumber({ return plumber({
errorHandler: function (err) { errorHandler: function (err) {
// Logs error in console // Logs error in console
@ -20,6 +20,5 @@ function catchErrors() {
this.emit('end'); this.emit('end');
} }
}); });
}
module.exports = catchErrors; }

View file

@ -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;

8
gulp/tasks/clean.mjs Normal file
View file

@ -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 + '**']);
}

View file

@ -1,16 +1,17 @@
const config = require('../config'); import config from '../config.js';
// const browserSync = require('browser-sync'), server = browserSync.create(); // 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 // Automagically reload browsers
function reload(done) { export function reload(done) {
server.reload; server.reload;
done(); done();
} }
// Serve files to the browser // Serve files to the browser
function serve(done) { export function serve(done) {
server.init({ server.init({
index: config.index, index: config.index,
open: false, open: false,
@ -19,8 +20,3 @@ function serve(done) {
done(); done();
} }
module.exports = {
serve: serve,
reload: reload
};

View file

@ -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;

14
gulp/tasks/validate.mjs Normal file
View file

@ -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;

View file

@ -2,43 +2,45 @@
// const hippie = require('hippie/hippie'); // const hippie = require('hippie/hippie');
// Setup project // Setup project
const config = require('./gulp/config'); import config from './gulp/config.js';
const hello = require('./gulp/tasks/hello'); import hello from './gulp/tasks/hello.js';
const plumber = require('./gulp/modules/plumber'); import { catchErrors } from './gulp/modules/plumber.mjs';
const { serve, reload } = require('./gulp/tasks/sync'); import { serve, reload } from './gulp/tasks/sync.mjs';
const clean = require('./gulp/tasks/clean'); import { clean } from './gulp/tasks/clean.mjs';
// const validate = require("./gulp/tasks/validate"); // const validate = require("./gulp/tasks/validate");
// Gulp requirements // Gulp requirements
const { watch, series, parallel } = require('gulp'); import gulp from 'gulp';
const { src, dest } = require('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 nunjucks = require('gulp-nunjucks');
const data = require('gulp-data'); import data from 'gulp-data';
const jsonConcat = require('gulp-json-concat'); import jsonConcat from 'gulp-json-concat';
const sass = require('gulp-sass')(require('sass')); import dartSass from 'sass';
const autoprefixer = require('gulp-autoprefixer'); import gulpSass from 'gulp-sass';
const sassLint = require('gulp-sass-lint'); const sass = gulpSass(dartSass);
const rename = require('gulp-rename'); import autoprefixer from 'gulp-autoprefixer';
const cleanCss = require('gulp-clean-css'); import sassLint from 'gulp-sass-lint';
const pump = require('pump'); import rename from 'gulp-rename';
const cached = require('gulp-cached'); import cleanCss from 'gulp-clean-css';
import pump from 'pump';
import cached from 'gulp-cached';
// const remember = require('gulp-remember'); // const remember = require('gulp-remember');
// const concat = require('gulp-concat'); // const concat = require('gulp-concat');
const uglify = require('gulp-uglify'); import uglify from 'gulp-uglify';
const jshint = require('gulp-jshint'); import jshint from 'gulp-jshint';
const gulpIf = require('gulp-if'); import gulpIf from 'gulp-if';
const changed = require('gulp-changed'); import changed from 'gulp-changed';
const merge = require('merge-stream'); import merge from 'merge-stream';
const spritesmith = require('gulp.spritesmith'); import spritesmith from 'gulp.spritesmith';
// const babel = require('gulp-babel'); // const babel = require('gulp-babel');
// const buffer = require('vinyl-buffer'); // const buffer = require('vinyl-buffer');
// const imagemin = require('gulp-imagemin'); // const imagemin = require('gulp-imagemin');
const useref = require('gulp-useref'); import useref from 'gulp-useref';
// Data variables // Data variables
const input = { const input = {
@ -86,7 +88,7 @@ if (config.demo === true) {
// Concatenate JSON files // Concatenate JSON files
function json() { function json() {
return src(config.frontendData) return src(config.frontendData)
.pipe(plumber()) .pipe(catchErrors())
.pipe(jsonConcat('db.json', function (data) { .pipe(jsonConcat('db.json', function (data) {
return new Buffer.from(JSON.stringify(data)); return new Buffer.from(JSON.stringify(data));
})) }))
@ -115,7 +117,7 @@ function getDataForTemplates() {
// Transpile HTML // Transpile HTML
function nunjucks() { function nunjucks() {
return src(input.screens) return src(input.screens)
.pipe(plumber()) .pipe(catchErrors())
// TODO only add data to pipe for necessary files // TODO only add data to pipe for necessary files
.pipe(data(getDataForTemplates)) .pipe(data(getDataForTemplates))
.pipe(nunjucksRender({ .pipe(nunjucksRender({
@ -131,7 +133,7 @@ function nunjucks() {
// This is for the looks // This is for the looks
function style() { function style() {
return src(input.style) return src(input.style)
.pipe(plumber()) .pipe(catchErrors())
// .pipe(sass.sync({ // .pipe(sass.sync({
.pipe(sass({ .pipe(sass({
includePaths: [input.vendor + '/**/*.s+(a|c)ss'] includePaths: [input.vendor + '/**/*.s+(a|c)ss']
@ -152,7 +154,7 @@ function styleLint() {
} }
let file = fs.createWriteStream(config.rep + 'sass-lint.html'); let file = fs.createWriteStream(config.rep + 'sass-lint.html');
let stream = src(input.style) let stream = src(input.style)
.pipe(plumber()) .pipe(catchErrors())
.pipe(sassLint({ .pipe(sassLint({
configFile: '.sasslintrc', configFile: '.sasslintrc',
files: { files: {
@ -175,7 +177,7 @@ function code(cb) {
sourcemaps: true, sourcemaps: true,
allowEmpty: true allowEmpty: true
}), }),
plumber(), catchErrors(),
// cache('code'), // cache('code'),
// babel({ presets: ['@babel/env'] }), // babel({ presets: ['@babel/env'] }),
// concat(config.hippie.jsFile + 'main.js'), // concat(config.hippie.jsFile + 'main.js'),
@ -192,7 +194,7 @@ function code(cb) {
// Linting // Linting
function codeLint() { function codeLint() {
return src(input.code, { allowEmpty: true }) return src(input.code, { allowEmpty: true })
.pipe(plumber()) .pipe(catchErrors())
.pipe(jshint()) .pipe(jshint())
.pipe(jshint.reporter('jshint-stylish')) .pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail', { .pipe(jshint.reporter('fail', {
@ -204,7 +206,7 @@ function codeLint() {
// Fonts // Fonts
function fonts() { function fonts() {
return src(input.fonts) return src(input.fonts)
.pipe(plumber()) .pipe(catchErrors())
.pipe(dest(output.fonts)); .pipe(dest(output.fonts));
} }
@ -212,13 +214,13 @@ function fonts() {
function art() { function art() {
// Move favicons to the root folder // Move favicons to the root folder
let favicons = src(input.art.favicons) let favicons = src(input.art.favicons)
.pipe(plumber()) .pipe(catchErrors())
.pipe(changed(output.art)) .pipe(changed(output.art))
.pipe(dest(config.dev)); .pipe(dest(config.dev));
// Move images to the root folder // Move images to the root folder
let images = src(input.art.images) let images = src(input.art.images)
.pipe(plumber()) .pipe(catchErrors())
.pipe(changed(output.art)) .pipe(changed(output.art))
.pipe(dest(output.art)); .pipe(dest(output.art));
@ -227,7 +229,7 @@ function art() {
// function art() { // function art() {
// // Move favicons and images to the root folder // // Move favicons and images to the root folder
// return src(input.art.favicons) // return src(input.art.favicons)
// .pipe(plumber()) // .pipe(catchErrors())
// .pipe(changed(config.dev)) // .pipe(changed(config.dev))
// .pipe(dest(config.dev)) // .pipe(dest(config.dev))
// .pipe(src(input.art.images)) // .pipe(src(input.art.images))
@ -239,7 +241,7 @@ function art() {
function sprites() { function sprites() {
// Assemble sprites // Assemble sprites
let sprites = src(input.art.sprites) let sprites = src(input.art.sprites)
.pipe(plumber()) .pipe(catchErrors())
.pipe(changed(output.art)) .pipe(changed(output.art))
.pipe(spritesmith({ .pipe(spritesmith({
imgName: 'sprite.png', imgName: 'sprite.png',
@ -262,7 +264,7 @@ function sprites() {
// Gather dependencies for tools // Gather dependencies for tools
function vendor() { function vendor() {
return src(input.vendor) return src(input.vendor)
.pipe(plumber()) .pipe(catchErrors())
.pipe(dest(output.vendor)); .pipe(dest(output.vendor));
} }