diff --git a/package.json b/package.json index 189ee4d..14ea8e0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/index.js b/src/index.js index 147db20..95f5c87 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; @@ -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) { diff --git a/yarn.lock b/yarn.lock index 718ae16..6052d5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"