Skip to content

Commit

Permalink
bunch of cleanup so far
Browse files Browse the repository at this point in the history
  • Loading branch information
eoneill committed Oct 28, 2015
1 parent 3ad6578 commit f571a2b
Show file tree
Hide file tree
Showing 23 changed files with 295 additions and 256 deletions.
32 changes: 30 additions & 2 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,2 +1,30 @@
/node_modules # Useless files
/coverage *.DS_Store

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
16 changes: 5 additions & 11 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,10 @@
language: node_js language: node_js
node_js: node_js:
- '0.12' - 0.12
- '4' - 4.0
#- iojs - 4.1
env: - 4.2
- COVERAGE=true - node
- COVERAGE=false
matrix:
exclude:
node_js: 'iojs'

before_install: before_install:
- if [ $TRAVIS_OS_NAME == "linux" ]; then - if [ $TRAVIS_OS_NAME == "linux" ]; then
export CC="gcc-4.7"; export CC="gcc-4.7";
Expand All @@ -19,7 +14,6 @@ before_install:
fi fi
- gcc --version - gcc --version
- g++ --version - g++ --version

addons: addons:
apt: apt:
sources: sources:
Expand Down
6 changes: 3 additions & 3 deletions Gruntfile.js
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = function(grunt) { module.exports = function(grunt) {
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON('package.json') pkg: grunt.file.readJSON("package.json")
}); });
grunt.loadNpmTasks('grunt-release'); grunt.loadNpmTasks("grunt-release");


grunt.registerTask('default', []); grunt.registerTask("default", []);
}; };
33 changes: 0 additions & 33 deletions build/coverage.js

This file was deleted.

2 changes: 1 addition & 1 deletion build/lint.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var config = require("eyeglass-dev-eslint");


module.exports = function(gulp, depends) { module.exports = function(gulp, depends) {
gulp.task("lint", depends, function() { gulp.task("lint", depends, function() {
return gulp.src(["build/**/*.js", "lib/**/*.js", "test/**/*.js"]) return gulp.src(["*.js", "{build,lib,test}/**/*.js"])
.pipe(eslint(config)) .pipe(eslint(config))
.pipe(eslint.formatEach("stylish", process.stderr)) .pipe(eslint.formatEach("stylish", process.stderr))
.pipe(eslint.failOnError()); .pipe(eslint.failOnError());
Expand Down
42 changes: 37 additions & 5 deletions build/test.js
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,44 @@
"use strict"; "use strict";


var istanbul = require("gulp-istanbul");
var mocha = require("gulp-mocha"); var mocha = require("gulp-mocha");


var testSrc = "test/**/test_*.js";

module.exports = function(gulp, depends) { module.exports = function(gulp, depends) {
gulp.task("test", depends, function() { function runTests() {
return gulp.src([ return gulp.src(testSrc, {
"test/**/test_*.js" read: false
], {read: false}) })
.pipe(mocha({reporter: "spec"})); .pipe(mocha({
reporter: "spec"
}));
}

gulp.task("test", depends, function (cb) {
gulp.src(["*.js", "lib/**/*.js", "test/*.js"])
.pipe(istanbul()) // Covering files
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on("finish", function () {
runTests()
.pipe(istanbul.writeReports()) // Creating the reports after tests runned
.pipe(istanbul.enforceThresholds({
thresholds: {
global: {
statements: 95.05,
branches: 86.64,
functions: 97.14,
lines: 95.05
}
}
}))
.on("end", cb)
.on("error", function(e) {
console.error(e.toString());
process.exit(1);
});
});
}); });

gulp.task("test:uncovered", depends, runTests);
}; };
3 changes: 1 addition & 2 deletions gulpfile.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ var gulp = require("gulp");
// Know the node-sass we wrap. It's vital to debugging, tests, and coverage reports // Know the node-sass we wrap. It's vital to debugging, tests, and coverage reports
console.log(require("node-sass").info); console.log(require("node-sass").info);


require("./build/lint")(gulp, []); require("./build/lint")(gulp);
require("./build/test")(gulp, ["lint"]); require("./build/test")(gulp, ["lint"]);
require("./build/coverage")(gulp, []);


gulp.task("default", ["test"]); gulp.task("default", ["test"]);
7 changes: 3 additions & 4 deletions lib/assets.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var fs = require("fs");
var fse = require("fs-extra"); var fse = require("fs-extra");
var glob = require("glob"); var glob = require("glob");
var path = require("path"); var path = require("path");
var hash = require("./util/hash");
var unquote = require("./util/unquote"); var unquote = require("./util/unquote");
var merge = require("lodash.merge");


// Returns whether a file exists. // Returns whether a file exists.
function existsSync(file) { function existsSync(file) {
Expand Down Expand Up @@ -37,10 +37,9 @@ function AssetPathEntry(srcPath, opts) {
this.httpPrefix = opts.httpPrefix || opts.name; this.httpPrefix = opts.httpPrefix || opts.name;
this.srcPath = srcPath; this.srcPath = srcPath;
this.pattern = opts.pattern || "**/*"; this.pattern = opts.pattern || "**/*";
this.globOpts = {}; this.globOpts = merge({}, this.defaultGlobOpts);
hash.merge(this.globOpts, this.defaultGlobOpts);
if (opts.globOpts) { if (opts.globOpts) {
hash.merge(this.globOpts, opts.globOpts); this.globOpts = merge(this.globOpts, opts.globOpts);
} }
this.globOpts.cwd = this.srcPath; // cannot be overridden by globOpts this.globOpts.cwd = this.srcPath; // cannot be overridden by globOpts
this.globOpts.root = this.srcPath; // cannot be overridden by globOpts this.globOpts.root = this.srcPath; // cannot be overridden by globOpts
Expand Down
16 changes: 8 additions & 8 deletions lib/function_loader.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


var discover = require("./util/discover"); var discover = require("./util/discover");
var syncFn = require("./util/sync_fn"); var syncFn = require("./util/sync_fn");
var hash = require("./util/hash"); var merge = require("lodash.merge");
var ARGUMENTS_REGEX = /\(.*\)$/; var ARGUMENTS_REGEX = /\(.*\)$/;


function autoDiscoverModules(root) { function autoDiscoverModules(root) {
Expand Down Expand Up @@ -32,19 +32,19 @@ function checkConflicts(obj1, obj2) {


module.exports = function(eyeglass, sass, options, existingFunctions) { module.exports = function(eyeglass, sass, options, existingFunctions) {
var root = options.root; var root = options.root;
var functions = {};
var modules = autoDiscoverModules(root); var modules = autoDiscoverModules(root);


modules.forEach(function(m) { var functions = modules.reduce(function(fns, mod) {
var obj = require(m)(eyeglass, sass); var obj = require(mod)(eyeglass, sass);
if (obj.functions) { if (obj.functions) {
checkConflicts(functions, obj.functions); checkConflicts(fns, obj.functions);
hash.merge(functions, obj.functions); return merge(fns, obj.functions);
} }
}); return fns;
}, {});


checkConflicts(functions, existingFunctions); checkConflicts(functions, existingFunctions);
hash.merge(functions, existingFunctions); functions = merge(functions, existingFunctions);


functions = syncFn.all(functions); functions = syncFn.all(functions);


Expand Down
14 changes: 7 additions & 7 deletions lib/functions.js
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict"; "use strict";


var hash = require("./util/hash"); var merge = require("lodash.merge");


module.exports = function(eyeglass, sass) { module.exports = function(eyeglass, sass) {
var functions = {}; return ["asset_url", "version"].reduce(function(functions, name) {
["asset_url", "version"].forEach(function(name) { return merge(
var fn = require("./functions/" + name)(eyeglass, sass); functions,
hash.merge(functions, fn); require("./functions/" + name)(eyeglass, sass)
}); );
return functions; }, {});
}; };
36 changes: 17 additions & 19 deletions lib/functions/version.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
var discover = require("../util/discover"); var discover = require("../util/discover");
var unquote = require("../util/unquote"); var unquote = require("../util/unquote");


// REFACTOR ME: this is copy pasta from module_importer.js
function eyeglassName(moduleDef) {
return (moduleDef.eyeglass &&
typeof moduleDef.eyeglass == "object" &&
moduleDef.eyeglass.name) ||
moduleDef.name;
}



module.exports = function(eyeglass, sass) { module.exports = function(eyeglass, sass) {
return { return {
"eyeglass-version($module: eyeglass)": function(moduleName, done) { "eyeglass-version($module: eyeglass)": function(moduleName, done) {
var name = unquote(moduleName.getValue()); var name = unquote(moduleName.getValue());
var modules = discover.all(eyeglass.root()).modules; // TODO Cache this value? var moduleDef;
var mod;
for (var i = 0; i < modules.length; i++) { // optimization if the name is `eyeglass` itself
if (eyeglassName(modules[i]) === name) { if (name === "eyeglass") {
mod = modules[i]; moduleDef = discover.getEyeglassDef();
break; } else {
} // find the requested module
discover.all(eyeglass.root()).modules.some(function(mod) {
if (mod.eyeglassName === name) {
moduleDef = mod;
return true;
}
});
} }
if (mod) {
done(sass.types.String('"' + (mod.version || "versonless") + '"')); if (moduleDef) {
// TODO - why do we quote it?
done(sass.types.String('"' + (moduleDef.version || "unversioned") + '"'));
} else { } else {
done(sass.types.Null()); done(sass.types.Null());
} }
Expand Down
1 change: 1 addition & 0 deletions lib/import_utils.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ImportUtilities.prototype = {
}, },


getModuleByName: function(moduleName, dir) { getModuleByName: function(moduleName, dir) {
//console.log("[getModuleByName]", moduleName, dir);
var allModules = this.allModulesCache[dir]; var allModules = this.allModulesCache[dir];
if (!allModules) { if (!allModules) {
allModules = discover.all(dir, true, dir === this.root).modules; allModules = discover.all(dir, true, dir === this.root).modules;
Expand Down
9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


var makeModuleImporter = require("./module_importer"); var makeModuleImporter = require("./module_importer");
var makeAssetImporter = require("./assets_importer"); var makeAssetImporter = require("./assets_importer");
var customFunctions = require("./function_loader"); var loadFunctions = require("./function_loader");
var hash = require("./util/hash"); var merge = require("lodash.merge");
var engineChecks = require("./semver_checker"); var engineChecks = require("./semver_checker");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
Expand Down Expand Up @@ -47,13 +47,12 @@ Eyeglass.prototype = {
}, },
sassOptions: function() { sassOptions: function() {
// TODO remove eyeglass specific options or maybe namespace them? // TODO remove eyeglass specific options or maybe namespace them?
var opts = {}; var opts = merge({}, this.options);
hash.merge(opts, this.options);
opts.eyeglass = this; opts.eyeglass = this;


var assetImporter = makeAssetImporter(this, this.sass, opts, opts.importer); var assetImporter = makeAssetImporter(this, this.sass, opts, opts.importer);
opts.importer = makeModuleImporter(this, this.sass, opts, assetImporter); opts.importer = makeModuleImporter(this, this.sass, opts, assetImporter);
opts.functions = customFunctions(this, this.sass, opts, opts.functions); opts.functions = loadFunctions(this, this.sass, opts, opts.functions);


return opts; return opts;
}, },
Expand Down
6 changes: 6 additions & 0 deletions lib/module_importer.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ function makeImporter(eyeglass, sass, options, fallbackImporter) {


/*eslint-disable */ /*eslint-disable */
return function(uri, prev, done) { return function(uri, prev, done) {
//console.log("-----------------------------");
//console.log("[module_importer]", uri, prev);
var isRealFile = importUtils.existsSync(prev); var isRealFile = importUtils.existsSync(prev);
var fragments = uri.split("/"); var fragments = uri.split("/");
var moduleName = fragments[0]; var moduleName = fragments[0];
var relativePath = fragments.slice(1).join("/"); var relativePath = fragments.slice(1).join("/");
var pkgRootDir = isRealFile ? importUtils.packageRootDir(path.dirname(prev)) : root; var pkgRootDir = isRealFile ? importUtils.packageRootDir(path.dirname(prev)) : root;
//console.log("[module_importer:isRealFile]", isRealFile);
//console.log("[module_importer:moduleName]", moduleName);
//console.log("[module_importer:relativePath]", relativePath);
//console.log("[module_importer:pkgRootDir]", pkgRootDir);
var jsFile = importUtils.getModuleByName(moduleName, pkgRootDir); var jsFile = importUtils.getModuleByName(moduleName, pkgRootDir);


if (jsFile) { if (jsFile) {
Expand Down
Loading

0 comments on commit f571a2b

Please sign in to comment.