Skip to content

Commit 1287712

Browse files
fix promise thing
1 parent ca9d682 commit 1287712

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

src/cli.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { compile, Options } from './index'
1515
const mkdirp = (path: string) => new Promise((res, rej) => {
1616
_mkdirp(path, (err, made) => {
1717
if (err) rej(err)
18-
else res(made)
18+
else res(made === null ? undefined : made)
1919
})
2020
})
2121

@@ -51,20 +51,27 @@ async function main(argv: minimist.ParsedArgs) {
5151

5252
function getFilesToProcess(argIn: string, argOut: string, argv: Partial<Options>): Promise<Promise<void>[]> {
5353
return new Promise(async (res, rej) => {
54-
if (isGlob(argIn)){
55-
let files = await glob(join(process.cwd(), argIn))
56-
57-
if (files.length === 0) {
58-
rej('No files match glob pattern')
59-
}
60-
61-
if (!existsSync(argOut)) {
62-
await mkdirp(argOut)
54+
try {
55+
if (isGlob(argIn)) {
56+
let files = await glob(join(process.cwd(), argIn))
57+
58+
if (files.length === 0) {
59+
rej('No files match glob pattern')
60+
}
61+
62+
if (argOut && !existsSync(argOut)) {
63+
await mkdirp(argOut)
64+
}
65+
66+
res(files.map(file => processFile(file, { dir: argOut }, argv)))
67+
return
68+
} else {
69+
res([processFile(argIn, { file: argOut }, argv)])
6370
}
64-
65-
res(files.map(file => processFile(file, { dir: argOut }, argv)))
71+
} catch (e) {
72+
console.error(whiteBright.bgRedBright('error'), e)
73+
process.exit(1)
6674
}
67-
res([processFile(argIn, { file: argOut }, argv)])
6875
})
6976
}
7077

test/__snapshots__/test/test.ts.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,30 @@ Generated by [AVA](https://ava.li).
16091609

16101610
> Snapshot 1
16111611
1612-
''
1612+
`/* tslint:disable */␊
1613+
/**␊
1614+
* This file was automatically generated by json-schema-to-typescript.␊
1615+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
1616+
* and run json-schema-to-typescript to regenerate this file.␊
1617+
*/␊
1618+
1619+
export interface ASchema {␊
1620+
f: string;␊
1621+
g?: number;␊
1622+
}␊
1623+
/* tslint:disable */␊
1624+
/**␊
1625+
* This file was automatically generated by json-schema-to-typescript.␊
1626+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,␊
1627+
* and run json-schema-to-typescript to regenerate this file.␊
1628+
*/␊
1629+
1630+
export interface BSchema {␊
1631+
x?: string;␊
1632+
y: number;␊
1633+
[k: string]: any;␊
1634+
}␊
1635+
`
16131636

16141637
## formatterOptions.js
16151638

test/__snapshots__/test/test.ts.snap

9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)