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

pull/23/head 0.16
cupcakearmy 5 years ago
parent bc36a39de4
commit 7e577c439a
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

@ -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

@ -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

@ -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)
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
}

Loading…
Cancel
Save