|
|
@@ -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,
|
|
|
};
|