Skip to content

Commit

Permalink
feat: add db cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Jun 18, 2020
1 parent a69359e commit 67e7701
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

require('dotenv').config()

const fs = require('fs')
const didYouMean = require('didyoumean')
const updateNotifier = require('update-notifier')
const program = require('commander')
Expand Down Expand Up @@ -84,7 +83,7 @@ module.exports = async (argv) => {
program.parse(argv)

if (program.debug) {
logger.level = 4
logger.level = 5
}
}

Expand Down
15 changes: 13 additions & 2 deletions lib/db.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
'use strict'

const exit = require('capture-exit')
const level = require('level')

const os = require('os')
const path = require('path')
const tildify = require('tildify')

const logger = require('./logger')

exit.captureExit()

const dbName = process.env.FLOCK_DB_NAME || 'flock'
const homeDir = os.homedir()
const tempDir = os.tmpdir()
const baseDir = homeDir || tempDir
const location = path.join(baseDir, homeDir ? `.${dbName}` : dbName)

// defaults to ~/.flock
logger.debug(`opening database ${tildify(location)}`)

module.exports = level(location, {
valueEncoding: 'json'
})

exit.onExit(async () => {
logger.debug(`closing database ${tildify(location)}`)
return module.exports.close()
})
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"btoa": "^1.2.1",
"capture-exit": "^2.0.0",
"clipboardy": "^2.3.0",
"commander": "^2.20.0",
"conf": "^6.2.4",
Expand Down Expand Up @@ -49,6 +50,7 @@
"random": "^2.2.0",
"saasify-client": "^1.20.0",
"shortid": "^2.2.15",
"tildify": "^2.0.0",
"twitter-lite": "^0.13.0",
"update-notifier": "^4.1.0",
"xlsx": "^0.16.2"
Expand Down
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ A more extensible design would allow for workflows comprised of [directed acycli
- [x] experiment with extracting public emails
- [x] default persistent storage ([leveldb](https://github.com/Level/level))
- [x] support commiting batch job updates
- [x] user-friendly cli skeleton
- [ ] basic cli commands
- [ ] cli oauth
- [x] user-friendly cli
- [x] cli support for different output formats
- [ ] initial set of cli commands
- [ ] cli oauth support
- via [sheetjs/xlsx](https://github.com/SheetJS/sheetjs#supported-output-formats)
- json, csv, txt, xls, xlsx, html, etc
- [ ] unit tests for snapshotting, serializing, deserializing
- [ ] unit tests for workflows
- [ ] convert transforms to batchjob
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ camelcase@^5.0.0, camelcase@^5.3.1:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

capture-exit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
integrity sha512-PiT/hQmTonHhl/HFGN+Lx3JJUznrVYJ3+AQsnthneZbvW7x+f08Tk7yLJTLEOUvBTbduLeeBkxEaYXUOUrRq6g==
dependencies:
rsvp "^4.8.4"

cfb@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/cfb/-/cfb-1.1.4.tgz#81fd35ede4c919d8f0962a94582e1dfaf7051e2a"
Expand Down Expand Up @@ -3417,6 +3424,11 @@ rimraf@^3.0.0:
dependencies:
glob "^7.1.3"

rsvp@^4.8.4:
version "4.8.5"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
integrity sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==

run-async@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
Expand Down Expand Up @@ -3793,6 +3805,11 @@ through@^2.3.6:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=

tildify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tildify/-/tildify-2.0.0.tgz#f205f3674d677ce698b7067a99e949ce03b4754a"
integrity sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw==

time-zone@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/time-zone/-/time-zone-1.0.0.tgz#99c5bf55958966af6d06d83bdf3800dc82faec5d"
Expand Down

0 comments on commit 67e7701

Please sign in to comment.