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

Commit b7980c4

Browse files
author
JSpru
authored
Create bf luis plugin (#349)
* bf-luis-cli plugin initial commit * Adding clone cmd * Deleting files * Get values from config if not present in flags * Add unit tests with HTTP mock * Lint fixes * Update readme * Move endpoint monkey patch into shared utils file so we only have to remove it once later * Convert utils filte to TS, lint fixes, read config dir refactor * Regenerate readme * Eliminate redundant var * Lint fix * Remove duplicate content from readme * Update readme * Remove outer try catch * Move input processing into utils file, add config filter and reducer * Only filter config if config * Update test mock to reflect input processing change * Remove space
1 parent 294689d commit b7980c4

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ export default class LuisVersionClone extends Command {
2626
async run() {
2727
const {flags} = this.parse(LuisVersionClone)
2828
const configDir = this.config.configDir
29+
const configPrefix = 'luis__'
2930

30-
const appId = flags.appId || await utils.getPropFromConfig('appId', configDir)
31-
const endpoint = flags.endpoint || await utils.getPropFromConfig('endpoint', configDir)
32-
const subscriptionKey = flags.subscriptionKey || await utils.getPropFromConfig('subscriptionKey', configDir)
33-
const versionId = flags.versionId || await utils.getPropFromConfig('versionId', configDir)
34-
const targetVersionId = flags.targetVersionId || await utils.getPropFromConfig('targetVersionId', configDir)
31+
const {appId, endpoint, subscriptionKey, versionId, targetVersionId} = await utils.processInputs(flags, configDir, configPrefix)
3532

3633
const requiredProps = {appId, endpoint, subscriptionKey, versionId, targetVersionId}
3734
utils.validateRequiredProps(requiredProps)

packages/luis/src/utils/index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*!
32
* Copyright (c) Microsoft Corporation. All rights reserved.
43
* Licensed under the MIT License.
@@ -10,6 +9,15 @@ const fs = require('fs-extra')
109
const msRest = require('ms-rest')
1110
const {LUISAuthoringClient} = require('azure-cognitiveservices-luis-authoring')
1211

12+
const filterConfig = (config: any, prefix: string) => {
13+
return Object.keys(config)
14+
.filter((key: string) => key.startsWith(prefix))
15+
.reduce((filteredConfig: any, key: string) => {
16+
filteredConfig[key] = config[key]
17+
return filteredConfig
18+
}, {})
19+
}
20+
1321
const getUserConfig = async (configPath: string) => {
1422
if (fs.existsSync(path.join(configPath, 'config.json'))) {
1523
return fs.readJSON(path.join(configPath, 'config.json'), {throws: false})
@@ -35,6 +43,19 @@ const getPropFromConfig = async (prop: string, configDir: string) => {
3543
}
3644
}
3745

46+
const processInputs = async (flags: any, configDir: string, prefix: string) => {
47+
let config = await getUserConfig(configDir)
48+
config = config ? filterConfig(config, prefix) : config
49+
const input = {
50+
appId: flags.appId || (config ? config.luis__appId : null),
51+
endpoint: flags.endpoint || (config ? config.luis__endpoint : null),
52+
subscriptionKey: flags.subscriptionKey || (config ? config.luis__subscriptionKey : null),
53+
versionId: flags.versionId || (config ? config.luis__versionId : null),
54+
targetVersionId: flags.targetVersionId || (config ? config.luis__targetVersionId : null)
55+
}
56+
return input
57+
}
58+
3859
const validateRequiredProps = (configObj: any) => {
3960
Object.keys(configObj).forEach(key => {
4061
if (!configObj[key]) {
@@ -44,5 +65,7 @@ const validateRequiredProps = (configObj: any) => {
4465
}
4566

4667
module.exports.getLUISClient = getLUISClient
68+
module.exports.getUserConfig = getUserConfig
4769
module.exports.getPropFromConfig = getPropFromConfig
70+
module.exports.processInputs = processInputs
4871
module.exports.validateRequiredProps = validateRequiredProps

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const utils = require('../../../../src/utils/index')
66
describe('luis:version:clone', () => {
77

88
beforeEach(() => {
9-
sinon.stub(utils, 'getPropFromConfig').callsFake(() => null)
9+
sinon.stub(utils, 'processInputs').returnsArg(0)
1010
})
1111

1212
afterEach(() => {

0 commit comments

Comments
 (0)