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

Commit eefd05a

Browse files
committed
Fixing stdin input reading
1 parent 8406f56 commit eefd05a

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

packages/command/src/readpipeddata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ const ReadPipedStdin = {
1010
}
1111

1212
const timer = setTimeout(async () => {
13-
clearTimeout(timer)
14-
if (input) return resolve(input)
1513
reject(new Error('No input'))
1614
}, 1000)
1715

1816
stdin.on('data', chunk => {
17+
clearTimeout(timer)
1918
input += chunk
2019
})
2120

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/utils/filehelper.ts

Lines changed: 9 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,9 @@ 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+
if (!fs.existsSync(newPath)) {
86+
throw new CLIError('Path not found: ' + newPath)
87+
}
8288
newPath = path.join(output, translatedLanguage)
8389
await fs.mkdirp(newPath)
8490
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+

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,12 @@ describe('qnamaker:convert with --sort option', () => {
102102
expect(await compareLuFiles('./../../../qna.lu', './../../fixtures/verified/qna_a_sorted.lu')).to.be.true
103103
})
104104
})
105+
106+
describe('qnamaker:convert file creation', () => {
107+
test
108+
.stderr()
109+
.command(['qnamaker:convert', '--in', `${path.join(__dirname, './../../fixtures/verified/all-qna.json')}`, '--out', '/testfolder/qna.lu'])
110+
.it('qnamaker:convert refresh command successfully reconstructs a markdown file from QnA input file', async (ctx) => {
111+
expect(ctx.stderr).to.contain('Path not found:')
112+
})
113+
})

0 commit comments

Comments
 (0)