-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby-cli): Migrate reporter to TypeScript (#22869)
* chore(gatsby-cli): Migrate reporter to TypeScript * Complete changes from Matts review * fix tests * fix enumeration of class
- Loading branch information
1 parent
e691d76
commit d07c7b1
Showing
15 changed files
with
659 additions
and
463 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
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,42 @@ | ||
/* | ||
* This module is used to catch if the user kills the gatsby process via cmd+c | ||
* When this happens, there is some clean up logic we need to fire offf | ||
*/ | ||
import signalExit from "signal-exit" | ||
import { getStore } from "./redux" | ||
import reporterActions from "./redux/actions" | ||
import { ActivityStatuses } from "./constants" | ||
import { reporter } from "./reporter" | ||
|
||
const interruptActivities = (): void => { | ||
const { activities } = getStore().getState().logs | ||
Object.keys(activities).forEach(activityId => { | ||
const activity = activities[activityId] | ||
if ( | ||
activity.status === ActivityStatuses.InProgress || | ||
activity.status === ActivityStatuses.NotStarted | ||
) { | ||
reporter.completeActivity(activityId, ActivityStatuses.Interrupted) | ||
} | ||
}) | ||
} | ||
|
||
export const prematureEnd = (): void => { | ||
// hack so at least one activity is surely failed, so | ||
// we are guaranteed to generate FAILED status | ||
// if none of activity did explicitly fail | ||
reporterActions.createPendingActivity({ | ||
id: `panic`, | ||
status: ActivityStatuses.Failed, | ||
}) | ||
|
||
interruptActivities() | ||
} | ||
|
||
export const catchExitSignals = (): void => { | ||
signalExit((code, signal) => { | ||
if (code !== 0 && signal !== `SIGINT` && signal !== `SIGTERM`) | ||
prematureEnd() | ||
else interruptActivities() | ||
}) | ||
} |
Oops, something went wrong.