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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*
coverage

node_modules
gen
dist
dist-ssr
*.local
Expand Down
16 changes: 2 additions & 14 deletions packages/cli/commands/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { dirname, isAbsolute, join, relative } from "node:path";
import ora, { Ora } from "ora";

import { createFeature, Feature, listFeatures } from "../services/features.js";
import { listStages, Stage } from "../services/stages.js";
import { configStore } from "../stores/config.js";
import { handleError, MissingAppIdError } from "../utils/errors.js";
import { genFeatureKey, genTypes, KeyFormatPatterns } from "../utils/gen.js";
Expand Down Expand Up @@ -76,8 +75,8 @@ export const listFeaturesAction = async () => {
);
console.table(
features.map(({ key, name, stage }) => ({
key,
name,
key,
stage: stage?.name,
})),
);
Expand All @@ -93,7 +92,6 @@ export const generateTypesAction = async () => {

let spinner: Ora | undefined;
let features: Feature[] = [];
let stages: Stage[] = [];
try {
if (!appId) throw new MissingAppIdError();
spinner = ora(
Expand All @@ -111,23 +109,13 @@ export const generateTypesAction = async () => {
return;
}

try {
spinner = ora(`Loading stages...`).start();
stages = await listStages(appId);
spinner.succeed(`Loaded stages.`);
} catch (error) {
spinner?.fail("Loading stages failed.");
void handleError(error, "Features Types");
return;
}

try {
spinner = ora("Generating feature types...").start();
const projectPath = configStore.getProjectPath();

// Generate types for each output configuration
for (const output of typesOutput) {
const types = await genTypes(features, stages, output.format);
const types = await genTypes(features, output.format);
const outPath = isAbsolute(output.path)
? output.path
: join(projectPath, output.path);
Expand Down
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.1",
"version": "0.2.2",
"packageManager": "yarn@4.1.1",
"description": "CLI for Bucket service",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/services/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export async function listApps(): Promise<App[]> {
throw new Error("No apps found");
}
return response.org.apps.map(({ id, name, demo }) => ({
id,
name,
demo,
id,
featureKeyFormat: org.featureKeyFormat ?? "custom",
demo,
}));
}
2 changes: 1 addition & 1 deletion packages/cli/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const SCHEMA_URL = `https://unpkg.com/@bucketco/cli@latest/schema.json`;

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 DEFAULT_TYPES_OUTPUT = join("gen", "features.d.ts");

export const loginUrl = (baseUrl: string, localPort: number) =>
`${baseUrl}/login?redirect_url=` +
Expand Down
12 changes: 1 addition & 11 deletions packages/cli/utils/gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { camelCase, kebabCase, pascalCase, snakeCase } from "change-case";

import { Feature, RemoteConfig } from "../services/features.js";
import { Stage } from "../services/stages.js";

import { JSONToType } from "./json.js";

Expand Down Expand Up @@ -90,11 +89,7 @@ export function genRemoteConfig(remoteConfigs?: RemoteConfig[]) {
);
}

export function genTypes(
features: Feature[],
stages: Stage[],
format: GenFormat = "react",
) {
export function genTypes(features: Feature[], format: GenFormat = "react") {
const configDefs = new Map<string, { name: string; definition: string }>();
features.forEach(({ key, name, remoteConfigs }) => {
const definition = genRemoteConfig(remoteConfigs);
Expand All @@ -110,11 +105,6 @@ export function genTypes(
import "@bucketco/${format}-sdk";

declare module "@bucketco/${format}-sdk" {
${
stages.length
? /* ts */ `export type Stage = ${stages.map(({ name }) => `"${name}"`).join(" | ")};\n`
: ""
}
export interface Features {
${features
.map(({ key }) => {
Expand Down