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

Commit 41daaf7

Browse files
authored
Adding export format option to luis:version:export (#1116)
1 parent 50bae19 commit 41daaf7

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

packages/luis/src/api/version.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export default {
2323

2424
async export(
2525
param: EndpointParameters,
26-
versionId: string) {
27-
let url = buildUrl(param.endpoint) + `/${param.appId}/versions/${versionId}/export?format=json"`
26+
versionId: string,
27+
format = 'json') {
28+
let url = buildUrl(param.endpoint) + `/${param.appId}/versions/${versionId}/export?format=${format}`
2829
return http.get(url, param.subscriptionKey)
2930
},
3031

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class LuisVersionExport extends Command {
2020
help: flags.help({char: 'h'}),
2121
appId: flags.string({description: '(required) LUIS application Id (defaults to config:LUIS:appId)'}),
2222
versionId: flags.string({description: '(required) Version to export (defaults to config:LUIS:versionId)'}),
23+
exportLU: flags.boolean({description: 'Export format type as LU'}),
2324
out: flags.string({char: 'o', description: 'Save exported application to specified file, uses STDOUT if not specified (optional)'}),
2425
force: flags.boolean({char: 'f', description: 'Overwrites output file if exists, otherwise creates a parallel numbered file (optional)', default: false}),
2526
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
@@ -44,7 +45,7 @@ export default class LuisVersionExport extends Command {
4445
utils.validateRequiredProps(requiredProps)
4546

4647
try {
47-
const messageData = await Version.export({subscriptionKey, endpoint, appId}, versionId)
48+
const messageData = await Version.export({subscriptionKey, endpoint, appId}, versionId, flags.exportLU ? 'lu' : 'json')
4849

4950
if (messageData.error) {
5051
throw new CLIError(messageData.error.message)
@@ -54,7 +55,7 @@ export default class LuisVersionExport extends Command {
5455
const writtenFilePath: string = await utils.writeToFile(out, messageData, force)
5556
this.log(`File successfully written: ${writtenFilePath}`)
5657
} else {
57-
await utils.writeToConsole(messageData)
58+
this.log(flags.exportLU ? messageData : JSON.stringify(messageData, null, 2))
5859
}
5960
} catch (error) {
6061
throw new CLIError(error)

packages/luis/src/utils/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ const writeToConsole = (outputContents: string) => {
9595
process.stdout.write(output)
9696
}
9797

98-
const writeToFile = async (outputLocation: string, content: any, force: boolean) => {
98+
const writeToFile = async (outputLocation: string, content: any, force: boolean, text = false) => {
9999
const isDir = isDirectory(outputLocation)
100100
let writeFile = isDir ? path.join(outputLocation, 'export.json') : outputLocation
101101
const validatedPath = utils.validatePath(writeFile, '', force)
102102
try {
103103
await fs.ensureFile(writeFile)
104-
await fs.writeJson(validatedPath, content, {spaces: 2})
104+
if (text) {
105+
await fs.writeFile(validatedPath, content)
106+
} else {
107+
await fs.writeJson(validatedPath, content, {spaces: 2})
108+
}
105109
} catch (error) {
106110
throw new CLIError(error)
107111
}

packages/luis/test/commands/luis/version/export.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ describe('luis:version:export', () => {
7070
expect(ctx.stdout).to.contain('domain_name')
7171
})
7272

73+
test
74+
.nock('https://westus.api.cognitive.microsoft.com', api => api
75+
.get(uri => uri.includes('export'))
76+
.reply(200, 'LU Content')
77+
)
78+
.stdout()
79+
.command(['luis:version:export', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--exportLU'])
80+
.it('exports a luis app and displays the export contents in the console as LU format', ctx => {
81+
expect(ctx.stdout).to.contain('LU Content')
82+
})
83+
7384
test
7485
.nock('https://westus.api.cognitive.microsoft.com', api => api
7586
.get(uri => uri.includes('export'))

0 commit comments

Comments
 (0)