diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml new file mode 100644 index 00000000..5d3526ed --- /dev/null +++ b/.github/workflows/cli.yml @@ -0,0 +1,19 @@ +name: CLI +on: + push: + paths: + - 'cli/**' +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + - name: Install dependencies + run: bun install + - name: 🔦 Run linter + run: bun run lint + - name: 🪐 Check TypeScript + run: bun run typecheck \ No newline at end of file diff --git a/cli/bun.lockb b/cli/bun.lockb new file mode 100755 index 00000000..45095b2c Binary files /dev/null and b/cli/bun.lockb differ diff --git a/cli/package.json b/cli/package.json new file mode 100644 index 00000000..378dd64e --- /dev/null +++ b/cli/package.json @@ -0,0 +1,53 @@ +{ + "name": "v1-run", + "version": "0.0.1", + "description": "A CLI for v1", + "publishConfig": { + "access": "public" + }, + "license": "MIT", + "author": { + "name": "pontusab", + "url": "https://twitter.com/pontusab" + }, + "repository": { + "type": "git", + "url": "https://github.com/midday-ai/v1.git", + "directory": "cli" + }, + "files": ["dist"], + "keywords": ["nextjs"], + "type": "module", + "exports": "./dist/index.js", + "bin": "./dist/index.js", + "scripts": { + "dev": "tsup --watch", + "build": "tsup", + "typecheck": "tsc --noEmit", + "clean": "rimraf dist && rimraf components", + "start:dev": "node dist/index.js", + "start": "node dist/index.js", + "release": "changeset version", + "pub:beta": "pnpm build && pnpm publish --no-git-checks --access public --tag beta", + "pub:next": "pnpm build && pnpm publish --no-git-checks --access public --tag next", + "pub:release": "pnpm build && pnpm publish --access public", + "test": "vitest run" + }, + "dependencies": { + "chalk": "5.2.0", + "commander": "^10.0.0", + "fast-glob": "^3.3.2", + "fs-extra": "^11.1.0", + "ora": "^6.1.2", + "prompts": "^2.4.2", + "zod": "^3.23.8" + }, + "devDependencies": { + "@types/fs-extra": "^11.0.1", + "@types/prompts": "^2.4.2", + "rimraf": "^4.1.3", + "tsup": "^6.6.3", + "type-fest": "^3.8.0", + "typescript": "^4.9.3" + } +} diff --git a/cli/src/commands/init.ts b/cli/src/commands/init.ts new file mode 100644 index 00000000..ab604bf5 --- /dev/null +++ b/cli/src/commands/init.ts @@ -0,0 +1,36 @@ +import { existsSync } from "node:fs"; +import path from "node:path"; +import { Command } from "commander"; +import { z } from "zod"; + +const initOptionsSchema = z.object({ + cwd: z.string(), + yes: z.boolean(), + defaults: z.boolean(), +}); + +export const init = new Command() + .name("init") + .description("initialize your project and install dependencies") + .option("-y, --yes", "skip confirmation prompt.", false) + .option("-d, --defaults,", "use default configuration.", false) + .option( + "-c, --cwd ", + "the working directory. defaults to the current directory.", + process.cwd(), + ) + .action(async (opts) => { + try { + const options = initOptionsSchema.parse(opts); + const cwd = path.resolve(options.cwd); + + // Ensure target directory exists. + if (!existsSync(cwd)) { + // logger.error(`The path ${cwd} does not exist. Please try again.`); + process.exit(1); + } + } catch (error) { + console.error(error); + process.exit(1); + } + }); diff --git a/cli/src/index.ts b/cli/src/index.ts new file mode 100644 index 00000000..ac494d56 --- /dev/null +++ b/cli/src/index.ts @@ -0,0 +1,27 @@ +#!/usr/bin/env node +import { init } from "@/src/commands/init"; +import { Command } from "commander"; +import { getPackageInfo } from "./utils/get-package-info"; + +process.on("SIGINT", () => process.exit(0)); +process.on("SIGTERM", () => process.exit(0)); + +async function main() { + const packageInfo = await getPackageInfo(); + + const program = new Command() + .name("v1-run") + .description("Blah") + .version( + packageInfo.version || "1.0.0", + "-v, --version", + "display the version number", + ); + + program.addCommand(init); + // .addCommand(add).addCommand(diff); + + program.parse(); +} + +main(); diff --git a/cli/src/utils/get-package-info.ts b/cli/src/utils/get-package-info.ts new file mode 100644 index 00000000..4081f01e --- /dev/null +++ b/cli/src/utils/get-package-info.ts @@ -0,0 +1,9 @@ +import path from "node:path"; +import fs from "fs-extra"; +import type { PackageJson } from "type-fest"; + +export function getPackageInfo() { + const packageJsonPath = path.join("package.json"); + + return fs.readJSONSync(packageJsonPath) as PackageJson; +} diff --git a/cli/tsconfig.json b/cli/tsconfig.json new file mode 100644 index 00000000..c84f91f6 --- /dev/null +++ b/cli/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "@v1/typescript/base.json", + "compilerOptions": { + "isolatedModules": false, + "module": "preserve", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "baseUrl": ".", + "paths": { + "@/*": ["./*"] + } + }, + "include": ["src/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/cli/tsup.config.ts b/cli/tsup.config.ts new file mode 100644 index 00000000..30e7a114 --- /dev/null +++ b/cli/tsup.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + clean: true, + dts: true, + entry: ["src/index.ts"], + format: ["esm"], + sourcemap: true, + minify: true, + target: "esnext", + outDir: "dist", +}); diff --git a/package.json b/package.json index ac45fa09..dce33dbc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "v1", "private": true, - "workspaces": ["packages/*", "apps/*", "tooling/*", "services/*", "cli/*"], + "workspaces": ["packages/*", "apps/*", "tooling/*", "services/*"], "scripts": { "build": "turbo build", "clean": "git clean -xdf node_modules", diff --git a/services/cal/config.json b/services/cal/config.json index 2f3b3af5..1625036f 100644 --- a/services/cal/config.json +++ b/services/cal/config.json @@ -1,5 +1,5 @@ { - "name": "cal", + "name": "Cal.com", "generate": { "src/example/index.tsx": "apps/web/src/app/talk-to-us/page.tsx" } diff --git a/services/dub/config.json b/services/dub/config.json index dd3691c4..26059d28 100644 --- a/services/dub/config.json +++ b/services/dub/config.json @@ -1,5 +1,5 @@ { - "name": "dub", + "name": "Dub", "envs": { "DUB_API_KEY": { "description": "The API key to use for Dub", diff --git a/services/openpanel/config.json b/services/openpanel/config.json index 1186691f..444337b9 100644 --- a/services/openpanel/config.json +++ b/services/openpanel/config.json @@ -1,5 +1,5 @@ { - "name": "openpanel", + "name": "OpenPanel", "envs": { "OPENPANEL_API_KEY": { "description": "The API key to use for OpenPanel", diff --git a/services/resend/config.json b/services/resend/config.json index 2826708b..e5461673 100644 --- a/services/resend/config.json +++ b/services/resend/config.json @@ -1,5 +1,5 @@ { - "name": "resend", + "name": "Resend", "envs": { "RESEND_API_KEY": { "description": "The API key to use for Resend", diff --git a/services/sentry/config.json b/services/sentry/config.json index eb15b556..8aa7b606 100644 --- a/services/sentry/config.json +++ b/services/sentry/config.json @@ -1,5 +1,5 @@ { - "name": "sentry", + "name": "Sentry", "envs": { "SENTRY_AUTH_TOKEN": { "description": "The auth token to use for Sentry", diff --git a/services/trigger/config.json b/services/trigger/config.json index a97dd4c9..0e5d04e2 100644 --- a/services/trigger/config.json +++ b/services/trigger/config.json @@ -1,5 +1,5 @@ { - "name": "trigger", + "name": "Trigger.dev", "envs": { "TRIGGER_API_KEY": { "description": "The API key to use for Trigger", diff --git a/services/upstash/config.json b/services/upstash/config.json index 7fb34103..2063aa27 100644 --- a/services/upstash/config.json +++ b/services/upstash/config.json @@ -1,5 +1,5 @@ { - "name": "upstash", + "name": "Upstash", "envs": { "UPSTASH_REDIS_REST_URL": { "description": "The URL to use for Upstash",