-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.js
46 lines (39 loc) · 1.61 KB
/
dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
/**
* It first imports necessary modules such as `node:path`, `node:process`, and `node:url`.
* It then uses `url.fileURLToPath` to convert the `import.meta.url` to a path to the current
* directory.
* It then joins this directory path with `src/index.ts` to obtain the full path to the TypeScript
* file.
*
* Finally, it uses the `execa` library to execute `npx ts-node-esm src/index.ts ...args` command
* with the current directory as working directory.
* It passes any output produced by the TypeScript file to the standard output stream.
*
* @requires path
* @requires process
* @requires url
* @requires execa
*/
import path from "node:path";
import process from "node:process";
import * as url from "node:url";
import { config } from "dotenv";
import { execa } from "execa";
/**
* Loads environment variables from a .env file and configures command-line interface options.
* This function should be called before any local imports to ensure that process variables are
* loaded correctly.
*/
config();
// Use `url.fileURLToPath` to convert the `import.meta.url` to a path to the current directory
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
// Join the directory path with entry to obtain the full path to the TypeScript file
const entry = path.join(__dirname, "src/dev.ts");
// Extract any additional command-line arguments and pass them to the TypeScript file
const argv = process.argv.splice(2);
// Pass any output produced by the TypeScript file to the standard output stream
await execa("npx", ["ts-node-esm", entry, ...argv], {
stdio: "inherit",
cwd: __dirname,
});