Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "postmark-cli",
"version": "1.4.6",
"version": "1.4.7",
"description": "A CLI tool for managing templates, sending emails, and fetching servers on Postmark.",
"main": "./dist/index.js",
"dependencies": {
"@types/traverse": "^0.6.32",
"@types/watch": "^1.0.1",
"app-root-path": "^3.0.0",
"chalk": "^2.4.2",
"consolidate": "^0.15.1",
"directory-tree": "^2.2.3",
Expand All @@ -27,7 +26,6 @@
"yargs": "^13.2.4"
},
"devDependencies": {
"@types/app-root-path": "^1.2.4",
"@types/chai": "^4.1.4",
"@types/consolidate": "^0.14.0",
"@types/execa": "^0.9.0",
Expand Down Expand Up @@ -56,7 +54,7 @@
"build": "npm run clean && npm run ts && npm run syncPreview && npm run permissions",
"test": "npm run lint && npm run build && node_modules/mocha/bin/mocha --timeout 10000 --retries 1 -r ts-node/register test/**/*test.ts",
"clean": "rm -r -f ./dist",
"syncPreview": "cp -R ./preview ./dist/preview",
"syncPreview": "cp -R ./preview ./dist/commands/templates/preview",
"ts": "node_modules/.bin/tsc",
"permissions": "chmod +x ./dist/index.js",
"lint": "eslint --ext .ts ./src",
Expand Down
20 changes: 11 additions & 9 deletions src/commands/templates/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chalk from 'chalk'
import appRoot from 'app-root-path'
import { existsSync } from 'fs-extra'
import { filter, find, replace, debounce } from 'lodash'
import untildify from 'untildify'
Expand All @@ -11,8 +10,9 @@ import { createManifest } from './helpers'
import { TemplatePreviewArguments } from '../../types'
import { TemplateValidationOptions } from 'postmark/dist/client/models'
import { log, validateToken } from '../../utils'
import path from 'path'

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

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

// Static assets
app.use(express.static(`${previewPath}assets`))
app.use(express.static(`${previewPath}/assets`))

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

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

if (template) {
consolidate.ejs(`${previewPath}template.ejs`, { template }, (err, html) =>
renderTemplateContents(res, err, html)
consolidate.ejs(
`${previewPath}/template.ejs`,
{ template },
(err, html) => renderTemplateContents(res, err, html)
)
} else {
// Redirect to index
Expand Down Expand Up @@ -231,19 +233,19 @@ const getSource = (version: 'html' | 'text', template: any, layout?: any) => {
}

const renderTemplateText = (res: express.Response, body: string) =>
consolidate.ejs(`${previewPath}templateText.ejs`, { body }, (err, html) =>
consolidate.ejs(`${previewPath}/templateText.ejs`, { body }, (err, html) =>
renderTemplateContents(res, err, html)
)

const renderTemplateInvalid = (res: express.Response, errors: any) =>
consolidate.ejs(
`${previewPath}templateInvalid.ejs`,
`${previewPath}/templateInvalid.ejs`,
{ errors },
(err, html) => renderTemplateContents(res, err, html)
)

const renderTemplate404 = (res: express.Response, version: string) =>
consolidate.ejs(`${previewPath}template404.ejs`, { version }, (err, html) =>
consolidate.ejs(`${previewPath}/template404.ejs`, { version }, (err, html) =>
renderTemplateContents(res, err, html)
)

Expand Down