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

Commit 48bac8c

Browse files
author
Jonathan Spruance (Insight Global)
committed
Refactor file writing fo rconfig
1 parent 5b09aa2 commit 48bac8c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/cli/scripts/postinstall.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const packageName = pjson.name
1313
const platform = os.platform()
1414
const isWindows = platform === 'win32'
1515
const home = process.env.HOME || (isWindows && windowsHome()) || os.homedir() || os.tmpdir()
16+
const today = new Date();
1617

1718
const getConfigDir = (isWindows, home, pname) => {
1819
const base = process.env[`XDG_CONFIG_HOME`]
@@ -36,6 +37,7 @@ const getUserConfig = async () => {
3637
const promptTelemetry = async () => {
3738
try {
3839
const userConfig = await getUserConfig()
40+
userConfig.lastVersionCheck = today;
3941
if (userConfig.telemetry === null) {
4042
const disableTelemetry = await cli.prompt(chalk.red('Telemetry is disabled. Would you like to opt in? Only command and flags usage will be sent. (Y/N)'))
4143
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
@@ -53,7 +55,6 @@ const getUserConfig = async () => {
5355
}
5456

5557
await fs.mkdirp(pathToConfigJson)
56-
5758
await fs.writeFile(path.join(pathToConfigJson, 'config.json'), JSON.stringify(userConfig, null, 2))
5859
}
5960
/* tslint:disable:no-unused */

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const hook: Hook<'init'> = async function (opts) {
1212
const curDateTime = new Date()
1313
const configFileExists = fs.existsSync(path.join(this.config.configDir, 'config.json'))
1414

15-
const createConfigDir = async (path: string) => {
15+
const writeUserConfig = async (userconfig: any) => {
1616
await fs.mkdirp(this.config.configDir)
17+
await fs.writeFile(path.join(this.config.configDir, 'config.json'), JSON.stringify(userconfig, null, 2))
1718
}
1819

1920
try {
@@ -37,10 +38,9 @@ const hook: Hook<'init'> = async function (opts) {
3738
}
3839
}
3940

40-
const updateUserConfig = (curVersionCheck: Date) => {
41+
const updateUserConfig = async (curVersionCheck: Date) => {
4142
userConfig.lastVersionCheck = curVersionCheck
42-
createConfigDir(this.config.configDir)
43-
fs.writeFileSync(path.join(this.config.configDir, 'config.json'), JSON.stringify(userConfig, null, 2))
43+
await writeUserConfig(userConfig)
4444
}
4545

4646
const isToday = (dateObj: Date | null, today: Date) => {
@@ -81,9 +81,7 @@ const hook: Hook<'init'> = async function (opts) {
8181
this.log(chalk.blue('bf config:telemetry:enable'))
8282
}
8383

84-
createConfigDir(this.config.configDir)
85-
86-
await fs.writeFile(path.join(this.config.configDir, 'config.json'), JSON.stringify(userConfig, null, 2))
84+
await writeUserConfig(userConfig)
8785
}
8886

8987
this.config.pjson.telemetry = userConfig.telemetry

0 commit comments

Comments
 (0)