Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit dd36356

Browse files
authored
fix the priority of stdin and in (#796)
* fix the priority of stdin and in * fix the same issue in bf luis:generate * repalce all priority between stdin and --in * fix logic * remove only in luis build tests
1 parent f3767ca commit dd36356

File tree

14 files changed

+39
-38
lines changed

14 files changed

+39
-38
lines changed

packages/lu/src/utils/filehelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ const globby = require('globby')
1717

1818
export async function getLuObjects(stdin: string, input: string | undefined, recurse = false, extType: string | undefined) {
1919
let luObjects: any = []
20-
if (stdin) {
21-
luObjects.push(new luObject(stdin, new LUOptions('stdin')))
22-
} else {
20+
if (input) {
2321
let luFiles = await getLuFiles(input, recurse, extType)
2422
for (let i = 0; i < luFiles.length; i++) {
2523
let luContent = await getContentFromFile(luFiles[i])
2624
const opts = new LUOptions(path.resolve(luFiles[i]))
2725
luObjects.push(new luObject(luContent, opts))
2826
}
27+
} else {
28+
luObjects.push(new luObject(stdin, new LUOptions('stdin')))
2929
}
3030

3131
return luObjects

packages/luis/src/commands/luis/application/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class LuisApplicationImport extends Command {
3838

3939
inVal = inVal ? inVal.trim() : flags.in
4040

41-
const appJSON = stdin ? stdin : await utils.getInputFromFile(inVal)
41+
const appJSON = inVal ? await utils.getInputFromFile(inVal) : stdin
4242
if (!appJSON) throw new CLIError('No import data found - please provide input through stdin or the --in flag')
4343

4444
// const client = utils.getLUISClient(subscriptionKey, endpoint)

packages/luis/src/commands/luis/build.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,7 @@ export default class LuisBuild extends Command {
107107
let multiRecognizers = new Map<string, any>()
108108
let settings = new Map<string, any>()
109109

110-
if (flags.stdin && flags.stdin !== '') {
111-
// load lu content from stdin and create default recognizer, multiRecognier and settings
112-
if (log) this.log('Load lu content from stdin\n')
113-
const content = new Content(flags.stdin, new LUOptions('stdin', true, defaultCulture, path.join(process.cwd(), 'stdin')))
114-
luContents.push(content)
115-
multiRecognizers.set('stdin', new MultiLanguageRecognizer(path.join(process.cwd(), 'stdin.lu.dialog'), {}))
116-
settings.set('stdin', new Settings(path.join(process.cwd(), `luis.settings.${suffix}.${region}.json`), {}))
117-
const recognizer = Recognizer.load(content.path, content.name, path.join(process.cwd(), `${content.name}.dialog`), settings.get('stdin'), {})
118-
recognizers.set(content.name, recognizer)
119-
} else {
110+
if ((inVal && inVal !== '') || files.length > 0) {
120111
if (log) this.log('Loading files...\n')
121112

122113
// get lu files from in.
@@ -135,6 +126,15 @@ export default class LuisBuild extends Command {
135126
recognizers = loadedResources.recognizers
136127
multiRecognizers = loadedResources.multiRecognizers
137128
settings = loadedResources.settings
129+
} else {
130+
// load lu content from stdin and create default recognizer, multiRecognier and settings
131+
if (log) this.log('Load lu content from stdin\n')
132+
const content = new Content(flags.stdin, new LUOptions('stdin', true, defaultCulture, path.join(process.cwd(), 'stdin')))
133+
luContents.push(content)
134+
multiRecognizers.set('stdin', new MultiLanguageRecognizer(path.join(process.cwd(), 'stdin.lu.dialog'), {}))
135+
settings.set('stdin', new Settings(path.join(process.cwd(), `luis.settings.${suffix}.${region}.json`), {}))
136+
const recognizer = Recognizer.load(content.path, content.name, path.join(process.cwd(), `${content.name}.dialog`), settings.get('stdin'), {})
137+
recognizers.set(content.name, recognizer)
138138
}
139139

140140
// update or create and then train and publish luis applications based on loaded resources

packages/luis/src/commands/luis/convert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class LuisConvert extends Command {
4949
throw new CLIError('No LU or Luis content parsed!')
5050
}
5151
} else {
52-
const luisContent = stdin ? stdin : await file.getContentFromFile(flags.in)
52+
const luisContent = flags.in ? await file.getContentFromFile(flags.in) : stdin
5353
const luisObject = new Luis(file.parseJSON(luisContent, 'Luis'))
5454
if (flags.sort) {
5555
sort(luisObject)

packages/luis/src/commands/luis/generate/cs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class LuisGenerateCs extends Command {
4242
const pathPrefix = flags.in && path.isAbsolute(flags.in) ? '' : process.cwd()
4343
let app: any
4444
try {
45-
app = stdInput ? JSON.parse(stdInput as string) : await fs.readJSON(path.join(pathPrefix, flags.in))
45+
app = flags.in ? await fs.readJSON(path.join(pathPrefix, flags.in)) : JSON.parse(stdInput as string)
4646
} catch (err) {
4747
throw new CLIError(err)
4848
}

packages/luis/src/commands/luis/generate/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class LuisGenerateTs extends Command {
4040
const pathPrefix = flags.in && path.isAbsolute(flags.in) ? '' : process.cwd()
4141
let app: any
4242
try {
43-
app = stdInput ? JSON.parse(stdInput as string) : await fs.readJSON(path.join(pathPrefix, flags.in))
43+
app = flags.in ? await fs.readJSON(path.join(pathPrefix, flags.in)) : JSON.parse(stdInput as string)
4444
} catch (error) {
4545
throw new CLIError(error)
4646
}

packages/luis/src/commands/luis/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class LuisTest extends Command {
5151
throw new CLIError('No LU content parsed!')
5252
}
5353
} else {
54-
const luisContent = stdin ? stdin : await file.getContentFromFile(flags.in)
54+
const luisContent = flags.in ? await file.getContentFromFile(flags.in) : stdin
5555
luisObject = new Luis(file.parseJSON(luisContent, 'Luis'))
5656
if (!hasContent(luisObject)) {
5757
throw new CLIError('No LUIS content found!')

packages/luis/src/commands/luis/translate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export default class LuisTranslate extends Command {
5151
})
5252
})
5353
} else {
54-
const json = stdin ? stdin : await fileHelper.getContentFromFile(flags.in)
54+
const json = flags.in ? await fileHelper.getContentFromFile(flags.in) : stdin
5555
const luisObject = new Luis(fileHelper.parseJSON(json, 'Luis'))
56-
const key = stdin ? 'stdin' : path.basename(flags.in)
56+
const key = flags.in ? path.basename(flags.in) : 'stdin'
5757
const translation = new Lu(luisObject.parseToLuContent(), key)
5858
const translatedLuis = await luTranslator.translateLu(translation, flags.translatekey, flags.tgtlang, flags.srclang, flags.translate_comments, flags.translate_link_text)
5959
result = {

packages/luis/src/commands/luis/version/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class LuisVersionImport extends Command {
3939

4040
inVal = inVal ? inVal.trim() : flags.in
4141

42-
const appJSON = stdin ? stdin : await utils.getInputFromFile(inVal)
42+
const appJSON = inVal ? await utils.getInputFromFile(inVal) : stdin
4343
if (!appJSON) throw new CLIError('No import data found - please provide input through stdin or the --in flag')
4444

4545
if (versionId) options.versionId = versionId

packages/luis/test/commands/luis/build.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ describe('luis:build create a new application successfully with locale set to it
817817
await fs.remove(path.join(__dirname, './../../../results/'))
818818
})
819819

820-
test.only()
820+
test
821821
.stdout()
822822
.command(['luis:build', '--in', './test/fixtures/testcases/lubuild/file-with-personName/personName.en-us.lu', '--authoringKey', uuidv1(), '--botName', 'test', '--log', '--suffix', 'development', '--out', './results', '--defaultCulture', 'it-it'])
823823
.it('should create a new application successfully for prebuilt entity personName with locale set to it-it', ctx => {

0 commit comments

Comments
 (0)