-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from RaoHai/feat/add-error-detect
feat: add error detect
- Loading branch information
Showing
9 changed files
with
160 additions
and
44 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 +1,32 @@ | ||
import React from 'react'; | ||
import { Partical } from '../matcher'; | ||
import { RawLogger } from './RawLogger'; | ||
import { ErrorMatcher } from '../errorMatcher'; | ||
|
||
import styles from '../style/log.module.less'; | ||
|
||
export interface LogContent { | ||
particals: Partical[]; | ||
style?: React.CSSProperties; | ||
linkify?: boolean; | ||
errorMatcher: ErrorMatcher; | ||
} | ||
|
||
export function LogContent({ particals, style, linkify }: LogContent) { | ||
return <pre id="log" className={styles.ansi} style={style}> | ||
{particals.map((partical, index) => { | ||
return ( | ||
<RawLogger | ||
key={`logger-line-${index}`} | ||
foldable={partical.type === 'partical'} | ||
partical={partical} | ||
index={index} | ||
linkify={linkify} | ||
/> | ||
); | ||
})} | ||
</pre>; | ||
export function LogContent({ particals, style, linkify, errorMatcher }: LogContent) { | ||
return ( | ||
<pre id="log" className={styles.ansi} style={style}> | ||
{particals.map((partical, index) => { | ||
return ( | ||
<RawLogger | ||
key={`logger-line-${index}`} | ||
foldable={partical.type === 'partical'} | ||
partical={partical} | ||
index={index} | ||
linkify={linkify} | ||
errorMatcher={errorMatcher} | ||
/> | ||
); | ||
})} | ||
</pre> | ||
); | ||
} |
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,37 @@ | ||
import { AnserJsonEntry } from 'anser'; | ||
|
||
export interface ErrorMatcherPattern { | ||
desc: string; | ||
link: string; | ||
patterns: string[]; | ||
} | ||
|
||
export type ErrorMatcherPatterns = ErrorMatcherPattern[]; | ||
|
||
export const defaultErrorMatchers = [ | ||
{ | ||
desc: 'MissingScript', | ||
link: 'https://stackoverflow.com/questions/31976722/start-script-missing-error-when-running-npm-start', | ||
patterns: [ | ||
'sh: 1: ts-node: not found' | ||
], | ||
} | ||
]; | ||
|
||
export class ErrorMatcher { | ||
patterns: Array<ErrorMatcherPattern & { regexs: RegExp[] }>; | ||
|
||
constructor(errorMatchers: ErrorMatcherPatterns) { | ||
this.patterns = errorMatchers.map(matcher => ({ | ||
...matcher, | ||
regexs: matcher.patterns.map(regex => new RegExp(regex)), | ||
})); | ||
} | ||
|
||
match(bundle: AnserJsonEntry) { | ||
return this.patterns.map(pattern => { | ||
const errors = pattern.regexs.map(regex => regex.exec(bundle.content)).filter(Boolean); | ||
return errors.length ? pattern : null; | ||
}).filter(Boolean) as ErrorMatcher['patterns']; | ||
} | ||
} |
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,15 @@ | ||
import { ErrorMatcherPattern } from '../errorMatcher'; | ||
import { createContext } from 'react'; | ||
|
||
const errorRefs = new Map<HTMLDivElement, ErrorMatcherPattern[]>(); | ||
|
||
export function addRefs(errors: ErrorMatcherPattern[], ref: HTMLDivElement) { | ||
errorRefs.set(ref, errors); | ||
} | ||
|
||
export { errorRefs }; | ||
|
||
export const ErrorContext = createContext({ | ||
refs: errorRefs, | ||
addRefs, | ||
}); |
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