소스 검색

Prompt installers to star the repo

Alvin Unreal 3 달 전
부모
커밋
259b5ab7e3
2개의 변경된 파일49개의 추가작업 그리고 1개의 파일을 삭제
  1. 48 1
      src/cli/install.ts
  2. 1 0
      src/cli/types.ts

+ 48 - 1
src/cli/install.ts

@@ -1,4 +1,5 @@
 import { existsSync } from 'node:fs';
+import { createInterface } from 'node:readline/promises';
 import {
   addPluginToOpenCodeConfig,
   addPluginToOpenCodeTuiConfig,
@@ -32,9 +33,12 @@ const SYMBOLS = {
   bullet: `${DIM}-${RESET}`,
   info: `${BLUE}[i]${RESET}`,
   warn: `${YELLOW}[!]${RESET}`,
-  star: `${YELLOW}*${RESET}`,
+  star: `${YELLOW}${RESET}`,
 };
 
+const GITHUB_REPO = 'alvinunreal/oh-my-opencode-slim';
+const GITHUB_URL = `https://github.com/${GITHUB_REPO}`;
+
 function printHeader(isUpdate: boolean): void {
   console.log();
   console.log(
@@ -60,6 +64,46 @@ function printInfo(message: string): void {
   console.log(`${SYMBOLS.info} ${message}`);
 }
 
+async function confirm(message: string, defaultYes = true): Promise<boolean> {
+  const suffix = defaultYes ? ' (Y/n) ' : ' (y/N) ';
+  const rl = createInterface({ input: process.stdin, output: process.stdout });
+
+  try {
+    const answer = (await rl.question(`${message}${suffix}`))
+      .trim()
+      .toLowerCase();
+    if (!answer) return defaultYes;
+    return answer === 'y' || answer === 'yes';
+  } finally {
+    rl.close();
+  }
+}
+
+async function askToStarRepo(config: InstallConfig): Promise<void> {
+  if (!config.promptForStar || config.dryRun || !process.stdin.isTTY) return;
+
+  console.log();
+  const shouldStar = await confirm(
+    `${SYMBOLS.star} Star the repo on GitHub?`,
+    true,
+  );
+  if (!shouldStar) return;
+
+  try {
+    const { execFileSync } = await import('node:child_process');
+    execFileSync(
+      'gh',
+      ['api', '--silent', '--method', 'PUT', `/user/starred/${GITHUB_REPO}`],
+      { stdio: 'ignore', timeout: 10_000 },
+    );
+    printSuccess('Thanks for starring! ★');
+  } catch {
+    printInfo(
+      `Couldn't star automatically. You can star manually:\n  ${BLUE}${GITHUB_URL}${RESET}`,
+    );
+  }
+}
+
 async function checkOpenCodeInstalled(): Promise<{
   ok: boolean;
   version?: string;
@@ -272,6 +316,8 @@ async function runInstall(config: InstallConfig): Promise<number> {
   console.log(`  ${BLUE}${docsUrl}${RESET}`);
   console.log();
 
+  await askToStarRepo(config);
+
   return 0;
 }
 
@@ -280,6 +326,7 @@ export async function install(args: InstallArgs): Promise<number> {
     hasTmux: false,
     installSkills: args.skills === 'yes',
     installCustomSkills: args.skills === 'yes',
+    promptForStar: args.tui,
     dryRun: args.dryRun,
     reset: args.reset ?? false,
   };

+ 1 - 0
src/cli/types.ts

@@ -18,6 +18,7 @@ export interface InstallConfig {
   hasTmux: boolean;
   installSkills: boolean;
   installCustomSkills: boolean;
+  promptForStar?: boolean;
   dryRun?: boolean;
   reset: boolean;
 }