notify user if config file was overwritten and make a copy of it as backup

This commit is contained in:
cupcakearmy 2020-03-02 19:08:20 +01:00
parent bc36a39de4
commit 7e577c439a
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
3 changed files with 22 additions and 6 deletions

View File

@ -1,4 +1,3 @@
## 0.15
## 0.16
- automatic binary releases
- code signing
- notify user if config file was overwritten and make a copy of it as backup

View File

@ -25,7 +25,7 @@ export const { _: commands, ...flags } = minimist(process.argv.slice(2), {
string: ['l', 'b'],
})
export const VERSION = '0.14'
export const VERSION = '0.16'
export const INSTALL_DIR = '/usr/local/bin'
export const VERBOSE = flags.verbose

View File

@ -1,4 +1,4 @@
import { readFileSync, writeFileSync, statSync } from 'fs'
import { readFileSync, writeFileSync, statSync, copyFileSync } from 'fs'
import { resolve } from 'path'
import { homedir } from 'os'
@ -88,10 +88,27 @@ export const init = (): Config | undefined => {
yaml.safeLoad(readFileSync(CONFIG_FILE).toString()),
)
const current = JSON.stringify(raw)
normalizeAndCheckBackends(raw)
normalizeAndCheckBackups(raw)
writeFileSync(CONFIG_FILE, yaml.safeDump(raw))
const changed = JSON.stringify(raw) !== current
if (changed) {
const OLD_CONFIG_FILE = CONFIG_FILE + '.old'
copyFileSync(CONFIG_FILE, OLD_CONFIG_FILE)
writeFileSync(CONFIG_FILE, yaml.safeDump(raw))
console.log(
'\n' +
'⚠️ MOVED OLD CONFIG FILE TO: ⚠️'.red.underline.bold +
'\n' +
OLD_CONFIG_FILE +
'\n' +
'What? Why? '.grey + 'https://git.io/Jv2D0'.underline.grey +
'\n'
)
}
return raw
}