Skip to content

Commit 3363f1d

Browse files
chore: wip
1 parent c57b8b7 commit 3363f1d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

bin/cli.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ cli
3737

3838
const certFilePath = options?.output ?? `${os.homedir()}/.stacks/ssl/stacks.localhost.crt`
3939

40-
console.log();
41-
4240
// Check if the certificate is expired or domain already exists
4341

4442
if ((await isCertificateExpired(certFilePath)) || !(await isDomainExists(domain, certFilePath))) {
45-
4643
log.debug(`Start to generate a new certificate for domain: ${domain}`)
4744

4845
console.log('Start to generate a new certificate for domain:', domain)

src/keys.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ const getCANotAfter = (notBefore: any) => {
5151
// Function to check if a certificate file has expired
5252
export const isCertificateExpired = async (certFilePath: string): Promise<boolean> => {
5353
return new Promise((resolve, reject) => {
54+
5455
try {
56+
// Check if the file exists
57+
if (!fs.existsSync(certFilePath)) {
58+
reject('Certificate not found')
59+
}
60+
5561
// Read the certificate file
5662
const certData = fs.readFileSync(certFilePath, 'utf8')
5763

64+
65+
5866
// check if cert exists
5967
if (!certData) {
6068
reject('Certificate not found')
@@ -69,10 +77,11 @@ export const isCertificateExpired = async (certFilePath: string): Promise<boolea
6977
const isExpired = expiryDate < new Date()
7078

7179
resolve(isExpired)
80+
7281
} catch (error) {
7382
// Handle errors
7483
console.error(`Error checking certificate expiry: ${error}`)
75-
reject(error) // Reject the promise with the error
84+
// reject(error) // Reject the promise with the error
7685
}
7786
})
7887
}
@@ -82,6 +91,12 @@ export const isDomainExists = async (domainToCheck: string, certificatePath: str
8291
// Read the certificate file
8392
const certificateContents = fs.readFileSync(certificatePath, 'utf8')
8493

94+
95+
if(!certificateContents) {
96+
97+
throw new Error('Certificate not found')
98+
}
99+
85100
// Parse the certificate data
86101
const certificate = forge.pki.certificateFromPem(certificateContents)
87102

0 commit comments

Comments
 (0)