File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,6 +38,6 @@ if (controllerName) {
3838 }
3939} else {
4040 console . error ( '\x1b[31mSpecify the name controller.' , '\x1b[0m' ) ;
41- console . log ( ` For example: recife-cli controller UserController ` ) ;
42- console . log ( ` Run recife-cli --help for more information\n` ) ;
41+ console . log ( ` For example: recife-cli controller User ` ) ;
42+ console . log ( ` Run --help for more information\n` ) ;
4343}
Original file line number Diff line number Diff line change @@ -38,5 +38,5 @@ if (projectName) {
3838} else {
3939 console . error ( '\x1b[31mSpecify the name project.' , '\x1b[0m' ) ;
4040 console . log ( ` For example: recife-cli project my-project-name` ) ;
41- console . log ( ` Run recife-cli --help for more information\n` ) ;
41+ console . log ( ` Run --help for more information\n` ) ;
4242}
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 scalarName : string = '' ;
8+
9+ commander
10+ . name ( `recife-cli scalar` )
11+ . arguments ( '<scalar-name>' )
12+ . action ( name => ( scalarName = name ) )
13+ . allowUnknownOption ( false )
14+ . parse ( process . argv ) ;
15+
16+ if ( scalarName ) {
17+ scalarName = capitalize ( scalarName . replace ( / S c a l a r | \. t s | \. j s / g, '' ) ) ;
18+
19+ scalarName += 'Scalar' ;
20+
21+ const source = path . join ( __dirname , '/../../templates/scalar/template' ) ;
22+ const target = path . join ( process . cwd ( ) , 'src/scalars' , `${ scalarName } .ts` ) ;
23+
24+ try {
25+ const contentFile = fs . readFileSync ( source ) . toString ( ) ;
26+ fs . writeFileSync (
27+ target ,
28+ replaceMask ( contentFile , {
29+ scalarName,
30+ name : scalarName . replace ( 'Scalar' , '' )
31+ } )
32+ ) ;
33+ } catch ( err ) {
34+ console . log ( `\x1b[31m${ err } \x1b[0m` ) ;
35+ }
36+ } else {
37+ console . error ( '\x1b[31mSpecify the name scalar.' , '\x1b[0m' ) ;
38+ console . log ( ` For example: recife-cli scalar Email` ) ;
39+ console . log ( ` Run -help for more information\n` ) ;
40+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ commander
2424 '../dist/generators/ControllerGenerator.js'
2525 )
2626 } )
27+ . command ( 'scalar' , 'Create a scalar' , {
28+ executableFile : path . join (
29+ __dirname ,
30+ '../dist/generators/ScalarGenerator.js'
31+ )
32+ } )
2733 . allowUnknownOption ( false ) ;
2834
2935commander . parse ( process . argv ) ;
Original file line number Diff line number Diff line change 1+ import { Kind, GraphQLError } from 'graphql';
2+ import ScalarType from 'recife';
3+
4+ const [[scalarName]]: ScalarType = {
5+ name: '[[name]]',
6+ description: 'A [[name]] scalar',
7+ parseValue: value => {
8+ return value;
9+ },
10+ serialize: value => {
11+ return value;
12+ },
13+ parseLiteral: ast => {
14+ if (ast.kind !== Kind.STRING) {
15+ throw new GraphQLError(`This "${ast}" is not a string`);
16+ }
17+
18+ return ast.value;
19+ }
20+ };
21+
22+ export default [[scalarName]];
You can’t perform that action at this time.
0 commit comments