Permalink
Browse files

Merge pull request #244 from vicapow/master

show meaningful less errors
  • Loading branch information...
mikermcneil committed Mar 21, 2013
2 parents 707970d + d2e7ea4 commit 744eea5820c0163523b55324e43a2373c6f6e1b8
Showing with 38 additions and 55 deletions.
  1. +37 −53 lib/assets.js
  2. +1 −2 package.json
View
@@ -14,7 +14,6 @@ var fs = require('fs');
var cleancss = require('clean-css');
var async = require('async');
var uglify = require('uglify-js');
-var less = require('less');
var isProduction = sails.config.environment === 'production';
var JavascriptAsset = rack.Asset.extend({
@@ -34,25 +33,23 @@ var JavascriptAsset = rack.Asset.extend({
});
} else if (path.indexOf('.ts') != -1) {
var tsc = require('node-typescript');
-
- var jscode = null;
- try {
- jscode = tsc.compile(path, fs.readFileSync(path, 'utf8'));
- } catch(e) {
- jscode = '';
- }
-
+ var jscode = null;
+ try {
+ jscode = tsc.compile(path, fs.readFileSync(path, 'utf8'));
+ } catch(e) {
+ jscode = '';
+ }
asset = new rack.Asset({
mimetype: 'text/javascript',
url: '/' + pathutil.relative(sails.config.appPath, path).replace('.ts', '.js').replace(/\\/g, '/'),
contents: jscode
});
} else {
- asset = new rack.Asset({
- mimetype: 'text/javascript',
- url: '/' + pathutil.relative(sails.config.appPath, path).replace(/\\/g, '/'),
- contents: fs.readFileSync(path, 'utf8')
- });
+ asset = new rack.Asset({
+ mimetype: 'text/javascript',
+ url: '/' + pathutil.relative(sails.config.appPath, path).replace(/\\/g, '/'),
+ contents: fs.readFileSync(path, 'utf8')
+ });
}
asset.isDev = true;
self.assets.push(asset);
@@ -80,45 +77,27 @@ var CssAsset = rack.Asset.extend({
self.regex = /(\.css|\.less)$/;
self.paths = search(sails.config.assets.sequence, self.regex);
self.assets = [];
- self.lessContents = '';
async.forEachSeries(self.paths, function(path, next) {
- var asset;
- if(pathutil.extname(path) == '.less') {
- self.lessContents += fs.readFileSync(path);
- return next();
- } else {
- asset = new rack.Asset({
- url: '/' + pathutil.relative(sails.config.appPath, path).replace(/\\/g, '/'),
- contents: fs.readFileSync(path, 'utf8')
- });
- }
+ var asset,
+ url = '/' + pathutil
+ .relative(sails.config.appPath, path).replace(/\\/g, '/')
+ .replace('.less', '.css');
+ if(pathutil.extname(path) === '.less')
+ asset = new rack.LessAsset({
+ url : url,
+ filename : path
+ })
+ else asset = new rack.Asset({
+ url: url,
+ contents: fs.readFileSync(path, 'utf8')
+ });
asset.isDev = true;
self.assets.push(asset);
asset.on('complete', next);
}, function(error) {
if(error) self.emit('error', error);
- var parser = new less.Parser();
- parser.parse(self.lessContents, function(error, tree) {
- if (error) return self.emit('error');
- var lessAsset = new rack.Asset({
- url: '/assets/styles/style.less.css',
- mimetype: 'text/css',
- contents: tree.toCSS()
- });
- lessAsset.isDev = true;
- self.assets.push(lessAsset);
- lessAsset.on('complete', function() {
- self.contents = '';
- if (isProduction) {
- _.each(self.assets, function(asset) {
- self.contents += asset.contents += '\n';
- });
- self.contents = cleancss.process(self.contents);
- }
- self.isDev = false;
- self.emit('created');
- });
- });
+ self.isDev = false;
+ self.emit('created');
});
}
});
@@ -174,15 +153,20 @@ var Rack = rack.Rack.extend({
}
});
+/**
+ * given a list directories with relative paths to `sails.config.appPath`
+ * and a regex, return all the files in the directories that match
+ * the given regex
+ */
var search = function(dirnames, regex) {
- paths = [];
+ var paths = [];
_.each(dirnames, function(dirname) {
- abspath = pathutil.join(sails.config.appPath, dirname);
- filenames = wrench.readdirSyncRecursive(abspath);
+ var abspath = pathutil.join(sails.config.appPath, dirname);
+ var filenames = wrench.readdirSyncRecursive(abspath);
_.each(filenames, function(filename) {
- path = pathutil.join(abspath, filename);
- if(!fs.statSync(path).isFile() || !regex.test(path)) return;
- paths.push(path);
+ var filepath = pathutil.join(abspath, filename);
+ if(!fs.statSync(filepath).isFile() || !regex.test(filepath)) return;
+ paths.push(filepath);
});
});
return paths;
View
@@ -71,7 +71,6 @@
"connect": "1.8.3",
"async": "0.1.22",
"underscore": "1.4.2",
- "less": "1.3.0",
"optimist": "0.3.4",
"underscore.string": "2.3.0",
"glob": "3.1.14",
@@ -80,7 +79,7 @@
"i18n": "0.3.5",
"wrench": "1.4.4",
"uglify-js": "2.2.4",
- "asset-rack": "2.0.6",
+ "asset-rack": "2.1.4",
"node-uuid": "~1.4.0",
"parley": "0.0.2",
"include-all": "0.0.5",

0 comments on commit 744eea5

Please sign in to comment.