-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aurelien Gaillard
committed
Sep 16, 2020
1 parent
7ef2531
commit a8bb017
Showing
7 changed files
with
7,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.