-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(changeset): new CLI infra using citty and server-function fix
- vinxi@0.5.1
- vinxi@0.5.0
- vinxi@0.4.3
- vinxi@0.4.2
- vinxi@0.4.1
- vinxi@0.4.0
- vinxi@0.3.14
- vinxi@0.3.13
- vinxi@0.3.12
- vinxi@0.3.11
- vinxi@0.3.10
- vinxi@0.3.9
- vinxi@0.3.8
- vinxi@0.3.7
- vinxi@0.3.6
- vinxi@0.3.5
- vinxi@0.3.4
- vinxi@0.3.3
- vinxi@0.3.2
- vinxi@0.3.1
- vinxi@0.3.0
- vinxi@0.2.1
- vinxi@0.2.0
- vinxi@0.1.10
- vinxi@0.1.9
- vinxi@0.1.8
- vinxi@0.1.7
- vinxi@0.1.6
- vinxi@0.1.5
- vinxi@0.1.4
- vinxi@0.1.3
- vinxi@0.1.2
- vinxi@0.1.1
- vinxi@0.1.0
- vinxi@0.0.64
- vinxi@0.0.63
- vinxi@0.0.62
- vinxi@0.0.61
- vinxi@0.0.60
- vinxi@0.0.58
- vinxi@0.0.57
- @vinxi/solid@0.1.3
- @vinxi/solid@0.1.2
- @vinxi/solid@0.1.1
- @vinxi/solid@0.1.0
- @vinxi/server-functions@1.0.0
- @vinxi/server-functions@0.5.0
- @vinxi/server-functions@0.4.3
- @vinxi/server-functions@0.4.2
- @vinxi/server-functions@0.4.1
- @vinxi/server-functions@0.3.3
- @vinxi/server-functions@0.3.2
- @vinxi/server-functions@0.3.1
- @vinxi/server-functions@0.3.0
- @vinxi/server-functions@0.2.1
- @vinxi/server-functions@0.2.0
- @vinxi/server-functions@0.1.4
- @vinxi/server-functions@0.1.3
- @vinxi/server-functions@0.1.2
- @vinxi/server-functions@0.1.1
- @vinxi/server-functions@0.1.0
- @vinxi/server-functions@0.0.61
- @vinxi/server-functions@0.0.60
- @vinxi/server-functions@0.0.59
- @vinxi/server-functions@0.0.58
- @vinxi/server-functions@0.0.57
- @vinxi/server-functions@0.0.55
- @vinxi/server-functions@0.0.54
- @vinxi/server-components@1.0.0
- @vinxi/server-components@0.5.0
- @vinxi/server-components@0.4.3
- @vinxi/server-components@0.4.2
- @vinxi/server-components@0.4.1
- @vinxi/server-components@0.3.3
- @vinxi/server-components@0.3.2
- @vinxi/server-components@0.3.1
- @vinxi/server-components@0.3.0
- @vinxi/server-components@0.2.0
- @vinxi/server-components@0.1.3
- @vinxi/server-components@0.1.2
- @vinxi/server-components@0.1.1
- @vinxi/server-components@0.1.0
- @vinxi/server-components@0.0.60
- @vinxi/server-components@0.0.59
- @vinxi/server-components@0.0.58
- @vinxi/server-components@0.0.57
- @vinxi/server-components@0.0.56
- @vinxi/server-components@0.0.54
- @vinxi/server-components@0.0.53
- @vinxi/router@1.0.0
- @vinxi/router@0.5.1
- @vinxi/router@0.5.0
- @vinxi/router@0.4.4
- @vinxi/router@0.4.3
- @vinxi/router@0.4.2
- @vinxi/router@0.4.1
- @vinxi/router@0.3.14
- @vinxi/router@0.3.13
- @vinxi/router@0.3.12
- @vinxi/router@0.3.11
- @vinxi/router@0.3.10
- @vinxi/router@0.3.9
- @vinxi/router@0.3.8
- @vinxi/router@0.3.7
- @vinxi/router@0.3.6
- @vinxi/router@0.3.5
- @vinxi/router@0.3.4
- @vinxi/router@0.3.3
- @vinxi/router@0.3.2
- @vinxi/router@0.3.1
- @vinxi/router@0.3.0
- @vinxi/router@0.2.1
- @vinxi/router@0.2.0
- @vinxi/router@0.1.10
- @vinxi/router@0.1.9
- @vinxi/router@0.1.8
- @vinxi/router@0.1.7
- @vinxi/router@0.1.6
- @vinxi/router@0.1.5
- @vinxi/router@0.1.4
- @vinxi/router@0.1.3
- @vinxi/router@0.1.2
- @vinxi/router@0.1.1
- @vinxi/router@0.1.0
- @vinxi/router@0.0.44
- @vinxi/router@0.0.43
- @vinxi/router@0.0.42
- @vinxi/router@0.0.41
- @vinxi/router@0.0.40
- @vinxi/router@0.0.38
- @vinxi/router@0.0.37
- @vinxi/react-server@0.2.12
- @vinxi/react-server@0.2.11
- @vinxi/react-server@0.2.10
- @vinxi/react-server@0.2.9
- @vinxi/react-server@0.2.8
- @vinxi/react-server@0.2.7
- @vinxi/react-server@0.2.6
- @vinxi/react-server@0.2.5
- @vinxi/react-server@0.2.4
- @vinxi/react-server@0.2.3
- @vinxi/react-server@0.2.2
- @vinxi/react-server@0.2.1
- @vinxi/react-server@0.2.0
- @vinxi/react-server@0.1.5
- @vinxi/react-server@0.1.4
- @vinxi/react-server@0.1.3
- @vinxi/react-server@0.1.2
- @vinxi/react-server@0.1.1
- @vinxi/react-server@0.1.0
- @vinxi/react-server@0.0.49
- @vinxi/react-server@0.0.48
- @vinxi/react-server@0.0.47
- @vinxi/react-server@0.0.46
- @vinxi/react-server@0.0.45
- @vinxi/react-server@0.0.43
- @vinxi/react-server@0.0.42
- @vinxi/react@0.2.5
- @vinxi/react@0.2.4
- @vinxi/react@0.2.3
- @vinxi/react@0.2.2
- @vinxi/react@0.2.1
- @vinxi/react@0.2.0
- @vinxi/react@0.1.2
- @vinxi/react@0.1.1
- @vinxi/react@0.1.0
- @vinxi/plugin-mdx@3.7.2
- @vinxi/plugin-mdx@3.7.1
- @vinxi/plugin-mdx@3.7.0
- @vinxi/plugin-directives@1.0.0
- @vinxi/plugin-directives@0.5.0
- @vinxi/plugin-directives@0.4.3
- @vinxi/plugin-directives@0.4.2
- @vinxi/plugin-directives@0.4.1
- @vinxi/plugin-directives@0.3.1
- @vinxi/plugin-directives@0.3.0
- @vinxi/plugin-directives@0.2.0
- @vinxi/plugin-directives@0.1.3
- @vinxi/plugin-directives@0.1.2
- @vinxi/plugin-directives@0.1.1
- @vinxi/plugin-directives@0.1.0
- @vinxi/plugin-directives@0.0.60
- @vinxi/plugin-directives@0.0.59
- @vinxi/plugin-directives@0.0.58
- @vinxi/plugin-directives@0.0.57
- @vinxi/plugin-directives@0.0.56
- @vinxi/plugin-directives@0.0.54
- @vinxi/plugin-directives@0.0.53
- @vinxi/openapi@0.2.2
- @vinxi/openapi@0.2.1
- @vinxi/openapi@0.2.0
- @vinxi/openapi@0.1.1
- @vinxi/openapi@0.1.0
- @vinxi/doc@0.1.3
- @vinxi/doc@0.1.2
- @vinxi/doc@0.1.1
- @vinxi/doc@0.1.0
- @vinxi/devtools@0.2.0
- @vinxi/devtools@0.1.1
- @vinxi/devtools@0.1.0
- @vinxi/deno-doc@0.1.1
- @vinxi/deno-doc@0.1.0
Showing
13 changed files
with
337 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@vinxi/server-functions": patch | ||
"vinxi": patch | ||
--- | ||
|
||
new CLI infra using citty and server-function fix |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,165 @@ | ||
#!/usr/bin/env node | ||
import chokidar from "chokidar"; | ||
import mri from "mri"; | ||
import { defineCommand, runMain } from "citty"; | ||
import fs from "fs"; | ||
// import mri from "mri"; | ||
import { fileURLToPath } from "url"; | ||
|
||
import { exec } from "node:child_process"; | ||
|
||
import { loadApp } from "../lib/load-app.js"; | ||
import { log } from "../lib/logger.js"; | ||
import { resolve } from "../lib/path.js"; | ||
|
||
async function main() { | ||
const args = mri(process.argv.slice(2)); | ||
const command = args._[0]; | ||
const rootDir = resolve(args._[1] || "."); | ||
const packageJson = JSON.parse( | ||
fs.readFileSync( | ||
fileURLToPath(new URL("../package.json", import.meta.url)), | ||
"utf-8", | ||
), | ||
); | ||
|
||
const configFile = args.config; | ||
globalThis.MANIFEST = {}; | ||
const app = await loadApp(configFile, args); | ||
const command = defineCommand({ | ||
meta: { | ||
name: "vinxi", | ||
version: packageJson.version, | ||
description: "Vinxi: The JavaScript/TypeScript Server SDK", | ||
}, | ||
args: { | ||
config: { | ||
type: "string", | ||
description: "Path to config file (default: app.config.js)", | ||
}, | ||
}, | ||
subCommands: () => ({ | ||
dev: { | ||
meta: { | ||
name: "dev", | ||
version: packageJson.version, | ||
description: "Start a Vinxi development server", | ||
}, | ||
args: { | ||
config: { | ||
type: "string", | ||
description: "Path to config file (default: app.config.js)", | ||
}, | ||
force: { | ||
type: "boolean", | ||
description: "Force optimize deps (default: false)", | ||
}, | ||
devtools: { | ||
type: "boolean", | ||
description: "Enable devtools (default: false)", | ||
}, | ||
port: { | ||
type: "number", | ||
description: "Port to listen on (default: 3000)", | ||
}, | ||
host: { | ||
type: "boolean", | ||
description: "Expose to host (default: false)", | ||
}, | ||
stack: { | ||
type: "string", | ||
description: "Stacks", | ||
alias: "s", | ||
}, | ||
}, | ||
async run({ args }) { | ||
const configFile = args.config; | ||
globalThis.MANIFEST = {}; | ||
const app = await loadApp(configFile, args); | ||
|
||
if (command === "dev") { | ||
let devServer; | ||
/** @type {import('chokidar').FSWatcher} */ | ||
let watcher; | ||
let devServer; | ||
/** @type {import('chokidar').FSWatcher} */ | ||
let watcher; | ||
|
||
function createWatcher() { | ||
watcher = chokidar.watch( | ||
["app.config.*", "vite.config.*", configFile].filter(Boolean), | ||
{ | ||
ignoreInitial: true, | ||
}, | ||
); | ||
watcher.on("all", async (ctx, path) => { | ||
log("change detected in", path); | ||
log("reloading app"); | ||
const newApp = await loadApp(configFile, args); | ||
if (!newApp) return; | ||
restartDevServer(newApp); | ||
}); | ||
} | ||
function createWatcher() { | ||
watcher = chokidar.watch( | ||
["app.config.*", "vite.config.*", configFile].filter(Boolean), | ||
{ | ||
ignoreInitial: true, | ||
}, | ||
); | ||
watcher.on("all", async (ctx, path) => { | ||
log("change detected in", path); | ||
log("reloading app"); | ||
const newApp = await loadApp(configFile, args); | ||
if (!newApp) return; | ||
restartDevServer(newApp); | ||
}); | ||
} | ||
|
||
async function restartDevServer(newApp) { | ||
const { createDevServer } = await import("../lib/dev-server.js"); | ||
await devServer?.close(); | ||
devServer = await createDevServer(newApp, { | ||
force: args.force, | ||
devtools: args.devtools || Boolean(process.env.DEVTOOLS), | ||
port: Number(process.env.PORT ?? 3000), | ||
}); | ||
log("restarting dev server"); | ||
devServer.listen(); | ||
} | ||
async function restartDevServer(newApp) { | ||
const { createDevServer } = await import("../lib/dev-server.js"); | ||
await devServer?.close(); | ||
devServer = await createDevServer(newApp, { | ||
force: args.force, | ||
devtools: args.devtools || Boolean(process.env.DEVTOOLS), | ||
port: Number(process.env.PORT ?? 3000), | ||
}); | ||
log("restarting dev server"); | ||
devServer.listen(); | ||
} | ||
|
||
if (!app) { | ||
let fsWatcher = (watcher = chokidar.watch( | ||
["app.config.*", "vite.config.*", configFile].filter(Boolean), | ||
{ | ||
ignoreInitial: true, | ||
persistent: true, | ||
}, | ||
)); | ||
fsWatcher.on("all", async (path) => { | ||
log("change detected in", path); | ||
log("reloading app"); | ||
const newApp = await loadApp(configFile, args); | ||
if (!newApp) return; | ||
if (!app) { | ||
let fsWatcher = (watcher = chokidar.watch( | ||
["app.config.*", "vite.config.*", configFile].filter(Boolean), | ||
{ | ||
ignoreInitial: true, | ||
persistent: true, | ||
}, | ||
)); | ||
fsWatcher.on("all", async (path) => { | ||
log("change detected in", path); | ||
log("reloading app"); | ||
const newApp = await loadApp(configFile, args); | ||
if (!newApp) return; | ||
|
||
fsWatcher.close(); | ||
fsWatcher.close(); | ||
createWatcher(); | ||
restartDevServer(newApp); | ||
}); | ||
return; | ||
} | ||
createWatcher(); | ||
restartDevServer(newApp); | ||
}); | ||
return; | ||
} | ||
createWatcher(); | ||
const { createDevServer } = await import("../lib/dev-server.js"); | ||
devServer = await createDevServer(app, { | ||
force: args.force, | ||
port: Number(process.env.PORT ?? 3000), | ||
devtools: args.devtools || Boolean(process.env.DEVTOOLS), | ||
}); | ||
devServer.listen(); | ||
} else if (command === "build") { | ||
process.env.NODE_ENV = "production"; | ||
const { createBuild } = await import("../lib/build.js"); | ||
await createBuild(app, {}); | ||
} else if (command === "start") { | ||
await exec(`node .output/server/index.mjs`); | ||
} else { | ||
throw new Error(`Unknown command ${command}`); | ||
} | ||
} | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
const { createDevServer } = await import("../lib/dev-server.js"); | ||
devServer = await createDevServer(app, { | ||
force: args.force, | ||
port: Number(process.env.PORT ?? 3000), | ||
devtools: args.devtools || Boolean(process.env.DEVTOOLS), | ||
}); | ||
devServer.listen(); | ||
}, | ||
}, | ||
build: { | ||
meta: { | ||
name: "build", | ||
version: packageJson.version, | ||
description: "Build your Vinxi app", | ||
}, | ||
args: { | ||
config: { | ||
type: "string", | ||
description: "Path to config file (default: app.config.js)", | ||
}, | ||
stack: { | ||
type: "string", | ||
description: "Stacks", | ||
}, | ||
preset: { | ||
type: "string", | ||
description: "Server preset (default: node-server)", | ||
}, | ||
}, | ||
async run({ args }) { | ||
const configFile = args.config; | ||
globalThis.MANIFEST = {}; | ||
const app = await loadApp(configFile, args); | ||
process.env.NODE_ENV = "production"; | ||
const { createBuild } = await import("../lib/build.js"); | ||
await createBuild(app, { preset: args.preset }); | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
runMain(command); |
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
Oops, something went wrong.