pp-parachute
Version:
Airdrop JS Applications
52 lines (44 loc) • 1.57 kB
JavaScript
var inherits = require('util').inherits;
var path = require('path');
var Promise = require('bluebird');
var Bundler = require('./bundler');
var Sass = require('./compilers/sass_compiler');
var fs = require('fs');
var StyleBundler = function (assetGlobs, name) {
Bundler.call(this, assetGlobs, name);
};
inherits(StyleBundler, Bundler);
StyleBundler.prototype.bundle = function (filePaths) {
return Sass.compile(filePaths);
};
StyleBundler.prototype.getWatchGlobs = function () {
if (!Array.isArray(this.assetGlobs)) this.assetGlobs = [this.assetGlobs];
this.assetGlobs.push('!styles/sass_tmp_**');
return Bundler.prototype.getWatchGlobs.call(this);
};
StyleBundler.prototype.showBundleErrorHtml = function () {
var retn = "<pre>File: " + this.bundleError.path;
retn += "\nError:" + this.bundleError.error;
retn += "\n" + this.bundleError.line + "</pre>";
return retn;
};
module.exports = StyleBundler;
//some node modules have ruby files hidden in them that rails will try to auto load. dont let this happen
function removeRubyFiles(dirPath) {
try {
var files = fs.readdirSync(dirPath);
}
catch (e) {
// console.log(e.stack);
return;
}
for (var i = 0; i < files.length; i++) {
var filePath = dirPath + '/' + files[i];
if (fs.statSync(filePath).isFile() && path.extname(filePath) === '.rb') {
fs.unlinkSync(filePath);
} else {
removeRubyFiles(filePath);
}
}
}
removeRubyFiles(path.resolve(__dirname + '/../node_modules'));