MCPcopy Create free account
hub / github.com/code-forge-io/react-router-devtools / main

Function main

docs/scripts/setup.ts:54–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53// Main command to run
54const main = () => {
55 // Allows us to run scripts from the scripts folder without having to wrap them in package.json with npm run execute
56 const command = process.argv[2].startsWith("scripts/") ? `npm run execute ${process.argv[2]}` : process.argv[2]
57 // Filter out the script command and the environment (the slice(3) part) and remove our custom args and pass everything else down
58 const filteredArgs = process.argv.slice(3).filter((arg) => !ENVIRONMENTS.includes(arg) && arg !== "confirm")
59 // Spawns a child process with the command to run
60 // param 1 - command to run
61 // param 2 - arguments to pass to the command
62 // param 3 - options for the child process
63 const child = spawn(command, filteredArgs, {
64 cwd: process.cwd(),
65 stdio: "inherit",
66 shell: true,
67 })
68 // If the child process exits, exit the parent process too if the exit code is not 0
69 child.on("exit", (exitCode) => {
70 if (exitCode !== 0) {
71 process.exit(exitCode ?? 1)
72 }
73 })
74 //
75
76 for (const signal of ["SIGINT", "SIGTERM"]) {
77 process.on(signal, () => {
78 // Kills the child only if it is still connected and alive
79 if (child.connected) {
80 child.kill(child.pid)
81 }
82 process.exit(1)
83 })
84 }
85}
86// Makes the user confirm the run if the confirm argument is passed
87if (process.argv.includes("confirm")) {
88 confirmRun()

Callers 1

setup.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…