diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f025cc..009c041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,3 @@ -## 0.15 +## 0.16 -- automatic binary releases -- code signing \ No newline at end of file +- notify user if config file was overwritten and make a copy of it as backup \ No newline at end of file diff --git a/src/autorestic.ts b/src/autorestic.ts index 09dfced..0b0a576 100644 --- a/src/autorestic.ts +++ b/src/autorestic.ts @@ -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 diff --git a/src/config.ts b/src/config.ts index 577e344..faebdb3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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 }