@@ -7,68 +7,78 @@ import { readFileSync, writeFileSync } from 'fs'
77dotenv . config ( )
88
99function hashEnv ( ) {
10- const sum = createHash ( 'sha256' )
11- const env = Object . fromEntries ( Object . entries ( process . env ) . filter (
12- ( [ key ] ) => ! [ 'HOSTNAME' , 'PATH' ] . includes ( key )
13- ) )
14- console . log ( 'env' , env )
15- sum . update ( JSON . stringify ( env ) )
16- return sum . digest ( 'hex' )
10+ const sum = createHash ( 'sha256' )
11+ const env = Object . fromEntries ( Object . entries ( process . env ) . filter (
12+ ( [ key ] ) => ! [ 'HOSTNAME' , 'PATH' ] . includes ( key )
13+ ) )
14+ console . log ( 'env' , env )
15+ sum . update ( JSON . stringify ( env ) )
16+ return sum . digest ( 'hex' )
1717}
1818
1919function readHash ( ) {
20- try {
21- return readFileSync ( '.env.hash' , 'utf8' )
22- } catch ( err ) {
23- return ''
24- }
20+ try {
21+ return readFileSync ( '.env.hash' , 'utf8' )
22+ } catch ( err ) {
23+ return ''
24+ }
2525}
2626
2727function buildNuxt ( ) {
28- return new Promise ( ( resolve , reject ) => {
29- consola . info ( 'Building Nuxt...' )
30- const building = spawn ( 'yarn' , [ 'build' ] , { env : process . env , shell : true } )
28+ return new Promise ( ( resolve , reject ) => {
29+ consola . info ( 'Building Nuxt...' )
30+ const building = spawn ( 'yarn' , [ 'build' ] , { env : process . env , shell : true } )
3131
32- building . stdout . on ( 'data' , ( data ) => {
33- process . stdout . write ( data . toString ( ) )
34- } )
32+ building . stdout . on ( 'data' , ( data ) => {
33+ process . stdout . write ( data . toString ( ) )
34+ } )
3535
36- building . stderr . on ( 'data' , ( data ) => {
37- process . stderr . write ( data . toString ( ) )
38- } )
36+ building . stderr . on ( 'data' , ( data ) => {
37+ process . stderr . write ( data . toString ( ) )
38+ } )
3939
40- building . on ( 'close' , ( code ) => {
41- consola . info ( `child process exited with code ${ code } ` )
42- code > 0 ? reject ( ) : resolve ( )
40+ building . on ( 'close' , ( code ) => {
41+ consola . info ( `child process exited with code ${ code } ` )
42+ code > 0 ? reject ( ) : resolve ( )
4343
44- if ( code > 0 ) return reject ( )
44+ if ( code > 0 ) return reject ( )
4545
46- consola . info ( 'Hashing .env...' )
47- writeFileSync ( '.env.hash' , hashEnv ( ) )
48- return resolve ( )
49- } )
46+ consola . info ( 'Hashing .env...' )
47+ writeFileSync ( '.env.hash' , hashEnv ( ) )
48+ return resolve ( )
5049 } )
50+ } )
5151}
5252
5353; ( async ( ) => {
54- if ( hashEnv ( ) !== readHash ( ) ) {
55- consola . warn ( 'Hash changed, rebuilding...' )
56- consola . info ( `Hash: ${ hashEnv ( ) } , Previous: ${ readHash ( ) } ` )
57- await buildNuxt ( )
54+ if ( / y e s | 1 | o n | t r u e / i. test ( `${ process . env . SESAME_HTTPS_ENABLED } ` ) ) {
55+ try {
56+ process . env . NITRO_SSL_KEY = readFileSync ( `${ process . env . SESAME_HTTPS_PATH_KEY } ` , 'utf8' )
57+ process . env . NITRO_SSL_CERT = readFileSync ( `${ process . env . SESAME_HTTPS_PATH_CERT } ` , 'utf8' )
58+ consola . info ( '[Nuxt] SSL certificates loaded successfully' )
59+ } catch ( error ) {
60+ consola . warn ( '[Nuxt] Error while reading SSL certificates' , error )
5861 }
62+ }
5963
60- consola . info ( 'Starting Nuxt...' )
61- const starting = spawn ( 'yarn' , [ 'start' ] , { env : process . env , shell : true } )
64+ if ( hashEnv ( ) !== readHash ( ) ) {
65+ consola . warn ( 'Hash changed, rebuilding...' )
66+ consola . info ( `Hash: ${ hashEnv ( ) } , Previous: ${ readHash ( ) } ` )
67+ await buildNuxt ( )
68+ }
6269
63- starting . stdout . on ( 'data' , ( data ) => {
64- process . stdout . write ( data . toString ( ) )
65- } )
70+ consola . info ( 'Starting Nuxt...' )
71+ const starting = spawn ( 'yarn' , [ 'start' ] , { env : process . env , shell : true } )
6672
67- starting . stderr . on ( 'data' , ( data ) => {
68- process . stderr . write ( data . toString ( ) )
69- } )
73+ starting . stdout . on ( 'data' , ( data ) => {
74+ process . stdout . write ( data . toString ( ) )
75+ } )
7076
71- starting . on ( 'close' , ( code ) => {
72- consola . warn ( `child process exited with code ${ code } ` )
73- } )
77+ starting . stderr . on ( 'data' , ( data ) => {
78+ process . stderr . write ( data . toString ( ) )
79+ } )
80+
81+ starting . on ( 'close' , ( code ) => {
82+ consola . warn ( `child process exited with code ${ code } ` )
83+ } )
7484} ) ( )
0 commit comments