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

Commit 6304a6c

Browse files
committed
Adding stdin readin to convert commands
1 parent a686cd4 commit 6304a6c

File tree

11 files changed

+72
-612
lines changed

11 files changed

+72
-612
lines changed

packages/luis/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"author": "Microsoft",
55
"bugs": "https://github.com/microsoft/botframework-cli/issues",
6-
"main": "parser/index.js",
6+
"main": "src/parser/index.js",
77
"dependencies": {
88
"@microsoft/bf-cli-command": "1.0.0",
99
"@oclif/config": "~1.13.3",
@@ -41,7 +41,7 @@
4141
},
4242
"files": [
4343
"/lib",
44-
"/parser",
44+
"/src/parser",
4545
"/npm-shrinkwrap.json",
4646
"/oclif.manifest.json"
4747
],

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
22
const exception = require('./../../parser/lufile/classes/exception')
33
const fs = require('fs-extra')
4-
const path = require('path')
54
const file = require('./../../utils/filehelper')
65
const luConverter = require('./../../parser/converters/lutoluisconverter')
76
const luisConverter = require('./../../parser/converters/luistoluconverter')
@@ -10,7 +9,7 @@ export default class LuisConvert extends Command {
109
static description = 'Convert .lu file(s) to a LUIS application JSON model or vice versa'
1110

1211
static flags: flags.Input<any> = {
13-
in: flags.string({description: 'Source .lu file(s) or LUIS application JSON model', required: true}),
12+
in: flags.string({description: 'Source .lu file(s) or LUIS application JSON model'}),
1413
recurse: flags.boolean({description: 'Indicates if sub-folders need to be considered to file .lu file(s)', default: false}),
1514
log: flags.boolean({description: 'Enables log messages', default: false}),
1615
sort: flags.boolean({description: 'When set, intent, utterances, entities are alphabetically sorted in .lu files', default: false}),
@@ -25,18 +24,21 @@ export default class LuisConvert extends Command {
2524
async run() {
2625
try {
2726
const {flags} = this.parse(LuisConvert)
27+
// Check if data piped in stdin
28+
let stdin = await this.readStdin()
29+
2830
//Check if file or folder
2931
//if folder, only lu to luis is supported
30-
let inputStat = await fs.stat(flags.in)
31-
let isLu = !inputStat.isFile() ? true : path.extname(flags.in) === '.lu'
32+
let isLu = await file.detectLuContent(stdin, flags.in)
3233

3334
// Parse the object depending on the input
3435
let result: any
3536
if (isLu) {
36-
const luFiles = await file.getLuObjects(flags.in, flags.recurse)
37+
const luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse)
3738
result = await luConverter.parseLuToLuis(luFiles, flags.log, flags.culture)
3839
} else {
39-
result = await luisConverter.parseLuisFileToLu(flags.in, flags.sort)
40+
const luisFile = stdin ? stdin : await file.getContentFromFile(flags.in)
41+
result = await luisConverter.parseLuisObjectToLu(luisFile, flags.sort, flags.in)
4042
}
4143

4244
// If result is null or undefined return

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
22
const exception = require('./../../parser/lufile/classes/exception')
33
const fs = require('fs-extra')
4-
const path = require('path')
54
const file = require('./../../utils/filehelper')
65
const luConverter = require('./../../parser/converters/qnatoqnajsonconverter')
76
const qnaConverter = require('./../../parser/converters/qnajsontoqnaconverter')
@@ -23,18 +22,21 @@ export default class QnamakerConvert extends Command {
2322
try {
2423
const {flags} = this.parse(QnamakerConvert)
2524

26-
// Check if file or folder
27-
// If folder, only lu to luis is supported
28-
let inputStat = await fs.stat(flags.in)
29-
let isQnA = !inputStat.isFile() ? true : path.extname(flags.in) === '.lu'
25+
// Check if data piped in stdin
26+
let stdin = await this.readStdin()
27+
28+
//Check if file or folder
29+
//if folder, only lu to luis is supported
30+
let isQnA = await file.detectLuContent(stdin, flags.in)
3031

3132
// Parse the object depending on the input
3233
let result: any
3334
if (isQnA) {
34-
const luFiles = await file.getLuObjects(flags.in, flags.recurse)
35+
const luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse)
3536
result = await luConverter.parseQnaToJson(luFiles, false, flags.luis_culture)
3637
} else {
37-
result = await qnaConverter.parseQnAFileToLu(flags.in, flags.sort, flags.alterations)
38+
const qnAFile = stdin ? stdin : await file.getContentFromFile(flags.in)
39+
result = await qnaConverter.parseQnAObjectToLu(qnAFile, flags.sort, flags.alterations)
3840
}
3941

4042
// If result is null or undefined return

packages/luis/src/parser/converters/luistoluconverter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const retCode = require('./../lufile/enums/CLI-errors')
1010
module.exports = {
1111
parseLuisFileToLu: async function(file, sort) {
1212
let LUISFileContent = await openFileAndReadContent(file)
13-
return await this.parseLuisObjectToLu(LUISFileContent, file, sort)
13+
return await this.parseLuisObjectToLu(LUISFileContent, sort, file)
1414
},
15-
parseLuisObjectToLu: async function(luisObjectString, src, sort) {
15+
parseLuisObjectToLu: async function(luisObjectString, sort, src = '', ) {
1616
let LUISJSON = await parseLuis(luisObjectString, src, sort)
1717
return await this.constructMdFromLUISJSON(LUISJSON.model)
1818
},

packages/luis/src/parser/converters/lumerger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const luisJSON = require('./../luisfile/parseLuisFile');
1616

1717
module.exports = {
1818
mergeAndResolveReferences: async function (luObjArray, verbose, luis_culture, luSearchFn){
19-
let allParsedContent = await buildLuObject(luObjArray, verbose, luis_culture, luSearchFn)
19+
let allParsedContent = await buildJsonObject(luObjArray, verbose, luis_culture, luSearchFn)
2020
await resolveReferencesInUtterances(allParsedContent)
2121
return allParsedContent
2222
}
2323
}
2424

25-
const buildLuObject = async function(luObjArray, log, luis_culture, luSearchFn = findLuFilesInDir){
25+
const buildJsonObject = async function(luObjArray, log, luis_culture, luSearchFn = findLuFilesInDir){
2626
let allParsedLUISContent = []
2727
let allParsedQnAContent = []
2828
let allParsedAlterationsContent = []

packages/luis/src/parser/lufile/helpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) Microsoft Corporation. All rights reserved.
44
* Licensed under the MIT License.
55
*/
6-
require('./utils');
76
const fs = require('fs');
87
const path = require('path');
98
const retCode = require('./enums/CLI-errors');

packages/luis/src/parser/lufile/parseFileContents.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) Microsoft Corporation. All rights reserved.
44
* Licensed under the MIT License.
55
*/
6-
require('./utils');
76
const LUISObjNameEnum = require('./enums/luisobjenum');
87
const PARSERCONSTS = require('./enums/parserconsts');
98
const builtInTypes = require('./enums/luisbuiltintypes');

0 commit comments

Comments
 (0)