Skip to content
Open
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
8 changes: 4 additions & 4 deletions extensions/MyCustomCommand.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Command } from "webiny/cli/features/Command";
import { CliCommand } from "webiny/cli/features/CliCommand";
import { UiService } from "webiny/cli/features/Ui";

export interface IMyCustomCommandParams {
name: string;
}

class MyCustomCommandImpl implements Command.Interface<IMyCustomCommandParams> {
class MyCustomCommandImpl implements CliCommand.Interface<IMyCustomCommandParams> {
constructor(private ui: UiService.Interface) {}

execute(): Command.CommandDefinition<IMyCustomCommandParams> {
execute(): CliCommand.CommandDefinition<IMyCustomCommandParams> {
return {
name: "my-custom-command",
description: "This is my custom command",
Expand All @@ -29,7 +29,7 @@ class MyCustomCommandImpl implements Command.Interface<IMyCustomCommandParams> {
}
}

export const MyCustomCommand = Command.createImplementation({
export const MyCustomCommand = CliCommand.createImplementation({
implementation: MyCustomCommandImpl,
dependencies: [UiService]
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@types/hoist-non-react-statics": "^3.3.7",
"@webiny/di": "^0.2.0"
"@webiny/di": "^0.2.1"
},
"engines": {
"node": ">=22.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/api-aco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@webiny/api-headless-cms": "0.0.0",
"@webiny/aws-sdk": "0.0.0",
"@webiny/db-dynamodb": "0.0.0",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/error": "0.0.0",
"@webiny/feature": "0.0.0",
"@webiny/handler": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"license": "MIT",
"dependencies": {
"@webiny/api": "0.0.0",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/error": "0.0.0",
"@webiny/feature": "0.0.0",
"@webiny/handler": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-headless-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@graphql-tools/schema": "^10.0.29",
"@webiny/api": "0.0.0",
"@webiny/api-core": "0.0.0",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/error": "0.0.0",
"@webiny/feature": "0.0.0",
"@webiny/handler": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "MIT",
"dependencies": {
"@webiny/aws-sdk": "0.0.0",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/plugins": "0.0.0",
"@webiny/utils": "0.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@webiny/admin-ui": "0.0.0",
"@webiny/app": "0.0.0",
"@webiny/app-security": "0.0.0",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/feature": "0.0.0",
"@webiny/form": "0.0.0",
"@webiny/icons": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@apollo/react-hooks": "^3.1.5",
"@emotion/styled": "11.10.6",
"@types/react": "18.2.79",
"@webiny/di": "^0.2.0",
"@webiny/di": "^0.2.1",
"@webiny/i18n": "0.0.0",
"@webiny/i18n-react": "0.0.0",
"@webiny/plugins": "0.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"description": "A command line interface (CLI) for managing Webiny projects.",
"license": "MIT",
"dependencies": {
"@webiny/di": "^0.2.0",
"@webiny/logger": "0.0.0",
"@webiny/di": "^0.2.1",
"@webiny/project": "0.0.0",
"@webiny/pulumi-sdk": "0.0.0",
"@webiny/telemetry": "0.0.0",
Expand All @@ -25,6 +24,8 @@
"load-json-file": "6.2.0",
"open": "^10.2.0",
"ora": "4.1.1",
"pino": "^9.13.1",
"pino-pretty": "^9.4.1",
"semver": "^7.7.2",
"type-fest": "^5.2.0",
"write-json-file": "^4.3.0",
Expand All @@ -40,7 +41,7 @@
},
"webiny": {
"exports": {
"./abstractions/features/Command.ts": "cli/features/Command",
"./abstractions/features/CliCommand.ts": "cli/features/CliCommand",
"./abstractions/services/UiService.ts": "cli/features/Ui"
}
},
Expand Down
46 changes: 46 additions & 0 deletions packages/cli-core/src/abstractions/features/CliCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";

export interface ICliCommandParamDefinition<TCommandParams> {
name: string;
description: string;
type: "boolean" | "number" | "string";
required?: boolean;
array?: boolean;
default?: any;
validation?: (value: TCommandParams) => boolean | string;
}

export interface ICliCommandOptionDefinition<TCommandParams> {
name: string;
description: string;
type: "boolean" | "number" | "string";
group?: string;
required?: boolean;
alias?: string;
default?: any;
validation?: (value: TCommandParams) => boolean | string;
}

export interface ICliCommandDefinition<TCommandParams> {
name: string;
description: string;
params?: ICliCommandParamDefinition<TCommandParams>[];
options?: ICliCommandOptionDefinition<TCommandParams>[];
examples?: string[];
handler: (params: TCommandParams) => void | Promise<void>;
}

export interface ICliCommand<TCommandParams> {
execute(): Promise<ICliCommandDefinition<TCommandParams>> | ICliCommandDefinition<TCommandParams>;
}

export const CliCommand = createAbstraction<ICliCommand<any>>("CliCommand");

export namespace CliCommand {
export type Interface<TCommandParams> = ICliCommand<TCommandParams>;

export type ParamDefinition<TCommandParams> = ICliCommandParamDefinition<TCommandParams>;
export type OptionDefinition<TCommandParams> = ICliCommandOptionDefinition<TCommandParams>;

export type CommandDefinition<TCommandParams> = ICliCommandDefinition<TCommandParams>;
}
46 changes: 0 additions & 46 deletions packages/cli-core/src/abstractions/features/Command.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/cli-core/src/abstractions/features/ErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";
import { Command } from "~/abstractions/index.js";
import { CliCommand } from "~/abstractions/index.js";

export type IError = Error;

export interface IErrorHandlerParams<TParams> {
error: Error;
command: Command.CommandDefinition<any>;
command: CliCommand.CommandDefinition<any>;
params: TParams;
}

Expand Down
28 changes: 28 additions & 0 deletions packages/cli-core/src/abstractions/features/GlobalCliOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";

export interface IGlobalCliOptionConfig {
type: "boolean" | "number" | "string";
description: string;
default?: any;
alias?: string;
choices?: string[];
}

export interface IGlobalCliOptionDefinition {
name: string;
config: IGlobalCliOptionConfig;
}

export interface IGlobalCliOption {
execute(): Promise<IGlobalCliOptionDefinition> | IGlobalCliOptionDefinition;
}

export const GlobalCliOption = createAbstraction<IGlobalCliOption>("GlobalCliOption");

export namespace GlobalCliOption {
export type Interface = IGlobalCliOption;
export type Definition = IGlobalCliOptionDefinition;
export type Config = IGlobalCliOptionConfig;
}


3 changes: 2 additions & 1 deletion packages/cli-core/src/abstractions/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Command } from "./Command.js";
export { CliCommand } from "./CliCommand.js";
export { ErrorHandler } from "./ErrorHandler.js";
export { GlobalCliOption } from "./GlobalCliOption.js";
12 changes: 12 additions & 0 deletions packages/cli-core/src/abstractions/services/ArgvParserService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";

export interface IArgvParserService {
parse<T = Record<string, any>>(argv: string[]): T;
}

export const ArgvParserService = createAbstraction<IArgvParserService>("ArgvParserService");

export namespace ArgvParserService {
export type Interface = IArgvParserService;
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface ICliParamsService {
}

export const CliParamsService = new Abstraction<ICliParamsService>("CliParamsService");
// export const CliParamsService = createAbstraction<ICliParamsService>("CliParamsService");

export namespace CliParamsService {
export type Interface = ICliParamsService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";
import { Command } from "~/abstractions/index.js";
import { CliCommand } from "~/abstractions/index.js";

export interface ICommandsRegistryService {
execute(): Command.Interface<any>[];
execute(): CliCommand.Interface<any>[];
}

export const CommandsRegistryService =
Expand Down
12 changes: 12 additions & 0 deletions packages/cli-core/src/abstractions/services/GetArgvService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";

export interface IGetArgvService {
execute<T = Record<string, any>>(): T;
}

export const GetArgvService = createAbstraction<IGetArgvService>("GetArgvService");

export namespace GetArgvService {
export type Interface = IGetArgvService;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createAbstraction } from "~/abstractions/createAbstraction.js";
import { GlobalCliOption } from "~/abstractions/index.js";

export interface IGlobalOptionsRegistryService {
execute(): GlobalCliOption.Interface[];
}

export const GlobalOptionsRegistryService = createAbstraction<IGlobalOptionsRegistryService>(
"GlobalOptionsRegistryService"
);

export namespace GlobalOptionsRegistryService {
export type Interface = IGlobalOptionsRegistryService;
}

3 changes: 3 additions & 0 deletions packages/cli-core/src/abstractions/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export * from "./ArgvParserService.js";
export * from "./CliParamsService.js";
export * from "./CommandsRegistryService.js";
export * from "./GetArgvService.js";
export * from "./GetCliRunnerService.js";
export * from "./GlobalOptionsRegistryService.js";
export * from "./GetProjectSdkService.js";
export * from "./LoggerService.js";
export * from "./RunCliRunnerService.js";
Expand Down
29 changes: 23 additions & 6 deletions packages/cli-core/src/createCliContainer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import path from "path";
import { Container } from "@webiny/di";
import {
argvParserService,
cliParamsService,
commandsRegistryService,
getArgvService,
getCliRunnerService,
globalOptionsRegistryService,
getProjectSdkService,
loggerService,
runCliRunnerService,
Expand Down Expand Up @@ -34,11 +37,16 @@ import {
linkProjectCommand,
loginCommand,
logoutCommand,
whoAmICommand
whoAmICommand,

// Global Options
showLogsGlobalOption,
logLevelGlobalOption,
stackTraceGlobalOption
} from "./features/index.js";

import chalk from "chalk";
import { CliParamsService, GetProjectSdkService, UiService } from "~/abstractions/index.js";
import { CliParamsService, GetArgvService, GetProjectSdkService, UiService } from "~/abstractions/index.js";
import { GracefulError } from "@webiny/project";
import {
commandsWithGracefulErrorHandling,
Expand Down Expand Up @@ -76,10 +84,18 @@ export const createCliContainer = async (params: CliParamsService.Params) => {
container.register(missingFilesInBuildGracefulErrorHandler).inSingletonScope();
container.register(pendingOperationsGracefulErrorHandler).inSingletonScope();

// Global options.
container.register(showLogsGlobalOption).inSingletonScope();
container.register(logLevelGlobalOption).inSingletonScope();
container.register(stackTraceGlobalOption).inSingletonScope();

// Services.
container.register(argvParserService).inSingletonScope();
container.register(cliParamsService).inSingletonScope();
container.register(commandsRegistryService).inSingletonScope();
container.register(getArgvService).inSingletonScope();
container.register(getCliRunnerService).inSingletonScope();
container.register(globalOptionsRegistryService).inSingletonScope();
container.register(getProjectSdkService).inSingletonScope();
container.register(loggerService).inSingletonScope();
container.register(runCliRunnerService).inSingletonScope();
Expand Down Expand Up @@ -131,10 +147,11 @@ export const createCliContainer = async (params: CliParamsService.Params) => {

ui.error(realError.message);

// Unfortunately, yargs doesn't provide passed args here, so we had to do it via process.argv.
const debugEnabled = process.argv.includes("--debug");
if (debugEnabled) {
realError.stack && ui.debug(realError.stack);
const argv = container.resolve(GetArgvService).execute();
if (argv.stackTrace && realError.stack) {
ui.newLine();
ui.debug("Stack trace:");
ui.text(realError.stack);
}

if (error && error instanceof GracefulError) {
Expand Down
Loading