From 3d913b6de4dd5fca7ff9c6b61a0d541732aceb7d Mon Sep 17 00:00:00 2001 From: Robert Field Date: Fri, 29 Sep 2023 19:46:29 +0100 Subject: [PATCH] feat: warning for non-composable projects --- .../integration/integration-command.tsx | 13 ++++++++---- .../commands/payments/payments-command.tsx | 2 ++ .../src/lib/composable-project-middleware.ts | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 packages/composable-cli/src/lib/composable-project-middleware.ts diff --git a/packages/composable-cli/src/commands/integration/integration-command.tsx b/packages/composable-cli/src/commands/integration/integration-command.tsx index ce88aab3..76a2429b 100644 --- a/packages/composable-cli/src/commands/integration/integration-command.tsx +++ b/packages/composable-cli/src/commands/integration/integration-command.tsx @@ -5,13 +5,17 @@ import { RootCommandArguments, } from "../../types/command" import { handleErrors } from "../../util/error-handler" -import {IntegrationCommandArguments, IntegrationCommandData, IntegrationCommandError +import { + IntegrationCommandArguments, + IntegrationCommandData, + IntegrationCommandError, } from "./integration.types" import { trackCommandHandler } from "../../util/track-command-handler" import { createAlgoliaIntegrationCommand } from "./algolia/algolia-integration-command" +import { createComposableProjectMiddleware } from "../../lib/composable-project-middleware" export function createIntegrationCommand( - ctx: CommandContext + ctx: CommandContext, ): yargs.CommandModule { return { command: "integration", @@ -19,19 +23,20 @@ export function createIntegrationCommand( describe: "setup Elastic Path integrations for your storefront", builder: (yargs) => { return yargs + .middleware(createComposableProjectMiddleware(ctx)) .command(createAlgoliaIntegrationCommand(ctx)) .help() .demandCommand(1) .strict() }, handler: handleErrors( - trackCommandHandler(ctx, createIntegrationCommandHandler) + trackCommandHandler(ctx, createIntegrationCommandHandler), ), } } export function createIntegrationCommandHandler( - _ctx: CommandContext + _ctx: CommandContext, ): CommandHandlerFunction< IntegrationCommandData, IntegrationCommandError, diff --git a/packages/composable-cli/src/commands/payments/payments-command.tsx b/packages/composable-cli/src/commands/payments/payments-command.tsx index a1825bc2..ea347f3f 100644 --- a/packages/composable-cli/src/commands/payments/payments-command.tsx +++ b/packages/composable-cli/src/commands/payments/payments-command.tsx @@ -14,6 +14,7 @@ import { PaymentsCommandError, } from "./payments.types" import { createActiveStoreMiddleware } from "../generate/generate-command" +import { createComposableProjectMiddleware } from "../../lib/composable-project-middleware" export function createPaymentsCommand( ctx: CommandContext, @@ -24,6 +25,7 @@ export function createPaymentsCommand( describe: "setup Elastic Path payment gateways for your storefront", builder: (yargs) => { return yargs + .middleware(createComposableProjectMiddleware(ctx)) .middleware(createActiveStoreMiddleware(ctx)) .command(createEPPaymentsCommand(ctx)) .help() diff --git a/packages/composable-cli/src/lib/composable-project-middleware.ts b/packages/composable-cli/src/lib/composable-project-middleware.ts new file mode 100644 index 00000000..a02eba78 --- /dev/null +++ b/packages/composable-cli/src/lib/composable-project-middleware.ts @@ -0,0 +1,21 @@ +import yargs, { MiddlewareFunction } from "yargs" +import { CommandContext } from "../types/command" +import boxen from "boxen" + +export function createComposableProjectMiddleware( + ctx: CommandContext, +): MiddlewareFunction { + return async function composableProjectMiddleware( + _args: yargs.ArgumentsCamelCase<{}>, + ) { + if (!ctx.composableRc) { + ctx.logger.info( + boxen( + "Failed to find .composablerc, is this a Composable Frontend workspace?\nThis command expects to be run in a composable frontend workspace and may not work as expected. It could be you're not inside your project folder.", + { padding: 1, margin: 1, borderColor: "yellow" }, + ), + ) + } + return + } +}