Skip to content

Commit

Permalink
feat: warning for non-composable projects
Browse files Browse the repository at this point in the history
  • Loading branch information
field123 committed Sep 29, 2023
1 parent c7dcbce commit 3d913b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@ 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<RootCommandArguments, IntegrationCommandArguments> {
return {
command: "integration",
aliases: ["int"],
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions packages/composable-cli/src/lib/composable-project-middleware.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 3d913b6

Please sign in to comment.