diff --git a/src/lib/Components/Commands/exports/Command.ts b/src/lib/Components/Commands/exports/Command.ts index 19025a3..2c8cb3c 100644 --- a/src/lib/Components/Commands/exports/Command.ts +++ b/src/lib/Components/Commands/exports/Command.ts @@ -1,10 +1,6 @@ import { Generable } from '../../index'; import { StringParameter } from '../../Parameters/types'; -import { - CommandParameters, - CommandShape, - CommandShorthandShape, -} from '../types/Command.types'; +import { AnyCommandShape, CommandParameters } from '../types/Command.types'; /** * Abstract - A generic Command @@ -22,5 +18,5 @@ export interface Command extends Generable { * Generate the JSON shape for the Command. * @param flatten - If true, short hand will be attempted. */ - generate(flatten?: boolean): CommandShape | CommandShorthandShape; + generate(flatten?: boolean): AnyCommandShape; } diff --git a/src/lib/Components/Commands/exports/Native/Checkout.ts b/src/lib/Components/Commands/exports/Native/Checkout.ts index d2c9798..004d744 100644 --- a/src/lib/Components/Commands/exports/Native/Checkout.ts +++ b/src/lib/Components/Commands/exports/Native/Checkout.ts @@ -1,6 +1,10 @@ import { GenerableType } from '../../../../Config/exports/Mapping'; import { StringParameter } from '../../../Parameters/types'; -import { CommandParameters, CommandShape } from '../../types/Command.types'; +import { + BodylessCommand, + CommandParameters, + CommandShape, +} from '../../types/Command.types'; import { Command } from '../Command'; /** @@ -17,7 +21,11 @@ export class Checkout implements Command { * Generate Checkout Command shape. * @returns The generated JSON for the Checkout Command. */ - generate(): CheckoutCommandShape { + generate(): CheckoutCommandShape | BodylessCommand { + if (this.parameters === undefined) { + return this.name; + } + return { checkout: { ...this.parameters }, }; diff --git a/src/lib/Components/Commands/exports/Reusable/ReusedCommand.ts b/src/lib/Components/Commands/exports/Reusable/ReusedCommand.ts index 0c92833..64aea79 100644 --- a/src/lib/Components/Commands/exports/Reusable/ReusedCommand.ts +++ b/src/lib/Components/Commands/exports/Reusable/ReusedCommand.ts @@ -33,7 +33,11 @@ export class ReusedCommand implements Command { /** * @returns JSON representation of the reusable command being called */ - generate(): CommandShape { + generate(): CommandShape | string { + if (this.parameters === undefined) { + return this.name; + } + return { [this.name]: this.generateContents(), }; diff --git a/src/lib/Components/Commands/types/Command.types.ts b/src/lib/Components/Commands/types/Command.types.ts index ead9eff..5aecf5e 100644 --- a/src/lib/Components/Commands/types/Command.types.ts +++ b/src/lib/Components/Commands/types/Command.types.ts @@ -17,9 +17,14 @@ export type CommandParameters = ComponentParameter; export type CommandShape = Record; +export type BodylessCommand = string; + export type CommandShorthandShape = Record; -export type AnyCommandShape = CommandShape | CommandShorthandShape; +export type AnyCommandShape = + | CommandShape + | CommandShorthandShape + | BodylessCommand; export type ReusableCommandBodyShape = { parameters?: CustomParametersListShape; diff --git a/tests/Commands.test.ts b/tests/Commands.test.ts index 9d9e62b..e27ddcb 100644 --- a/tests/Commands.test.ts +++ b/tests/Commands.test.ts @@ -20,10 +20,9 @@ describe('Instantiate a Run step', () => { describe('Instantiate a Checkout step', () => { const checkout = new CircleCI.commands.Checkout(); - const checkoutBasicResult = { checkout: {} }; it('Should produce checkout string', () => { - expect(checkout.generate()).toEqual(checkoutBasicResult); + expect(checkout.generate()).toEqual('checkout'); }); const checkoutWithPathResult = { diff --git a/tsconfig.json b/tsconfig.json index 1f12ad6..c6322c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,10 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "lib": [ + "es2017" + ] }, "include": ["src/**/*.ts"], "exclude": ["node_modules", "**/*.d.ts", "**/*.test.ts"],