@@ -6,20 +6,32 @@ import type { PluginBasicSslOptions } from './index.js';
66
77type HttpsConfig = ServerConfig [ 'https' ] ;
88
9- export const resolveHttpsConfig = (
9+ async function ensureDir ( dir : string ) {
10+ try {
11+ await fs . promises . access ( dir ) ;
12+ } catch ( error ) {
13+ await ensureDir ( path . dirname ( dir ) ) ;
14+ await fs . promises . mkdir ( dir ) ;
15+ }
16+ }
17+
18+ export const resolveHttpsConfig = async (
1019 config : HttpsConfig ,
1120 options : PluginBasicSslOptions ,
12- ) : {
21+ ) : Promise < {
1322 key : NonNullable < HttpsConfig > [ 'key' ] ;
1423 cert : NonNullable < HttpsConfig > [ 'cert' ] ;
15- } => {
24+ } > => {
1625 const { key, cert } = config ?? { } ;
1726
1827 if ( key && cert ) {
1928 return { key, cert } ;
2029 }
2130
22- const certPath = path . join ( __dirname , options . filename ?? 'fake-cert.pem' ) ;
31+ const certPath = path . join (
32+ options . outputPath ?? __dirname ,
33+ options . filename ?? 'fake-cert.pem' ,
34+ ) ;
2335
2436 if ( fs . existsSync ( certPath ) ) {
2537 const stats = fs . statSync ( certPath ) ;
@@ -45,7 +57,13 @@ export const resolveHttpsConfig = (
4557 ) ;
4658
4759 const content = pem . private + pem . cert ;
60+
61+ if ( options . outputPath ) {
62+ await ensureDir ( options . outputPath ) ;
63+ }
64+
4865 fs . writeFileSync ( certPath , content , { encoding : 'utf-8' } ) ;
66+
4967 return {
5068 key : content ,
5169 cert : content ,
0 commit comments