var autoprefixer = require('autoprefixer'),
gulp = require('gulp'),
gulpif = require('gulp-if'),
postcss = require('gulp-postcss'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
watch = require('gulp-watch'),
minimist = require('minimist'),
replace = require("replace"),
browsersync = require('browser-sync').create(),
config = {
cssPath: './css',
fontsPath: './font',
imgPath: './img',
jsPath: './js',
sassSources: ['scss/style.scss'],
sassBasePath: './scss',
sassWatchPaths: [
'./scss/**/*.scss'
],
},
knownOptions = {
string: 'env',
default: {env: process.env.NODE_ENV || 'development'}
},
options = minimist(process.argv.slice(2), knownOptions);
// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function () {
return gulp.src(config.sassSources)
.pipe(gulpif(options.env !== 'production', sourcemaps.init()))
.pipe(sass({
outputStyle: gulpif(options.env !== 'production', 'nested', 'compressed'),
includePaths: [
config.sassBasePath,
config.sassBasePath + '/environment/' + options.env,
]
})
.on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulpif(options.env !== 'production', sourcemaps.write('./maps')))
.pipe(gulp.dest(config.cssPath))
.pipe(browsersync.reload({ stream: true }));
});
// Copy the javascript files into our js folder
gulp.task('js-copy', function () {
return gulp.src([
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js.map',
'node_modules/popper.js/dist/umd/popper.min.js',
'node_modules/popper.js/dist/umd/popper.min.js.map'
])
.pipe(gulp.dest(config.jsPath));
});
// Patch the javascript files
gulp.task('js-patch', function(done) {
done();
});
// Copy and patch the javascript files
gulp.task('js', gulp.series('js-copy', 'js-patch'));
// Move the img files into our img folder
gulp.task('img', function () {
});
// Move the font files into our font folder
gulp.task('fonts', function () {
});
// Static Server + watching scss/html files
gulp.task('watch', function () {
browsersync.init({
proxy: 'apache',
socket: {
domain: 'bs-' + process.env.DOCKER4DRUPAL_NODE_DOMAIN + process.env.DOCKER4DRUPAL_NODE_PORT
},
open: false,
callbacks: {
ready: function(err, bs) {
console.log(' Docker:');
console.log(' Site: ' + process.env.DOCKER4DRUPAL_NODE_SCHEMA + '://bs-' + process.env.DOCKER4DRUPAL_NODE_DOMAIN + process.env.DOCKER4DRUPAL_NODE_PORT);
console.log(' UI: ' + process.env.DOCKER4DRUPAL_NODE_SCHEMA + '://bsui-' + process.env.DOCKER4DRUPAL_NODE_DOMAIN + process.env.DOCKER4DRUPAL_NODE_PORT);
console.log(' -----------------------------------');
}
}
});
return watch(config.sassWatchPaths, {verbose: true}, gulp.parallel('sass'));
});
gulp.task('default', gulp.parallel('fonts', 'img', 'js', 'sass', 'watch'));