Skip to content

Commit 4f395bd

Browse files
Merge pull request #26 from wildbit/fix-preview
Fix template preview
2 parents 967140b + 44d20cb commit 4f395bd

3 files changed

Lines changed: 14 additions & 25 deletions

File tree

package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "postmark-cli",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"description": "A CLI tool for managing templates, sending emails, and fetching servers on Postmark.",
55
"main": "./dist/index.js",
66
"dependencies": {
77
"@types/traverse": "^0.6.32",
88
"@types/watch": "^1.0.1",
9-
"app-root-path": "^3.0.0",
109
"chalk": "^2.4.2",
1110
"consolidate": "^0.15.1",
1211
"directory-tree": "^2.2.3",
@@ -27,7 +26,6 @@
2726
"yargs": "^13.2.4"
2827
},
2928
"devDependencies": {
30-
"@types/app-root-path": "^1.2.4",
3129
"@types/chai": "^4.1.4",
3230
"@types/consolidate": "^0.14.0",
3331
"@types/execa": "^0.9.0",
@@ -56,7 +54,7 @@
5654
"build": "npm run clean && npm run ts && npm run syncPreview && npm run permissions",
5755
"test": "npm run lint && npm run build && node_modules/mocha/bin/mocha --timeout 10000 --retries 1 -r ts-node/register test/**/*test.ts",
5856
"clean": "rm -r -f ./dist",
59-
"syncPreview": "cp -R ./preview ./dist/preview",
57+
"syncPreview": "cp -R ./preview ./dist/commands/templates/preview",
6058
"ts": "node_modules/.bin/tsc",
6159
"permissions": "chmod +x ./dist/index.js",
6260
"lint": "eslint --ext .ts ./src",

src/commands/templates/preview.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import chalk from 'chalk'
2-
import appRoot from 'app-root-path'
32
import { existsSync } from 'fs-extra'
43
import { filter, find, replace, debounce } from 'lodash'
54
import untildify from 'untildify'
@@ -11,8 +10,9 @@ import { createManifest } from './helpers'
1110
import { TemplatePreviewArguments } from '../../types'
1211
import { TemplateValidationOptions } from 'postmark/dist/client/models'
1312
import { log, validateToken } from '../../utils'
13+
import path from 'path'
1414

15-
const previewPath = `${appRoot.path}/preview/`
15+
const previewPath = path.join(__dirname, 'preview')
1616

1717
export const command = 'preview <templates directory> [options]'
1818
export const desc = 'Preview your templates and layouts'
@@ -74,7 +74,7 @@ const preview = (serverToken: string, args: TemplatePreviewArguments) => {
7474
let manifest = createManifest(templatesdirectory)
7575

7676
// Static assets
77-
app.use(express.static(`${previewPath}assets`))
77+
app.use(express.static(`${previewPath}/assets`))
7878

7979
const updateEvent = () => {
8080
// Generate new manifest
@@ -100,7 +100,7 @@ const preview = (serverToken: string, args: TemplatePreviewArguments) => {
100100
const path = untildify(templatesdirectory).replace(/\/$/, '')
101101

102102
consolidate.ejs(
103-
`${previewPath}index.ejs`,
103+
`${previewPath}/index.ejs`,
104104
{ templates, layouts, path },
105105
(err, html) => renderTemplateContents(res, err, html)
106106
)
@@ -113,8 +113,10 @@ const preview = (serverToken: string, args: TemplatePreviewArguments) => {
113113
const template = find(manifest, { Alias: req.params.alias })
114114

115115
if (template) {
116-
consolidate.ejs(`${previewPath}template.ejs`, { template }, (err, html) =>
117-
renderTemplateContents(res, err, html)
116+
consolidate.ejs(
117+
`${previewPath}/template.ejs`,
118+
{ template },
119+
(err, html) => renderTemplateContents(res, err, html)
118120
)
119121
} else {
120122
// Redirect to index
@@ -231,19 +233,19 @@ const getSource = (version: 'html' | 'text', template: any, layout?: any) => {
231233
}
232234

233235
const renderTemplateText = (res: express.Response, body: string) =>
234-
consolidate.ejs(`${previewPath}templateText.ejs`, { body }, (err, html) =>
236+
consolidate.ejs(`${previewPath}/templateText.ejs`, { body }, (err, html) =>
235237
renderTemplateContents(res, err, html)
236238
)
237239

238240
const renderTemplateInvalid = (res: express.Response, errors: any) =>
239241
consolidate.ejs(
240-
`${previewPath}templateInvalid.ejs`,
242+
`${previewPath}/templateInvalid.ejs`,
241243
{ errors },
242244
(err, html) => renderTemplateContents(res, err, html)
243245
)
244246

245247
const renderTemplate404 = (res: express.Response, version: string) =>
246-
consolidate.ejs(`${previewPath}template404.ejs`, { version }, (err, html) =>
248+
consolidate.ejs(`${previewPath}/template404.ejs`, { version }, (err, html) =>
247249
renderTemplateContents(res, err, html)
248250
)
249251

0 commit comments

Comments
 (0)