@@ -13,7 +13,6 @@ import { snapshotStorage } from "../utils/storage";
1313import { formatRollupError } from "./error" ;
1414import { writeTypes } from "./types" ;
1515import { getProperty } from "dot-prop" ;
16- import { consola } from "consola" ;
1716
1817export async function buildProduction (
1918 nitro : Nitro ,
@@ -45,8 +44,8 @@ export async function buildProduction(
4544 nitro : nitroVersion ,
4645 } ,
4746 commands : {
48- preview : nitro . options . commands . preview ,
49- deploy : nitro . options . commands . deploy ,
47+ preview : resolveTmplPath ( nitro . options . commands . preview , nitro ) ,
48+ deploy : resolveTmplPath ( nitro . options . commands . deploy , nitro ) ,
5049 } ,
5150 config : {
5251 ...Object . fromEntries (
@@ -72,26 +71,14 @@ export async function buildProduction(
7271 await nitro . hooks . callHook ( "compiled" , nitro ) ;
7372
7473 // Show deploy and preview hints
75- const rOutput = relative ( process . cwd ( ) , nitro . options . output . dir ) ;
76- const rewriteRelativePaths = ( input : string ) => {
77- return input . replace ( / ( [ \s : ] ) \. \/ ( \S * ) / g, `$1${ rOutput } /$2` ) ;
78- } ;
79- if ( buildInfo . commands ! . preview ) {
74+ if ( buildInfo . commands ?. preview ) {
8075 nitro . logger . success (
81- `You can preview this build using \`${ _compilePathCommandTemplate (
82- rewriteRelativePaths ( buildInfo . commands ! . preview ) ,
83- nitro . options ,
84- nitro . options . rootDir
85- ) } \``
76+ `You can preview this build using \`${ buildInfo . commands ?. preview } \``
8677 ) ;
8778 }
88- if ( buildInfo . commands ! . deploy ) {
79+ if ( buildInfo . commands ? .deploy ) {
8980 nitro . logger . success (
90- `You can deploy this build using \`${ _compilePathCommandTemplate (
91- rewriteRelativePaths ( buildInfo . commands ! . deploy ) ,
92- nitro . options ,
93- nitro . options . rootDir
94- ) } \``
81+ `You can deploy this build using \`${ buildInfo . commands ?. deploy } \``
9582 ) ;
9683 }
9784}
@@ -123,22 +110,20 @@ async function _snapshot(nitro: Nitro) {
123110 ) ;
124111}
125112
126- function _compilePathCommandTemplate (
127- contents : string ,
128- data : Record < string , any > ,
129- base : string
130- ) {
131- if ( ! contents . includes ( "{{" ) ) {
132- return contents ;
113+ function resolveTmplPath ( input : string | undefined , nitro : Nitro ) {
114+ if ( ! input || ! input . includes ( "{{" ) ) {
115+ return input ;
133116 }
134-
135- return contents . replace ( / { { ? ( [ \w . ] + ) ? } } / g, ( _ , match ) => {
136- let val = getProperty < Record < string , string > , string > ( data , match ) ;
117+ return input . replace ( / { { ? ( [ \w . ] + ) ? } } / g, ( _ , match ) => {
118+ let val = getProperty < Record < string , string > , string > (
119+ nitro . options as unknown as Record < string , string > ,
120+ match
121+ ) ;
137122 if ( val ) {
138- val = relative ( base , val ) ;
123+ val = relative ( nitro . options . rootDir , val ) ;
139124 } else {
140- consola . warn (
141- `cannot resolve template param '${ match } ' in ${ contents . slice ( 0 , 20 ) } `
125+ nitro . logger . warn (
126+ `cannot resolve template param '${ match } ' in ${ input . slice ( 0 , 20 ) } `
142127 ) ;
143128 }
144129 return val || `${ match } ` ;
0 commit comments