From 9cfe9ec9334a0400452e6c6dd002856a84177cc6 Mon Sep 17 00:00:00 2001 From: Nikita Date: Sun, 8 Sep 2024 14:57:12 +0300 Subject: [PATCH] cli > scripts, readme --- .gitignore | 1 - cli/readme.md | 5 +++ package.json | 4 +- readme.md | 31 ++++++++------ scripts/past-seed.ts | 88 ++++++++++++++++++++++++++++++++++++++++ {cli => scripts}/run.ts | 0 {cli => scripts}/seed.ts | 0 7 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 cli/readme.md create mode 100644 scripts/past-seed.ts rename {cli => scripts}/run.ts (100%) rename {cli => scripts}/seed.ts (100%) diff --git a/.gitignore b/.gitignore index d77f5022..d909cfed 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ pnpm-lock.yaml .next # repos -cli private docs diff --git a/cli/readme.md b/cli/readme.md new file mode 100644 index 00000000..f4b786b3 --- /dev/null +++ b/cli/readme.md @@ -0,0 +1,5 @@ +# CLI + +> CLI for interfacing with LA + +Will be modelled after [Encore's Go CLI](https://github.com/encoredev/encore/tree/main/cli/cmd/encore). diff --git a/package.json b/package.json index 55478bce..fbf1a31a 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "dev": "bun web", "web": "cd web && bun dev", "web:build": "bun run --filter '*' build", - "cli": "bun run --watch cli/run.ts", - "seed": "bun --watch cli/seed.ts", + "cli": "bun run --watch scripts/run.ts", + "seed": "bun --watch scripts/seed.ts", "tauri": "tauri", "app:build": "bun tauri build -b dmg -v" }, diff --git a/readme.md b/readme.md index 4eb26f93..397b8f3d 100644 --- a/readme.md +++ b/readme.md @@ -2,33 +2,40 @@ > Organize world's knowledge, explore connections and curate learning paths +## Files + +- [api](api) - http services (using TS/[Encore](https://encore.dev/)) +- [app](app) - desktop app (wrapping the [website](web) with desktop specific logic) (using [Tauri](https://v2.tauri.app/)) +- [cli](cli) - cli (using [Go](https://go.dev)) +- [docs](https://github.com/learn-anything/docs) - public docs hosted on [docs.learn-anything.xyz](https://docs.learn-anything.xyz/) (separate repo, to be managed by LA itself soon) +- [lib](lib) - shared utility functions in TS +- [nix](nix) - shared nix code +- [scripts](scripts) - utility scripts in TS +- [web](web) - website hosted on [learn-anything.xyz](https://learn-anything.xyz) (using [React](https://react.dev/)/[Next.js](https://nextjs.org/) + [Jazz](https://jazz.tools/) for local/global state) + ## Setup +> [!NOTE] +> Project is currently in unstable state but actively improving. Reach out on [Discord](https://discord.gg/bxtD8x6aNF) for help. + Using [Bun](https://bun.sh): ``` bun i ``` -> [!NOTE] -> Project is currently in unstable state but actively improving. Reach out on [Discord](https://discord.gg/bxtD8x6aNF) for help. +> [!NOTE] > `bun setup` is not yet done but will be a command to fully bootstrap a local working env for the project, without it, running `bun web` is impossible yet + +``` +bun setup +``` ## Run website -> [!NOTE] -> Requires jazz to be seeded, docs for this are TODO: - ``` bun web ``` -## Stack - -- [React](https://react.dev/)/[Next.js](https://nextjs.org/) - website built on this -- [Encore](https://encore.dev/) - http services in ts/node -- [Jazz](https://jazz.tools/) - global/local state management in both react and encore ts http services -- [Tauri](https://v2.tauri.app/)/[Rust](https://www.rust-lang.org) - desktop app (wrapping the website with desktop specific logic) - ## Contributing If you want to help contribute to code, ask for help on [Discord](https://discord.gg/bxtD8x6aNF)'s `#dev` channel. You will be onboarded and unblocked fast. diff --git a/scripts/past-seed.ts b/scripts/past-seed.ts new file mode 100644 index 00000000..07ec79e5 --- /dev/null +++ b/scripts/past-seed.ts @@ -0,0 +1,88 @@ +// @ts-nocheck +async function devSeed() { + const { worker } = await startWorker({ + accountID: "co_zhvp7ryXJzDvQagX61F6RCZFJB9", + accountSecret: JAZZ_WORKER_SECRET + }) + const user = (await ( + await LaAccount.createAs(worker, { + creationProps: { name: "nikiv" } + }) + ).ensureLoaded({ root: { personalLinks: [], pages: [], todos: [] } }))! + const globalLinksGroup = Group.create({ owner: worker }) + globalLinksGroup.addMember("everyone", "reader") + const globalLink1 = GlobalLink.create({ url: "https://google.com" }, { owner: globalLinksGroup }) + const globalLink2 = GlobalLink.create({ url: "https://jazz.tools" }, { owner: globalLinksGroup }) + // TODO: make note: optional + const personalLink1 = PersonalLink.create( + { globalLink: globalLink1, type: "personalLink", note: "" }, + { owner: user } + ) + const personalLink2 = PersonalLink.create( + { globalLink: globalLink2, type: "personalLink", note: "Great framework" }, + { owner: user } + ) + user.root.personalLinks.push(personalLink1) + user.root.personalLinks.push(personalLink2) + const pageOneTitle = "Physics" + const pageTwoTitle = "Karabiner" + const page1 = PersonalPage.create( + { title: pageOneTitle, slug: generateUniqueSlug([], pageOneTitle), content: "Physics is great" }, + { owner: user } + ) + const page2 = PersonalPage.create( + { title: pageTwoTitle, slug: generateUniqueSlug([], pageTwoTitle), content: "Karabiner is great" }, + { owner: user } + ) + user.root.personalPages?.push(page1) + user.root.personalPages?.push(page2) + const page1 = Page.create({ title: "Physics", content: "Physics is great" }, { owner: user }) + const page2 = Page.create({ title: "Karabiner", content: "Karabiner is great" }, { owner: user }) + user.root.pages.push(page1) + user.root.pages.push(page2) + const credentials = { + accountID: user.id, + accountSecret: (user._raw as RawControlledAccount).agentSecret + } + await Bun.write( + "./web/.env", + `VITE_SEED_ACCOUNTS='${JSON.stringify({ + nikiv: credentials + })}'` + ) + await Bun.write( + "./.env", + `VITE_SEED_ACCOUNTS='${JSON.stringify({ + nikiv: credentials + })}'` + ) +} +const globalLink = GlobalLink.create( + { + url: "https://google.com", + urlTitle: "Google", + protocol: "https" + }, + { owner: globalGroup } +) +const user = (await ( + await LaAccount.createAs(worker, { + creationProps: { name: "nikiv" } + }) +).ensureLoaded({ root: { personalLinks: [], pages: [], todos: [] } }))! +console.log(process.env.JAZZ_GLOBAL_GROUP!, "group") +console.log(worker) +// TODO: type err +console.log(globalGroup, "group") +return +const currentFilePath = import.meta.path +const connectionsFilePath = `${currentFilePath.replace("seed.ts", "/seed/connections.json")}` +const file = Bun.file(connectionsFilePath) +const fileContent = await file.text() +const topicsWithConnections = JSON.parse(fileContent) +// let topicsWithConnections = JSON.stringify(obj, null, 2) +console.log(topicsWithConnections) +// TODO: type err +topicsWithConnections.map(topic => { + const globalTopic = GlobalTopic.create({ name: topic.name, description: topic.description }, { owner: globalGroup }) +}) diff --git a/cli/run.ts b/scripts/run.ts similarity index 100% rename from cli/run.ts rename to scripts/run.ts diff --git a/cli/seed.ts b/scripts/seed.ts similarity index 100% rename from cli/seed.ts rename to scripts/seed.ts