Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add proper module api for node users
- Loading branch information
sbertal
committed
Dec 20, 2016
1 parent
84c18af
commit cd6364f
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); |