Skip to content

Commit ab4f278

Browse files
committed
Update config error and link to README
1 parent bb9bef4 commit ab4f278

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ const envConfig = {
2222
serverUrl: process.env.CMD_CLI_SERVER_URL
2323
}
2424

25-
const readConfig = fs.existsSync(configFilePath) ? JSON.parse(fs.readFileSync(configFilePath, 'utf-8')) : {}
25+
const hasExistingConfig = fs.existsSync(configFilePath)
26+
const readConfig = hasExistingConfig ? JSON.parse(fs.readFileSync(configFilePath, 'utf-8')) : {}
2627

27-
export default defaults(readConfig, envConfig, defaultConfig)
28+
const defaultServerUrl = 'PLEASE FILL THE SERVER URL'
29+
if (!hasExistingConfig) {
30+
fs.writeFileSync(configFilePath, JSON.stringify({serverUrl: defaultServerUrl}, null, 2), 'utf-8')
31+
}
32+
33+
const config = defaults(readConfig, envConfig, defaultConfig)
34+
35+
if (!config.serverUrl || config.serverUrl === defaultServerUrl) {
36+
throw new Error(`
37+
38+
Please specify CodiMD server url either in ${configFilePath} or by environment varaible.
39+
40+
You can learn how to config codimd-cli on https://github.com/hackmdio/codimd-cli
41+
42+
`)
43+
}
44+
45+
export default config

0 commit comments

Comments
 (0)