Commit fc49889e authored by Steve Streza's avatar Steve Streza
Browse files

Cleanup

parent 25e48b6c
Pipeline #702 canceled with stage
in 1 minute and 7 seconds
import DataStore from "@microjournal/data-store";
import FolderAccessor from "@microjournal/accessor-folder";
import { join as joinPath } from "path"
import { homedir } from "os"
import * as Commander from "commander"
const createStore = () => {
const path = (Commander.path as string) || joinPath(homedir(), ".microjournal")
const accessor = new FolderAccessor(path);
const store = new DataStore(accessor);
return store
}
const journalName = () => ((Commander.journal as string) || "personal")
import create from "./commands/create"
import journals from "./commands/journals"
import list from "./commands/list"
import search from "./commands/search"
Commander
.version("0.0.1")
.option("-p, --path <path>", "The path to the journal (defaults to ~/.microjournal)")
.option("-j, --journal <name>", "The name of the journal (defaults to personal)")
Commander
.command("create <message>")
.description("creates a new journal entry")
.action(message => {
const journal = (Commander.journal as string) || "personal"
const store = createStore();
if (message && journal) {
store.accessor
.create(journal, {
date: new Date(),
data: {
message
}
})
.subscribe({
error: error => {
console.error("ERROR: ", error);
process.exit(1)
}
});
}
})
Commander
.command("journals")
.description("lists journals")
.action(() => {
const store = createStore();
store.accessor.listJournals()
.subscribe({
next: j => {
console.log("" + j.slug)
}
})
})
create(Commander)
journals(Commander)
list(Commander)
search(Commander)
Commander
.command("list")
.description("lists the contents of the journal")
.action(() => {
const store = createStore()
store.accessor.list(journalName())
.subscribe({
next: entry => {
if (entry.date) {
console.log("" + entry.date.toLocaleDateString() + " " + entry.date.toLocaleTimeString() + ": " + entry.data.message)
}
else {
console.log("" + entry.data.message)
}
}
})
})
Commander
.command("search [term]")
.description("searches the messages in the journal for a given term")
.action((term: string) => {
console.log("Searching: ", term)
if (term) {
const store = createStore()
store.accessor.search(term, journalName())
.subscribe({
next: entry => {
if (entry.date) {
console.log("" + entry.date.toLocaleDateString() + " " + entry.date.toLocaleTimeString() + ": " + entry.data.message)
}
else {
console.log("" + entry.data.message)
}
}
})
}
})
Commander.parse(process.argv)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment