Skip to content

Commit

Permalink
CLI: add sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Nov 3, 2024
1 parent 07e324b commit 4728346
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-peas-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/cli": minor
---

add 'sync' command
10 changes: 10 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
"default": "./_cjs/shared.cjs"
}
},
"./sync": {
"import": {
"types": "./dist/sync.d.ts",
"default": "./dist/sync.js"
},
"require": {
"types": "./dist/sync.d.ts",
"default": "./_cjs/sync.cjs"
}
},
"./unlink": {
"import": {
"types": "./dist/unlink.d.ts",
Expand Down
21 changes: 20 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import { Array, Equivalence } from "effect"
import fs from "fs"
import w from "node-watch"
import path from "path"
import readline from "readline/promises"
import { sync } from "./sync.js"

function askQuestion(query: string) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

return rl.question(query)
}

const _cmd = process.argv[2]
const supportedCommands = [
Expand All @@ -15,7 +26,8 @@ const supportedCommands = [
"packagejson-target",
"packagejson-packages",
"link",
"unlink"
"unlink",
"sync"
] as const
if (
!supportedCommands.includes(_cmd as any)
Expand Down Expand Up @@ -234,6 +246,13 @@ switch (cmd) {
.forEach((_) => monitorPackagejson(_))
break
}

case "sync": {
console.log("Sync all snippets?")

await askQuestion("Are you sure you want to sync snippets")
await sync()
}
}

if (cmds.length) {
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import fs from "fs/promises"

const baseUrl = `https://raw.githubusercontent.com/effect-app/boilerplate/refs/heads/main`
const vscode = `${baseUrl}/.vscode`
const snippets = [
"model.code-snippets",
"service.code-snippets"
]

export async function sync() {
await Promise.all(snippets.map(async (snippet) => {
const url = `${vscode}/${snippet}`
const res = await fetch(url)
const content = await res.text()
await fs.writeFile(`.vscode/${snippet}`, content, "utf-8")
}))
}

0 comments on commit 4728346

Please sign in to comment.