-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
197 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
import { runMain } from "../dist/cli.mjs"; | ||
|
||
runMain(); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,91 @@ | ||
import { resolve } from "node:path"; | ||
import { defineCommand, runMain as _runMain } from "citty"; | ||
import { name, description, version } from "../package.json"; | ||
import { listen } from "./listen"; | ||
import { listenAndWatch } from "./watch"; | ||
import type { ListenOptions, WatchOptions } from "./types"; | ||
import { createImporter } from "./_utils"; | ||
|
||
export const main = defineCommand({ | ||
meta: { | ||
name, | ||
description, | ||
version, | ||
}, | ||
args: { | ||
cwd: { | ||
type: "string", | ||
description: "Current working directory", | ||
}, | ||
entry: { | ||
type: "positional", | ||
description: "Listener entry file (./app.ts)", | ||
required: true, | ||
}, | ||
port: { | ||
type: "string", | ||
description: | ||
"Port to listen on (use PORT environment variable to override)", | ||
}, | ||
host: { | ||
type: "string", | ||
description: | ||
"Host to listen on (use HOST environment variable to override)", | ||
}, | ||
clipboard: { | ||
type: "boolean", | ||
description: "Copy the URL to the clipboard", | ||
default: false, | ||
}, | ||
open: { | ||
type: "boolean", | ||
description: "Open the URL in the browser", | ||
default: false, | ||
}, | ||
baseURL: { | ||
type: "string", | ||
description: "Base URL to use", | ||
}, | ||
name: { | ||
type: "string", | ||
description: "Name to use in the banner", | ||
}, | ||
https: { | ||
type: "boolean", | ||
description: "Enable HTTPS", | ||
default: false, | ||
}, | ||
watch: { | ||
type: "boolean", | ||
description: "Watch for changes", | ||
alias: "w", | ||
default: false, | ||
}, | ||
}, | ||
async run({ args }) { | ||
const cwd = resolve(args.cwd || "."); | ||
process.chdir(cwd); | ||
|
||
const opts: Partial<ListenOptions & WatchOptions> = { | ||
...args, | ||
cwd, | ||
port: args.port, | ||
hostname: args.host, | ||
clipboard: args.clipboard, | ||
open: args.open, | ||
baseURL: args.baseURL, | ||
name: args.name, | ||
https: args.https, // TODO: Support custom cert | ||
}; | ||
|
||
if (args.watch) { | ||
await listenAndWatch(args.entry, opts); | ||
} else { | ||
const importer = await createImporter(args.entry); | ||
const handler = await importer.import(); | ||
await listen(handler, opts); | ||
} | ||
}, | ||
}); | ||
|
||
export const runMain = () => _runMain(main); |
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