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

Commit 3443954

Browse files
authored
Merge pull request #217 from microsoft/emimunoz/luis
Change telemetry message and fix to stdin reading
2 parents 563659b + 9128769 commit 3443954

File tree

11 files changed

+43
-31
lines changed

11 files changed

+43
-31
lines changed

packages/cli/scripts/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const getUserConfig = async () => {
3838
const userConfig = await getUserConfig()
3939
userConfig.lastVersionCheck = new Date()
4040
if (userConfig.telemetry === null) {
41-
const disableTelemetry = await cli.prompt(chalk.red('Telemetry is disabled. Would you like to opt in? Only command and flags usage will be sent. (Y/N)'))
41+
const disableTelemetry = await cli.prompt(chalk.red('Help us improve products by allowing Microsoft to collect anonymous command and flags usage: (Y/N)'))
4242
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
4343
userConfig.telemetry = true
4444
console.log(chalk.blue('Telemetry has been enabled.'))

packages/cli/src/hooks/init/inithook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const hook: Hook<'init'> = async function (opts) {
6666
// Ensure telemetry is set
6767
try {
6868
if (userConfig.telemetry === null) {
69-
const disableTelemetry = await cli.prompt(chalk.red('Telemetry is disabled. Would you like to opt in?. Only command and flags usage will be sent. (Y/N)'))
69+
const disableTelemetry = await cli.prompt(chalk.red('Help us improve products by allowing Microsoft to collect anonymous command and flags usage: (Y/N)'))
7070
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
7171
userConfig.telemetry = true
7272
this.log(chalk.blue('Telemetry has been enabled.'))

packages/command/src/readpipeddata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const ReadPipedStdin = {
1616
}, 1000)
1717

1818
stdin.on('data', chunk => {
19+
clearTimeout(timer)
1920
input += chunk
2021
})
2122

packages/command/test/command.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ describe('command', () => {
9595
.do(output => expect(output.stderr).to.equal(''))
9696
.it('Command should return empty string if no stdin')
9797

98-
fancy
99-
.stdin('test reading of piped data')
100-
.stdout()
101-
.do(async () => {
102-
try {
103-
const resp: any = await ReadPipedStdin.read()
104-
if (resp) console.log(resp)
105-
} catch (error) {
106-
if (error) console.log(`Error: ${error}`)
107-
}
108-
})
109-
.do(output => expect(output.stdout).to.equal('test reading of piped data\n'))
110-
.it('should read and echo the stdin input')
111-
11298
fancy
11399
.stdin('')
114100
.stdout()

packages/lu/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@
6363
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
6464
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.**\"",
6565
"version": "oclif-dev readme && git add README.md"
66+
},
67+
"nyc": {
68+
"exclude": [
69+
"**/lufile/generated/**"
70+
]
6671
}
6772
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default class LuisConvert extends Command {
7777
// write out the final file
7878
try {
7979
await fs.writeFile(filePath, convertedObject, 'utf-8')
80-
8180
} catch (err) {
8281
throw new CLIError('Unable to write file - ' + filePath + ' Error: ' + err.message)
8382
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@ export default class LuisTranslate extends Command {
2828
const {flags} = this.parse(LuisTranslate)
2929
// Check if data piped in stdin
3030
let stdin = await this.readStdin()
31-
let outputStat = flags.out ? await fs.stat(flags.out) : null
32-
33-
if (outputStat && outputStat.isFile()) {
34-
throw new CLIError('Output can only be writen to a folder')
35-
}
36-
3731
let isLu = await fileHelper.detectLuContent(stdin, flags.in)
3832
let result: any
33+
3934
if (isLu) {
4035
let luFiles = await fileHelper.getLuObjects(stdin, flags.in, flags.recurse, fileExtEnum.LUFile)
4136
result = await luTranslator.translateLuList(luFiles, flags.translatekey, flags.tgtlang, flags.srclang, flags.translate_comments, flags.translate_link_text)

packages/lu/src/commands/qnamaker/translate.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ export default class QnamakerTranslate extends Command {
2828
const {flags} = this.parse(QnamakerTranslate)
2929
// Check if data piped in stdin
3030
let stdin = await this.readStdin()
31-
let outputStat = flags.out ? await fs.stat(flags.out) : null
32-
33-
if (outputStat && outputStat.isFile()) {
34-
throw new CLIError('Output can only be writen to a folder')
35-
}
3631

3732
let isLu = await fileHelper.detectLuContent(stdin, flags.in)
3833
let result: any

packages/lu/src/utils/filehelper.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ export async function getContentFromFile(file: string) {
6060

6161
export async function generateNewFilePath(outFileName: string, inputfile: string, isLu: boolean, prefix = '', extType: string = helpers.FileExtTypeEnum.LUFile): Promise<string> {
6262
let base = path.resolve(outFileName)
63+
let root = path.dirname(base)
64+
if (!fs.existsSync(root)) {
65+
throw new CLIError('Path not found: ' + root)
66+
}
67+
6368
let extension = path.extname(base)
6469
if (extension) {
65-
let root = path.dirname(base)
66-
let file = path.basename(base)
67-
return path.join(root, prefix + file)
70+
return path.join(root, prefix + path.basename(base))
6871
}
6972

7073
let name = ''
@@ -79,6 +82,16 @@ export async function generateNewFilePath(outFileName: string, inputfile: string
7982

8083
export async function generateNewTranslatedFilePath(fileName: string, translatedLanguage: string, output: string): Promise<string> {
8184
let newPath = path.resolve(output)
85+
86+
let extension = path.extname(newPath)
87+
if (extension) {
88+
throw new CLIError('Output can only be writen to a folder')
89+
}
90+
91+
if (!fs.existsSync(newPath)) {
92+
throw new CLIError('Path not found: ' + newPath)
93+
}
94+
8295
newPath = path.join(output, translatedLanguage)
8396
await fs.mkdirp(newPath)
8497
return path.join(newPath, fileName)

packages/lu/test/commands/luis/convert.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,12 @@ describe('luis:convert new entity format', () => {
470470
})
471471
})
472472

473+
describe('luis:convert file creation', () => {
474+
test
475+
.stderr()
476+
.command(['luis:convert', '--in', `${path.join(__dirname, './../../fixtures/testcases/newEntity1.json')}`, '--out', './newfolder/newEntity.lu'])
477+
.it('luis:convert throws error if path to write doesnt exist', async (ctx) => {
478+
expect(ctx.stderr).to.contain('Path not found:')
479+
})
480+
})
481+

0 commit comments

Comments
 (0)