Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit f1b2ca6

Browse files
author
Jonathan Spruance (Insight Global)
committed
Refactor to make code dry-er
1 parent c790ec6 commit f1b2ca6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/cli/src/hooks/init/inithook.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,20 @@ const hook: Hook<'init'> = async function (opts) {
3838
fs.writeFileSync(path.join(this.config.configDir, 'config.json'), JSON.stringify(userConfig, null, 2))
3939
}
4040

41-
const isToday = (dateObj: Date, today: Date) => {
42-
return dateObj.getDate() === today.getDate() &&
41+
const isToday = (dateObj: Date | null, today: Date) => {
42+
return dateObj && dateObj.getDate() === today.getDate() &&
4343
dateObj.getMonth() === today.getMonth() &&
4444
dateObj.getFullYear() === today.getFullYear()
4545
}
4646

4747
// if there's no timestamp in config, create one and check for updates
48-
if (!userConfig.lastVersionCheck) {
49-
await checkForUpdate()
50-
updateUserConfig(curDateTime)
51-
} else {
52-
// if there is a timestamp in config and it's not from today, check for updates
53-
const lastCheck = new Date(userConfig.lastVersionCheck)
48+
// if there is a timestamp in config and it's not from today, check for updates
49+
const lastCheck = userConfig.lastVersionCheck ? new Date(userConfig.lastVersionCheck) : null
5450
if (!isToday(lastCheck, curDateTime)) {
5551
await checkForUpdate()
5652
updateUserConfig(curDateTime)
57-
}
5853
}
54+
5955
/* tslint:disable:no-unused */
6056
} catch (err) {
6157
// swallow the exception; we don't want to crash the app

0 commit comments

Comments
 (0)