Skip to content

Commit fda14db

Browse files
committed
fix: stdin stream not consued and been paused
1 parent 1314cfd commit fda14db

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

src/commands/notes/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {CommentPermissionType, CreateNoteOptions, NotePermissionRole} from '@hackmd/api/dist/type'
22
import {CliUx, Flags} from '@oclif/core'
3-
import * as fs from 'fs'
43

54
import HackMDCommand from '../../command'
65
import {commentPermission, noteContent, notePermission, noteTitle} from '../../flags'
6+
import {safePipeRead} from '../../utils'
77

88
export default class Create extends HackMDCommand {
99
static description = 'Create a note'
@@ -31,7 +31,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
3131

3232
async run() {
3333
const {flags} = await this.parse(Create)
34-
const pipeString = await readStdin()
34+
const pipeString = safePipeRead()
3535

3636
const options: CreateNoteOptions = {
3737
title: flags.title,

src/commands/team-notes/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {CliUx, Flags} from '@oclif/core'
33

44
import HackMDCommand from '../../command'
55
import {commentPermission, noteContent, notePermission, noteTitle, teamPath} from '../../flags'
6-
import readStdin from '../../read-stdin-stream'
6+
import {safePipeRead} from '../../utils'
77

88
export default class Create extends HackMDCommand {
99
static description = 'Create a team note'
@@ -31,7 +31,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
3131

3232
async run() {
3333
const {flags} = await this.parse(Create)
34-
const pipeString = await readStdin()
34+
const pipeString = safePipeRead()
3535

3636
const {teamPath} = flags
3737
const options: CreateNoteOptions = {

src/read-stdin-stream.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ export function setAccessTokenConfig(token: string) {
2323
}
2424
})
2525
}
26+
27+
export function safePipeRead() {
28+
let result
29+
try {
30+
result = fs.readFileSync(process.stdin.fd).toString()
31+
} catch {}
32+
33+
return result
34+
}

0 commit comments

Comments
 (0)