-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make Command Line Invocation Easier Fixes #16
- Loading branch information
Showing
5 changed files
with
137 additions
and
97 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 |
---|---|---|
@@ -1,31 +1,53 @@ | ||
import * as clipboardy from "clipboardy"; | ||
import { Stats } from "fs"; | ||
import * as fs from "fs/promises"; | ||
import { StackConverter } from "../lib/stack-converter"; | ||
|
||
(async () => { | ||
try { | ||
if (process.argv.length != 4) { | ||
if ( | ||
process.argv.some(arg => arg === '-h') | ||
|| process.argv.some(arg => arg === '/h') | ||
|| process.argv.some(arg => arg === '-help') | ||
|| process.argv.some(arg => arg === '/help') | ||
) { | ||
helpAndExit(); | ||
} | ||
|
||
const stackFilePath = process.argv[2]; | ||
const sourceMapPath = process.argv[3]; | ||
|
||
try { | ||
await fs.lstat(stackFilePath) | ||
} catch { | ||
throw new Error(`Stack file path ${stackFilePath} does not exist`); | ||
let sourceMapPath = process.argv[2]; | ||
if (!sourceMapPath) { | ||
sourceMapPath = "."; | ||
} | ||
|
||
let sourceMapStat: Stats; | ||
try { | ||
sourceMapStat = await fs.lstat(sourceMapPath) | ||
} catch { | ||
throw new Error(`Source map path ${stackFilePath} does not exist`); | ||
throw new Error(`Source map path ${sourceMapPath} does not exist`); | ||
} | ||
|
||
let stackFileContents; | ||
const stackFilePath = process.argv[3]; | ||
if (!stackFilePath) { | ||
stackFileContents = await clipboardy.read(); | ||
} else { | ||
try { | ||
await fs.lstat(stackFilePath) | ||
} catch { | ||
throw new Error(`Stack file path ${stackFilePath} does not exist`); | ||
} | ||
try { | ||
stackFileContents = await fs.readFile(stackFilePath, 'utf-8'); | ||
} catch { | ||
throw new Error(`Could not read contents of ${stackFilePath}`); | ||
} | ||
} | ||
|
||
if (!stackFileContents) { | ||
throw new Error('Stack contents are empty'); | ||
} | ||
|
||
const converter = sourceMapStat.isDirectory() ? await StackConverter.createFromDirectory(sourceMapPath) : new StackConverter([sourceMapPath]); | ||
const stackFileContents = await fs.readFile(stackFilePath, 'utf-8'); | ||
const { error, stack } = await converter.convert(stackFileContents); | ||
if (error) { | ||
throw new Error(error); | ||
|
@@ -44,7 +66,10 @@ function helpAndExit() { | |
stack-converter command line usage: | ||
stack-converter "/path/to/stack.txt" [ "/path/to/source-maps-dir" OR "/path/to/stack.js.map" ]' | ||
stack-converter [ [ "/source-map-directory" OR "/source.map.js" ] [ "/stack-trace.txt" ] ] | ||
* Optionally provide either a path to a directory containing source maps or a .map.js file - Defaults to current directory | ||
* Optionally provide a path to a .txt file containing a JavaScript Error stack trace - Defaults to value in clipboard | ||
❤️ [email protected] | ||
`; | ||
|
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
Oops, something went wrong.