Skip to content

Commit

Permalink
remove unnecessary packages and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
doowb committed Jun 26, 2018
1 parent 8d45285 commit 021cdda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 51 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
var path = require('path');
var clone = require('clone-deep');
var relative = require('relative');
var chalk = require('chalk');
var red = require('ansi-red');
var bold = require('ansi-bold');

/**
* Asynchronously get the resolved path to "main" file for
Expand Down Expand Up @@ -73,7 +74,7 @@ function tryResolve(fp) {
try {
return require(path.resolve(fp));
} catch(err) {
console.error(chalk.red('helper-resolve cannot find'), chalk.bold(fp), err);
console.error(red('helper-resolve cannot find'), bold(fp), err);
}
return {};
};
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
"test": "mocha"
},
"dependencies": {
"chalk": "^1.0.0",
"clone-deep": "^0.1.1",
"relative": "^3.0.0"
"ansi-bold": "^0.1.1",
"ansi-red": "^0.1.1",
"clone-deep": "^4.0.0",
"relative": "^3.0.2"
},
"devDependencies": {
"engine-lodash": "^0.6.2",
"handlebars": "^3.0.1",
"jquery": "^2.1.3",
"handlebars": "^4.0.11",
"jquery": "^3.3.1",
"mocha": "*",
"should": "*",
"template": "^0.12.6"
"should": "*"
},
"keywords": [
"helper",
Expand Down
41 changes: 0 additions & 41 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,10 @@
/* deps:mocha jquery */
require('should');
var handlebars = require('handlebars');
var Template = require('template');
var resolve = require('./');
var template;

describe('resolve helper', function () {
beforeEach(function () {
template = new Template();
template.engine('*', require('engine-lodash'));
});

it('should work as an async helper with Template:', function () {
var str = '<script src="<%= resolve("jquery") %>"></script>';

template.asyncHelper('resolve', function (name, key, cb) {
if (typeof key === 'function') {
cb = key;
key = 'main';
}
resolve(name, function (err, res) {
cb(null, res[key]);
});
});

template.render(str, function (err, content) {
if (err) console.log(err);
content.should.equal('<script src="node_modules/jquery/dist/jquery.js"></script>');
});
});

it('should work as a sync helper with Template:', function () {
template.helper('resolve', resolve.sync);

var main = '<script src="<%= resolve("jquery").main %>"></script>';
template.render(main, function (err, content) {
if (err) console.log(err);
content.should.equal('<script src="node_modules/jquery/dist/jquery.js"></script>');
});

var homepage = '<script src="<%= resolve("jquery").homepage %>"></script>';
template.render(homepage, function (err, content) {
if (err) console.log(err);
content.should.equal('<script src="http://jquery.com"></script>');
});
});

it('should work as a handlebars helper:', function () {
var str = '{{resolve "jquery"}}';
handlebars.registerHelper('resolve', function (fp, key) {
Expand Down

0 comments on commit 021cdda

Please sign in to comment.