You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
918 B
25 lines
918 B
import { builtinModules } from "module"
|
|
import { get } from "http"
|
|
import { green } from "chalk"
|
|
import { exec, spawn, ChildProcess } from "child_process"
|
|
|
|
/** 轮询监听 vite 启动 */
|
|
export function waitOn(arg0: { port: string | number; interval?: number }) {
|
|
return new Promise(resolve => {
|
|
const { port, interval = 149 } = arg0
|
|
const url = `http://localhost:${port}`
|
|
let counter = 0
|
|
const timer: NodeJS.Timer = setInterval(() => {
|
|
get(url, res => {
|
|
clearInterval(timer)
|
|
console.log("[waitOn]", green(`"${url}" are already responsive.`), `(${res.statusCode}: ${res.statusMessage})`)
|
|
resolve(res.statusCode)
|
|
}).on("error", err => {
|
|
console.log("[waitOn]", `counter: ${counter++}`)
|
|
})
|
|
}, interval)
|
|
})
|
|
}
|
|
|
|
/** node.js builtins module */
|
|
export const builtins = () => builtinModules.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x))
|
|
|