-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Command.ts
72 lines (63 loc) · 1.58 KB
/
Command.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* @adonisjs/assembler
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { join } from 'path'
import { args } from '@adonisjs/ace'
import { snakeCase } from 'snake-case'
import { RcFile } from '@ioc:Adonis/Core/Application'
import { BaseGenerator } from './Base'
/**
* Command to make a new command
*/
export default class MakeCommand extends BaseGenerator {
/**
* Required by BaseGenerator
*/
protected $pattern = 'pascalcase' as const
protected $resourceName: string
/**
* Command meta data
*/
public static commandName = 'make:command'
public static description = 'Make a new ace command'
@args.string({ description: 'Make of the command class' })
public name: string
/**
* Returns the template stub based upon the `--resource`
* flag value
*/
protected $getStub (): string {
return join(
__dirname,
'..',
'..',
'templates',
'command.txt',
)
}
/**
* Path to the commands directory
*/
protected $getDestinationPath (rcFile: RcFile): string {
return rcFile.directories.commands || 'commands'
}
/**
* Passed down to the template.
*/
protected $templateData (): { toCommandName: (filename: string) => string } {
return {
toCommandName: (filename: string): string => {
return snakeCase(filename).replace(/_/, ':')
},
}
}
public async handle (): Promise<void> {
this.$resourceName = this.name
await super.generate()
}
}