1- import { CLIError , Command , flags } from '@microsoft/bf-cli-command'
2- import { camelCase , upperFirst } from 'lodash'
1+ import { CLIError , Command , flags } from '@microsoft/bf-cli-command'
2+ import { camelCase , upperFirst } from 'lodash'
33import * as path from 'path'
44
5- import { LuisToCsConverter } from '../../../parser/converters/luis-to-cs-converter'
6- import { Utils } from '../../../utils'
5+ import { LuisToCsConverter } from '../../../parser/converters/luis-to-cs-converter'
6+ import { Utils } from '../../../utils'
77
88const fs = require ( 'fs-extra' )
99
1010export default class LuisGenerateCs extends Command {
1111 static description = 'Generate:cs generates a strongly typed C# source code from an exported (json) LUIS model.'
1212
1313 static flags : flags . Input < any > = {
14- in : flags . string ( { description : 'Source .lu file(s) or LUIS application JSON model' } ) ,
15- out : flags . string ( { description : 'Output file or folder name. If not specified stdout will be used as output' , default : '' } ) ,
16- className : flags . string ( { description : 'Name of the class' } ) ,
14+ in : flags . string ( { description : 'Source .lu file(s) or LUIS application JSON model' } ) ,
15+ out : flags . string ( { description : 'Output file or folder name. If not specified stdout will be used as output' , default : '' } ) ,
16+ className : flags . string ( { description : 'Name of the class' } ) ,
1717 }
1818
1919 reorderEntities ( app : any , name : string ) : void {
@@ -23,39 +23,35 @@ export default class LuisGenerateCs extends Command {
2323 }
2424
2525 async run ( ) {
26- try {
27- const { flags} = this . parse ( LuisGenerateCs )
28- let space = 'Luis'
29- let stdInput = await this . readStdin ( )
30-
31- const pathPrefix = path . isAbsolute ( flags . in ) ? '' : process . cwd ( )
32- const app = stdInput ? JSON . parse ( stdInput as string ) : await fs . readJSON ( path . join ( pathPrefix , flags . in ) )
33-
34- flags . className = flags . className || app . name
35- flags . className = upperFirst ( camelCase ( flags . className ) )
36-
37- const dot_index = flags . className ? flags . className . indexOf ( '.' ) : - 1
38- if ( dot_index !== - 1 ) {
39- space = flags . className . substr ( dot_index + 1 )
40- flags . className = flags . className . substr ( 0 , dot_index )
41- }
42-
43- this . reorderEntities ( app , 'entities' )
44- this . reorderEntities ( app , 'prebuiltEntities' )
45- this . reorderEntities ( app , 'closedLists' )
46- this . reorderEntities ( app , 'regex_entities' )
47- this . reorderEntities ( app , 'patternAnyEntities' )
48- this . reorderEntities ( app , 'composites' )
49-
50- const outputPath = Utils . validatePath ( flags . out , process . cwd ( ) , flags . className + '.cs' )
51-
52- this . log (
53- `Generating file at ${ outputPath || '' } that contains class ${ space } .${ flags . className } .`
54- )
55-
56- await LuisToCsConverter . writeFromLuisJson ( app , flags . className , space , outputPath )
57- } catch ( err ) {
58- throw new CLIError ( err )
26+ const { flags } = this . parse ( LuisGenerateCs )
27+ let space = 'Luis'
28+ let stdInput = await this . readStdin ( )
29+
30+ const pathPrefix = path . isAbsolute ( flags . in ) ? '' : process . cwd ( )
31+ const app = stdInput ? JSON . parse ( stdInput as string ) : await fs . readJSON ( path . join ( pathPrefix , flags . in ) )
32+
33+ flags . className = flags . className || app . name
34+ flags . className = upperFirst ( camelCase ( flags . className ) )
35+
36+ const dot_index = flags . className ? flags . className . indexOf ( '.' ) : - 1
37+ if ( dot_index !== - 1 ) {
38+ space = flags . className . substr ( dot_index + 1 )
39+ flags . className = flags . className . substr ( 0 , dot_index )
5940 }
41+
42+ this . reorderEntities ( app , 'entities' )
43+ this . reorderEntities ( app , 'prebuiltEntities' )
44+ this . reorderEntities ( app , 'closedLists' )
45+ this . reorderEntities ( app , 'regex_entities' )
46+ this . reorderEntities ( app , 'patternAnyEntities' )
47+ this . reorderEntities ( app , 'composites' )
48+
49+ const outputPath = Utils . validatePath ( flags . out , process . cwd ( ) , flags . className + '.cs' )
50+
51+ this . log (
52+ `Generating file at ${ outputPath || '' } that contains class ${ space } .${ flags . className } .`
53+ )
54+
55+ await LuisToCsConverter . writeFromLuisJson ( app , flags . className , space , outputPath )
6056 }
6157}
0 commit comments