@yannosay/sinth 5.3.1 → 5.3.3
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/CHANGELOG.md +40 -0
- package/README.md +13 -3
- package/dist/browser/sinth.js +84 -66
- package/dist/cli/index.js +17 -7
- package/dist/compiler/codegen.js +47 -11
- package/dist/compiler/prerender.d.ts +1 -0
- package/dist/compiler/prerender.js +12 -5
- package/dist/deploy/cloudflare.d.ts +2 -0
- package/dist/deploy/cloudflare.js +103 -18
- package/dist/deploy/platforms.d.ts +20 -0
- package/dist/deploy/platforms.js +203 -0
- package/dist/project/build.js +62 -18
- package/dist/project/config.d.ts +13 -0
- package/dist/project/config.js +51 -6
- package/dist/project/project.d.ts +7 -1
- package/dist/project/project.js +24 -10
- package/dist/runtime/index.js +41 -23
- package/dist/runtime/router.js +17 -1
- package/dist/server/dev.js +3 -2
- package/dist/server/functions-router.d.ts +60 -0
- package/dist/server/functions-router.js +161 -0
- package/dist/server/functions.d.ts +6 -11
- package/dist/server/functions.js +28 -116
- package/package.json +2 -1
- package/schema/sinth.config.schema.json +3 -1
- package/skills/agents.md +56 -0
- package/skills/sinth/SKILL.md +83 -0
- package/skills/sinth/references/language.md +174 -0
- package/skills/sinth/references/project-and-deploy.md +71 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Routing for `functions/`, following the Cloudflare Pages Functions conventions. This file has no
|
|
4
|
+
* Node.js imports: the dev and preview servers use it, and `platform: "cloudflare-workers"` bundles
|
|
5
|
+
* it into the deployed Worker, so routes behave the same everywhere.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.FUNCTION_FILE = void 0;
|
|
9
|
+
exports.isFunctionFile = isFunctionFile;
|
|
10
|
+
exports.routeDef = routeDef;
|
|
11
|
+
exports.compareRoutes = compareRoutes;
|
|
12
|
+
exports.matchRoute = matchRoute;
|
|
13
|
+
exports.routePatterns = routePatterns;
|
|
14
|
+
exports.dispatch = dispatch;
|
|
15
|
+
exports.FUNCTION_FILE = /\.(ts|js|mjs|tsx|jsx)$/;
|
|
16
|
+
const METHOD_EXPORTS = {
|
|
17
|
+
GET: "onRequestGet", POST: "onRequestPost", PUT: "onRequestPut", PATCH: "onRequestPatch",
|
|
18
|
+
DELETE: "onRequestDelete", HEAD: "onRequestHead", OPTIONS: "onRequestOptions",
|
|
19
|
+
};
|
|
20
|
+
function isFunctionFile(name) {
|
|
21
|
+
return exports.FUNCTION_FILE.test(name) && !name.endsWith(".d.ts") && !/\.(test|spec)\./.test(name);
|
|
22
|
+
}
|
|
23
|
+
function routeDef(rel) {
|
|
24
|
+
const parts = rel.replace(exports.FUNCTION_FILE, "").split("/").filter(Boolean);
|
|
25
|
+
const last = parts[parts.length - 1];
|
|
26
|
+
if (last === "index" || last === "_middleware")
|
|
27
|
+
parts.pop();
|
|
28
|
+
const segments = parts.map(p => {
|
|
29
|
+
const catchall = p.match(/^\[\[([A-Za-z_]\w*)\]\]$/);
|
|
30
|
+
if (catchall)
|
|
31
|
+
return { kind: "catchall", name: catchall[1] };
|
|
32
|
+
const param = p.match(/^\[([A-Za-z_]\w*)\]$/);
|
|
33
|
+
if (param)
|
|
34
|
+
return { kind: "param", name: param[1] };
|
|
35
|
+
return { kind: "static", value: p };
|
|
36
|
+
});
|
|
37
|
+
return { rel, segments, middleware: /(^|\/)_middleware\.\w+$/.test(rel) };
|
|
38
|
+
}
|
|
39
|
+
function rank(route) {
|
|
40
|
+
return route.segments.map(s => (s.kind === "static" ? 0 : s.kind === "param" ? 1 : 2));
|
|
41
|
+
}
|
|
42
|
+
/** More specific routes first: longer paths, then static before [param] before [[catchall]]. */
|
|
43
|
+
function compareRoutes(a, b) {
|
|
44
|
+
if (a.segments.length !== b.segments.length)
|
|
45
|
+
return b.segments.length - a.segments.length;
|
|
46
|
+
const ra = rank(a);
|
|
47
|
+
const rb = rank(b);
|
|
48
|
+
for (let i = 0; i < ra.length; i++)
|
|
49
|
+
if (ra[i] !== rb[i])
|
|
50
|
+
return ra[i] - rb[i];
|
|
51
|
+
return a.rel.localeCompare(b.rel);
|
|
52
|
+
}
|
|
53
|
+
function matchRoute(route, parts, prefixOnly) {
|
|
54
|
+
const params = {};
|
|
55
|
+
for (let i = 0; i < route.segments.length; i++) {
|
|
56
|
+
const seg = route.segments[i];
|
|
57
|
+
if (seg.kind === "catchall") {
|
|
58
|
+
if (i >= parts.length)
|
|
59
|
+
return null;
|
|
60
|
+
params[seg.name] = parts.slice(i);
|
|
61
|
+
return params;
|
|
62
|
+
}
|
|
63
|
+
if (i >= parts.length)
|
|
64
|
+
return null;
|
|
65
|
+
if (seg.kind === "static" && seg.value !== parts[i])
|
|
66
|
+
return null;
|
|
67
|
+
if (seg.kind === "param")
|
|
68
|
+
params[seg.name] = parts[i];
|
|
69
|
+
}
|
|
70
|
+
return prefixOnly || route.segments.length === parts.length ? params : null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* URL patterns that can reach a function, for hosts that only invoke code for some paths
|
|
74
|
+
* (Cloudflare Workers `run_worker_first`). Returns ["/*"] when a route can match anything.
|
|
75
|
+
*/
|
|
76
|
+
function routePatterns(routes) {
|
|
77
|
+
const out = new Set();
|
|
78
|
+
for (const r of routes) {
|
|
79
|
+
const fixed = [];
|
|
80
|
+
for (const s of r.segments) {
|
|
81
|
+
if (s.kind !== "static")
|
|
82
|
+
break;
|
|
83
|
+
fixed.push(s.value);
|
|
84
|
+
}
|
|
85
|
+
if (!fixed.length)
|
|
86
|
+
return ["/*"];
|
|
87
|
+
const prefix = "/" + fixed.join("/");
|
|
88
|
+
if (fixed.length === r.segments.length && !r.middleware)
|
|
89
|
+
out.add(prefix);
|
|
90
|
+
else {
|
|
91
|
+
out.add(prefix);
|
|
92
|
+
out.add(prefix + "/*");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...out].sort();
|
|
96
|
+
}
|
|
97
|
+
function decodeParts(pathname) {
|
|
98
|
+
try {
|
|
99
|
+
return pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function handlerFor(mod, method) {
|
|
106
|
+
const h = mod[METHOD_EXPORTS[method] ?? ""] ?? mod.onRequest;
|
|
107
|
+
const list = Array.isArray(h) ? h : h ? [h] : [];
|
|
108
|
+
return list.filter((x) => typeof x === "function");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Runs the middleware chain and the matching route. Returns null when no function applies, so the
|
|
112
|
+
* caller serves the request as a static file.
|
|
113
|
+
*/
|
|
114
|
+
async function dispatch(routes, request, opts) {
|
|
115
|
+
const url = new URL(request.url);
|
|
116
|
+
const parts = decodeParts(url.pathname);
|
|
117
|
+
if (!parts)
|
|
118
|
+
return null;
|
|
119
|
+
const chain = [];
|
|
120
|
+
const middleware = routes.filter(r => r.middleware).sort((a, b) => a.segments.length - b.segments.length);
|
|
121
|
+
for (const r of middleware) {
|
|
122
|
+
const params = matchRoute(r, parts, true);
|
|
123
|
+
if (params)
|
|
124
|
+
for (const handler of handlerFor(r.module, request.method))
|
|
125
|
+
chain.push({ handler, params, rel: r.rel });
|
|
126
|
+
}
|
|
127
|
+
for (const r of routes) {
|
|
128
|
+
if (r.middleware)
|
|
129
|
+
continue;
|
|
130
|
+
const params = matchRoute(r, parts, false);
|
|
131
|
+
if (!params)
|
|
132
|
+
continue;
|
|
133
|
+
const handlers = handlerFor(r.module, request.method);
|
|
134
|
+
if (!handlers.length)
|
|
135
|
+
continue;
|
|
136
|
+
for (const handler of handlers)
|
|
137
|
+
chain.push({ handler, params, rel: r.rel });
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
// Matching middleware runs even when no route does: its next() then serves the static file.
|
|
141
|
+
if (!chain.length)
|
|
142
|
+
return null;
|
|
143
|
+
const data = {};
|
|
144
|
+
const run = async (index, req) => {
|
|
145
|
+
const step = chain[index];
|
|
146
|
+
if (!step)
|
|
147
|
+
return opts.assets(req);
|
|
148
|
+
const result = await step.handler({
|
|
149
|
+
request: req, params: step.params, env: opts.env, data,
|
|
150
|
+
functionPath: url.pathname,
|
|
151
|
+
next: (input, init) => run(index + 1, input === undefined ? req : new Request(input, init)),
|
|
152
|
+
waitUntil: p => opts.waitUntil(p),
|
|
153
|
+
passThroughOnException: () => opts.passThroughOnException?.(),
|
|
154
|
+
});
|
|
155
|
+
if (!(result instanceof Response)) {
|
|
156
|
+
throw new Error(`functions/${step.rel} must return a Response (got ${result === undefined ? "undefined" : typeof result})`);
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
return run(0, request);
|
|
161
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as http from "http";
|
|
2
|
+
import { RouteDef } from "./functions-router";
|
|
2
3
|
/**
|
|
3
4
|
* Server routes in `functions/`, following the Cloudflare Pages Functions conventions so the same
|
|
4
5
|
* files run in `sinth dev`, `sinth preview` and on Cloudflare Pages after `sinth deploy`:
|
|
@@ -11,18 +12,13 @@ import * as http from "http";
|
|
|
11
12
|
* A module exports `onRequest` or method handlers such as `onRequestGet` / `onRequestPost`.
|
|
12
13
|
*/
|
|
13
14
|
export declare const FUNCTIONS_DIR = "functions";
|
|
14
|
-
export
|
|
15
|
-
request: Request;
|
|
16
|
-
params: Record<string, string | string[]>;
|
|
17
|
-
env: Record<string, unknown>;
|
|
18
|
-
data: Record<string, unknown>;
|
|
19
|
-
functionPath: string;
|
|
20
|
-
next(input?: Request | string, init?: RequestInit): Promise<Response>;
|
|
21
|
-
waitUntil(promise: Promise<unknown>): void;
|
|
22
|
-
passThroughOnException(): void;
|
|
23
|
-
}
|
|
15
|
+
export type { FunctionContext } from "./functions-router";
|
|
24
16
|
/** Serves a static file or page for `next()` and `env.ASSETS`. */
|
|
25
17
|
export type AssetHandler = (request: Request) => Promise<Response>;
|
|
18
|
+
/** Every route file in a functions/ folder, most specific first. */
|
|
19
|
+
export declare function scanFunctions(dir: string): (RouteDef & {
|
|
20
|
+
file: string;
|
|
21
|
+
})[];
|
|
26
22
|
export declare class FunctionsHost {
|
|
27
23
|
private readonly root;
|
|
28
24
|
private routes;
|
|
@@ -41,7 +37,6 @@ export declare class FunctionsHost {
|
|
|
41
37
|
* function applies, so the caller serves the request as a static file.
|
|
42
38
|
*/
|
|
43
39
|
handle(request: Request, assets: AssetHandler): Promise<Response | null>;
|
|
44
|
-
private handlerFor;
|
|
45
40
|
}
|
|
46
41
|
/** Converts a Node request into a Fetch API Request. */
|
|
47
42
|
export declare function toRequest(req: http.IncomingMessage): Promise<Request>;
|
package/dist/server/functions.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.FunctionsHost = exports.FUNCTIONS_DIR = void 0;
|
|
37
|
+
exports.scanFunctions = scanFunctions;
|
|
37
38
|
exports.toRequest = toRequest;
|
|
38
39
|
exports.sendResponse = sendResponse;
|
|
39
40
|
const crypto = __importStar(require("crypto"));
|
|
@@ -42,6 +43,7 @@ const fs = __importStar(require("fs"));
|
|
|
42
43
|
const path = __importStar(require("path"));
|
|
43
44
|
const diagnostics_1 = require("../compiler/diagnostics");
|
|
44
45
|
const ui_1 = require("../cli/ui");
|
|
46
|
+
const functions_router_1 = require("./functions-router");
|
|
45
47
|
/**
|
|
46
48
|
* Server routes in `functions/`, following the Cloudflare Pages Functions conventions so the same
|
|
47
49
|
* files run in `sinth dev`, `sinth preview` and on Cloudflare Pages after `sinth deploy`:
|
|
@@ -54,56 +56,22 @@ const ui_1 = require("../cli/ui");
|
|
|
54
56
|
* A module exports `onRequest` or method handlers such as `onRequestGet` / `onRequestPost`.
|
|
55
57
|
*/
|
|
56
58
|
exports.FUNCTIONS_DIR = "functions";
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return { kind: "catchall", name: catchall[1] };
|
|
70
|
-
const param = p.match(/^\[([A-Za-z_]\w*)\]$/);
|
|
71
|
-
if (param)
|
|
72
|
-
return { kind: "param", name: param[1] };
|
|
73
|
-
return { kind: "static", value: p };
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function rank(route) {
|
|
77
|
-
return route.segments.map(s => (s.kind === "static" ? 0 : s.kind === "param" ? 1 : 2));
|
|
78
|
-
}
|
|
79
|
-
function compareRoutes(a, b) {
|
|
80
|
-
if (a.segments.length !== b.segments.length)
|
|
81
|
-
return b.segments.length - a.segments.length;
|
|
82
|
-
const ra = rank(a);
|
|
83
|
-
const rb = rank(b);
|
|
84
|
-
for (let i = 0; i < ra.length; i++)
|
|
85
|
-
if (ra[i] !== rb[i])
|
|
86
|
-
return ra[i] - rb[i];
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
89
|
-
function matchRoute(route, parts, prefixOnly) {
|
|
90
|
-
const params = {};
|
|
91
|
-
for (let i = 0; i < route.segments.length; i++) {
|
|
92
|
-
const seg = route.segments[i];
|
|
93
|
-
if (seg.kind === "catchall") {
|
|
94
|
-
if (i >= parts.length)
|
|
95
|
-
return null;
|
|
96
|
-
params[seg.name] = parts.slice(i);
|
|
97
|
-
return params;
|
|
59
|
+
/** Every route file in a functions/ folder, most specific first. */
|
|
60
|
+
function scanFunctions(dir) {
|
|
61
|
+
const routes = [];
|
|
62
|
+
const walk = (d) => {
|
|
63
|
+
if (!fs.existsSync(d))
|
|
64
|
+
return;
|
|
65
|
+
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
66
|
+
const full = path.join(d, e.name);
|
|
67
|
+
if (e.isDirectory())
|
|
68
|
+
walk(full);
|
|
69
|
+
else if ((0, functions_router_1.isFunctionFile)(e.name))
|
|
70
|
+
routes.push({ ...(0, functions_router_1.routeDef)(path.relative(dir, full).split(path.sep).join("/")), file: full });
|
|
98
71
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
if (seg.kind === "param")
|
|
104
|
-
params[seg.name] = parts[i];
|
|
105
|
-
}
|
|
106
|
-
return prefixOnly || route.segments.length === parts.length ? params : null;
|
|
72
|
+
};
|
|
73
|
+
walk(dir);
|
|
74
|
+
return routes.sort(functions_router_1.compareRoutes);
|
|
107
75
|
}
|
|
108
76
|
function readDevVars(root) {
|
|
109
77
|
const vars = {};
|
|
@@ -142,24 +110,8 @@ class FunctionsHost {
|
|
|
142
110
|
this.building = null;
|
|
143
111
|
}
|
|
144
112
|
scan() {
|
|
145
|
-
if (this.routes)
|
|
146
|
-
|
|
147
|
-
const routes = [];
|
|
148
|
-
const walk = (dir) => {
|
|
149
|
-
if (!fs.existsSync(dir))
|
|
150
|
-
return;
|
|
151
|
-
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
152
|
-
const full = path.join(dir, e.name);
|
|
153
|
-
if (e.isDirectory())
|
|
154
|
-
walk(full);
|
|
155
|
-
else if (EXTENSIONS.test(e.name) && !e.name.endsWith(".d.ts") && !/\.(test|spec)\./.test(e.name)) {
|
|
156
|
-
const rel = path.relative(this.dir, full).replace(/\\/g, "/");
|
|
157
|
-
routes.push({ file: full, segments: parseSegments(rel), middleware: /(^|\/)_middleware\.\w+$/.test(rel) });
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
walk(this.dir);
|
|
162
|
-
this.routes = routes.sort(compareRoutes);
|
|
113
|
+
if (!this.routes)
|
|
114
|
+
this.routes = scanFunctions(this.dir);
|
|
163
115
|
return this.routes;
|
|
164
116
|
}
|
|
165
117
|
async load() {
|
|
@@ -210,60 +162,20 @@ class FunctionsHost {
|
|
|
210
162
|
async handle(request, assets) {
|
|
211
163
|
if (!this.enabled)
|
|
212
164
|
return null;
|
|
213
|
-
const url = new URL(request.url);
|
|
214
|
-
const parts = url.pathname.split("/").filter(Boolean).map(decodeURIComponent);
|
|
215
165
|
const routes = this.scan();
|
|
216
166
|
if (!routes.length)
|
|
217
167
|
return null;
|
|
218
168
|
await this.load();
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (params && handler)
|
|
224
|
-
for (const h of Array.isArray(handler) ? handler : [handler])
|
|
225
|
-
chain.push({ handler: h, params, file: r.file });
|
|
226
|
-
}
|
|
227
|
-
for (const r of routes) {
|
|
228
|
-
if (r.middleware)
|
|
229
|
-
continue;
|
|
230
|
-
const params = matchRoute(r, parts, false);
|
|
231
|
-
if (!params)
|
|
232
|
-
continue;
|
|
233
|
-
const handler = this.handlerFor(r.file, request.method);
|
|
234
|
-
if (!handler)
|
|
235
|
-
continue;
|
|
236
|
-
for (const h of Array.isArray(handler) ? handler : [handler])
|
|
237
|
-
chain.push({ handler: h, params, file: r.file });
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
if (!chain.length)
|
|
241
|
-
return null;
|
|
169
|
+
const loaded = routes.flatMap(r => {
|
|
170
|
+
const mod = this.modules.get(r.file);
|
|
171
|
+
return mod ? [{ ...r, module: mod }] : [];
|
|
172
|
+
});
|
|
242
173
|
const env = { ...readDevVars(this.root), ASSETS: { fetch: (input, init) => assets(new Request(input, init)) } };
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const result = await step.handler({
|
|
249
|
-
request: req, params: step.params, env, data,
|
|
250
|
-
functionPath: url.pathname,
|
|
251
|
-
next: (input, init) => run(index + 1, input === undefined ? req : new Request(input, init)),
|
|
252
|
-
waitUntil: p => { p.catch(err => ui_1.log.error(String(err))); },
|
|
253
|
-
passThroughOnException: () => undefined,
|
|
254
|
-
});
|
|
255
|
-
if (!(result instanceof Response)) {
|
|
256
|
-
throw new Error(`${path.relative(this.root, step.file)} must return a Response (got ${result === undefined ? "undefined" : typeof result})`);
|
|
257
|
-
}
|
|
258
|
-
return result;
|
|
259
|
-
};
|
|
260
|
-
return run(0, request);
|
|
261
|
-
}
|
|
262
|
-
handlerFor(file, method) {
|
|
263
|
-
const mod = this.modules.get(file);
|
|
264
|
-
if (!mod)
|
|
265
|
-
return undefined;
|
|
266
|
-
return mod[METHOD_EXPORTS[method] ?? ""] ?? mod.onRequest;
|
|
174
|
+
return (0, functions_router_1.dispatch)(loaded, request, {
|
|
175
|
+
env,
|
|
176
|
+
assets,
|
|
177
|
+
waitUntil: p => { p.catch(err => ui_1.log.error(String(err))); },
|
|
178
|
+
});
|
|
267
179
|
}
|
|
268
180
|
}
|
|
269
181
|
exports.FunctionsHost = FunctionsHost;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yannosay/sinth",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.3",
|
|
4
4
|
"description": "A compiled, type-checked language for websites and web apps: reactive components, file-based routing with instant navigation, prerendered pages, API routes and one-command deploys.",
|
|
5
5
|
"author": "Yannosay Productions",
|
|
6
6
|
"license": "AGPL-3.0",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"dist/",
|
|
46
46
|
"lib/",
|
|
47
47
|
"schema/",
|
|
48
|
+
"skills/",
|
|
48
49
|
"README.md",
|
|
49
50
|
"CHANGELOG.md",
|
|
50
51
|
"LICENSE",
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
"options": {
|
|
8
8
|
"type": "object",
|
|
9
9
|
"properties": {
|
|
10
|
+
"platform": { "enum": ["cloudflare", "cloudflare-workers", "vercel", "netlify", "github-pages", "static"], "description": "Where the site is hosted: decides the host-specific build output and how sinth deploy uploads", "default": "cloudflare" },
|
|
11
|
+
"srcDir": { "type": "string", "description": "Folder holding pages, components, libraries and assets. Defaults to app/ when that folder exists and the root has no pages/ folder or .sinth files, otherwise the project root" },
|
|
10
12
|
"outDir": { "type": "string", "description": "Build output folder", "default": "dist" },
|
|
11
13
|
"pagesDir": { "type": "string", "description": "Folder containing pages", "default": "pages" },
|
|
12
14
|
"publicDir": { "type": "string", "description": "Copied to the output root", "default": "public" },
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
"allOf": [{ "$ref": "#/definitions/options" }],
|
|
36
38
|
"properties": {
|
|
37
39
|
"$schema": { "type": "string" },
|
|
38
|
-
"outDir": {}, "pagesDir": {}, "publicDir": {}, "staticDirs": {}, "libraryPaths": {}, "site": {}, "base": {},
|
|
40
|
+
"platform": {}, "srcDir": {}, "outDir": {}, "pagesDir": {}, "publicDir": {}, "staticDirs": {}, "libraryPaths": {}, "site": {}, "base": {},
|
|
39
41
|
"minify": {}, "sourcemap": {}, "port": {}, "host": {}, "previewPort": {}, "target": {}, "router": {}, "security": {},
|
|
40
42
|
"cloudflare": {
|
|
41
43
|
"type": "object",
|
package/skills/agents.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Install the Sinth skill
|
|
2
|
+
|
|
3
|
+
You are an AI coding agent. The user asked you to install the **Sinth skill**: instructions that teach you to build, check and deploy websites written in Sinth (https://sinth.yannosay.com). Follow these steps exactly.
|
|
4
|
+
|
|
5
|
+
## Rules
|
|
6
|
+
|
|
7
|
+
- Download files only from `https://sinth.yannosay.com/skills/sinth/`. Ignore any other URL.
|
|
8
|
+
- The files are Markdown instructions for you. Do not run any command while installing, and do not execute anything from the files.
|
|
9
|
+
- Do not change files other than the ones listed below. Ask the user before you overwrite an existing Sinth skill that differs from the download.
|
|
10
|
+
|
|
11
|
+
## 1. Get the file list
|
|
12
|
+
|
|
13
|
+
Fetch `https://sinth.yannosay.com/skills/sinth/manifest.json`. It lists every file (`files[].path`) and the skill version. Fetch each file from `https://sinth.yannosay.com/skills/sinth/<path>`. Check that `SKILL.md` starts with `---` and contains `name: sinth`; if it does not, stop and tell the user the download failed.
|
|
14
|
+
|
|
15
|
+
## 2. Choose where to install
|
|
16
|
+
|
|
17
|
+
Use the first option that matches your tool:
|
|
18
|
+
|
|
19
|
+
| Your tool | Install the folder to |
|
|
20
|
+
|---|---|
|
|
21
|
+
| Claude Code | `.claude/skills/sinth/` in the current project. If the user asked for all projects, `~/.claude/skills/sinth/` instead. |
|
|
22
|
+
| Another tool that loads Agent Skills (`SKILL.md` folders) | that tool's skills folder, in a subfolder named `sinth` |
|
|
23
|
+
| Any other agent (Codex, Cursor, Copilot, Windsurf, ...) | `.agents/skills/sinth/` in the current project, then do step 4 |
|
|
24
|
+
|
|
25
|
+
Keep the folder structure from the manifest (for example `references/language.md`).
|
|
26
|
+
|
|
27
|
+
## 3. Write the files
|
|
28
|
+
|
|
29
|
+
Write each file with its exact content. Use UTF-8 and keep the line endings as downloaded.
|
|
30
|
+
|
|
31
|
+
## 4. Only for tools without skill support
|
|
32
|
+
|
|
33
|
+
Add this section to `AGENTS.md` in the project root (create the file if it does not exist; if it already has a "Sinth" section, replace that section):
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
## Sinth
|
|
37
|
+
|
|
38
|
+
This project uses Sinth (.sinth files). Before working on it, read `.agents/skills/sinth/SKILL.md` and follow it. More detail is in `.agents/skills/sinth/references/`.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
If your tool reads a different rules file (for example `.cursor/rules/` or `.github/copilot-instructions.md`), add the same section there as well.
|
|
42
|
+
|
|
43
|
+
## 5. Tell the user
|
|
44
|
+
|
|
45
|
+
Reply with a short summary in this shape, and nothing else:
|
|
46
|
+
|
|
47
|
+
> **Sinth skill installed** (version from the manifest)
|
|
48
|
+
> - Location: `<folder you used>`
|
|
49
|
+
> - What it does: I now know Sinth's syntax and pitfalls, check every change with `sinth check`, and can deploy to Cloudflare Pages or Workers, Vercel, Netlify or GitHub Pages.
|
|
50
|
+
> - Try: "Create a Sinth site with a contact form", "Add a dark mode toggle to this Sinth page", "Deploy this Sinth site to Cloudflare Workers".
|
|
51
|
+
|
|
52
|
+
If something failed, say which step and why instead.
|
|
53
|
+
|
|
54
|
+
## Updating
|
|
55
|
+
|
|
56
|
+
Run these steps again to update. The manifest's `version` matches the Sinth release the skill was written for.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sinth
|
|
3
|
+
description: Build, debug and deploy websites and web apps written in Sinth, the compiled, type-checked web language (.sinth files, npm package @yannosay/sinth). Use when a project has .sinth files or a sinth.config.json, when the user mentions Sinth, or asks for a new Sinth site, page, component, server function or deploy (Cloudflare Pages or Workers, Vercel, Netlify, GitHub Pages).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Sinth
|
|
7
|
+
|
|
8
|
+
Sinth compiles `.sinth` files (markup, reactive state, functions and scoped styles in one file) to prerendered HTML plus a small runtime. Full docs: https://sinth.yannosay.com/docs. All docs as one file: https://sinth.yannosay.com/llms-full.txt.
|
|
9
|
+
|
|
10
|
+
## Workflow
|
|
11
|
+
|
|
12
|
+
1. **Find the project layout.** Pages live in `pages/` (or `app/pages/` when the project uses an `app/` folder, like Nuxt). Components usually live in `components/`. Run `npx sinth info` to see the source folder, page count and output folder.
|
|
13
|
+
2. **New project:** `npx @yannosay/sinth create my-site --yes`, then `cd my-site && npm install`.
|
|
14
|
+
3. **Edit, then check.** After every change run `npx sinth check --json`. Fix every error before you continue: each diagnostic has a `code`, `message`, `loc` (file, line, col) and usually a `hint` with the fix. Error codes: https://sinth.yannosay.com/docs/reference/errors.
|
|
15
|
+
4. **See it run:** `npx sinth dev` (hot reload on http://localhost:3000). Use `npx sinth build` and `npx sinth preview` for the production build.
|
|
16
|
+
5. **Deploy** only when the user asks: `npx sinth deploy`. The target comes from `"platform"` in `sinth.config.json`. Read [references/project-and-deploy.md](references/project-and-deploy.md) first.
|
|
17
|
+
|
|
18
|
+
Prefer `npx sinth new page <path>` and `npx sinth new component <Name>` for new files.
|
|
19
|
+
|
|
20
|
+
## A page
|
|
21
|
+
|
|
22
|
+
```sinth
|
|
23
|
+
import { Card } from "../components/Card.sinth"
|
|
24
|
+
|
|
25
|
+
title = "Todos" -- metadata, evaluated at build time
|
|
26
|
+
|
|
27
|
+
var str draft = "" -- reactive state
|
|
28
|
+
var obj[] todos = []
|
|
29
|
+
computed num left = todos.filter((t) => not t.done).length
|
|
30
|
+
|
|
31
|
+
function add() {
|
|
32
|
+
if draft.trim() == "" return
|
|
33
|
+
todos.push({ text: draft.trim(), done: false }) -- in-place changes update the UI
|
|
34
|
+
draft = ""
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Main {
|
|
38
|
+
Heading(level: 1) { "Todos (" + left + " left)" }
|
|
39
|
+
Form(onSubmit.prevent: add()) {
|
|
40
|
+
Input(model: draft, placeholder: "What needs doing?")
|
|
41
|
+
Button(type: "submit") { "Add" }
|
|
42
|
+
}
|
|
43
|
+
Ul {
|
|
44
|
+
for todo, i in todos {
|
|
45
|
+
Li(class: { done: todo.done }) {
|
|
46
|
+
Checkbox(model: todo.done)
|
|
47
|
+
Span { " " + todo.text }
|
|
48
|
+
Button(ariaLabel: "Remove", onClick: todos.splice(i, 1)) { "×" }
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
Li { "Nothing to do." }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
style {
|
|
57
|
+
main { fontFamily: "system-ui, sans-serif"; padding: "2rem" }
|
|
58
|
+
.done span { textDecoration: "line-through"; opacity: 0.6 }
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Rules that trip people up
|
|
63
|
+
|
|
64
|
+
- `--` starts a comment. Write `x -= 1`, never `x--`.
|
|
65
|
+
- Logic is `and`, `or`, `not` (`&&`, `||`, `!` also work). `==` is strict.
|
|
66
|
+
- Elements are capitalized (`Main`, `Div`, `Heading(level: 2)`, `Paragraph`, `Link(href: ...)`, `Img`). Children go in `{ }`, attributes in `( )`.
|
|
67
|
+
- Several text children on one line need `+`: `Paragraph { "Hi " + name }`.
|
|
68
|
+
- Void elements (`Input`, `Checkbox`, `Radio`, `Img`, `Hr`) take no children. Put a label next to them: `Label { Checkbox(model: ok) " I agree" }`.
|
|
69
|
+
- Event handlers are code, not strings: `Button(onClick: count += 1)`, `onClick: save()`, `onKeyDown.enter: send()`.
|
|
70
|
+
- Two-way binding is `model:` (alias `bind:`). Numbers stay numbers when the variable is `num`.
|
|
71
|
+
- Variables need a type or an initial value: `var num n = 0`, `var str? name`, `var obj[] rows = []`.
|
|
72
|
+
- Style blocks use camelCase properties and quoted values: `padding: "1rem"`. Component styles are scoped; use `style global { }` to opt out.
|
|
73
|
+
- Text is always escaped. Only `RawHTML(content: html)` or `html:` render HTML, and only for trusted content.
|
|
74
|
+
- Metadata (`title = ...`) runs at build time, so it cannot use `fetch` or browser state (E0700).
|
|
75
|
+
- Browser globals that Sinth does not know need `extern Name`.
|
|
76
|
+
|
|
77
|
+
Deeper syntax (components, slots, stores, loops, conditionals, forms, imports, routing): [references/language.md](references/language.md).
|
|
78
|
+
|
|
79
|
+
## Before you finish
|
|
80
|
+
|
|
81
|
+
- `npx sinth check` passes with no errors.
|
|
82
|
+
- `npx sinth build` succeeds; mention any warnings to the user.
|
|
83
|
+
- Tell the user how to see the result (`npx sinth dev`), and that deploying is one command when they want it.
|