(argv, options: RunNextCommandOptions = {})
| 142 | } |
| 143 | |
| 144 | export function runBlitzCommand(argv, options: RunNextCommandOptions = {}) { |
| 145 | const nextnextbin = getCommandBin("blitz", options.cwd) |
| 146 | const blitzBin = path.join(nextnextbin, "dist/index.cjs") |
| 147 | const cwd = options.cwd || process.cwd() |
| 148 | // Let Next.js decide the environment |
| 149 | const env = { |
| 150 | ...process.env, |
| 151 | NODE_ENV: "production" as const, |
| 152 | __NEXT_TEST_MODE: "true", |
| 153 | ...options.env, |
| 154 | } |
| 155 | |
| 156 | return new Promise((resolve, reject) => { |
| 157 | console.log(`Running command "blitz ${argv.join(" ")}"`) |
| 158 | const instance = spawn("node", [blitzBin, ...argv], { |
| 159 | cwd, |
| 160 | env, |
| 161 | stdio: ["ignore", "pipe", "pipe"], |
| 162 | }) |
| 163 | |
| 164 | if (typeof options.instance === "function") { |
| 165 | options.instance(instance) |
| 166 | } |
| 167 | |
| 168 | let mergedStdio = "" |
| 169 | |
| 170 | let stderrOutput = "" |
| 171 | if (options.stderr) { |
| 172 | instance.stderr?.on("data", function (chunk) { |
| 173 | mergedStdio += chunk |
| 174 | stderrOutput += chunk |
| 175 | |
| 176 | if (options.stderr === "log") { |
| 177 | console.log(chunk.toString()) |
| 178 | } |
| 179 | }) |
| 180 | } else { |
| 181 | instance.stderr?.on("data", function (chunk) { |
| 182 | mergedStdio += chunk |
| 183 | }) |
| 184 | } |
| 185 | |
| 186 | let stdoutOutput = "" |
| 187 | if (options.stdout) { |
| 188 | instance.stdout?.on("data", function (chunk) { |
| 189 | mergedStdio += chunk |
| 190 | stdoutOutput += chunk |
| 191 | |
| 192 | if (options.stdout === "log") { |
| 193 | console.log(chunk.toString()) |
| 194 | } |
| 195 | }) |
| 196 | } else { |
| 197 | instance.stdout?.on("data", function (chunk) { |
| 198 | mergedStdio += chunk |
| 199 | }) |
| 200 | } |
| 201 |
no test coverage detected