noofpi 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -2
- package/bin/noofpi.mjs +2 -0
- package/client.d.ts +79 -0
- package/dist/build-77DKK3YK.js +48 -0
- package/dist/chunk-2XCZWFIQ.js +253 -0
- package/dist/chunk-6OWKWAIW.js +68 -0
- package/dist/chunk-ELXCFUA4.js +97 -0
- package/dist/chunk-EZPJF4D4.js +314 -0
- package/dist/chunk-FIJJ3EGL.js +353 -0
- package/dist/chunk-G35DW4NA.js +129 -0
- package/dist/chunk-KAV3UNMO.js +996 -0
- package/dist/chunk-KGZP2RCF.js +51 -0
- package/dist/chunk-MTWSTW7V.js +44 -0
- package/dist/chunk-MTXQR32N.js +8 -0
- package/dist/chunk-NALDZ3PS.js +90 -0
- package/dist/chunk-WX2V6EYH.js +102 -0
- package/dist/chunk-WXEYXDO6.js +280 -0
- package/dist/chunk-X34Y6ESE.js +810 -0
- package/dist/chunk-Y3NBZ6DW.js +55 -0
- package/dist/chunk-YZAZ7IWK.js +27 -0
- package/dist/cli.js +93 -0
- package/dist/dev-ZJ732ORK.js +122 -0
- package/dist/devtools-KTDSD5PR.js +564 -0
- package/dist/images-BNwTAi50.d.ts +36 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +15 -0
- package/dist/route-rules-COilNsVT.d.ts +127 -0
- package/dist/runtime/default-app.js +15 -0
- package/dist/runtime/entry-client.js +70 -0
- package/dist/runtime/entry-server.js +107 -0
- package/dist/runtime/index.d.ts +523 -0
- package/dist/runtime/index.js +224 -0
- package/dist/runtime/routes.js +14 -0
- package/dist/server/bun.js +47 -0
- package/dist/server/index.d.ts +109 -0
- package/dist/server/index.js +48 -0
- package/dist/server/node.js +15 -0
- package/dist/start-I2LQWV7B.js +61 -0
- package/dist/validation-ClXd_DAW.d.ts +159 -0
- package/package.json +101 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/runtime/routes.ts
|
|
2
|
+
var PAGES_DIR = "/app/pages/";
|
|
3
|
+
function filePathToRoute(file) {
|
|
4
|
+
const relative = file.slice(file.indexOf(PAGES_DIR) + PAGES_DIR.length).replace(/\.vue$/, "");
|
|
5
|
+
const segments = relative.split("/").filter(
|
|
6
|
+
(segment, index, all) => !(segment === "index" && index === all.length - 1)
|
|
7
|
+
).map((segment) => {
|
|
8
|
+
const catchAll = /^\[\.\.\.(\w+)\]$/.exec(segment);
|
|
9
|
+
if (catchAll) return `:${catchAll[1]}(.*)*`;
|
|
10
|
+
const param = /^\[(\w+)\]$/.exec(segment);
|
|
11
|
+
return param ? `:${param[1]}` : segment;
|
|
12
|
+
});
|
|
13
|
+
return "/" + segments.join("/");
|
|
14
|
+
}
|
|
15
|
+
function createRoutes(pages, layouts = {}, middleware = {}) {
|
|
16
|
+
return Object.entries(pages).map(([file, importPage]) => {
|
|
17
|
+
const meta = {
|
|
18
|
+
layout: layouts[file],
|
|
19
|
+
middleware: middleware[file]
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
path: filePathToRoute(file),
|
|
23
|
+
// The page's `definePage()` export is read once the module is imported, which the router awaits before it resolves a navigation
|
|
24
|
+
component: async () => {
|
|
25
|
+
const module = await importPage();
|
|
26
|
+
meta.loader = module?.page?.loader;
|
|
27
|
+
return module;
|
|
28
|
+
},
|
|
29
|
+
meta
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function filePathToLayoutName(file) {
|
|
34
|
+
const name = file.slice(file.lastIndexOf("/") + 1).replace(/\.vue$/, "");
|
|
35
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
function createLayouts(modules) {
|
|
38
|
+
return Object.fromEntries(
|
|
39
|
+
Object.entries(modules).map(([file, component]) => [
|
|
40
|
+
filePathToLayoutName(file),
|
|
41
|
+
component
|
|
42
|
+
])
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function normalizeLayout(value) {
|
|
46
|
+
return typeof value === "string" || value === false ? value : void 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
filePathToRoute,
|
|
51
|
+
createRoutes,
|
|
52
|
+
filePathToLayoutName,
|
|
53
|
+
createLayouts,
|
|
54
|
+
normalizeLayout
|
|
55
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/validation.ts
|
|
2
|
+
var FORM_ERROR_KEY = "";
|
|
3
|
+
function issuesToErrors(issues) {
|
|
4
|
+
const errors = {};
|
|
5
|
+
for (const issue of issues ?? []) {
|
|
6
|
+
const key = issue.path.map(String).join(".");
|
|
7
|
+
(errors[key] ??= []).push(issue.message);
|
|
8
|
+
}
|
|
9
|
+
return errors;
|
|
10
|
+
}
|
|
11
|
+
function validate(schema, value) {
|
|
12
|
+
const result = schema.safeParse(value);
|
|
13
|
+
return result.success ? { ok: true, data: result.data } : { ok: false, errors: issuesToErrors(result.error.issues) };
|
|
14
|
+
}
|
|
15
|
+
function errorsFromFailure(failure) {
|
|
16
|
+
if (typeof failure !== "object" || failure === null) return void 0;
|
|
17
|
+
const { status, issues } = failure;
|
|
18
|
+
if (status !== 400 || !Array.isArray(issues)) return void 0;
|
|
19
|
+
return issuesToErrors(issues);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
FORM_ERROR_KEY,
|
|
24
|
+
issuesToErrors,
|
|
25
|
+
validate,
|
|
26
|
+
errorsFromFailure
|
|
27
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILD_PRESETS,
|
|
3
|
+
assertBuildPreset,
|
|
4
|
+
resolveConfig
|
|
5
|
+
} from "./chunk-WXEYXDO6.js";
|
|
6
|
+
import "./chunk-ELXCFUA4.js";
|
|
7
|
+
import "./chunk-FIJJ3EGL.js";
|
|
8
|
+
|
|
9
|
+
// src/cli.ts
|
|
10
|
+
import path2 from "path";
|
|
11
|
+
|
|
12
|
+
// src/load-config.ts
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { createJiti } from "jiti";
|
|
16
|
+
var CONFIG_FILES = [
|
|
17
|
+
"noofpi.config.ts",
|
|
18
|
+
"noofpi.config.mts",
|
|
19
|
+
"noofpi.config.js",
|
|
20
|
+
"noofpi.config.mjs"
|
|
21
|
+
];
|
|
22
|
+
async function loadConfig(root) {
|
|
23
|
+
const file = CONFIG_FILES.map((name) => path.join(root, name)).find(
|
|
24
|
+
existsSync
|
|
25
|
+
);
|
|
26
|
+
if (!file) return resolveConfig({});
|
|
27
|
+
const jiti = createJiti(import.meta.url, { interopDefault: true });
|
|
28
|
+
const loaded = await jiti.import(
|
|
29
|
+
file
|
|
30
|
+
);
|
|
31
|
+
const config = loaded && "default" in loaded ? loaded.default : loaded;
|
|
32
|
+
return resolveConfig(config);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/cli.ts
|
|
36
|
+
var USAGE = `noofpi <command> [options]
|
|
37
|
+
|
|
38
|
+
Commands:
|
|
39
|
+
dev Start the dev server with live reload
|
|
40
|
+
build Build for production into .output/
|
|
41
|
+
start Run the production build
|
|
42
|
+
|
|
43
|
+
Options:
|
|
44
|
+
--root <dir> Project root (default: current directory)
|
|
45
|
+
--port <port> Server port
|
|
46
|
+
--host <host> Server host
|
|
47
|
+
--preset <name> Build target: ${BUILD_PRESETS.join(" | ")} (default: build.preset or node)`;
|
|
48
|
+
function option(args, name) {
|
|
49
|
+
const index = args.indexOf(name);
|
|
50
|
+
return index === -1 ? void 0 : args[index + 1];
|
|
51
|
+
}
|
|
52
|
+
async function loadEnvFiles(root, mode) {
|
|
53
|
+
const { loadEnv } = await import("vite");
|
|
54
|
+
const env = loadEnv(mode, root, "");
|
|
55
|
+
for (const [key, value] of Object.entries(env)) {
|
|
56
|
+
process.env[key] ??= value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function main() {
|
|
60
|
+
const [command, ...args] = process.argv.slice(2);
|
|
61
|
+
const root = path2.resolve(option(args, "--root") ?? process.cwd());
|
|
62
|
+
const portArg = option(args, "--port");
|
|
63
|
+
const overrides = {
|
|
64
|
+
port: portArg ? Number(portArg) : void 0,
|
|
65
|
+
host: option(args, "--host")
|
|
66
|
+
};
|
|
67
|
+
if (command !== "dev" && command !== "build" && command !== "start") {
|
|
68
|
+
console.log(USAGE);
|
|
69
|
+
process.exit(command ? 1 : 0);
|
|
70
|
+
}
|
|
71
|
+
process.env.NODE_ENV ??= command === "dev" ? "development" : "production";
|
|
72
|
+
await loadEnvFiles(root, command === "dev" ? "development" : "production");
|
|
73
|
+
const config = await loadConfig(root);
|
|
74
|
+
if (command === "dev") {
|
|
75
|
+
const { startDev } = await import("./dev-ZJ732ORK.js");
|
|
76
|
+
await startDev(root, config, overrides);
|
|
77
|
+
} else if (command === "build") {
|
|
78
|
+
const { buildApp } = await import("./build-77DKK3YK.js");
|
|
79
|
+
const preset = option(args, "--preset");
|
|
80
|
+
await buildApp(
|
|
81
|
+
root,
|
|
82
|
+
config,
|
|
83
|
+
preset ? assertBuildPreset(preset, "--preset") : void 0
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
const { startProd } = await import("./start-I2LQWV7B.js");
|
|
87
|
+
await startProd(root, config, overrides);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
main().catch((error) => {
|
|
91
|
+
console.error(error instanceof Error ? error.message : error);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
localUrl,
|
|
3
|
+
printBanner
|
|
4
|
+
} from "./chunk-WX2V6EYH.js";
|
|
5
|
+
import {
|
|
6
|
+
DEV_ENTRY,
|
|
7
|
+
createViteConfig,
|
|
8
|
+
htmlTemplate,
|
|
9
|
+
resolveCss,
|
|
10
|
+
resolveFonts
|
|
11
|
+
} from "./chunk-KAV3UNMO.js";
|
|
12
|
+
import "./chunk-WXEYXDO6.js";
|
|
13
|
+
import {
|
|
14
|
+
createHandler
|
|
15
|
+
} from "./chunk-2XCZWFIQ.js";
|
|
16
|
+
import "./chunk-MTXQR32N.js";
|
|
17
|
+
import {
|
|
18
|
+
sendWebResponse,
|
|
19
|
+
toWebRequest
|
|
20
|
+
} from "./chunk-NALDZ3PS.js";
|
|
21
|
+
import "./chunk-KGZP2RCF.js";
|
|
22
|
+
import "./chunk-ELXCFUA4.js";
|
|
23
|
+
import "./chunk-EZPJF4D4.js";
|
|
24
|
+
import "./chunk-G35DW4NA.js";
|
|
25
|
+
import "./chunk-FIJJ3EGL.js";
|
|
26
|
+
import "./chunk-Y3NBZ6DW.js";
|
|
27
|
+
|
|
28
|
+
// src/vite/dev.ts
|
|
29
|
+
import { createServer as createHttpServer } from "http";
|
|
30
|
+
import path from "path";
|
|
31
|
+
import { createServer as createViteServer, normalizePath } from "vite";
|
|
32
|
+
|
|
33
|
+
// src/shortcuts.ts
|
|
34
|
+
import { spawn } from "child_process";
|
|
35
|
+
function openBrowser(url) {
|
|
36
|
+
const [command, args] = process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : process.platform === "darwin" ? ["open", [url]] : ["xdg-open", [url]];
|
|
37
|
+
const child = spawn(command, args, { stdio: "ignore", detached: true });
|
|
38
|
+
child.on("error", () => console.log(` Could not open the browser: ${url}`));
|
|
39
|
+
child.unref();
|
|
40
|
+
}
|
|
41
|
+
function bindShortcuts(options) {
|
|
42
|
+
const { stdin } = process;
|
|
43
|
+
if (!stdin.isTTY || !process.stdout.isTTY) return false;
|
|
44
|
+
let closing = false;
|
|
45
|
+
const quit = () => {
|
|
46
|
+
if (closing) return;
|
|
47
|
+
closing = true;
|
|
48
|
+
options.close().finally(() => process.exit(0));
|
|
49
|
+
};
|
|
50
|
+
stdin.setRawMode(true);
|
|
51
|
+
stdin.setEncoding("utf-8");
|
|
52
|
+
stdin.resume();
|
|
53
|
+
stdin.on("data", (key) => {
|
|
54
|
+
if (key === "" || key.toLowerCase() === "q") quit();
|
|
55
|
+
else if (key.toLowerCase() === "b") openBrowser(options.url);
|
|
56
|
+
});
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/vite/dev.ts
|
|
61
|
+
async function startDev(root, config, overrides) {
|
|
62
|
+
const startedAt = performance.now();
|
|
63
|
+
const port = overrides.port ?? config.devServer.port;
|
|
64
|
+
const host = overrides.host ?? config.devServer.host;
|
|
65
|
+
const httpServer = createHttpServer();
|
|
66
|
+
const fonts = await resolveFonts(root, config);
|
|
67
|
+
const vite = await createViteServer(
|
|
68
|
+
createViteConfig(
|
|
69
|
+
root,
|
|
70
|
+
{
|
|
71
|
+
...config,
|
|
72
|
+
vite: {
|
|
73
|
+
...config.vite,
|
|
74
|
+
server: { middlewareMode: true, hmr: { server: httpServer } }
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"dev",
|
|
78
|
+
fonts
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
const stylesheets = resolveCss(root, config, fonts).map((file) => {
|
|
82
|
+
const relative = path.relative(root, file);
|
|
83
|
+
const outside = relative.startsWith("..") || path.isAbsolute(relative);
|
|
84
|
+
const url = outside ? "/@fs/" + normalizePath(file) : "/" + normalizePath(relative);
|
|
85
|
+
return url + "?direct";
|
|
86
|
+
});
|
|
87
|
+
const handler = createHandler({
|
|
88
|
+
load: () => vite.ssrLoadModule("virtual:noofpi/server"),
|
|
89
|
+
getTemplate: (url) => vite.transformIndexHtml(url, htmlTemplate(DEV_ENTRY, stylesheets)),
|
|
90
|
+
onError: (error) => {
|
|
91
|
+
if (error instanceof Error) vite.ssrFixStacktrace(error);
|
|
92
|
+
console.error(error);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
httpServer.on("request", (req, res) => {
|
|
96
|
+
vite.middlewares(req, res, () => {
|
|
97
|
+
handler(toWebRequest(req)).then(
|
|
98
|
+
(response) => sendWebResponse(res, response),
|
|
99
|
+
(error) => {
|
|
100
|
+
console.error(error);
|
|
101
|
+
res.statusCode = 500;
|
|
102
|
+
res.end("Internal Server Error");
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
await new Promise((resolve) => httpServer.listen(port, host, resolve));
|
|
108
|
+
vite.ssrLoadModule("virtual:noofpi/server").catch(() => {
|
|
109
|
+
});
|
|
110
|
+
for (const url of stylesheets) vite.warmupRequest(url).catch(() => {
|
|
111
|
+
});
|
|
112
|
+
const close = () => vite.close().then(() => {
|
|
113
|
+
httpServer.closeAllConnections();
|
|
114
|
+
httpServer.close();
|
|
115
|
+
});
|
|
116
|
+
const shortcuts = bindShortcuts({ url: localUrl(host, port), close });
|
|
117
|
+
printBanner({ mode: "development", host, port, startedAt, shortcuts });
|
|
118
|
+
return { vite, httpServer, close };
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
startDev
|
|
122
|
+
};
|