Skip to content

Commit

Permalink
Add themes task to gulpfile
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Oct 14, 2017
1 parent 132f55d commit 1f65e0e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions config/gulp-tasks/themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const path = require('path');
const gulp = require('gulp');
const pump = require('pump');
const sass = require('node-sass');
const through = require('through2');
const gulpUtil = require('gulp-util');
const helpers = require('../helpers');

const cssnano = require('cssnano');
const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
const stripInlineComments = require('postcss-strip-inline-comments');


const config = {
themesDir: helpers.root('src/styles/themes/**/*.scss'),
stylesDir: helpers.root('src/styles/share-buttons.scss'),
themesOutputDir: helpers.root('dist/styles/themes'),
stylesOutputDir: helpers.root('dist/styles')
};

const compileThemes = () => {
return through.obj((file, encoding, callback) => {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new gulpUtil.PluginError('compileThemes', 'Streaming not supported'));
}
if (path.basename(file.path).startsWith('_')) {
return cb();
}
if (!file.contents.length) {
file.path = gulpUtil.replaceExtension(file.path, '.css');
return cb(null, file);
}

/**
* Remove comments, autoprefixer, Minifier
*/
let processors = [
stripInlineComments,
autoprefixer,
cssnano
];
if (/\.(scss|sass)$/.test(path.extname(file.path))) {
let sassObj = sass.renderSync({ file: file.path });
if (sassObj && sassObj['css']) {
let css = sassObj.css.toString('utf8');
postcss(processors).process(css).then(function (result) {
result.warnings().forEach(function (warn) {
gulpUtil.warn(warn.toString());
});
file.contents = new Buffer(result.css);
file.path = gulpUtil.replaceExtension(file.path, '.css');
callback(null, file);
});
}
}

});
};

gulp.task('themes', (cb) => {

pump(
[
gulp.src(config.themesDir),
compileThemes(),
gulp.dest(config.themesOutputDir),
gulp.src(config.stylesDir),
compileThemes(),
gulp.dest(config.stylesOutputDir)
],
cb);
});
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ gulp.task('compile', (cb) => {

// Build the 'dist' folder (without publishing it to NPM)
gulp.task('build', ['clean'], (cb) => {
runSequence('compile', 'test', 'npm-package', 'rollup-bundle', cb);
runSequence('compile', 'test', 'npm-package', 'rollup-bundle', 'themes', cb);
});

// Same as 'build' but without cleaning temp folders (to avoid breaking demo app, if currently being served)
Expand Down

0 comments on commit 1f65e0e

Please sign in to comment.