()
| 197 | } |
| 198 | |
| 199 | async function readScript() { |
| 200 | const [firstArg] = argv._ |
| 201 | let script = '' |
| 202 | let scriptPath = '' |
| 203 | let tempPath = '' |
| 204 | let argSlice = 1 |
| 205 | |
| 206 | if (argv.eval) { |
| 207 | argSlice = 0 |
| 208 | script = argv.eval |
| 209 | tempPath = getFilepath($.cwd, 'zx', argv.ext) |
| 210 | } else if (!firstArg || firstArg === '-') { |
| 211 | script = await readScriptFromStdin() |
| 212 | tempPath = getFilepath($.cwd, 'zx', argv.ext) |
| 213 | if (script.length === 0) { |
| 214 | printUsage() |
| 215 | process.exitCode = 1 |
| 216 | throw new Fail('No script provided') |
| 217 | } |
| 218 | } else if (/^https?:/.test(firstArg)) { |
| 219 | const { name, ext = argv.ext } = path.parse(new URL(firstArg).pathname) |
| 220 | script = await readScriptFromHttp(firstArg) |
| 221 | tempPath = getFilepath($.cwd, name, ext) |
| 222 | } else { |
| 223 | script = await fs.readFile(firstArg, 'utf8') |
| 224 | scriptPath = firstArg.startsWith('file:') |
| 225 | ? url.fileURLToPath(firstArg) |
| 226 | : path.resolve(firstArg) |
| 227 | } |
| 228 | |
| 229 | const { ext, base, dir } = path.parse(tempPath || scriptPath) |
| 230 | if (ext === '' || (argv.ext && !EXT_RE.test(ext))) { |
| 231 | tempPath = getFilepath(dir, base) |
| 232 | } |
| 233 | if (ext === '.md') { |
| 234 | script = transformMarkdown(script) |
| 235 | tempPath = getFilepath(dir, base) |
| 236 | } |
| 237 | if (argSlice) updateArgv(argv._.slice(argSlice)) |
| 238 | |
| 239 | return { script, scriptPath, tempPath } |
| 240 | } |
| 241 | |
| 242 | async function readScriptFromStdin(): Promise<string> { |
| 243 | return process.stdin.isTTY ? '' : stdin() |
no test coverage detected
searching dependent graphs…