theme for RDM site
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.4 KiB

2 years ago
//@format
const yaml = require('js-yaml');
const fs = require('fs');
2 years ago
const { SITE, PORT, BSREWRITE, PATHS } = loadConfig();
2 years ago
//var server = require('browser-sync').create();
//global.server = server;
const gulp = require('gulp');
const plumber = require('gulp-plumber');
const autoprefixer = require('gulp-autoprefixer');
const sass = require('gulp-sass')(require('sass'));
const browsersync = require('browser-sync').create();
const sourcemaps = require('gulp-sourcemaps');
2 years ago
2 years ago
function loadConfig() {
var ymlFile = fs.readFileSync('config.yml', 'utf8');
return yaml.load(ymlFile);
}
2 years ago
2 years ago
// BrowserSync
2 years ago
function bsInit__local(done) {
2 years ago
browsersync.init({
logLevel: 'debug',
2 years ago
//proxy: SITE.Local.Url,
proxy: 'https://rdm.lndo.site/',
2 years ago
});
done();
}
2 years ago
2 years ago
function bsInit__remote(done) {
browsersync.init({
2 years ago
logLevel: 'debug',
2 years ago
proxy: SITE.Remote.Url,
serveStatic: ['.'],
files: PATHS.Watch,
plugins: ['bs-rewrite-rules'],
rewriteRules: [
{
2 years ago
match: BSREWRITE.Css.Match,
replace: BSREWRITE.Css.Replace
2 years ago
},
{
match: BSREWRITE.Js.Match,
2 years ago
replace: BSREWRITE.Js.Replace
}
]
2 years ago
});
done();
}
2 years ago
2 years ago
// BrowserSync Reload
function bsReload(done) {
browsersync.reload();
done();
}
2 years ago
2 years ago
var cp = require('child_process');
function drush() {
return cp.exec('lando drush cr');
}
2 years ago
2 years ago
// Compile CSS
function styles() {
'use strict';
return gulp
//.src(PATHS.Scss.Dir + '/**/*.scss')
.src('./css/sass/**/*.scss')
2 years ago
.pipe(plumber())
2 years ago
.pipe(sourcemaps.init())
2 years ago
.pipe(
sass
.sync({
2 years ago
includePaths: PATHS.Scss.Libraries
2 years ago
})
2 years ago
.on('error', sass.logError)
2 years ago
)
2 years ago
.pipe(sourcemaps.write('.'))
//.pipe(gulp.dest(PATHS.Css.Dir))
.pipe(gulp.dest('./css'))
2 years ago
.pipe(browsersync.stream());
}
2 years ago
2 years ago
// Watch Files
function watchFiles() {
'use strict';
2 years ago
//gulp.watch(PATHS.Scss.Dir + '/**/*.scss', styles);
gulp.watch('css/sass/**/*.scss', styles);
2 years ago
gulp.watch('./templates/**/*.twig', drush);
}
2 years ago
2 years ago
// Group complex tasks
const build = gulp.parallel(styles);
2 years ago
const watch_remote = gulp.series(
styles,
gulp.parallel(watchFiles, bsInit__remote)
);
const watch_local = gulp.series(
styles,
gulp.parallel(watchFiles, bsInit__local)
);
2 years ago
2 years ago
// Export tasks
exports.build = build;
exports.styles = styles;
exports.drush = drush;
2 years ago
exports.watch = watch_remote;
exports.remote = watch_remote;
exports.local = watch_local;
exports.default = watch_remote;