Init
This commit is contained in:
167
Prefab.Web/wwwroot/template/sources/gulp/tasks.js
Normal file
167
Prefab.Web/wwwroot/template/sources/gulp/tasks.js
Normal file
@@ -0,0 +1,167 @@
|
||||
const gulp = require('gulp');
|
||||
const gulpTwig = require('gulp-twig');
|
||||
const gulpData = require('gulp-data');
|
||||
const gulpRename = require('gulp-rename');
|
||||
const gulpDartSass = require('gulp-dart-sass');
|
||||
const gulpSourcemaps = require('gulp-sourcemaps');
|
||||
const gulpAutoprefixer = require('gulp-autoprefixer');
|
||||
const gulpHtmlBeautify = require('gulp-html-beautify');
|
||||
const gulpCssNano = require('gulp-cssnano');
|
||||
const gulpIf = require('gulp-if');
|
||||
const gulpSvg = require('gulp-svg-sprite');
|
||||
const gulpAppendPrepend = require('gulp-append-prepend');
|
||||
const fancyLog = require('fancy-log');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mergeStream = require('merge-stream');
|
||||
|
||||
|
||||
/**
|
||||
* Compiles twig files to html
|
||||
*/
|
||||
function twig(options) {
|
||||
options = Object.assign({
|
||||
analytics: '',
|
||||
direction: 'ltr',
|
||||
}, typeof options !== 'undefined' ? options : {});
|
||||
|
||||
return gulp.src(['src/twig/pages/*'])
|
||||
.pipe(gulpData(() => {
|
||||
const result = {
|
||||
analytics: options.analytics,
|
||||
direction: options.direction,
|
||||
};
|
||||
const files = fs.readdirSync('src/data');
|
||||
|
||||
for (let file of files) {
|
||||
result[path.basename(file, '.json')] = JSON.parse(fs.readFileSync('src/data/'+file).toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}))
|
||||
.pipe(gulpTwig({base: 'src/twig/', data: gulpData}))
|
||||
.on('error', function (error) {
|
||||
fancyLog.error(error);
|
||||
this.emit('end');
|
||||
})
|
||||
.pipe(gulpRename(path => path.extname = '.html'))
|
||||
.pipe(gulpHtmlBeautify({indent_size: 4, max_preserve_newlines: 0}));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles scss files to css
|
||||
*/
|
||||
function scss(options) {
|
||||
options = Object.assign({
|
||||
production: false,
|
||||
theme: 'classic',
|
||||
pack: false,
|
||||
}, typeof options !== 'undefined' ? options : {});
|
||||
|
||||
let prependText = '//';
|
||||
|
||||
if (options.theme !== 'classic') {
|
||||
prependText = '@import "'+options.theme+'-theme";';
|
||||
}
|
||||
|
||||
let src = ['src/scss/style.scss'];
|
||||
|
||||
if (options.pack) {
|
||||
src.push('src/scss/style.ltr.scss');
|
||||
src.push('src/scss/style.rtl.scss');
|
||||
}
|
||||
|
||||
return gulp.src(src)
|
||||
.pipe(gulpIf(!options.production, gulpSourcemaps.init()))
|
||||
.pipe(gulpAppendPrepend.prependText(prependText))
|
||||
.pipe(gulpDartSass({
|
||||
outputStyle: 'expanded'
|
||||
}))
|
||||
.pipe(gulpAutoprefixer())
|
||||
.on('error', function (error) {
|
||||
fancyLog.error(error);
|
||||
this.emit('end');
|
||||
})
|
||||
.pipe(gulpIf(options.production, gulpCssNano()))
|
||||
.pipe(gulpIf(!options.production, gulpSourcemaps.write('./')))
|
||||
.pipe(gulpRename(path => path.dirname = `css/${path.dirname}`));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies vendor directory to dist directory
|
||||
*/
|
||||
function vendor() {
|
||||
const tasks = [
|
||||
gulp.src(['src/vendor/**/*']).pipe(gulpRename(path => path.dirname = `vendor/${path.dirname}`)),
|
||||
];
|
||||
|
||||
const modules = {
|
||||
'node_modules/@fortawesome/fontawesome-free/css/**/*': 'vendor/fontawesome/css',
|
||||
'node_modules/@fortawesome/fontawesome-free/webfonts/**/*': 'vendor/fontawesome/webfonts',
|
||||
'node_modules/@fortawesome/fontawesome-free/LICENSE.txt': 'vendor/fontawesome',
|
||||
'node_modules/jquery/dist/**/*': 'vendor/jquery',
|
||||
'node_modules/nouislider/dist/**/*': 'vendor/nouislider',
|
||||
'node_modules/owl.carousel/dist/**/*': 'vendor/owl-carousel',
|
||||
'node_modules/photoswipe/dist/**/*': 'vendor/photoswipe',
|
||||
'node_modules/svg4everybody/dist/**/*': 'vendor/svg4everybody',
|
||||
'node_modules/bootstrap/dist/**/*': 'vendor/bootstrap',
|
||||
};
|
||||
|
||||
for (let source in modules) {
|
||||
if (modules.hasOwnProperty(source)) {
|
||||
const dest = modules[source];
|
||||
|
||||
tasks.push(
|
||||
gulp.src(source).pipe(gulpRename(path => path.dirname = `${dest}/${path.dirname}`))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return mergeStream(...tasks);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies images to dist directory
|
||||
*/
|
||||
function images() {
|
||||
return gulp.src(['src/images/**/*'])
|
||||
.pipe(gulpRename(path => path.dirname = `images/${path.dirname}`));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles svg sprite
|
||||
*/
|
||||
function svg() {
|
||||
return gulp.src('src/svg/**/*.svg')
|
||||
.pipe(gulpSvg({
|
||||
mode: {
|
||||
symbol: {
|
||||
dest: '',
|
||||
sprite: 'sprite.svg',
|
||||
prefix: 'svg-%s'
|
||||
}
|
||||
}
|
||||
}))
|
||||
.pipe(gulpRename(path => path.dirname = `images/${path.dirname}`));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles js
|
||||
*/
|
||||
function js() {
|
||||
return gulp.src(['src/js/**/*'])
|
||||
.pipe(gulpRename(path => path.dirname = `js/${path.dirname}`));
|
||||
}
|
||||
|
||||
|
||||
exports.twig = twig;
|
||||
exports.scss = scss;
|
||||
exports.vendor = vendor;
|
||||
exports.images = images;
|
||||
exports.svg = svg;
|
||||
exports.js = js;
|
||||
Reference in New Issue
Block a user