summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2025-11-08 18:55:03 +0100
committerLeo Goetz <dev@leogtz.de>2025-11-08 18:55:03 +0100
commit16a0e9a9d2c24af28142ed3420ef6cb373c454f7 (patch)
treeb948472cea12b505ae3f2cc04b66801207ebc6aa
parent91a6ac10e416dcf2c29b6e37e3dfe19672eb0f84 (diff)
started making the command and json db
-rw-r--r--.gitignore1
-rw-r--r--db.json3
-rw-r--r--index.js9
-rw-r--r--package.json10
-rw-r--r--pnpm-lock.yaml115
-rw-r--r--src/command.js71
-rw-r--r--src/db.js17
7 files changed, 216 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..07e6e47
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/node_modules
diff --git a/db.json b/db.json
new file mode 100644
index 0000000..8de43c7
--- /dev/null
+++ b/db.json
@@ -0,0 +1,3 @@
+{
+ "notes": []
+}
diff --git a/index.js b/index.js
index 36d56ef..8496e47 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,2 @@
#!/usr/bin/env node
-
-const note = process.argv[2];
-const newNote = {
- content: note,
- id: Date.now(),
-};
-
-console.log(newNote);
+import "./src/command.js";
diff --git a/package.json b/package.json
index cafb329..c766335 100644
--- a/package.json
+++ b/package.json
@@ -2,13 +2,19 @@
"name": "intro-node",
"version": "1.0.0",
"description": "",
+ "type": "module",
"main": "index.js",
"bin": {
"note": "./index.js"
},
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "note": "node index.js"
},
+ "keywords": [],
"author": "",
- "license": "ISC"
+ "license": "ISC",
+ "packageManager": "pnpm@10.20.0",
+ "dependencies": {
+ "yargs": "^18.0.0"
+ }
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
new file mode 100644
index 0000000..500f767
--- /dev/null
+++ b/pnpm-lock.yaml
@@ -0,0 +1,115 @@
+lockfileVersion: '9.0'
+
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
+
+importers:
+
+ .:
+ dependencies:
+ yargs:
+ specifier: ^18.0.0
+ version: 18.0.0
+
+packages:
+
+ ansi-regex@6.2.2:
+ resolution: {integrity: sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==}
+ engines: {node: '>=12'}
+
+ ansi-styles@6.2.3:
+ resolution: {integrity: sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==}
+ engines: {node: '>=12'}
+
+ cliui@9.0.1:
+ resolution: {integrity: sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w==}
+ engines: {node: '>=20'}
+
+ emoji-regex@10.6.0:
+ resolution: {integrity: sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==}
+
+ escalade@3.2.0:
+ resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==}
+ engines: {node: '>=6'}
+
+ get-caller-file@2.0.5:
+ resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
+ engines: {node: 6.* || 8.* || >= 10.*}
+
+ get-east-asian-width@1.4.0:
+ resolution: {integrity: sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q==}
+ engines: {node: '>=18'}
+
+ string-width@7.2.0:
+ resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==}
+ engines: {node: '>=18'}
+
+ strip-ansi@7.1.2:
+ resolution: {integrity: sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==}
+ engines: {node: '>=12'}
+
+ wrap-ansi@9.0.2:
+ resolution: {integrity: sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==}
+ engines: {node: '>=18'}
+
+ y18n@5.0.8:
+ resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
+ engines: {node: '>=10'}
+
+ yargs-parser@22.0.0:
+ resolution: {integrity: sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=23}
+
+ yargs@18.0.0:
+ resolution: {integrity: sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg==}
+ engines: {node: ^20.19.0 || ^22.12.0 || >=23}
+
+snapshots:
+
+ ansi-regex@6.2.2: {}
+
+ ansi-styles@6.2.3: {}
+
+ cliui@9.0.1:
+ dependencies:
+ string-width: 7.2.0
+ strip-ansi: 7.1.2
+ wrap-ansi: 9.0.2
+
+ emoji-regex@10.6.0: {}
+
+ escalade@3.2.0: {}
+
+ get-caller-file@2.0.5: {}
+
+ get-east-asian-width@1.4.0: {}
+
+ string-width@7.2.0:
+ dependencies:
+ emoji-regex: 10.6.0
+ get-east-asian-width: 1.4.0
+ strip-ansi: 7.1.2
+
+ strip-ansi@7.1.2:
+ dependencies:
+ ansi-regex: 6.2.2
+
+ wrap-ansi@9.0.2:
+ dependencies:
+ ansi-styles: 6.2.3
+ string-width: 7.2.0
+ strip-ansi: 7.1.2
+
+ y18n@5.0.8: {}
+
+ yargs-parser@22.0.0: {}
+
+ yargs@18.0.0:
+ dependencies:
+ cliui: 9.0.1
+ escalade: 3.2.0
+ get-caller-file: 2.0.5
+ string-width: 7.2.0
+ y18n: 5.0.8
+ yargs-parser: 22.0.0
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 <note>",
+ "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 <filter>",
+ "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 <id>",
+ "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();
+};