@@ -3,14 +3,15 @@ const fs = require('fs-extra')
33const path = require ( 'path' )
44const helpers = require ( './../parser/lufile/helpers' )
55const luObject = require ( './../parser/lufile/classes/luObject' )
6+
67/* tslint:disable:prefer-for-of no-unused*/
78
8- export async function getLuObjects ( stdin : string , input : string | undefined , recurse = false ) {
9+ export async function getLuObjects ( stdin : string , input : string | undefined , recurse = false , extType : string | undefined ) {
910 let luObjects : any = [ ]
1011 if ( stdin ) {
1112 luObjects . push ( new luObject ( 'stdin' , stdin ) )
1213 } else {
13- let luFiles = await getLuFiles ( input , recurse )
14+ let luFiles = await getLuFiles ( input , recurse , extType )
1415 for ( let i = 0 ; i < luFiles . length ; i ++ ) {
1516 let luContent = await getContentFromFile ( luFiles [ i ] )
1617 luObjects . push ( new luObject ( path . resolve ( luFiles [ i ] ) , luContent ) )
@@ -20,7 +21,7 @@ export async function getLuObjects(stdin: string, input: string | undefined, rec
2021 return luObjects
2122}
2223
23- async function getLuFiles ( input : string | undefined , recurse = false ) : Promise < Array < any > > {
24+ async function getLuFiles ( input : string | undefined , recurse = false , extType : string | undefined ) : Promise < Array < any > > {
2425 let filesToParse = [ ]
2526 let fileStat = await fs . stat ( input )
2627 if ( fileStat . isFile ( ) ) {
@@ -32,10 +33,10 @@ async function getLuFiles(input: string | undefined, recurse = false): Promise<A
3233 throw new CLIError ( 'Sorry, ' + input + ' is not a folder or does not exist' )
3334 }
3435
35- filesToParse = helpers . findLUFiles ( input , recurse )
36+ filesToParse = helpers . findLUFiles ( input , recurse , extType )
3637
3738 if ( filesToParse . length === 0 ) {
38- throw new CLIError ( ' Sorry, no .lu files found in the specified folder.' )
39+ throw new CLIError ( ` Sorry, no ${ extType } files found in the specified folder.` )
3940 }
4041 return filesToParse
4142}
@@ -57,7 +58,7 @@ export async function getContentFromFile(file: string) {
5758 return fileContent
5859}
5960
60- export async function generateNewFilePath ( outFileName : string , inputfile : string , isLu : boolean , prefix = '' ) : Promise < string > {
61+ export async function generateNewFilePath ( outFileName : string , inputfile : string , isLu : boolean , prefix = '' , extType : string = helpers . FileExtTypeEnum . LUFile ) : Promise < string > {
6162 let base = path . resolve ( outFileName )
6263 let extension = path . extname ( base )
6364 if ( extension ) {
@@ -69,9 +70,9 @@ export async function generateNewFilePath(outFileName: string, inputfile: string
6970 let name = ''
7071 let inputStat = await fs . stat ( inputfile )
7172 if ( inputStat . isFile ( ) ) {
72- name += path . basename ( inputfile , path . extname ( inputfile ) ) + ( isLu ? '.json' : '.lu' )
73+ name += path . basename ( inputfile , path . extname ( inputfile ) ) + ( isLu ? '.json' : extType )
7374 } else {
74- name += isLu ? 'converted.json' : ' converted.lu'
75+ name += isLu ? 'converted.json' : ` converted.${ extType } `
7576 }
7677 return path . join ( base , prefix + name )
7778}
@@ -133,7 +134,7 @@ export async function detectLuContent(stdin: string, input: string) {
133134 }
134135
135136 let inputStat = await fs . stat ( input )
136- return ! inputStat . isFile ( ) ? true : path . extname ( input ) === '.lu'
137+ return ! inputStat . isFile ( ) ? true : ( path . extname ( input ) === '.lu' || path . extname ( input ) === '.qna' )
137138 }
138139
139140 try {
0 commit comments