@kaidev-studio/cli-kit 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,8 @@ await run(cli, [auth.command, ...myCommands]);
20
20
 
21
21
  - The app's build defines `process.env.CLI_BUILD` as `"release"`; anything else is the dev CLI, run as
22
22
  `bun <name>` from a root package.json script, with its state in `<app cli>/.dev`.
23
+ - Optional settings: `configDir` moves the session, `afterUpgrade` runs after `upgrade` (devhub restarts its services
24
+ there), and `createAuth`'s `afterLogin` runs once a new session is stored.
23
25
  - Commands are `command({ name, description, positionals, options, run })` and `group({ name, commands })`, with zod
24
26
  schemas; `.meta({ short: "x" })`, `.meta({ negatable: true })` and `.meta({ hidden: true })` tune options.
25
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaidev-studio/cli-kit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Boilerplate for a Bun CLI that signs in through its web app and updates itself",
5
5
  "type": "module",
6
6
  "repository": {
package/src/auth.ts CHANGED
@@ -17,6 +17,8 @@ export type AuthConfig = {
17
17
  server: string;
18
18
  /** The web app the dev CLI signs in to, e.g. read from the app's .env; the installed CLI's `server` without it. */
19
19
  devServer?: () => Promise<string>;
20
+ /** Runs after `auth login` has stored the new session. */
21
+ afterLogin?: () => Promise<unknown>;
20
22
  };
21
23
 
22
24
  const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
@@ -116,6 +118,7 @@ export const createAuth = (cli: Cli, config: AuthConfig) => {
116
118
  await createCliAuthClient(previous)
117
119
  .signOut()
118
120
  .catch(() => undefined);
121
+ await config.afterLogin?.();
119
122
  console.log(`Signed in as ${session.user.email} on ${server}.`);
120
123
  },
121
124
  });
package/src/cli.ts CHANGED
@@ -16,6 +16,10 @@ export type CliConfig = {
16
16
  registry?: string;
17
17
  /** The oldest Bun the CLI runs on. */
18
18
  minBun: string;
19
+ /** Where the CLI keeps its session, instead of the default below. */
20
+ configDir?: string;
21
+ /** Runs once `upgrade` has installed and checked the new version; what it returns is added to the final line. */
22
+ afterUpgrade?: () => Promise<string | undefined>;
19
23
  };
20
24
 
21
25
  export type Cli = ReturnType<typeof createCli>;
@@ -41,7 +45,9 @@ export const createCli = (config: CliConfig) => {
41
45
  * The dev CLI keeps its state next to its source (Bun.main is `<app cli>/src/index.ts`), so signing in to a
42
46
  * local app never replaces the installed CLI's session. Gitignore `.dev` in the app's CLI.
43
47
  */
44
- configDir: isDev ? join(dirname(Bun.main), "..", ".dev") : join(xdg("XDG_CONFIG_HOME", ".config"), config.name),
48
+ configDir:
49
+ config.configDir ??
50
+ (isDev ? join(dirname(Bun.main), "..", ".dev") : join(xdg("XDG_CONFIG_HOME", ".config"), config.name)),
45
51
  cacheDir: join(xdg("XDG_CACHE_HOME", ".cache"), config.name),
46
52
  };
47
53
  };
package/src/upgrade.ts CHANGED
@@ -43,6 +43,7 @@ export const upgradeCommand = (cli: Cli) =>
43
43
  });
44
44
  const [installed, code] = await Promise.all([new Response(check.stdout).text(), check.exited]);
45
45
  if (code !== 0) throw new Error(`The installed ${cli.program} doesn't run: '--version' exited ${code}.`);
46
- console.log(`${cli.program} ${cli.version} → ${installed.trim()}.`);
46
+ const after = await cli.afterUpgrade?.();
47
+ console.log(`${cli.program} ${cli.version} → ${installed.trim()}${after ? `; ${after}` : ""}.`);
47
48
  },
48
49
  });