Skip to content

Commit

Permalink
files added
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien Gaillard committed Sep 16, 2020
1 parent 7ef2531 commit a8bb017
Show file tree
Hide file tree
Showing 7 changed files with 7,085 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Windows generated files
Thumbs.db
desktop.ini

# OS X Generated files
.DS_Store
.Spotlight-V100
.Trashes
._*

# VS Code Settings
.vscode/*

# Node.js modules
node_modules/

# Project build
dist
141 changes: 141 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// load modules
const gulp = require('gulp');
const del = require('del');
const fs = require('fs');
const browsersync_server = require('browser-sync').create();
const htmlmin = require('gulp-htmlmin');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const csso = require('gulp-csso');
const sourcemaps = require('gulp-sourcemaps');

// creates default src folder structure
function createStructure(done) {
const folders = [
'dist',
'src',
'src/fonts',
'src/img',
'src/scss',
];
const files = [
'src/index.html',
];

folders.forEach(dir => {
if(!fs.existsSync(dir)) {
fs.mkdirSync(dir);
console.log('folder created:', dir);
}
});

files.forEach(file => {
if(!fs.existsSync(file)) {
fs.writeFileSync(file, '');
console.log('file created:', file);
}
});

return done();
}

// deletes all assets (HTML, fonts, images) in dist
function cleanAssets(done) {
return del(
['dist/**/*.html', 'dist/fonts/**/*', 'dist/img/**/*'],
{ force: true }
);
}

// publish HTML files src into dist
function publishHtml(done, for_production = false) {
let pipeline = gulp.src('src/**/*.html');

if (for_production) {
pipeline.pipe(htmlmin({ collapseWhitespace: true }));
}

return pipeline.pipe(gulp.dest('dist'));
}

// publish HTML for production
function publishHtmlProduction(done) {
return publishHtml(done, true);
}

// publish HTML for development
function publishHtmlDevelopment(done) {
return publishHtml(done, false);
}

// Copy all fonts from src/fonts into dist
function publishFonts(done) {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
}

// Copy all images from src/img into dist
function publishImages(done) {
return gulp.src('src/img/**/*')
.pipe(gulp.dest('dist/img'));
}

// compile SCSS files
function compileScss(done, for_production = false) {
let pipeline = gulp.src('src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))

if (for_production) {
pipeline.pipe(autoprefixer({
overrideBrowserslist: [
"last 2 version",
"> 2%"
],
cascade: false
}))
.pipe(csso());
}

return pipeline.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'));
}

function compileScssProduction(done) {
return compileScss(done, true);
}

function compileScssDevelopment(done) {
return compileScss(done, false);
}

// watch files
function watchFiles(done) {
gulp.watch("src/**/*.html", gulp.series(publishHtml, reload));
gulp.watch("src/fonts/**/*", gulp.series(publishFonts, reload));
gulp.watch("src/img/**/*", gulp.series(publishImages, reload));
gulp.watch("src/scss/**/*.scss", gulp.series(compileScss, reload));
}

// browserSync server
function serve(done) {
browsersync_server.init({
server: {
baseDir: './dist/'
}
});
done();
}

// browserSync reload
function reload(done) {
browsersync_server.reload();
done();
}

// export tasks
exports.structure = createStructure;
exports.publish = gulp.series(cleanAssets, publishHtml, publishFonts, publishImages);
exports.build = gulp.series(cleanAssets, publishHtmlProduction, publishFonts, publishImages, compileScssProduction);
exports.build_dev = gulp.series(cleanAssets, publishHtmlDevelopment, publishFonts, publishImages, compileScssDevelopment);
exports.watch = gulp.series(cleanAssets, publishHtmlDevelopment, publishFonts, publishImages, compileScssDevelopment, serve, watchFiles);
Loading

0 comments on commit a8bb017

Please sign in to comment.