Skip to content

Commit

Permalink
refactor: lint and format files
Browse files Browse the repository at this point in the history
  • Loading branch information
neodmy committed Nov 27, 2023
1 parent 456b43a commit 855dcbb
Show file tree
Hide file tree
Showing 50 changed files with 1,589 additions and 1,285 deletions.
6 changes: 3 additions & 3 deletions packages/@guidesmiths/cuckoojs-cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from '@jest/globals';

describe('pr-template', () => {
it('hello world', () => {
expect('hello world').toBe('hello world');
});
it('hello world', () => {
expect('hello world').toBe('hello world');
});
});
107 changes: 56 additions & 51 deletions packages/@guidesmiths/cuckoojs-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,70 @@
#!/usr/bin/env node
import {Option, Command} from 'commander';
import {version} from '../package.json';
import {NewCommand, GenerateCommand} from './commands';
import {LambdaNewCommand} from "./commands/lambda-new.command";
import { Option, Command } from 'commander';
import { version } from '../package.json';
import { NewCommand, GenerateCommand } from './commands';
import { LambdaNewCommand } from './commands/lambda-new.command';

const init = (): void => {
const cuckoo = new Command('cuckoo');
const cuckoo = new Command('cuckoo');

cuckoo
.version(
version,
'-v, --version',
'Output the current version.',
);
cuckoo.version(version, '-v, --version', 'Output the current version.');

cuckoo
.helpOption('-h, --help', 'Output usage information.')
.showHelpAfterError()
.usage('<command> [options]');
cuckoo
.helpOption('-h, --help', 'Output usage information.')
.showHelpAfterError()
.usage('<command> [options]');

const nest = cuckoo
.command('nest')
.description('Generate nest template')
const nest = cuckoo.command('nest').description('Generate nest template');

nest
.command('new <name> [options...]')
.alias('n')
.description('Generate Nest application with basic tooling.')
.action(async (name: string) => {
await new NewCommand(name).execute();
});
nest
.command('new <name> [options...]')
.alias('n')
.description('Generate Nest application with basic tooling.')
.action(async (name: string) => {
await new NewCommand(name).execute();
});

nest
.command('generate <schematic> <name> [options...]')
.alias('g')
.description('Generate a Nest element.')
.action(async (schematic: string, name: string, options: string[]) => {
await new GenerateCommand(schematic, name, options).execute();
});
nest
.command('generate <schematic> <name> [options...]')
.alias('g')
.description('Generate a Nest element.')
.action(async (schematic: string, name: string, options: string[]) => {
await new GenerateCommand(schematic, name, options).execute();
});

const lambda = cuckoo
.command('lambda')
.description('Generate lambda template')
const lambda = cuckoo
.command('lambda')
.description('Generate lambda template');

lambda
.command('new <name>')
.alias('n')
.description('Generate an AWS Lambda Quickstart')
.addOption(
new Option('-g, --git-provider <gitProvider>', 'Git provider to host the repo')
.choices(['github', 'azuredevops'])
.default('github'))
.addOption(
new Option('--skip-git-init', 'Skip git repository initialization')
)
.action(async (name: string, options: { gitProvider: string, skipGitInit: string}) => {
await new LambdaNewCommand(name, options.gitProvider, !!options.skipGitInit).execute();
});
lambda
.command('new <name>')
.alias('n')
.description('Generate an AWS Lambda Quickstart')
.addOption(
new Option(
'-g, --git-provider <gitProvider>',
'Git provider to host the repo',
)
.choices(['github', 'azuredevops'])
.default('github'),
)
.addOption(
new Option('--skip-git-init', 'Skip git repository initialization'),
)
.action(
async (
name: string,
options: { gitProvider: string; skipGitInit: string },
) => {
await new LambdaNewCommand(
name,
options.gitProvider,
!!options.skipGitInit,
).execute();
},
);

cuckoo
.parse(process.argv);
cuckoo.parse(process.argv);
};

init();
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import Printer from '../lib/printer/printer';

export class AbstractCommand {
protected static endProcess(status: number) {
process.exit(status);
}
protected static endProcess(status: number) {
process.exit(status);
}

protected printSuccess = Printer.format({fontColor: 'green', decoration: 'bold'});
protected printError = Printer.format({fontColor: 'red', decoration: 'bold'});
protected printNeutral = Printer.format({decoration: 'bold'});
protected printSuccess = Printer.format({
fontColor: 'green',
decoration: 'bold',
});
protected printError = Printer.format({
fontColor: 'red',
decoration: 'bold',
});
protected printNeutral = Printer.format({ decoration: 'bold' });
}

50 changes: 28 additions & 22 deletions packages/@guidesmiths/cuckoojs-cli/src/commands/generate.command.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import {messages} from '../lib/ui/ui';
import {AbstractCommand} from './abstract.command';
import {NestRunner} from '../lib/runners/nest.runner';
import { messages } from '../lib/ui/ui';
import { AbstractCommand } from './abstract.command';
import { NestRunner } from '../lib/runners/nest.runner';

export class GenerateCommand extends AbstractCommand {
private readonly schematicRunner: NestRunner = new NestRunner();
private readonly schematicRunner: NestRunner = new NestRunner();

constructor(
private readonly schematic: string,
private readonly name: string,
private readonly options: string[],
) {
super();
}
constructor(
private readonly schematic: string,
private readonly name: string,
private readonly options: string[],
) {
super();
}

public async execute() {
this.printSuccess(messages.banner);
public async execute() {
this.printSuccess(messages.banner);

try {
this.printNeutral(`Generating Nest ${this.schematic}.`);
await this.schematicRunner.generateNestElement(this.schematic, this.name, this.options);
this.printSuccess(`Nest ${this.schematic} generated.`);
} catch (error: unknown) {
this.printError(`Error generating Nest ${this.schematic}: ${(error as Error).message}`);
GenerateCommand.endProcess(1);
}
}
try {
this.printNeutral(`Generating Nest ${this.schematic}.`);
await this.schematicRunner.generateNestElement(
this.schematic,
this.name,
this.options,
);
this.printSuccess(`Nest ${this.schematic} generated.`);
} catch (error: unknown) {
this.printError(
`Error generating Nest ${this.schematic}: ${(error as Error).message}`,
);
GenerateCommand.endProcess(1);
}
}
}
4 changes: 2 additions & 2 deletions packages/@guidesmiths/cuckoojs-cli/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {NewCommand} from './new.command';
export {GenerateCommand} from './generate.command';
export { NewCommand } from './new.command';
export { GenerateCommand } from './generate.command';
Loading

0 comments on commit 855dcbb

Please sign in to comment.