File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import fs from 'fs' ;
2+ import path from 'path' ;
3+ import commander from 'commander' ;
4+ import capitalize from '../utils/capitalize' ;
5+ import replaceMask from '../utils/replaceMask' ;
6+
7+ let validatorName : string = '' ;
8+
9+ commander
10+ . name ( `recife-cli validator` )
11+ . arguments ( '<validator-name>' )
12+ . action ( name => ( validatorName = name ) )
13+ . allowUnknownOption ( false )
14+ . parse ( process . argv ) ;
15+
16+ if ( validatorName ) {
17+ validatorName = capitalize ( validatorName . replace ( / V a l i d a t o r | \. t s | \. j s / g, '' ) ) ;
18+
19+ validatorName += 'Validator' ;
20+
21+ const source = path . join ( __dirname , '/../../templates/validator/template' ) ;
22+ const target = path . join (
23+ process . cwd ( ) ,
24+ 'src/validators' ,
25+ `${ validatorName } .ts`
26+ ) ;
27+
28+ try {
29+ const contentFile = fs . readFileSync ( source ) . toString ( ) ;
30+ fs . writeFileSync ( target , replaceMask ( contentFile , { name : validatorName } ) ) ;
31+ } catch ( err ) {
32+ console . log ( `\x1b[31m${ err } \x1b[0m` ) ;
33+ }
34+ } else {
35+ console . error ( '\x1b[31mSpecify the name validator.' , '\x1b[0m' ) ;
36+ console . log ( ` For example: recife-cli validator User` ) ;
37+ console . log ( ` Run --help for more information\n` ) ;
38+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ commander
3030 '../dist/generators/ScalarGenerator.js'
3131 )
3232 } )
33+ . command ( 'validator' , 'Create a validator' , {
34+ executableFile : path . join (
35+ __dirname ,
36+ '../dist/generators/ValidatorGenerator.js'
37+ )
38+ } )
3339 . allowUnknownOption ( false ) ;
3440
3541commander . parse ( process . argv ) ;
Original file line number Diff line number Diff line change 1+ class [[name]] {
2+ constructor() {
3+ //
4+ }
5+ }
6+
7+ export default [[name]];
You can’t perform that action at this time.
0 commit comments