Skip to content
This repository was archived by the owner on Jan 23, 2021. It is now read-only.

Commit 6e4d0e2

Browse files
committed
1 parent 6beee67 commit 6e4d0e2

File tree

7 files changed

+54
-73
lines changed

7 files changed

+54
-73
lines changed

.jshintrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
var fs = require('fs');
33
var path = require('path');
44
var Readable = require('stream').Readable;
5-
65
var assign = require('object-assign');
76
var convert = require('convert-source-map');
87
var dargs = require('dargs');
@@ -13,7 +12,6 @@ var osTmpdir = require('os-tmpdir');
1312
var pathExists = require('path-exists');
1413
var rimraf = require('rimraf');
1514
var spawn = require('cross-spawn-async');
16-
1715
var logger = require('./logger');
1816
var utils = require('./utils');
1917

@@ -28,9 +26,11 @@ var defaults = {
2826
emitCompileError: false
2927
};
3028

31-
function gulpRubySass (sources, options) {
29+
function gulpRubySass(sources, options) {
3230
var stream = new Readable({objectMode: true});
33-
stream._read = function () {}; // redundant but necessary
31+
32+
// redundant but necessary
33+
stream._read = function () {};
3434

3535
options = assign({}, defaults, options);
3636

@@ -53,7 +53,9 @@ function gulpRubySass (sources, options) {
5353
options.update = true;
5454

5555
// simplified handling of array sources, like gulp.src
56-
if (!Array.isArray(sources)) { sources = [sources]; }
56+
if (!Array.isArray(sources)) {
57+
sources = [sources];
58+
}
5759

5860
var matches = [];
5961
var bases = [];

logger.js

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var gutil = require('gulp-util');
33
var emitErr = require('./utils').emitErr;
44

55
// Remove intermediate directory for more Sass-like logging
6-
function prettifyDirectoryLogging (msg, intermediateDir) {
6+
function prettifyDirectoryLogging(msg, intermediateDir) {
77
return msg.replace(new RegExp(intermediateDir + '/?', 'g'), './');
88
}
99

@@ -17,23 +17,17 @@ logger.verbose = function (command, args) {
1717
};
1818

1919
logger.stdout = function (stream, intermediateDir, data) {
20-
// Bundler error: no Sass version found
2120
if (/bundler: command not found: sass/.test(data)) {
21+
// Bundler error: no Sass version found
2222
emitErr(stream, 'bundler: command not found: sass');
23-
}
24-
25-
// Bundler error: Gemfile not found
26-
else if (/Could not locate Gemfile or .bundle\/ directory/.test(data)) {
23+
} else if (/Could not locate Gemfile or .bundle\/ directory/.test(data)) {
24+
// Bundler error: Gemfile not found
2725
emitErr(stream, 'bundler: could not locate Gemfile or .bundle directory');
28-
}
29-
30-
// Sass error: directory missing
31-
else if (/No such file or directory @ rb_sysopen/.test(data)) {
26+
} else if (/No such file or directory @ rb_sysopen/.test(data)) {
27+
// Sass error: directory missing
3228
emitErr(stream, data.trim());
33-
}
34-
35-
// Not an error: Sass logging
36-
else {
29+
} else {
30+
// Not an error: Sass logging
3731
data = prettifyDirectoryLogging(data, intermediateDir);
3832
data = data.trim();
3933
gutil.log(data);
@@ -44,37 +38,29 @@ logger.stderr = function (stream, intermediateDir, data) {
4438
var bundlerMissing = /Could not find 'bundler' \((.*?)\)/.exec(data);
4539
var sassVersionMissing = /Could not find gem 'sass \((.*?)\) ruby'/.exec(data);
4640

47-
// Ruby error: Bundler gem not installed
4841
if (bundlerMissing) {
42+
// Ruby error: Bundler gem not installed
4943
emitErr(stream, 'ruby: Could not find \'bundler\' (' + bundlerMissing[1] + ').');
50-
}
51-
52-
// Bundler error: no matching Sass version
53-
else if (sassVersionMissing) {
44+
} else if (sassVersionMissing) {
45+
// Bundler error: no matching Sass version
5446
emitErr(stream, 'bundler: Could not find gem \'sass (' + sassVersionMissing[1] + ')\'.');
55-
}
56-
57-
// Sass error: file missing
58-
else if (/No such file or directory @ rb_sysopen/.test(data)) {
47+
} else if (/No such file or directory @ rb_sysopen/.test(data)) {
48+
// Sass error: file missing
5949
emitErr(stream, data.trim());
60-
}
61-
62-
// Not an error: Sass warnings, debug statements
63-
else {
50+
} else {
51+
// Not an error: Sass warnings, debug statements
6452
data = prettifyDirectoryLogging(data, intermediateDir);
6553
data = data.trim();
6654
gutil.log(data);
6755
}
6856
};
6957

7058
logger.error = function (stream, err) {
71-
// Spawn error: gems not installed
7259
if (err.code === 'ENOENT') {
60+
// Spawn error: gems not installed
7361
emitErr(stream, 'Gem ' + err.path + ' is not installed.');
74-
}
75-
76-
// Other errors
77-
else {
62+
} else {
63+
// Other errors
7864
emitErr(stream, err);
7965
}
8066
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"node": ">=0.10.0"
2121
},
2222
"scripts": {
23-
"test": "cd test && mocha test.js"
23+
"test": "xo && cd test && mocha test.js"
2424
},
2525
"files": [
2626
"index.js",
@@ -59,6 +59,7 @@
5959
"gulp": "^3.8.11",
6060
"gulp-sourcemaps": "^1.2.7",
6161
"mocha": "*",
62-
"vinyl-file": "^1.2.1"
62+
"vinyl-file": "^1.2.1",
63+
"xo": "*"
6364
}
6465
}

test/gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ var gulp = require('gulp');
33
var sass = require('../');
44
var sourcemaps = require('gulp-sourcemaps');
55

6-
gulp.task('sass', function() {
7-
return sass('source/**/*.scss', { verbose: true })
6+
gulp.task('sass', function () {
7+
return sass('source/**/*.scss', {verbose: true})
88
.on('error', sass.logError)
99
.pipe(sourcemaps.write())
1010
.pipe(gulp.dest('result'));

test/test.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
/* eslint-env mocha */
12
'use strict';
23
var path = require('path');
34
var assert = require('assert');
45
var assign = require('object-assign');
56
var pathExists = require('path-exists');
67
var rimraf = require('rimraf');
78
var vinylFile = require('vinyl-file');
8-
99
var sass = require('../');
1010

1111
var defaultOptions = {
1212
quiet: true,
13-
unixNewlines: true // normalize compilation results on Windows systems
13+
// normalize compilation results on Windows systems
14+
unixNewlines: true
1415
};
1516

1617
// load the expected result file from the compiled results directory
1718
var loadExpectedFile = function (relativePath, base) {
1819
base = base || 'result';
1920
var file = path.join(base, relativePath);
20-
return vinylFile.readSync(file, { base: base });
21+
return vinylFile.readSync(file, {base: base});
2122
};
2223

2324
var sortByRelative = function (a, b) {
24-
return a.relative.localeCompare(b.relative);
25+
return a.relative.localeCompare(b.relative);
2526
};
2627

2728
describe('single file', function () {
@@ -100,8 +101,7 @@ describe('multiple files', function () {
100101
file.contents.toString().indexOf(expectedError) !== -1,
101102
'The error file does not contain the expected message "' + expectedError + '".'
102103
);
103-
}
104-
else {
104+
} else {
105105
assert.deepEqual(
106106
file.contents.toString(),
107107
expected[i].contents.toString()
@@ -113,6 +113,7 @@ describe('multiple files', function () {
113113

114114
describe('array sources', function () {
115115
this.timeout(20000);
116+
116117
var files = [];
117118
var expected = [
118119
loadExpectedFile('file with spaces.css', 'result/directory with spaces'),
@@ -161,9 +162,13 @@ describe('concurrently run tasks', function () {
161162
var bFiles = [];
162163
var cFiles = [];
163164
var counter = 0;
165+
164166
var isDone = function (done) {
165167
counter++;
166-
if (counter === 3) { done(); }
168+
169+
if (counter === 3) {
170+
done();
171+
}
167172
};
168173

169174
before(function (done) {
@@ -201,8 +206,9 @@ describe('concurrently run tasks', function () {
201206

202207
describe('sourcemap', function () {
203208
this.timeout(20000);
209+
204210
var files = [];
205-
var options = assign({}, defaultOptions, { sourcemap: true });
211+
var options = assign({}, defaultOptions, {sourcemap: true});
206212

207213
before(function (done) {
208214
sass('source/file.scss', options)
@@ -287,7 +293,7 @@ describe('options', function () {
287293
var error;
288294

289295
before(function (done) {
290-
var options = assign({}, defaultOptions, { emitCompileError: true });
296+
var options = assign({}, defaultOptions, {emitCompileError: true});
291297

292298
sass('source/error.scss', options)
293299
.on('data', function () {})
@@ -313,7 +319,7 @@ describe('options', function () {
313319
loadExpectedFile('directory/file.css'),
314320
loadExpectedFile('file.css')
315321
];
316-
var options = assign({}, defaultOptions, { base: 'source' });
322+
var options = assign({}, defaultOptions, {base: 'source'});
317323

318324
before(function (done) {
319325
sass(['source/file.scss', 'source/directory/file.scss'], options)
@@ -352,7 +358,7 @@ describe('options', function () {
352358
it('compiles files to the specified directory', function (done) {
353359
var source = 'source/file.scss';
354360
var tempDir = './custom-temp-dir';
355-
var options = assign({}, defaultOptions, { tempDir: tempDir });
361+
var options = assign({}, defaultOptions, {tempDir: tempDir});
356362

357363
assert.equal(
358364
pathExists.sync(tempDir),
@@ -392,9 +398,11 @@ describe('caching', function () {
392398
var runtimeTwo = new Date() - endOne;
393399

394400
assert(
395-
runtimeOne > runtimeTwo + 50, // pad time to avoid potential intermittents
401+
// pad time to avoid potential intermittents
402+
runtimeOne > runtimeTwo + 50,
396403
'Compilation times were not decreased significantly. Caching may be broken.'
397404
);
405+
398406
done();
399407
});
400408
});

utils.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ var glob2base = require('glob2base');
55
var gutil = require('gulp-util');
66
var md5Hex = require('md5-hex');
77

8-
var utils = {};
9-
10-
utils.emitErr = function (stream, err) {
8+
exports.emitErr = function (stream, err) {
119
stream.emit('error', new gutil.PluginError('gulp-ruby-sass', err));
1210
};
1311

1412
// Create unique temporary directory path per task using cwd, options, sources,
1513
// and all matched files. Sourcemap option switching does not break Sass cache
1614
// so we do it ourselves. Possibly a bug: https://github.com/sass/sass/issues/1830
17-
utils.createIntermediatePath = function (sources, matches, options) {
15+
exports.createIntermediatePath = function (sources, matches, options) {
1816
return path.join(
1917
options.tempDir,
2018
'gulp-ruby-sass',
@@ -27,15 +25,13 @@ utils.createIntermediatePath = function (sources, matches, options) {
2725
);
2826
};
2927

30-
utils.calculateBase = function (source) {
28+
exports.calculateBase = function (source) {
3129
return glob2base(new glob.Glob(source));
3230
};
3331

34-
utils.replaceLocation = function (origPath, currentLoc, newLoc) {
32+
exports.replaceLocation = function (origPath, currentLoc, newLoc) {
3533
return path.join(
3634
newLoc,
3735
path.relative(currentLoc, origPath)
3836
);
3937
};
40-
41-
module.exports = utils;

0 commit comments

Comments
 (0)