1
1
import { join } from 'path' ;
2
- import { existsSync , copyFileSync } from 'fs' ;
2
+ import { existsSync , copyFileSync , writeFileSync , readFileSync } from 'fs' ;
3
3
import { spawnSync } from 'child_process' ;
4
4
5
5
const baseFolder = process . env . APPDATA
6
6
? `${ process . env . APPDATA } /ASP.NET/https`
7
7
: `${ process . env . HOME } /.aspnet/https` ;
8
8
9
- const certificateName = 'dotnet-nuxt' ;
9
+ const nameFilePath = '.cert.name' ;
10
+ if ( ! existsSync ( nameFilePath ) ) writeFileSync ( nameFilePath , crypto . randomUUID ( ) ) ;
11
+ const certificateName = readFileSync ( nameFilePath ) ;
10
12
11
- const certFilePath = join ( baseFolder , `${ certificateName } .pem` ) ;
12
- const keyFilePath = join ( baseFolder , `${ certificateName } .key` ) ;
13
+ const certFilePath = join ( baseFolder , `. ${ certificateName } .pem` ) ;
14
+ const keyFilePath = join ( baseFolder , `. ${ certificateName } .key` ) ;
13
15
14
16
if ( ! existsSync ( certFilePath ) || ! existsSync ( keyFilePath ) ) {
15
17
spawnSync ( 'dotnet' , [ 'dev-certs' , 'https' , '--trust' ] , {
16
- stdio : 'inherit'
18
+ stdio : 'inherit' ,
17
19
} ) ;
18
20
19
21
const res = spawnSync (
@@ -25,13 +27,13 @@ if (!existsSync(certFilePath) || !existsSync(keyFilePath)) {
25
27
certFilePath ,
26
28
'--format' ,
27
29
'Pem' ,
28
- '--no-password'
30
+ '--no-password' ,
29
31
] ,
30
32
{ stdio : 'inherit' }
31
33
) ;
32
34
33
35
if ( res . status !== 0 ) process . exit ( res . status ) ;
34
36
}
35
37
36
- copyFileSync ( certFilePath , './cert.pem' ) ;
37
- copyFileSync ( keyFilePath , './cert.key' ) ;
38
+ copyFileSync ( certFilePath , './. cert.pem' ) ;
39
+ copyFileSync ( keyFilePath , './. cert.key' ) ;
0 commit comments