From 16a0e9a9d2c24af28142ed3420ef6cb373c454f7 Mon Sep 17 00:00:00 2001 From: Leo Goetz Date: Sat, 8 Nov 2025 18:55:03 +0100 Subject: started making the command and json db --- src/command.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/db.js | 17 ++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/command.js create mode 100644 src/db.js (limited to 'src') diff --git a/src/command.js b/src/command.js new file mode 100644 index 0000000..20a23b2 --- /dev/null +++ b/src/command.js @@ -0,0 +1,71 @@ +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; + +yargs(hideBin(process.argv)) + .command( + "new ", + "create a new note", + (yargs) => { + return yargs.positional("note", { + type: "string", + description: "The content of the note to create", + }); + }, + (argv) => { + console.log(argv.note); + }, + ) + .option("tags", { + alias: "t", + type: "string", + description: "tags to add to the note", + }) + .command( + "all", + "get all notes", + () => {}, + async (argv) => {}, + ) + .command( + "find ", + "get matching notes", + (yargs) => { + return yargs.positional("filter", { + describe: + "The search term to filter notes by, will be applied to note.content", + type: "string", + }); + }, + async (argv) => {}, + ) + .command( + "remove ", + "remove a note by id", + (yargs) => { + return yargs.positional("id", { + type: "number", + description: "The id of the note you want to remove", + }); + }, + async (argv) => {}, + ) + .command( + "web [port]", + "launch website to see notes", + (yargs) => { + return yargs.positional("port", { + describe: "port to bind on", + default: 5000, + type: "number", + }); + }, + async (argv) => {}, + ) + .command( + "clean", + "remove all notes", + () => {}, + async (argv) => {}, + ) + .demandCommand(1) + .parse(); diff --git a/src/db.js b/src/db.js new file mode 100644 index 0000000..39fdc29 --- /dev/null +++ b/src/db.js @@ -0,0 +1,17 @@ +import fs from "node:fs/promises"; + +const DB_PATH = new URL("../db.json", import.meta.url).pathname; + +export const getDB = async () => { + const db = await fs.readFile(DB_PATH, "utf-8"); + return JSON.parse(db); +}; + +export const saveDB = async (db) => { + await fs.writeFile(DB_PATH, JSON.stringify(db, null, 2)); + return db; +}; + +export const insertDB = async (note) => { + const db = await getDB(); +}; -- cgit v1.3