Skip to content

Commit

Permalink
add proper module api for node users
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertal committed Dec 20, 2016
1 parent 84c18af commit cd6364f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
19 changes: 19 additions & 0 deletions index.js
@@ -0,0 +1,19 @@
var fs = require('fs');
var path = require('path');
var cache = {};

module.exports = {
getFile: function(name) {
if (!cache[name]) {
try {
cache[name] = fs.readFileSync(this.getFilePath(name), 'utf-8');
} catch(e) {
throw new Error(name + ' does not exist');
}
}
return cache[name];
},
getFilePath: function(name) {
return path.resolve(__dirname, 'build', name);
}
};
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -6,7 +6,8 @@
"url": "git://github.com/yahoo/pure.git"
},
"scripts": {
"test": "grunt test",
"pretest": "grunt build",
"test": "grunt test && tap test/*.js",
"prepublish": "grunt release"
},
"files": "build/",
Expand All @@ -25,14 +26,16 @@
"grunt-css-selectors": "^1.1.0",
"grunt-postcss": "^0.8.0",
"grunt-pure-grids": "^1.0.0",
"grunt-stripmq": "0.0.6"
"grunt-stripmq": "0.0.6",
"tap": "^8.0.1"
},
"description": "Pure is a ridiculously tiny CSS library you can use to start any web project.",
"bugs": {
"url": "https://github.com/yahoo/pure/issues"
},
"homepage": "http://purecss.io",
"main": "build/pure-min.css",
"main": "index.js",
"browser": "build/pure-min.css",
"keywords": [
"pure",
"css",
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
@@ -0,0 +1,11 @@
var tap = require('tap');
var pure = require('../index.js');

// api
tap.ok(pure.getFile);
tap.ok(pure.getFilePath);

// assertions
tap.match(pure.getFile('pure-min.css'), /pure\-button/, 'should load the file');
tap.match(pure.getFilePath('pure-min.css'), /pure\-min\.css/, 'should return file path');
tap.throws(pure.getFile, new Error('undefined does not exist'));

0 comments on commit cd6364f

Please sign in to comment.