penambahan web socket

This commit is contained in:
2025-09-18 19:01:22 +07:00
parent 1d053646a9
commit d7bb2eb5bb
15070 changed files with 2402916 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
import nodeCrypto from 'node:crypto';
import { defineCommand } from 'citty';
import { createNitro, prepare, copyPublicAssets, prerender, build as build$1 } from 'nitropack/core';
import { resolve } from 'pathe';
import { c as commonArgs } from './common.mjs';
if (!globalThis.crypto) {
globalThis.crypto = nodeCrypto;
}
const build = defineCommand({
meta: {
name: "build",
description: "Build nitro project for production"
},
args: {
...commonArgs,
minify: {
type: "boolean",
description: "Minify the output (overrides preset defaults you can also use `--no-minify` to disable)."
},
preset: {
type: "string",
description: "The build preset to use (you can also use `NITRO_PRESET` environment variable)."
},
compatibilityDate: {
type: "string",
description: "The date to use for preset compatibility (you can also use `NITRO_COMPATIBILITY_DATE` environment variable)."
}
},
async run({ args }) {
const rootDir = resolve(args.dir || args._dir || ".");
const nitro = await createNitro(
{
rootDir,
dev: false,
minify: args.minify,
preset: args.preset
},
{
compatibilityDate: args.compatibilityDate
}
);
await prepare(nitro);
await copyPublicAssets(nitro);
await prerender(nitro);
await build$1(nitro);
await nitro.close();
}
});
export { build as default };

View File

@@ -0,0 +1,13 @@
const commonArgs = {
dir: {
type: "string",
description: "project root directory"
},
_dir: {
type: "positional",
default: ".",
description: "project root directory (prefer using `--dir`)"
}
};
export { commonArgs as c };

View File

@@ -0,0 +1,66 @@
import nodeCrypto from 'node:crypto';
import { defineCommand } from 'citty';
import { consola } from 'consola';
import { getArgs, parseArgs } from 'listhen/cli';
import { createNitro, createDevServer, prepare, build } from 'nitropack/core';
import { resolve } from 'pathe';
import { c as commonArgs } from './common.mjs';
const hmrKeyRe = /^runtimeConfig\.|routeRules\./;
if (!globalThis.crypto) {
globalThis.crypto = nodeCrypto;
}
const dev = defineCommand({
meta: {
name: "dev",
description: "Start the development server"
},
args: {
...commonArgs,
...getArgs()
},
async run({ args }) {
const rootDir = resolve(args.dir || args._dir || ".");
let nitro;
const reload = async () => {
if (nitro) {
consola.info("Restarting dev server...");
if ("unwatch" in nitro.options._c12) {
await nitro.options._c12.unwatch();
}
await nitro.close();
}
nitro = await createNitro(
{
rootDir,
dev: true,
_cli: { command: "dev" }
},
{
watch: true,
c12: {
async onUpdate({ getDiff, newConfig }) {
const diff = getDiff();
if (diff.length === 0) {
return;
}
consola.info(
"Nitro config updated:\n" + diff.map((entry) => ` ${entry.toString()}`).join("\n")
);
await (diff.every((e) => hmrKeyRe.test(e.key)) ? nitro.updateConfig(newConfig.config || {}) : reload());
}
}
}
);
nitro.hooks.hookOnce("restart", reload);
const server = createDevServer(nitro);
const listhenOptions = parseArgs(args);
await server.listen(listhenOptions.port || 3e3, listhenOptions);
await prepare(nitro);
await build(nitro);
};
await reload();
}
});
export { dev as default };

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env node
import { defineCommand, runMain } from 'citty';
import { version } from 'nitropack/meta';
const main = defineCommand({
meta: {
name: "nitro",
description: "Nitro CLI",
version: version
},
subCommands: {
dev: () => import('./dev.mjs').then((r) => r.default),
build: () => import('./build.mjs').then((r) => r.default),
prepare: () => import('./prepare.mjs').then((r) => r.default),
task: () => import('./index2.mjs').then((r) => r.default)
}
});
runMain(main);

View File

@@ -0,0 +1,14 @@
import { defineCommand } from 'citty';
const index = defineCommand({
meta: {
name: "task",
description: "Operate in nitro tasks (experimental)"
},
subCommands: {
list: () => import('./list.mjs').then((r) => r.default),
run: () => import('./run.mjs').then((r) => r.default)
}
});
export { index as default };

View File

@@ -0,0 +1,32 @@
import { defineCommand } from 'citty';
import { consola } from 'consola';
import { loadOptions, listTasks } from 'nitropack/core';
import { resolve } from 'pathe';
const list = defineCommand({
meta: {
name: "run",
description: "List available tasks (experimental)"
},
args: {
dir: {
type: "string",
description: "project root directory"
}
},
async run({ args }) {
const cwd = resolve(args.dir || args.cwd || ".");
const options = await loadOptions({ rootDir: cwd }).catch(() => void 0);
const tasks = await listTasks({
cwd,
buildDir: options?.buildDir || ".nitro"
});
for (const [name, task] of Object.entries(tasks)) {
consola.log(
` - \`${name}\`${task.meta?.description ? ` - ${task.meta.description}` : ""}`
);
}
}
});
export { list as default };

View File

@@ -0,0 +1,21 @@
import { defineCommand } from 'citty';
import { createNitro, writeTypes } from 'nitropack/core';
import { resolve } from 'pathe';
import { c as commonArgs } from './common.mjs';
const prepare = defineCommand({
meta: {
name: "prepare",
description: "Generate types for the project"
},
args: {
...commonArgs
},
async run({ args }) {
const rootDir = resolve(args.dir || args._dir || ".");
const nitro = await createNitro({ rootDir });
await writeTypes(nitro);
}
});
export { prepare as default };

View File

@@ -0,0 +1,58 @@
import { defineCommand } from 'citty';
import { consola } from 'consola';
import destr from 'destr';
import { loadOptions, runTask } from 'nitropack/core';
import { resolve } from 'pathe';
const run = defineCommand({
meta: {
name: "run",
description: "Run a runtime task in the currently running dev server (experimental)"
},
args: {
name: {
type: "positional",
description: "task name",
required: true
},
dir: {
type: "string",
description: "project root directory"
},
payload: {
type: "string",
description: "payload json to pass to the task"
}
},
async run({ args }) {
const cwd = resolve(args.dir || args.cwd || ".");
const options = await loadOptions({ rootDir: cwd }).catch(() => void 0);
consola.info(`Running task \`${args.name}\`...`);
let payload = destr(args.payload || "{}");
if (typeof payload !== "object") {
consola.error(
`Invalid payload: \`${args.payload}\` (it should be a valid JSON object)`
);
payload = void 0;
}
try {
const { result } = await runTask(
{
name: args.name,
context: {},
payload
},
{
cwd,
buildDir: options?.buildDir || ".nitro"
}
);
consola.success("Result:", result);
} catch (error) {
consola.error(`Failed to run task \`${args.name}\`: ${error}`);
process.exit(1);
}
}
});
export { run as default };