From 40e03b4e03195e74f414083eb3e7f17bceddae44 Mon Sep 17 00:00:00 2001 From: Erik Hughes Date: Wed, 12 Mar 2025 15:49:26 +0100 Subject: [PATCH] fix: remove stages gen (not ready yet) and update some defaults --- .gitignore | 1 + packages/cli/commands/features.ts | 16 ++-------------- packages/cli/package.json | 2 +- packages/cli/services/bootstrap.ts | 4 ++-- packages/cli/utils/constants.ts | 2 +- packages/cli/utils/gen.ts | 12 +----------- 6 files changed, 8 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index c25132d4..9b388fbb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ lerna-debug.log* coverage node_modules +gen dist dist-ssr *.local diff --git a/packages/cli/commands/features.ts b/packages/cli/commands/features.ts index a6f4fed7..46e4a2fc 100644 --- a/packages/cli/commands/features.ts +++ b/packages/cli/commands/features.ts @@ -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"; @@ -76,8 +75,8 @@ export const listFeaturesAction = async () => { ); console.table( features.map(({ key, name, stage }) => ({ - key, name, + key, stage: stage?.name, })), ); @@ -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( @@ -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); diff --git a/packages/cli/package.json b/packages/cli/package.json index 80999282..3123007a 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/services/bootstrap.ts b/packages/cli/services/bootstrap.ts index 054f213d..f1f5d20a 100644 --- a/packages/cli/services/bootstrap.ts +++ b/packages/cli/services/bootstrap.ts @@ -29,9 +29,9 @@ export async function listApps(): Promise { throw new Error("No apps found"); } return response.org.apps.map(({ id, name, demo }) => ({ - id, name, - demo, + id, featureKeyFormat: org.featureKeyFormat ?? "custom", + demo, })); } diff --git a/packages/cli/utils/constants.ts b/packages/cli/utils/constants.ts index 062bc0de..bed1a97d 100644 --- a/packages/cli/utils/constants.ts +++ b/packages/cli/utils/constants.ts @@ -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=` + diff --git a/packages/cli/utils/gen.ts b/packages/cli/utils/gen.ts index 02515e0d..88363980 100644 --- a/packages/cli/utils/gen.ts +++ b/packages/cli/utils/gen.ts @@ -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"; @@ -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(); features.forEach(({ key, name, remoteConfigs }) => { const definition = genRemoteConfig(remoteConfigs); @@ -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 }) => {