mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 16:26:25 +00:00
upgrade packages, included lock file, fixed types
This commit is contained in:
parent
1a891fffbd
commit
b332897713
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
# Node
|
# Node
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
|
||||||
|
|
||||||
# Build & Runtime
|
# Build & Runtime
|
||||||
bin
|
bin
|
||||||
|
24
package.json
24
package.json
@ -10,21 +10,21 @@
|
|||||||
"docs:dev": "codedoc serve"
|
"docs:dev": "codedoc serve"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@codedoc/cli": "^0.1.4",
|
"@codedoc/cli": "0.1.x",
|
||||||
"@types/js-yaml": "^3.12.1",
|
"@types/js-yaml": "3.x.x",
|
||||||
"@types/minimist": "^1.2.0",
|
"@types/minimist": "1.x.x",
|
||||||
"@types/node": "^12.11.7",
|
"@types/node": "14.x.x",
|
||||||
"pkg": "^4.4.0",
|
"pkg": "4.4.x",
|
||||||
"ts-node-dev": "^1.0.0-pre.40",
|
"ts-node-dev": "^1.0.0-pre.40",
|
||||||
"typescript": "^3.7"
|
"typescript": "3.9.x"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.0",
|
"axios": "0.19.x",
|
||||||
"clitastic": "0.0.1",
|
"clitastic": "0.0.1",
|
||||||
"colors": "^1.3.3",
|
"colors": "1.x.x",
|
||||||
"cron-parser": "^2.13.0",
|
"cron-parser": "2.x.x",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "3.x.x",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "1.x.x",
|
||||||
"uhrwerk": "^1.0.0"
|
"uhrwerk": "1.x.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,32 +9,23 @@ import { flags } from './autorestic'
|
|||||||
import { Backend, Config } from './types'
|
import { Backend, Config } from './types'
|
||||||
import { makeArrayIfIsNot, makeObjectKeysLowercase, rand } from './utils'
|
import { makeArrayIfIsNot, makeObjectKeysLowercase, rand } from './utils'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export enum LocationFromPrefixes {
|
export enum LocationFromPrefixes {
|
||||||
Filesystem,
|
Filesystem,
|
||||||
DockerVolume
|
DockerVolume,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const normalizeAndCheckBackends = (config: Config) => {
|
export const normalizeAndCheckBackends = (config: Config) => {
|
||||||
config.backends = makeObjectKeysLowercase(config.backends)
|
config.backends = makeObjectKeysLowercase(config.backends)
|
||||||
|
|
||||||
for (const [name, { type, path, key, ...rest }] of Object.entries(
|
for (const [name, { type, path, key, ...rest }] of Object.entries(config.backends)) {
|
||||||
config.backends,
|
if (!type || !path) throw new Error(`The backend "${name}" is missing some required attributes`)
|
||||||
)) {
|
|
||||||
if (!type || !path)
|
|
||||||
throw new Error(
|
|
||||||
`The backend "${name}" is missing some required attributes`,
|
|
||||||
)
|
|
||||||
|
|
||||||
const tmp: any = {
|
const tmp: any = {
|
||||||
type,
|
type,
|
||||||
path,
|
path,
|
||||||
key: key || rand(128),
|
key: key || rand(128),
|
||||||
}
|
}
|
||||||
for (const [key, value] of Object.entries(rest))
|
for (const [key, value] of Object.entries(rest)) tmp[key.toUpperCase()] = value
|
||||||
tmp[key.toUpperCase()] = value
|
|
||||||
|
|
||||||
config.backends[name] = tmp as Backend
|
config.backends[name] = tmp as Backend
|
||||||
}
|
}
|
||||||
@ -45,18 +36,15 @@ export const normalizeAndCheckLocations = (config: Config) => {
|
|||||||
const backends = Object.keys(config.backends)
|
const backends = Object.keys(config.backends)
|
||||||
|
|
||||||
const checkDestination = (backend: string, location: string) => {
|
const checkDestination = (backend: string, location: string) => {
|
||||||
if (!backends.includes(backend))
|
if (!backends.includes(backend)) throw new Error(`Cannot find the backend "${backend}" for "${location}"`)
|
||||||
throw new Error(`Cannot find the backend "${backend}" for "${location}"`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [name, { from, to, cron, ...rest }] of Object.entries(config.locations)) {
|
for (const [name, { from, to, cron, ...rest }] of Object.entries(config.locations)) {
|
||||||
if (!from)
|
if (!from) throw new Error(`The location "${name.blue}" is missing the "${'from'.underline.red}" source folder. See https://git.io/Jf0xw`)
|
||||||
throw new Error(`The location "${name.blue}" is missing the "${'from'.underline.red}" source folder. See https://git.io/Jf0xw`)
|
|
||||||
if (!to || (Array.isArray(to) && !to.length))
|
if (!to || (Array.isArray(to) && !to.length))
|
||||||
throw new Error(`The location "${name.blue}" has no backend "${'to'.underline.red}" to save the backups. See https://git.io/Jf0xw`)
|
throw new Error(`The location "${name.blue}" has no backend "${'to'.underline.red}" to save the backups. See https://git.io/Jf0xw`)
|
||||||
|
|
||||||
for (const t of makeArrayIfIsNot(to))
|
for (const t of makeArrayIfIsNot(to)) checkDestination(t, name)
|
||||||
checkDestination(t, name)
|
|
||||||
|
|
||||||
if (cron) {
|
if (cron) {
|
||||||
try {
|
try {
|
||||||
@ -70,17 +58,12 @@ export const normalizeAndCheckLocations = (config: Config) => {
|
|||||||
|
|
||||||
const findConfigFile = (): string => {
|
const findConfigFile = (): string => {
|
||||||
const config = '.autorestic.yml'
|
const config = '.autorestic.yml'
|
||||||
const paths = [
|
const paths = [resolve(flags.config || ''), resolve('./' + config), homedir() + '/' + config]
|
||||||
resolve(flags.config || ''),
|
|
||||||
resolve('./' + config),
|
|
||||||
homedir() + '/' + config,
|
|
||||||
]
|
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
try {
|
try {
|
||||||
const file = statSync(path)
|
const file = statSync(path)
|
||||||
if (file.isFile()) return path
|
if (file.isFile()) return path
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new Error('Config file not found')
|
throw new Error('Config file not found')
|
||||||
}
|
}
|
||||||
@ -91,9 +74,9 @@ export const init = (): Config => {
|
|||||||
const file = findConfigFile()
|
const file = findConfigFile()
|
||||||
CONFIG_FILE = file
|
CONFIG_FILE = file
|
||||||
|
|
||||||
const raw: Config = makeObjectKeysLowercase(
|
const parsed = yaml.safeLoad(readFileSync(CONFIG_FILE).toString())
|
||||||
yaml.safeLoad(readFileSync(CONFIG_FILE).toString()),
|
if (!parsed || typeof parsed === 'string') throw new Error('Could not parse the config file')
|
||||||
)
|
const raw: Config = makeObjectKeysLowercase(parsed)
|
||||||
|
|
||||||
const current = JSON.stringify(raw)
|
const current = JSON.stringify(raw)
|
||||||
|
|
||||||
@ -112,7 +95,8 @@ export const init = (): Config => {
|
|||||||
'\n' +
|
'\n' +
|
||||||
OLD_CONFIG_FILE +
|
OLD_CONFIG_FILE +
|
||||||
'\n' +
|
'\n' +
|
||||||
'What? Why? '.grey + 'https://git.io/Jf0xK'.underline.grey +
|
'What? Why? '.grey +
|
||||||
|
'https://git.io/Jf0xK'.underline.grey +
|
||||||
'\n'
|
'\n'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user