Permalink
Browse files

add proper module api for node users

  • Loading branch information...
1 parent 84c18af commit cd6364faa81f335ec3aa03b73f95a7a7d1b2613e @redonkulus redonkulus committed Dec 20, 2016
Showing with 36 additions and 3 deletions.
  1. +19 −0 index.js
  2. +6 −3 package.json
  3. +11 −0 test/index.js
View
@@ -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);
+ }
+};
View
@@ -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/",
@@ -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",
View
@@ -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.