aboutsummaryrefslogtreecommitdiffstats
path: root/apps/cli
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-04-24 11:37:35 +0100
committerMohamedBassem <me@mbassem.com>2024-04-24 12:21:55 +0100
commit3352a3ea393849550573deff8d774ba6bf149471 (patch)
treea7d78db4fadbe7123c7d5045f5a537965382b84a /apps/cli
parentaf0cf9c1ee10901ab91b04a1d73afdcb2191a88f (diff)
downloadkarakeep-3352a3ea393849550573deff8d774ba6bf149471.tar.zst
build(cli): Prepare for publishing CLI to npm
Diffstat (limited to 'apps/cli')
-rw-r--r--apps/cli/.gitignore1
-rw-r--r--apps/cli/.npmignore4
-rw-r--r--apps/cli/package.json34
-rw-r--r--apps/cli/src/commands/bookmarks.ts (renamed from apps/cli/commands/bookmarks.ts)2
-rw-r--r--apps/cli/src/commands/lists.ts (renamed from apps/cli/commands/lists.ts)2
-rw-r--r--apps/cli/src/commands/tags.ts (renamed from apps/cli/commands/tags.ts)2
-rw-r--r--apps/cli/src/commands/whoami.ts (renamed from apps/cli/commands/whoami.ts)2
-rw-r--r--apps/cli/src/index.ts (renamed from apps/cli/index.ts)11
-rw-r--r--apps/cli/src/lib/globals.ts (renamed from apps/cli/lib/globals.ts)0
-rw-r--r--apps/cli/src/lib/trpc.ts (renamed from apps/cli/lib/trpc.ts)3
-rw-r--r--apps/cli/tsconfig.json7
-rw-r--r--apps/cli/vite.config.mts21
12 files changed, 66 insertions, 23 deletions
diff --git a/apps/cli/.gitignore b/apps/cli/.gitignore
new file mode 100644
index 00000000..1521c8b7
--- /dev/null
+++ b/apps/cli/.gitignore
@@ -0,0 +1 @@
+dist
diff --git a/apps/cli/.npmignore b/apps/cli/.npmignore
new file mode 100644
index 00000000..18a504f5
--- /dev/null
+++ b/apps/cli/.npmignore
@@ -0,0 +1,4 @@
+.turbo/**
+src/**
+vite.config.mts
+tsconfig.json
diff --git a/apps/cli/package.json b/apps/cli/package.json
index 87c02c3d..2878ad96 100644
--- a/apps/cli/package.json
+++ b/apps/cli/package.json
@@ -1,9 +1,20 @@
{
"$schema": "https://json.schemastore.org/package.json",
- "name": "@hoarder/cli",
- "version": "0.1.0",
- "private": true,
- "dependencies": {
+ "name": "@hoarderapp/cli",
+ "version": "0.12.1",
+ "description": "Command Line Interface (CLI) for Hoarder",
+ "license": "GNU Affero General Public License version 3",
+ "keywords": [
+ "hoarder",
+ "cli"
+ ],
+ "exports": "./dist/index.mjs",
+ "bin": {
+ "hoarder": "dist/index.mjs"
+ },
+ "devDependencies": {
+ "@hoarder/eslint-config": "workspace:^0.2.0",
+ "@hoarder/prettier-config": "workspace:^0.1.0",
"@commander-js/extra-typings": "^12.0.1",
"@hoarder/shared": "workspace:^0.1.0",
"@hoarder/trpc": "workspace:^0.1.0",
@@ -15,18 +26,21 @@
"commander": "^12.0.0",
"superjson": "^2.2.1",
"table": "^6.8.2",
- "tsx": "^4.7.1"
- },
- "devDependencies": {
- "@hoarder/eslint-config": "workspace:^0.2.0",
- "@hoarder/prettier-config": "workspace:^0.1.0"
+ "tsx": "^4.7.1",
+ "vite": "^5.1.0"
},
"scripts": {
- "run": "tsx index.ts",
+ "build": "vite build",
+ "run": "tsx src/index.ts",
"lint": "eslint .",
"format": "prettier . --ignore-path ../../.prettierignore",
"typecheck": "tsc --noEmit"
},
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/MohamedBassem/hoarder-app.git",
+ "directory": "apps/cli"
+ },
"eslintConfig": {
"root": true,
"extends": [
diff --git a/apps/cli/commands/bookmarks.ts b/apps/cli/src/commands/bookmarks.ts
index 0da3dd71..264ad818 100644
--- a/apps/cli/commands/bookmarks.ts
+++ b/apps/cli/src/commands/bookmarks.ts
@@ -1,7 +1,7 @@
import * as fs from "node:fs";
+import { getAPIClient } from "@/lib/trpc";
import { Command } from "@commander-js/extra-typings";
import chalk from "chalk";
-import { getAPIClient } from "lib/trpc";
import type { ZBookmark } from "@hoarder/shared/types/bookmarks";
diff --git a/apps/cli/commands/lists.ts b/apps/cli/src/commands/lists.ts
index 099b7869..abf6f78c 100644
--- a/apps/cli/commands/lists.ts
+++ b/apps/cli/src/commands/lists.ts
@@ -1,5 +1,5 @@
+import { getAPIClient } from "@/lib/trpc";
import { Command } from "@commander-js/extra-typings";
-import { getAPIClient } from "lib/trpc";
import { getBorderCharacters, table } from "table";
import { listsToTree } from "@hoarder/shared/utils/listUtils";
diff --git a/apps/cli/commands/tags.ts b/apps/cli/src/commands/tags.ts
index f9df83cd..f74f1df6 100644
--- a/apps/cli/commands/tags.ts
+++ b/apps/cli/src/commands/tags.ts
@@ -1,5 +1,5 @@
+import { getAPIClient } from "@/lib/trpc";
import { Command } from "@commander-js/extra-typings";
-import { getAPIClient } from "lib/trpc";
import { getBorderCharacters, table } from "table";
export const tagsCmd = new Command()
diff --git a/apps/cli/commands/whoami.ts b/apps/cli/src/commands/whoami.ts
index 2b32f2f0..b55bfa67 100644
--- a/apps/cli/commands/whoami.ts
+++ b/apps/cli/src/commands/whoami.ts
@@ -1,5 +1,5 @@
+import { getAPIClient } from "@/lib/trpc";
import { Command } from "@commander-js/extra-typings";
-import { getAPIClient } from "lib/trpc";
export const whoamiCmd = new Command()
.name("whoami")
diff --git a/apps/cli/index.ts b/apps/cli/src/index.ts
index 5971b811..cdb2956e 100644
--- a/apps/cli/index.ts
+++ b/apps/cli/src/index.ts
@@ -1,9 +1,10 @@
+#! /usr/bin/env node
+import { bookmarkCmd } from "@/commands/bookmarks";
+import { listsCmd } from "@/commands/lists";
+import { tagsCmd } from "@/commands/tags";
+import { whoamiCmd } from "@/commands/whoami";
+import { setGlobalOptions } from "@/lib/globals";
import { Command, Option } from "@commander-js/extra-typings";
-import { bookmarkCmd } from "commands/bookmarks";
-import { listsCmd } from "commands/lists";
-import { tagsCmd } from "commands/tags";
-import { whoamiCmd } from "commands/whoami";
-import { setGlobalOptions } from "lib/globals";
const program = new Command()
.name("hoarder-cli")
diff --git a/apps/cli/lib/globals.ts b/apps/cli/src/lib/globals.ts
index 771136da..771136da 100644
--- a/apps/cli/lib/globals.ts
+++ b/apps/cli/src/lib/globals.ts
diff --git a/apps/cli/lib/trpc.ts b/apps/cli/src/lib/trpc.ts
index 6f0dccfe..aa7aec21 100644
--- a/apps/cli/lib/trpc.ts
+++ b/apps/cli/src/lib/trpc.ts
@@ -1,10 +1,9 @@
+import { getGlobalOptions } from "@/lib/globals";
import { createTRPCClient, httpBatchLink } from "@trpc/client";
import superjson from "superjson";
import type { AppRouter } from "@hoarder/trpc/routers/_app";
-import { getGlobalOptions } from "./globals";
-
export function getAPIClient() {
const globals = getGlobalOptions();
return createTRPCClient<AppRouter>({
diff --git a/apps/cli/tsconfig.json b/apps/cli/tsconfig.json
index dc71844c..43577686 100644
--- a/apps/cli/tsconfig.json
+++ b/apps/cli/tsconfig.json
@@ -1,11 +1,14 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@hoarder/tsconfig/node.json",
- "include": ["**/*.ts"],
- "exclude": ["node_modules"],
+ "include": ["src", "vite.config.mts"],
+ "exclude": ["node_modules", "dist"],
"compilerOptions": {
"baseUrl": ".",
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"strictNullChecks": true,
+ "paths": {
+ "@/*": ["./src/*"]
+ }
}
}
diff --git a/apps/cli/vite.config.mts b/apps/cli/vite.config.mts
new file mode 100644
index 00000000..4c18902f
--- /dev/null
+++ b/apps/cli/vite.config.mts
@@ -0,0 +1,21 @@
+// This file is shamelessly copied from immich's CLI vite config
+// https://github.com/immich-app/immich/blob/main/cli/vite.config.ts
+import { defineConfig } from "vite";
+import tsconfigPaths from "vite-tsconfig-paths";
+
+export default defineConfig({
+ build: {
+ rollupOptions: {
+ input: "src/index.ts",
+ output: {
+ dir: "dist",
+ },
+ },
+ ssr: true,
+ },
+ ssr: {
+ // bundle everything except for Node built-ins
+ noExternal: /^(?!node:).*$/,
+ },
+ plugins: [tsconfigPaths()],
+});