Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use promises in styleguide.js, use named functions instead of comments, general readability improvements #193

Merged
merged 4 commits into from
Nov 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ gulp.task('styleguide', function() {
if (!fs.existsSync(__dirname + distPath)) {
process.stderr.write(chalk.red.bold('Error:') + ' Directory ' + distPath + ' does not exist. You probably installed library by cloning repository directly instead of NPM repository.\n');
process.stderr.write('You need to run ' + chalk.green.bold('gulp build') + ' first\n');
process.exit(1)
process.exit(1);
return 1;
}
return gulp.src([sourcePath + '/**/*.scss'])
Expand Down Expand Up @@ -102,7 +102,8 @@ gulp.task('sass', function() {
.pipe(plumber())
.pipe(sass({
// Include bourbon & neat
includePaths: neat.includePaths
includePaths: neat.includePaths,
errLogToConsole: true
}))
.pipe(sourcemaps.init())
.pipe(please({
Expand Down
28 changes: 11 additions & 17 deletions lib/modules/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ module.exports = function(ioServer, options) {

var loadVariables,
saveVariables,
reloadStyles,
currentSocket,
emitProgressStart,
emitProgressEnd,
emitCompileError,
emitCompileSuccess,
io = ioServer;

if (options.styleVariables && !fs.existsSync(options.styleVariables)) {
Expand All @@ -21,9 +15,8 @@ module.exports = function(ioServer, options) {

loadVariables = function(socket) {
return function() {
var syntax = path.extname(options.styleVariables).substring(1);
var values, syntax = path.extname(options.styleVariables).substring(1);
fs.readFile(options.styleVariables, {encoding: 'utf8'}, function(err, data) {
var values = {};
if (err) {
return console.error(err);
}
Expand All @@ -50,21 +43,23 @@ module.exports = function(ioServer, options) {
};
};

emitProgressStart = function() {
function emitProgressStart() {
io.sockets.emit('styleguide progress start');
};
}

emitProgressEnd = function() {
function emitProgressEnd() {
io.sockets.emit('styleguide progress end');
};
}

emitCompileError = function(err) {
function emitCompileError(err) {
io.sockets.emit('styleguide compile error', err);
};
emitProgressEnd();
}

emitCompileSuccess = function() {
function emitCompileSuccess() {
io.sockets.emit('styleguide compile success');
};
emitProgressEnd();
}

io.on('connection', function(socket) {
console.log('Socket connection established (id:', socket.conn.id + ')');
Expand All @@ -74,7 +69,6 @@ module.exports = function(ioServer, options) {

return {
emitProgressStart: emitProgressStart,
emitProgressEnd: emitProgressEnd,
emitCompileError: emitCompileError,
emitCompileSuccess: emitCompileSuccess
}
Expand Down
36 changes: 8 additions & 28 deletions lib/modules/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,24 @@ var concat = require('gulp-concat'),
filter = require('gulp-filter'),
less = require('gulp-less'),
sass = require('gulp-sass'),
vfs = require('vinyl-fs'),
_ = require('lodash'),
proxyOnce = function(obj, key, fn) {
var original = obj[key];
obj[key] = function proxy() {
var args = Array.prototype.slice.call(arguments);
if (_.isFunction(fn)) {
fn.apply(undefined, args);
}
if (_.isFunction(original)) {
original.apply(undefined, args);
}
obj[key] = original;
}
};
vfs = require('vinyl-fs');

module.exports = {
// Processes all SASS/LESS/CSS files and combine to a single file
getStream: function(files, opt) {
var sassStream,
lessStream,
cssStream;

proxyOnce(opt.sass, 'onError', opt.onCompileError);
proxyOnce(opt.sass, 'onSuccess', opt.onCompileSuccess);
/**
* Process all SASS/LESS/CSS files and combine them into a single stream
*/
getStream: function(files, opt, errback) {
var sassStream, lessStream, cssStream;

sassStream = vfs.src(opt.sass.src || files)
.pipe(filter('**/*.scss'))
.pipe(sass(opt.sass))
.pipe(sass(opt.sass).on('error', errback))
.pipe(concat('sass.css'));

lessStream = vfs.src(opt.less.src || files)
.pipe(filter('**/*.less'))
.pipe(less(opt.less))
.on('error', function(err) {
console.error('An error occurred when compiling LESS');
console.error(err.toString());
})
.pipe(less(opt.less).on('error', errback))
.pipe(concat('less.css'));

cssStream = vfs.src(files)
Expand Down
Loading