11import chalk from 'chalk'
2- import appRoot from 'app-root-path'
32import { existsSync } from 'fs-extra'
43import { filter , find , replace , debounce } from 'lodash'
54import untildify from 'untildify'
@@ -11,8 +10,9 @@ import { createManifest } from './helpers'
1110import { TemplatePreviewArguments } from '../../types'
1211import { TemplateValidationOptions } from 'postmark/dist/client/models'
1312import { log , validateToken } from '../../utils'
13+ import path from 'path'
1414
15- const previewPath = ` ${ appRoot . path } / preview/`
15+ const previewPath = path . join ( __dirname , ' preview' )
1616
1717export const command = 'preview <templates directory> [options]'
1818export 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
233235const 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
238240const 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
245247const 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