-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0b07e2
commit 0061a48
Showing
3 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import chalk from 'chalk'; | ||
|
||
export const tryPanic = (fn: (...args: any[]) => any, message: string) => { | ||
try { | ||
return fn(); | ||
} catch (err) { | ||
console.error(chalk.red(message)); | ||
process.exit(1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { resolve } from 'path'; | ||
import { toMarkdownFile } from './lib/markdown'; | ||
import { tryPanic } from './lib/try-panic'; | ||
|
||
export const run = async ({ sourcePath }: { sourcePath: string }) => { | ||
const dataPath = resolve(process.cwd(), sourcePath); | ||
const source = require(dataPath); | ||
const tree = await source.getHelpDocument(); | ||
const REQUIRE_ERROR = `Failed to require('${dataPath}');`; | ||
const source = tryPanic(() => require(dataPath), REQUIRE_ERROR); | ||
const GET_DOCUMENT_ERROR = `Failed to call getHelpDocument() from ${dataPath}`; | ||
const tree = await tryPanic(() => source.getHelpDocument(), GET_DOCUMENT_ERROR); | ||
const markdown = await toMarkdownFile(tree); | ||
console.log(markdown); | ||
}; |