Skip to content

Instantly share code, notes, and snippets.

@Rawphs
Created October 11, 2018 13:05
Show Gist options
  • Save Rawphs/4f0ef360ddab7794549fa7b9b7e8b821 to your computer and use it in GitHub Desktop.
Save Rawphs/4f0ef360ddab7794549fa7b9b7e8b821 to your computer and use it in GitHub Desktop.
import { GeneratorCommand } from '../Library/Command';
export const cli = {
commands: [
Cli.program('generator', {
commands: [
Cli.command('generator:controller <name>', GeneratorCommand, 'generateController', {
description: 'Generates a new controller file',
examples: [
`$ stix generator:controller user`,
`$ stix generator:module auth`,
],
}),
],
}),
],
};
import { AbstractActionController, ContextInterface } from 'stix';
export class {{ name }}Controller extends AbstractActionController {
public async root({ params }: ContextInterface) {
return this.okResponse({ Hello: 'world!' });
}
}
import { ContextInterface } from 'stix';
export class {{ name }} extends AbstractGate {
public passThrough (ctx: ContextInterface) {
return false;
}
}
import { AbstractCommand } from '../Command';
import { inject } from '../ServiceManager/decorators';
import { CliService } from '../Cli';
import { Output } from '../Output';
import { TapeRoller } from 'tape-roller';
import * as path from 'path';
export class GeneratorCommand extends AbstractCommand {
@inject(CliService)
private cliService: CliService;
async generateController (output: Output, params: { [key: string]: any }) {
const tapeRoller = new TapeRoller({
sourceDirectory: path.resolve(__dirname, '..', '..', '..', 'templates', 'controller'),
targetDirectory: path.resolve(process.cwd(), 'app', 'src', 'Controller'),
});
try {
await tapeRoller.read('Controller.ts').replace({ name: params.name }).write(`${params.name}Controller.ts`);
} catch (error) {
console.log(error);
}
}
}
import { {{ name }} } from './src/{{ name }}';
export default {{ name }};
import * as config from '../config';
import { ModuleInterface } from 'stix';
export class {{ name }} implements ModuleInterface {
getConfig() {
return config;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment