Skip to content

Commit

Permalink
Fixes issue with template not found
Browse files Browse the repository at this point in the history
  • Loading branch information
d4nyll committed Aug 31, 2017
1 parent 7772217 commit 38e0acc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "revoice",
"version": "0.1.11",
"version": "0.1.12",
"description": "Generate HTML / PDF receipts and invoices",
"main": "dist/index.js",
"homepage": "https://github.com/brewhk/revoice",
Expand Down Expand Up @@ -47,6 +47,7 @@
},
"dependencies": {
"ajv": "^5.2.2",
"app-root-path": "^2.0.1",
"crypto-js": "^3.1.9-1",
"currency-formatter": "^1.2.1",
"handlebars": "^4.0.10",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import ItemSchema from './schema/item.json';

import * as errorStrings from './errors.js';

import appRoot from 'app-root-path';

const Revoice = {};

Revoice.DEFAULT_TEMPLATE = 'default';
Expand All @@ -28,13 +30,13 @@ Revoice.DEFAULT_OPTIONS = {
* Get the URL of the template HTML
*/
Revoice.getTemplateUrl = function getTemplateUrl(template) {
if (!template) return `./templates/${Revoice.DEFAULT_TEMPLATE}.html`;
if (!template) return `${appRoot}/templates/${Revoice.DEFAULT_TEMPLATE}.html`;
// If the template is a alphanumeric string,
// we assume it's using a pre-defined template
// and we return the path to it
// Otherwise, we treat it as a user-provided path,
// and simply return that
return /^[a-zA-Z0-9]+$/.test(template) ? `./templates/${template}.html` : template;
return /^[a-zA-Z0-9]+$/.test(template) ? `${appRoot}/templates/${template}.html` : template;
}

Revoice.getTemplate = function (template = Revoice.DEFAULT_TEMPLATE) {
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ anymatch@^1.3.0:
micromatch "^2.1.5"
normalize-path "^2.0.0"

app-root-path@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.0.1.tgz#cd62dcf8e4fd5a417efc664d2e5b10653c651b46"

append-transform@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-0.4.0.tgz#d76ebf8ca94d276e247a36bad44a4b74ab611991"
Expand Down

0 comments on commit 38e0acc

Please sign in to comment.