broccoli-ruby-sass
Advanced tools
Comparing version 0.2.0 to 0.3.0
var compileSass = require('./index'); | ||
var pickFiles = require('broccoli-static-compiler'); | ||
var mergeTrees = require('broccoli-merge-trees'); | ||
module.exports = function(broccoli) { | ||
var tree = | ||
pickFiles('test/input', { | ||
srcDir: '/', | ||
destDir: '/' | ||
}); | ||
var tree = pickFiles('test/input', { | ||
srcDir: '/', | ||
destDir: '/' | ||
}); | ||
return compileSass([tree], 'splitbutton.scss', 'splitbutton.css', { | ||
outputStyle: 'expanded' | ||
}); | ||
}; | ||
var tree1 = compileSass(tree, 'splitbutton.scss', 'splitbutton.css', { | ||
outputStyle: 'expanded', | ||
sourceMap: 'none' | ||
}); | ||
var tree2 = compileSass(tree, 'loadpath_main.scss', 'loadpath_main.css', { | ||
outputStyle: 'expanded', | ||
sourceMap: 'none', | ||
loadPath: ['/loadpath'] | ||
}); | ||
module.exports = mergeTrees([tree1, tree2]); |
156
index.js
@@ -1,16 +0,17 @@ | ||
var fs = require('fs'); | ||
/* jshint node: true */ | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var includePathSearcher = require('include-path-searcher'); | ||
var quickTemp = require('quick-temp'); | ||
var mapSeries = require('promise-map-series'); | ||
var _ = require('lodash'); | ||
var Writer = require('broccoli-caching-writer'); | ||
var dargs = require('dargs'); | ||
var spawn = require('win-spawn'); | ||
var Promise = require('rsvp').Promise; | ||
var _ = require('lodash'); | ||
module.exports = SassCompiler; | ||
function SassCompiler (sourceTrees, inputFile, outputFile, options) { | ||
if (!(this instanceof SassCompiler)) return new SassCompiler(sourceTrees, inputFile, outputFile, options); | ||
this.sourceTrees = sourceTrees; | ||
SassCompiler.prototype = Object.create(Writer.prototype); | ||
SassCompiler.prototype.constructor = SassCompiler; | ||
function SassCompiler (inputTree, inputFile, outputFile, options) { | ||
if (!(this instanceof SassCompiler)) return new SassCompiler(inputTree, inputFile, outputFile, options); | ||
Writer.call(this, inputTree, options); | ||
this.inputFile = inputFile; | ||
@@ -23,92 +24,99 @@ this.outputFile = outputFile; | ||
sourceComments: options.sourceComments, | ||
sourcemap: options.sourceMap, | ||
sourcemap: options.sourceMap || 'none', | ||
bundleExec: options.bundleExec, | ||
require: options.require, | ||
loadPath: options.loadPath || [] | ||
loadPath: options.loadPath || [], | ||
precision: options.precision, | ||
unixNewlines: options.unixNewlines, | ||
cacheLocation: options.cacheLocation | ||
}; | ||
this.customArgs = options.customArgs || []; | ||
} | ||
SassCompiler.prototype.read = function (readTree) { | ||
var self = this; | ||
SassCompiler.prototype.updateCache = function (srcDir, destDir) { | ||
var bundleExec = this.sassOptions.bundleExec; | ||
quickTemp.makeOrRemake(this, '_tmpDestDir'); | ||
var destFile = this._tmpDestDir + '/' + this.outputFile; | ||
var destFile = destDir + '/' + this.outputFile; | ||
var includePaths = [srcDir]; | ||
mkdirp.sync(path.dirname(destFile)); | ||
return mapSeries(this.sourceTrees, readTree) | ||
.then(function (includePaths) { | ||
includePaths.unshift(path.dirname(self.inputFile)); | ||
self.sassOptions.loadPath = self.sassOptions.loadPath.concat(includePaths); | ||
var passedArgs = dargs(self.sassOptions, ['bundleExec']); | ||
var args = [ | ||
'sass', | ||
includePathSearcher.findFileSync(self.inputFile, includePaths), | ||
destFile | ||
].concat(passedArgs); | ||
if(bundleExec) { | ||
args.unshift('bundle', 'exec'); | ||
} | ||
includePaths.unshift(path.dirname(this.inputFile)); | ||
if(path.extname(self.inputFile) === '.css') { | ||
args.push('--scss'); | ||
} | ||
var loadPaths = this.sassOptions.loadPath; | ||
var loadPath = srcDir.map(function(dir){ | ||
return loadPaths.map(function(loadPath){ | ||
return path.join(dir, loadPath); | ||
}); | ||
}); | ||
loadPath = _.flatten(loadPath); | ||
loadPath = loadPath.concat(includePaths); | ||
loadPath = dargs({loadPath: loadPath}); | ||
var passedArgs = dargs(this.sassOptions, ['bundleExec', 'loadPath']); | ||
var args = [ | ||
'sass', | ||
includePathSearcher.findFileSync(this.inputFile, includePaths), | ||
destFile | ||
].concat(passedArgs).concat(this.customArgs).concat(loadPath); | ||
return new Promise(function(resolve, reject) { | ||
var cmd = args.shift(); | ||
var cp = spawn(cmd, args); | ||
if(bundleExec) { | ||
args.unshift('bundle', 'exec'); | ||
} | ||
function isWarning(error) { | ||
return /DEPRECATION WARNING/.test(error.toString()) || /WARNING:/.test(error.toString()); | ||
} | ||
if(path.extname(this.inputFile) === '.css') { | ||
args.push('--scss'); | ||
} | ||
cp.on('error', function(err) { | ||
if (isWarning(err)) { | ||
console.warn(err); | ||
return; | ||
} | ||
return new Promise(function(resolve, reject) { | ||
var cmd = args.shift(); | ||
var cp = spawn(cmd, args); | ||
console.error('[broccoli-ruby-sass] '+ err); | ||
reject(err); | ||
}); | ||
function isWarning(error) { | ||
return /DEPRECATION WARNING/.test(error.toString()) || /WARNING:/.test(error.toString()); | ||
} | ||
var errors = ''; | ||
cp.on('error', function(err) { | ||
if (isWarning(err)) { | ||
console.warn(err); | ||
return; | ||
} | ||
cp.on('data', function(data) { | ||
// ignore deprecation warnings | ||
console.error('[broccoli-ruby-sass] '+ err); | ||
reject(err); | ||
}); | ||
if (isWarning(err)) { | ||
console.warn(err); | ||
return; | ||
} | ||
var errors = ''; | ||
errors += data; | ||
}); | ||
cp.on('data', function(data){ | ||
// ignore deprecation warnings | ||
cp.stderr.on('data', function(data) { | ||
if (!isWarning(data)) { | ||
errors += data; | ||
} else { | ||
console.warn('[broccoli-ruby-sass] ' + data); | ||
} | ||
}); | ||
if (isWarning(data)) { | ||
console.warn(data); | ||
return; | ||
} | ||
cp.on('close', function(code) { | ||
if(errors) { | ||
reject(errors); | ||
} | ||
errors += data; | ||
}); | ||
if(code > 0) { | ||
reject('broccoli-ruby-sass exited with error code ' + code); | ||
} | ||
cp.stderr.on('data', function(data) { | ||
if (!isWarning(data)) { | ||
errors += data; | ||
} else { | ||
console.warn('[broccoli-ruby-sass] ' + data); | ||
} | ||
}); | ||
resolve(self._tmpDestDir); | ||
}); | ||
cp.on('close', function(code) { | ||
if(errors) { | ||
reject(errors); | ||
} | ||
return self._tmpDestDir; | ||
}); | ||
if(code > 0) { | ||
reject('broccoli-ruby-sass exited with error code ' + code); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
SassCompiler.prototype.cleanup = function () { | ||
quickTemp.remove(this, '_tmpDestDir'); | ||
}; | ||
module.exports = SassCompiler; |
{ | ||
"name": "broccoli-ruby-sass", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Broccoli plugin that compiles Sass using the Ruby-based compiler", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha test/broccoli-ruby-sass-test.js" | ||
"test": "mocha test" | ||
}, | ||
@@ -31,19 +31,22 @@ "repository": { | ||
"devDependencies": { | ||
"rsvp": "^3.0.6", | ||
"broccoli": "^0.13.2", | ||
"broccoli-merge-trees": "^0.2.1", | ||
"chai": "^1.9.1", | ||
"chai-as-promised": "^4.1.1", | ||
"mocha": "^1.18.2", | ||
"broccoli": "^0.7.1" | ||
"rsvp": "^3.0.6" | ||
}, | ||
"dependencies": { | ||
"broccoli": "^0.13.2", | ||
"broccoli-caching-writer": "^0.5.2", | ||
"broccoli-static-compiler": "^0.1.4", | ||
"dargs": "^2.0.0", | ||
"include-path-searcher": "^0.1.0", | ||
"lodash": "^2.4.1", | ||
"mkdirp": "^0.3.5", | ||
"promise-map-series": "^0.2.0", | ||
"quick-temp": "^0.1.0", | ||
"promise-map-series": "^0.2.0", | ||
"dargs": "^0.1.0", | ||
"win-spawn": "^2.0.0", | ||
"include-path-searcher": "^0.1.0", | ||
"lodash": "^2.4.1", | ||
"broccoli-static-compiler": "^0.1.2", | ||
"rsvp": "^3.0.6" | ||
"rsvp": "^3.0.6", | ||
"win-spawn": "^2.0.0" | ||
} | ||
} |
@@ -7,2 +7,3 @@ var RSVP = require('rsvp'); | ||
var broccoli = require('broccoli'); | ||
var path = require('path'); | ||
@@ -18,10 +19,5 @@ chai.use(chaiAsPromised); | ||
function build() { | ||
return new RSVP.Promise(function(resolve) { | ||
var tree = broccoli.loadBrocfile(); | ||
var builder = new broccoli.Builder(tree); | ||
return builder.build().then(function(dir) { | ||
// TODO: If I don't do this, the file built does not exist to node, huh? | ||
setTimeout(resolve.bind(null, dir), 750); | ||
}); | ||
}); | ||
var tree = broccoli.loadBrocfile(); | ||
var builder = new broccoli.Builder(tree); | ||
return builder.build(); | ||
} | ||
@@ -31,3 +27,3 @@ | ||
return build().then(function(dir) { | ||
builtTo = dir; | ||
builtTo = dir.directory; | ||
}); | ||
@@ -37,4 +33,3 @@ }); | ||
it('compiles templates with @extend', function() { | ||
var actualPath = require('path').resolve('./' + builtTo + '/splitbutton.css'); | ||
console.log(actualPath); | ||
var actualPath = require('path').resolve(builtTo + '/splitbutton.css'); | ||
var readActual = readFile.bind(null, actualPath); | ||
@@ -50,2 +45,14 @@ var readExpected = readFile.bind(null, './test/output/splitbutton.css'); | ||
it("uses the load path correctly, e.g. doesn't look up in file system root", function(){ | ||
var actualPath = require('path').resolve(builtTo + '/loadpath_main.css'); | ||
var readActual = readFile.bind(null, actualPath); | ||
var readExpected = readFile.bind(null, './test/output/loadpath_main.css'); | ||
return RSVP.all([readActual(), readExpected()]).then(function(result) { | ||
var actual = result[0].toString(), expected = result[1].toString(); | ||
assert(actual, 'actual is undefined'); | ||
assert(expected, 'expected is undefined'); | ||
assert.equal(actual, expected); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
10112
12
188
1
120
1
11
6
1
+ Addedbroccoli@^0.13.2
+ Addedamdefine@1.0.1(transitive)
+ Addedasync@0.2.10(transitive)
+ Addedbody-parser@1.8.4(transitive)
+ Addedbroccoli@0.13.6(transitive)
+ Addedbroccoli-caching-writer@0.5.5(transitive)
+ Addedbroccoli-slow-trees@1.1.0(transitive)
+ Addedbytes@1.0.0(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedconnect@3.7.0(transitive)
+ Addedcopy-dereference@1.0.0(transitive)
+ Addedcore-object@0.0.3(transitive)
+ Addeddargs@2.1.0(transitive)
+ Addeddebug@2.0.02.6.9(transitive)
+ Addeddepd@0.4.5(transitive)
+ Addedee-first@1.0.51.1.1(transitive)
+ Addedencodeurl@1.0.2(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedfaye-websocket@0.7.3(transitive)
+ Addedfinalhandler@1.1.2(transitive)
+ Addedfindup-sync@0.1.3(transitive)
+ Addedglob@3.2.11(transitive)
+ Addedhandlebars@2.0.0(transitive)
+ Addedhttp-parser-js@0.5.8(transitive)
+ Addediconv-lite@0.4.4(transitive)
+ Addedlivereload-js@2.4.0(transitive)
+ Addedlodash-node@2.4.1(transitive)
+ Addedlru-cache@2.7.3(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.12.0(transitive)
+ Addedmime-types@2.0.14(transitive)
+ Addedminimatch@0.3.0(transitive)
+ Addedms@0.6.22.0.0(transitive)
+ Addedon-finished@2.1.02.3.0(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedqs@2.2.42.2.5(transitive)
+ Addedraw-body@1.3.0(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsigmund@1.0.1(transitive)
+ Addedsource-map@0.1.43(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedsymlink-or-copy@1.3.1(transitive)
+ Addedtiny-lr@0.1.7(transitive)
+ Addedtype-is@1.5.7(transitive)
+ Addeduglify-js@2.3.6(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addedwebsocket-driver@0.7.4(transitive)
+ Addedwebsocket-extensions@0.1.4(transitive)
+ Addedwordwrap@0.0.3(transitive)
- Removeddargs@0.1.0(transitive)
Updateddargs@^2.0.0