Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Bucket CLI

Command-line interface for interacting with Bucket services. The CLI allows you to manage apps, features, authentication, and generate TypeScript types for your Bucket features. With this tool, you can streamline your feature flagging workflow directly from your terminal.
Command-line interface for interacting with Bucket services. The CLI allows you to manage apps,
features, authentication, and generate TypeScript types for your Bucket features. With this tool,
you can streamline your feature flagging workflow directly from your terminal.

## Quick Start

Get started quickly by running the CLI directly: initializing the CLI, creating a feature, and generate the types all at once.
Get started quickly by running the CLI directly from your project's root directory:
initializing the CLI (if not already setup), creating a feature, and generate the types all at once.

```bash
# Initialize CLI (if not setup), create a feature, and generate types all at once
# Initialize CLI (if not already setup), create a feature, and generate types all at once
npx @bucketco/cli new
```

Expand All @@ -33,7 +36,8 @@ yarn bucket new

### Global installation

You can also install the CLI globally adding the it to your PATH allowing you to use the shorthand `bucket`
You can also install the CLI globally adding the it to your PATH allowing you to use the shorthand `bucket`,
but we recommend installing it locally instead to better maintain the version.

```bash
npm install -g @bucketco/cli
Expand All @@ -58,7 +62,8 @@ bucket features types

## Configuration

The CLI creates a `bucket.config.json` file in your project directory when you run `bucket init`. This file contains all the necessary settings for your Bucket integration.
The CLI creates a `bucket.config.json` file in your project directory when you run `bucket init`.
This file contains all the necessary settings for your Bucket integration.

### Configuration File Structure

Expand Down Expand Up @@ -95,7 +100,8 @@ You can override these settings using command-line options for individual comman

### `bucket init`

Initialize a new Bucket configuration in your project. This creates a `bucket.config.json` file with your settings and prompts for any required information not provided via options.
Initialize a new Bucket configuration in your project.
This creates a `bucket.config.json` file with your settings and prompts for any required information not provided via options.

```bash
bucket init [--overwrite]
Expand All @@ -109,7 +115,8 @@ Options:

### `bucket new [featureName]`

All-in-one command to get started quickly. This command combines `init`, feature creation, and type generation in a single step. Use this for the fastest way to get up and running with Bucket.
All-in-one command to get started quickly. This command combines `init`, feature creation,
and type generation in a single step. Use this for the fastest way to get up and running with Bucket.

```bash
bucket new "My Feature" [--key my-feature] [--app-id ap123456789] [--key-format custom] [--out gen/features.ts] [--format react]
Expand Down Expand Up @@ -147,7 +154,8 @@ Manage your Bucket features with the following subcommands.

#### `bucket features create [featureName]`

Create a new feature in your Bucket app. The command guides you through the feature creation process with interactive prompts if options are not provided.
Create a new feature in your Bucket app.
The command guides you through the feature creation process with interactive prompts if options are not provided.

```bash
bucket features create "My Feature" [--key my-feature] [--app-id ap123456789] [--key-format custom]
Expand All @@ -161,7 +169,8 @@ Options:

#### `bucket features list`

List all features for the current app. This helps you visualize what features are available and their current configurations.
List all features for the current app.
This helps you visualize what features are available and their current configurations.

```bash
bucket features list [--app-id ap123456789]
Expand All @@ -173,7 +182,8 @@ Options:

#### `bucket features types`

Generate TypeScript types for your features. This ensures type safety when using Bucket features in your TypeScript/JavaScript applications.
Generate TypeScript types for your features.
This ensures type safety when using Bucket features in your TypeScript/JavaScript applications.

```bash
bucket features types [--app-id ap123456789] [--out gen/features.ts] [--format react]
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const loginAction = async () => {
const spinner = ora(`Logging in to ${chalk.cyan(baseUrl)}...`).start();
try {
await authenticateUser(baseUrl);
spinner.succeed(`Logged in to ${chalk.cyan(baseUrl)} successfully! 🎉`);
spinner.succeed(`Logged in to ${chalk.cyan(baseUrl)} successfully!`);
} catch (error) {
spinner.fail("Login failed.");
void handleError(error, "Login");
Expand All @@ -24,7 +24,7 @@ export const logoutAction = async () => {
const spinner = ora("Logging out...").start();
try {
await authStore.setToken(baseUrl, undefined);
spinner.succeed("Logged out successfully! 👋");
spinner.succeed("Logged out successfully!");
} catch (error) {
spinner.fail("Logout failed.");
void handleError(error, "Logout");
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/commands/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const createFeatureAction = async (
const feature = await createFeature(appId, name, key);
// todo: would like to link to feature here but we don't have the env id, only app id
spinner.succeed(
`Created feature ${chalk.cyan(feature.name)} with key ${chalk.cyan(feature.key)} at ${chalk.cyan(baseUrl)}. 🎉`,
`Created feature ${chalk.cyan(feature.name)} with key ${chalk.cyan(feature.key)} at ${chalk.cyan(baseUrl)}.`,
);
} catch (error) {
spinner?.fail("Feature creation failed.");
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ora, { Ora } from "ora";

import { App, listApps } from "../services/bootstrap.js";
import { configStore, typeFormats } from "../stores/config.js";
import { chalkBrand, DEFAULT_TYPES_OUTPUT } from "../utils/constants.js";
import { DEFAULT_TYPES_OUTPUT } from "../utils/constants.js";
import { handleError } from "../utils/errors.js";
import { overwriteOption } from "../utils/options.js";

Expand All @@ -27,7 +27,7 @@ export const initAction = async (args: InitArgs = {}) => {
);
}

console.log(chalkBrand("\nWelcome to Bucket! 🪣\n"));
console.log("\nWelcome to Bucket!\n");
const baseUrl = configStore.getConfig("baseUrl");

// Load apps
Expand Down
9 changes: 1 addition & 8 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
import chalk from "chalk";
import { program } from "commander";
import { join } from "node:path";

import { registerAppCommands } from "./commands/apps.js";
import { registerAuthCommands } from "./commands/auth.js";
Expand Down Expand Up @@ -54,10 +53,4 @@ async function main() {
program.parse(process.argv);
}

// Run the main function if this file is run directly and not imported
if (
process.argv[1].endsWith(join("cli", "dist", "index.js")) ||
process.argv[1].endsWith(join(".bin", "bucket"))
) {
void main();
}
void main();
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bucketco/cli",
"version": "0.2.0",
"version": "0.2.1",
"packageManager": "yarn@4.1.1",
"description": "CLI for Bucket service",
"main": "./dist/index.js",
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { join } from "path";
import chalk from "chalk";

export const CONFIG_FILE_NAME = "bucket.config.json";
export const AUTH_FILE = join(
Expand All @@ -12,8 +11,6 @@ export const DEFAULT_BASE_URL = "https://app.bucket.co";
export const DEFAULT_API_URL = `${DEFAULT_BASE_URL}/api`;
export const DEFAULT_TYPES_OUTPUT = join("gen", "features.ts");

export const chalkBrand = chalk.hex("#847CFB");

export const loginUrl = (baseUrl: string, localPort: number) =>
`${baseUrl}/login?redirect_url=` +
encodeURIComponent("/cli-login?port=" + localPort);