Skip to content

Commit

Permalink
cli wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Sep 7, 2024
1 parent fbaba9c commit 4adc0e5
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 8 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added cli/bun.lockb
Binary file not shown.
53 changes: 53 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
36 changes: 36 additions & 0 deletions cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -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 <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);
}
});
27 changes: 27 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 9 additions & 0 deletions cli/src/utils/get-package-info.ts
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 15 additions & 0 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
12 changes: 12 additions & 0 deletions cli/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -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",
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion services/cal/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cal",
"name": "Cal.com",
"generate": {
"src/example/index.tsx": "apps/web/src/app/talk-to-us/page.tsx"
}
Expand Down
2 changes: 1 addition & 1 deletion services/dub/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dub",
"name": "Dub",
"envs": {
"DUB_API_KEY": {
"description": "The API key to use for Dub",
Expand Down
2 changes: 1 addition & 1 deletion services/openpanel/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "openpanel",
"name": "OpenPanel",
"envs": {
"OPENPANEL_API_KEY": {
"description": "The API key to use for OpenPanel",
Expand Down
2 changes: 1 addition & 1 deletion services/resend/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "resend",
"name": "Resend",
"envs": {
"RESEND_API_KEY": {
"description": "The API key to use for Resend",
Expand Down
2 changes: 1 addition & 1 deletion services/sentry/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sentry",
"name": "Sentry",
"envs": {
"SENTRY_AUTH_TOKEN": {
"description": "The auth token to use for Sentry",
Expand Down
2 changes: 1 addition & 1 deletion services/trigger/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "trigger",
"name": "Trigger.dev",
"envs": {
"TRIGGER_API_KEY": {
"description": "The API key to use for Trigger",
Expand Down
2 changes: 1 addition & 1 deletion services/upstash/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "upstash",
"name": "Upstash",
"envs": {
"UPSTASH_REDIS_REST_URL": {
"description": "The URL to use for Upstash",
Expand Down

0 comments on commit 4adc0e5

Please sign in to comment.