@yannosay/sinth 4.1.0 → 5.1.1

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/DOCS.md +1359 -0
  3. package/README.md +83 -74
  4. package/bin/sinth.js +2 -1
  5. package/dist/cli/args.d.ts +11 -0
  6. package/dist/cli/args.js +74 -0
  7. package/dist/cli/index.d.ts +1 -0
  8. package/dist/cli/index.js +437 -0
  9. package/dist/cli/templates.d.ts +10 -0
  10. package/dist/cli/templates.js +193 -0
  11. package/dist/cli/ui.d.ts +28 -0
  12. package/dist/cli/ui.js +61 -0
  13. package/dist/cli/update-check.d.ts +2 -0
  14. package/dist/cli/update-check.js +124 -0
  15. package/dist/compiler/ast.d.ts +315 -0
  16. package/dist/compiler/ast.js +4 -0
  17. package/dist/compiler/codegen.d.ts +143 -0
  18. package/dist/compiler/codegen.js +1326 -0
  19. package/dist/compiler/diagnostics.d.ts +36 -0
  20. package/dist/compiler/diagnostics.js +142 -0
  21. package/dist/compiler/elements.d.ts +14 -0
  22. package/dist/compiler/elements.js +78 -0
  23. package/dist/compiler/globals.d.ts +2 -0
  24. package/dist/compiler/globals.js +27 -0
  25. package/dist/compiler/html.d.ts +37 -0
  26. package/dist/compiler/html.js +152 -0
  27. package/dist/compiler/lexer.d.ts +42 -0
  28. package/dist/compiler/lexer.js +404 -0
  29. package/dist/compiler/parser.d.ts +95 -0
  30. package/dist/compiler/parser.js +1374 -0
  31. package/dist/compiler/prerender.d.ts +72 -0
  32. package/dist/compiler/prerender.js +910 -0
  33. package/dist/compiler/script-analysis.d.ts +6 -0
  34. package/dist/compiler/script-analysis.js +106 -0
  35. package/dist/compiler/style.d.ts +39 -0
  36. package/dist/compiler/style.js +463 -0
  37. package/dist/deploy/cloudflare.d.ts +9 -0
  38. package/dist/deploy/cloudflare.js +111 -0
  39. package/dist/index.d.ts +13 -0
  40. package/dist/index.js +23 -0
  41. package/dist/project/build.d.ts +31 -0
  42. package/dist/project/build.js +425 -0
  43. package/dist/project/config.d.ts +33 -0
  44. package/dist/project/config.js +142 -0
  45. package/dist/project/project.d.ts +74 -0
  46. package/dist/project/project.js +555 -0
  47. package/dist/runtime/index.d.ts +68 -0
  48. package/dist/runtime/index.js +912 -0
  49. package/dist/server/client.d.ts +1 -0
  50. package/dist/server/client.js +112 -0
  51. package/dist/server/dev.d.ts +8 -0
  52. package/dist/server/dev.js +244 -0
  53. package/dist/server/preview.d.ts +6 -0
  54. package/dist/server/preview.js +106 -0
  55. package/dist/server/static.d.ts +10 -0
  56. package/dist/server/static.js +136 -0
  57. package/lib/ui/index.sinth +436 -0
  58. package/package.json +33 -15
  59. package/schema/sinth.config.schema.json +54 -0
  60. package/dist/browser/compile.js +0 -63
  61. package/dist/cli.js +0 -509
  62. package/dist/core/builtins.js +0 -117
  63. package/dist/core/cli-compiler.js +0 -705
  64. package/dist/core/compiler.js +0 -1489
  65. package/dist/core/expr.js +0 -129
  66. package/dist/core/head-builder.js +0 -130
  67. package/dist/core/lexer.js +0 -410
  68. package/dist/core/parser.js +0 -1646
  69. package/dist/core/runtime/custom-element.js +0 -81
  70. package/dist/core/runtime/functions.js +0 -99
  71. package/dist/core/runtime/helpers.js +0 -347
  72. package/dist/core/runtime/render.js +0 -136
  73. package/dist/core/style-processor.js +0 -317
  74. package/dist/core/types.js +0 -93
  75. package/dist/resolver.js +0 -175
  76. package/dist/server.js +0 -174
  77. package/dist/update-check.js +0 -109
  78. package/dist/utils.js +0 -80
@@ -0,0 +1,437 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.main = main;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const readline = __importStar(require("readline"));
40
+ const diagnostics_1 = require("../compiler/diagnostics");
41
+ const build_1 = require("../project/build");
42
+ const config_1 = require("../project/config");
43
+ const project_1 = require("../project/project");
44
+ const cloudflare_1 = require("../deploy/cloudflare");
45
+ const dev_1 = require("../server/dev");
46
+ const preview_1 = require("../server/preview");
47
+ const args_1 = require("./args");
48
+ const templates_1 = require("./templates");
49
+ const ui_1 = require("./ui");
50
+ const update_check_1 = require("./update-check");
51
+ const VERSION = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf-8")).version;
52
+ const ROOT_FLAG = {
53
+ root: { type: "string", description: "Project root (default: current directory)" },
54
+ };
55
+ function projectRoot(args) {
56
+ return path.resolve(String(args.flags.root ?? process.cwd()));
57
+ }
58
+ function openProject(args, mode) {
59
+ const root = projectRoot(args);
60
+ (0, diagnostics_1.setDisplayRoot)(root);
61
+ const { config, warnings } = (0, config_1.loadConfig)(root, mode);
62
+ for (const w of warnings)
63
+ ui_1.log.warn(w);
64
+ if (typeof args.flags.out === "string")
65
+ config.outDir = path.resolve(root, args.flags.out);
66
+ if (args.flags.minify !== undefined)
67
+ config.minify = !!args.flags.minify;
68
+ if (args.flags.sourcemap !== undefined)
69
+ config.sourcemap = !!args.flags.sourcemap;
70
+ return new project_1.Project(root, config, mode === "development");
71
+ }
72
+ const commands = {
73
+ dev: {
74
+ summary: "Start the dev server with hot reload",
75
+ usage: "sinth dev [--port 3000] [--host [address]] [--open]",
76
+ flags: {
77
+ ...ROOT_FLAG,
78
+ port: { type: "number", alias: "p", description: "Port to listen on" },
79
+ host: { type: "string", description: "Expose on the network (default address 0.0.0.0)", optionalValue: "0.0.0.0" },
80
+ open: { type: "boolean", alias: "o", description: "Open the browser" },
81
+ },
82
+ async run(args) {
83
+ console.log(`\n ${(0, ui_1.brand)("dev", VERSION)}`);
84
+ const project = openProject(args, "development");
85
+ const update = (0, update_check_1.startUpdateCheck)(VERSION);
86
+ await (0, dev_1.startDevServer)(project, {
87
+ port: Number(args.flags.port ?? project.config.port),
88
+ host: String(args.flags.host ?? project.config.host),
89
+ open: !!args.flags.open,
90
+ });
91
+ setTimeout(() => {
92
+ const msg = update();
93
+ if (msg)
94
+ console.log(` ${msg}\n`);
95
+ }, 1600).unref();
96
+ return -1;
97
+ },
98
+ },
99
+ build: {
100
+ summary: "Build the site for production",
101
+ usage: "sinth build [--out dist] [--no-minify] [--sourcemap]",
102
+ flags: {
103
+ ...ROOT_FLAG,
104
+ out: { type: "string", description: "Output directory" },
105
+ minify: { type: "boolean", description: "Minify output (default: on)" },
106
+ sourcemap: { type: "boolean", description: "Emit source maps" },
107
+ verbose: { type: "boolean", description: "List every page, even on large sites" },
108
+ },
109
+ async run(args) {
110
+ console.log(`\n ${(0, ui_1.brand)("build", VERSION)}\n`);
111
+ const update = (0, update_check_1.startUpdateCheck)(VERSION);
112
+ const project = openProject(args, "production");
113
+ const out = await (0, build_1.buildProject)(project, { write: true });
114
+ for (const w of out.warnings)
115
+ (0, ui_1.printDiagnostic)(w);
116
+ const rows = [];
117
+ const LIMIT = 40;
118
+ const listed = args.flags.verbose || out.pages.length <= LIMIT ? out.pages : out.pages.slice(0, LIMIT - 10);
119
+ for (const p of listed) {
120
+ const js = p.js ? out.files.get(p.js.slice(project.config.base.length)) : undefined;
121
+ const css = p.css ? out.files.get(p.css.slice(project.config.base.length)) : undefined;
122
+ rows.push([
123
+ ui_1.c.cyan(p.page.route),
124
+ ui_1.c.gray(p.page.outFile),
125
+ (0, ui_1.formatBytes)(p.bytes),
126
+ js ? ui_1.c.yellow("js " + (0, ui_1.formatBytes)(js.contents.byteLength)) : ui_1.c.green("no js"),
127
+ css ? ui_1.c.magenta("css " + (0, ui_1.formatBytes)(css.contents.byteLength)) : "",
128
+ ]);
129
+ }
130
+ console.log((0, ui_1.table)(rows.map(r => [" " + r[0], ...r.slice(1)])));
131
+ if (listed.length < out.pages.length)
132
+ console.log(ui_1.c.gray(` ... and ${out.pages.length - listed.length} more (use --verbose to list all)`));
133
+ const total = [...out.files.values()].reduce((n, f) => n + f.contents.byteLength, 0);
134
+ console.log();
135
+ ui_1.log.success(`Built ${ui_1.c.bold(String(out.pages.length))} page(s) into ${ui_1.c.bold(path.relative(process.cwd(), project.config.outDir) || ".")} ${ui_1.c.gray(`(${out.files.size} files, ${(0, ui_1.formatBytes)(total)}) in ${(0, ui_1.formatMs)(out.durationMs)}`)}`);
136
+ const msg = update();
137
+ if (msg)
138
+ console.log(`\n ${msg}`);
139
+ return 0;
140
+ },
141
+ },
142
+ preview: {
143
+ summary: "Serve the production build locally",
144
+ usage: "sinth preview [--port 4000] [--host [address]] [--open]",
145
+ flags: {
146
+ ...ROOT_FLAG,
147
+ port: { type: "number", alias: "p", description: "Port to listen on" },
148
+ host: { type: "string", description: "Expose on the network", optionalValue: "0.0.0.0" },
149
+ open: { type: "boolean", alias: "o", description: "Open the browser" },
150
+ out: { type: "string", description: "Directory to serve (default: outDir)" },
151
+ },
152
+ async run(args) {
153
+ console.log(`\n ${(0, ui_1.brand)("preview", VERSION)}`);
154
+ const project = openProject(args, "production");
155
+ await (0, preview_1.startPreview)(project.config.outDir, {
156
+ port: Number(args.flags.port ?? project.config.previewPort),
157
+ host: String(args.flags.host ?? project.config.host),
158
+ open: !!args.flags.open,
159
+ });
160
+ return -1;
161
+ },
162
+ },
163
+ deploy: {
164
+ summary: "Build and deploy to Cloudflare Pages",
165
+ usage: "sinth deploy [--preview] [--branch name] [--project name] [--create] [--skip-build]",
166
+ flags: {
167
+ ...ROOT_FLAG,
168
+ preview: { type: "boolean", description: "Deploy to a preview URL instead of production" },
169
+ branch: { type: "string", description: "Branch name for the deployment" },
170
+ project: { type: "string", description: "Cloudflare Pages project name" },
171
+ create: { type: "boolean", description: "Create the Pages project first" },
172
+ "skip-build": { type: "boolean", description: "Deploy the existing build without rebuilding" },
173
+ },
174
+ async run(args) {
175
+ console.log(`\n ${(0, ui_1.brand)("deploy", VERSION)}\n`);
176
+ const project = openProject(args, "production");
177
+ if (!args.flags["skip-build"]) {
178
+ const out = await (0, build_1.buildProject)(project, { write: true });
179
+ for (const w of out.warnings)
180
+ (0, ui_1.printDiagnostic)(w);
181
+ ui_1.log.success(`Built ${out.pages.length} page(s) in ${(0, ui_1.formatMs)(out.durationMs)}`);
182
+ }
183
+ await (0, cloudflare_1.deployToCloudflare)(project.root, project.config.outDir, project.config, {
184
+ preview: !!args.flags.preview,
185
+ branch: args.flags.branch,
186
+ projectName: args.flags.project,
187
+ create: !!args.flags.create,
188
+ });
189
+ return 0;
190
+ },
191
+ },
192
+ check: {
193
+ summary: "Type-check every page without writing output",
194
+ usage: "sinth check [--json]",
195
+ flags: { ...ROOT_FLAG, json: { type: "boolean", description: "Print diagnostics as JSON (for editors)" } },
196
+ async run(args) {
197
+ if (args.flags.json) {
198
+ const root = projectRoot(args);
199
+ const { config } = (0, config_1.loadConfig)(root, "production");
200
+ const result = (0, build_1.checkProject)(new project_1.Project(root, config, false));
201
+ process.stdout.write(JSON.stringify({ version: 1, errors: result.errors.map(e => e.diagnostic), warnings: result.warnings }) + "\n");
202
+ return result.errors.length ? 1 : 0;
203
+ }
204
+ console.log(`\n ${(0, ui_1.brand)("check", VERSION)}\n`);
205
+ const project = openProject(args, "production");
206
+ const started = Date.now();
207
+ const result = (0, build_1.checkProject)(project);
208
+ for (const w of result.warnings)
209
+ (0, ui_1.printDiagnostic)(w);
210
+ for (const e of result.errors)
211
+ (0, ui_1.printDiagnostic)(e.diagnostic);
212
+ if (result.errors.length) {
213
+ ui_1.log.error(`${result.errors.length} error(s) in ${result.pages.length} page(s)`);
214
+ return 1;
215
+ }
216
+ ui_1.log.success(`${result.pages.length} page(s) checked, no errors${result.warnings.length ? `, ${result.warnings.length} warning(s)` : ""} ${ui_1.c.gray((0, ui_1.formatMs)(Date.now() - started))}`);
217
+ return 0;
218
+ },
219
+ },
220
+ create: {
221
+ summary: "Create a new Sinth project",
222
+ usage: "sinth create [name] [--template starter|minimal|blank] [--yes]",
223
+ flags: {
224
+ template: { type: "string", alias: "t", description: "Template: starter, minimal or blank" },
225
+ yes: { type: "boolean", alias: "y", description: "Accept defaults without prompting" },
226
+ force: { type: "boolean", description: "Write into a non-empty directory" },
227
+ },
228
+ async run(args) {
229
+ return createProject(args);
230
+ },
231
+ },
232
+ new: {
233
+ summary: "Add a page or component",
234
+ usage: "sinth new page <path> | sinth new component <Name>",
235
+ flags: { ...ROOT_FLAG },
236
+ async run(args) {
237
+ const [kind, name] = args.positionals;
238
+ const root = projectRoot(args);
239
+ if (kind === "page" && name) {
240
+ const rel = name.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.sinth$/, "");
241
+ if (!/^[a-z0-9][a-z0-9/_-]*$/i.test(rel) || rel.split("/").includes(".."))
242
+ throw new diagnostics_1.SinthError("E1300", `Invalid page path '${name}'`);
243
+ const { config } = (0, config_1.loadConfig)(root, "development");
244
+ const file = path.join(config.pagesDir, rel + ".sinth");
245
+ writeNew(file, (0, templates_1.pageTemplate)(titleCase(path.basename(rel))));
246
+ return 0;
247
+ }
248
+ if (kind === "component" && name) {
249
+ if (!/^[A-Z][A-Za-z0-9]*$/.test(name))
250
+ throw new diagnostics_1.SinthError("E1301", `Component names must be PascalCase, like 'ProductCard'`);
251
+ writeNew(path.join(root, "components", name + ".sinth"), (0, templates_1.componentTemplate)(name));
252
+ return 0;
253
+ }
254
+ throw new diagnostics_1.SinthError("E1302", "Usage: sinth new page <path> | sinth new component <Name>");
255
+ },
256
+ },
257
+ info: {
258
+ summary: "Print environment and project information",
259
+ usage: "sinth info",
260
+ flags: { ...ROOT_FLAG },
261
+ async run(args) {
262
+ const root = projectRoot(args);
263
+ const { config, file } = (0, config_1.loadConfig)(root, "production");
264
+ const project = new project_1.Project(root, config, false);
265
+ let pages;
266
+ try {
267
+ pages = project.findPages().length;
268
+ }
269
+ catch {
270
+ pages = 0;
271
+ }
272
+ console.log((0, ui_1.table)([
273
+ ["Sinth", VERSION],
274
+ ["Node.js", process.version],
275
+ ["Platform", `${process.platform} ${process.arch}`],
276
+ ["Project", root],
277
+ ["Config", file ? path.relative(root, file) : ui_1.c.gray("none (defaults)")],
278
+ ["Pages", `${pages} in ${path.relative(root, config.pagesDir) || "."}`],
279
+ ["Output", path.relative(root, config.outDir)],
280
+ ].map(([k, v]) => [ui_1.c.gray(k), v])));
281
+ return 0;
282
+ },
283
+ },
284
+ };
285
+ const ALIASES = { init: "create", serve: "preview", start: "dev", "-v": "version", "--version": "version", "-h": "help", "--help": "help" };
286
+ function titleCase(s) {
287
+ return s.replace(/[-_]+/g, " ").replace(/\b\w/g, m => m.toUpperCase());
288
+ }
289
+ function writeNew(file, contents) {
290
+ if (fs.existsSync(file))
291
+ throw new diagnostics_1.SinthError("E1303", `${path.relative(process.cwd(), file)} already exists`);
292
+ fs.mkdirSync(path.dirname(file), { recursive: true });
293
+ fs.writeFileSync(file, contents);
294
+ ui_1.log.success(`Created ${ui_1.c.cyan(path.relative(process.cwd(), file))}`);
295
+ }
296
+ function ask(rl, question, fallback) {
297
+ return new Promise(resolve => rl.question(question, answer => resolve(answer.trim() || fallback)));
298
+ }
299
+ function choose(options, initial = 0) {
300
+ return new Promise(resolve => {
301
+ let selected = initial;
302
+ const stdin = process.stdin;
303
+ const render = (first) => {
304
+ if (!first)
305
+ process.stdout.write(`\u001b[${options.length}A`);
306
+ options.forEach((o, i) => {
307
+ const active = i === selected;
308
+ process.stdout.write(`\u001b[2K ${active ? ui_1.c.violet("›") : " "} ${active ? ui_1.c.bold(o.label) : o.label} ${ui_1.c.gray(o.description)}\n`);
309
+ });
310
+ };
311
+ readline.emitKeypressEvents(stdin);
312
+ if (stdin.isTTY)
313
+ stdin.setRawMode(true);
314
+ stdin.resume();
315
+ const onKey = (_s, key) => {
316
+ if (key.ctrl && key.name === "c") {
317
+ if (stdin.isTTY)
318
+ stdin.setRawMode(false);
319
+ process.stdout.write("\n");
320
+ process.exit(130);
321
+ }
322
+ if (key.name === "up" || key.name === "k")
323
+ selected = (selected - 1 + options.length) % options.length;
324
+ else if (key.name === "down" || key.name === "j")
325
+ selected = (selected + 1) % options.length;
326
+ else if (key.name === "return") {
327
+ stdin.off("keypress", onKey);
328
+ if (stdin.isTTY)
329
+ stdin.setRawMode(false);
330
+ stdin.pause();
331
+ resolve(selected);
332
+ return;
333
+ }
334
+ else
335
+ return;
336
+ render(false);
337
+ };
338
+ stdin.on("keypress", onKey);
339
+ render(true);
340
+ });
341
+ }
342
+ async function createProject(args) {
343
+ console.log(`\n ${(0, ui_1.brand)("create", VERSION)}\n`);
344
+ const interactive = process.stdin.isTTY && !args.flags.yes;
345
+ let name = args.positionals[0];
346
+ if (!name && interactive) {
347
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
348
+ name = await ask(rl, ` ${ui_1.c.bold("Project name")} ${ui_1.c.gray("(my-site)")} `, "my-site");
349
+ rl.close();
350
+ }
351
+ name = name ?? "my-site";
352
+ const dir = path.resolve(process.cwd(), name);
353
+ const pkgName = path.basename(dir).toLowerCase().replace(/[^a-z0-9-_.]+/g, "-").replace(/^[-_.]+|[-_.]+$/g, "") || "sinth-site";
354
+ let template = args.flags.template;
355
+ if (template && !templates_1.TEMPLATES.some(t => t.name === template)) {
356
+ throw new diagnostics_1.SinthError("E1304", `Unknown template '${template}'`, undefined, `Choose one of: ${templates_1.TEMPLATES.map(t => t.name).join(", ")}`);
357
+ }
358
+ if (!template) {
359
+ if (interactive) {
360
+ console.log(`\n ${ui_1.c.bold("Template")} ${ui_1.c.gray("(use arrow keys)")}`);
361
+ template = templates_1.TEMPLATES[await choose(templates_1.TEMPLATES.map(t => ({ label: t.label.padEnd(8), description: t.description })))].name;
362
+ }
363
+ else
364
+ template = "starter";
365
+ }
366
+ if (fs.existsSync(dir) && fs.readdirSync(dir).length && !args.flags.force) {
367
+ throw new diagnostics_1.SinthError("E1305", `Directory '${name}' is not empty`, undefined, "Choose another name or pass --force");
368
+ }
369
+ const files = (0, templates_1.templateFiles)(template, pkgName, VERSION);
370
+ for (const [rel, contents] of Object.entries(files)) {
371
+ const full = path.join(dir, rel);
372
+ fs.mkdirSync(path.dirname(full), { recursive: true });
373
+ fs.writeFileSync(full, contents);
374
+ }
375
+ console.log();
376
+ ui_1.log.success(`Created ${ui_1.c.bold(pkgName)} ${ui_1.c.gray(`(${template})`)} in ${ui_1.c.cyan(path.relative(process.cwd(), dir) || ".")}`);
377
+ console.log(`\n ${ui_1.c.bold("Next steps")}\n`);
378
+ if (path.relative(process.cwd(), dir))
379
+ console.log(` cd ${path.relative(process.cwd(), dir)}`);
380
+ console.log(" npm install");
381
+ console.log(` ${ui_1.c.cyan("npm run dev")}\n`);
382
+ return 0;
383
+ }
384
+ function printHelp(command) {
385
+ if (command && commands[command]) {
386
+ const cmd = commands[command];
387
+ console.log(`\n ${ui_1.c.bold(cmd.summary)}\n\n ${ui_1.c.gray("Usage:")} ${cmd.usage}\n`);
388
+ const rows = Object.entries(cmd.flags).map(([n, f]) => [` --${n}${f.alias ? `, -${f.alias}` : ""}`, ui_1.c.gray(f.description)]);
389
+ if (rows.length)
390
+ console.log((0, ui_1.table)(rows) + "\n");
391
+ return;
392
+ }
393
+ console.log(`\n ${(0, ui_1.brand)("", VERSION)}\n\n ${ui_1.c.gray("Usage:")} sinth <command> [options]\n`);
394
+ console.log((0, ui_1.table)(Object.entries(commands).map(([n, cmd]) => [` ${ui_1.c.cyan(n)}`, cmd.summary])));
395
+ console.log(`\n ${ui_1.c.gray("Run")} sinth help <command> ${ui_1.c.gray("for details. Docs:")} ${ui_1.c.underline("https://sinth.yannosay.com")}\n`);
396
+ }
397
+ async function main(argv) {
398
+ const [first, ...rest] = argv;
399
+ const name = ALIASES[first] ?? first;
400
+ if (!name || name === "help") {
401
+ printHelp(rest[0]);
402
+ return;
403
+ }
404
+ if (name === "version") {
405
+ console.log(VERSION);
406
+ return;
407
+ }
408
+ const cmd = commands[name];
409
+ if (!cmd) {
410
+ const near = Object.keys(commands).find(k => k.startsWith(name.slice(0, 2)));
411
+ ui_1.log.error(`Unknown command '${name}'${near ? `. Did you mean '${near}'?` : ""}`);
412
+ printHelp();
413
+ process.exitCode = 1;
414
+ return;
415
+ }
416
+ try {
417
+ if (rest.includes("--help") || rest.includes("-h")) {
418
+ printHelp(name);
419
+ return;
420
+ }
421
+ const code = await cmd.run((0, args_1.parseArgs)(rest, cmd.flags));
422
+ if (code >= 0)
423
+ process.exitCode = code;
424
+ }
425
+ catch (err) {
426
+ if (err instanceof diagnostics_1.SinthError) {
427
+ (0, ui_1.printDiagnostic)(err.diagnostic);
428
+ process.exitCode = 1;
429
+ return;
430
+ }
431
+ ui_1.log.error(err.stack ?? String(err));
432
+ process.exitCode = 1;
433
+ }
434
+ }
435
+ if (require.main === module) {
436
+ void main(process.argv.slice(2));
437
+ }
@@ -0,0 +1,10 @@
1
+ export type TemplateName = "starter" | "minimal" | "blank";
2
+ export interface TemplateInfo {
3
+ name: TemplateName;
4
+ label: string;
5
+ description: string;
6
+ }
7
+ export declare const TEMPLATES: TemplateInfo[];
8
+ export declare function templateFiles(template: TemplateName, name: string, version: string): Record<string, string>;
9
+ export declare function pageTemplate(title: string): string;
10
+ export declare function componentTemplate(name: string): string;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TEMPLATES = void 0;
4
+ exports.templateFiles = templateFiles;
5
+ exports.pageTemplate = pageTemplate;
6
+ exports.componentTemplate = componentTemplate;
7
+ exports.TEMPLATES = [
8
+ { name: "starter", label: "Starter", description: "Two pages, a layout component and the sinth:ui library" },
9
+ { name: "minimal", label: "Minimal", description: "One page with a counter, nothing else" },
10
+ { name: "blank", label: "Blank", description: "Config and folders only" },
11
+ ];
12
+ function templateFiles(template, name, version) {
13
+ const files = {
14
+ "sinth.config.json": JSON.stringify({
15
+ $schema: "./node_modules/@yannosay/sinth/schema/sinth.config.schema.json",
16
+ outDir: "dist",
17
+ pagesDir: "pages",
18
+ cloudflare: { projectName: name },
19
+ }, null, 2) + "\n",
20
+ "package.json": JSON.stringify({
21
+ name,
22
+ version: "0.1.0",
23
+ private: true,
24
+ scripts: { dev: "sinth dev", build: "sinth build", preview: "sinth preview", check: "sinth check", deploy: "sinth deploy" },
25
+ devDependencies: { "@yannosay/sinth": `^${version.replace(/-.*$/, "")}` },
26
+ }, null, 2) + "\n",
27
+ ".gitignore": "node_modules/\ndist/\n.sinth/\n.wrangler/\n",
28
+ "README.md": `# ${name}\n\nBuilt with [Sinth](https://sinth.yannosay.com).\n\n\`\`\`bash\nnpm install\nnpm run dev # http://localhost:3000\nnpm run build # production build in dist/\nnpm run deploy # deploy to Cloudflare Pages\n\`\`\`\n`,
29
+ "public/robots.txt": "User-agent: *\nAllow: /\n",
30
+ };
31
+ if (template === "blank") {
32
+ files["pages/.gitkeep"] = "";
33
+ files["components/.gitkeep"] = "";
34
+ return files;
35
+ }
36
+ if (template === "minimal") {
37
+ files["pages/index.sinth"] = `title = "${name}"
38
+ descr = "A Sinth site."
39
+
40
+ var num count = 0
41
+
42
+ Main {
43
+ Heading(level: 1) { "Hello, Sinth!" }
44
+ Paragraph { "Edit pages/index.sinth and save. The page updates instantly." }
45
+ Button(onClick: count += 1) { "Clicked " + count + (count == 1 ? " time" : " times") }
46
+ }
47
+
48
+ style {
49
+ main {
50
+ maxWidth: "40rem"
51
+ margin: "4rem auto"
52
+ padding: "0 1.25rem"
53
+ fontFamily: "system-ui, sans-serif"
54
+ }
55
+ button {
56
+ font: "inherit"
57
+ padding: "0.6rem 1.1rem"
58
+ borderRadius: "8px"
59
+ border: "1px solid #d4d4d8"
60
+ cursor: "pointer"
61
+ }
62
+ }
63
+ `;
64
+ return files;
65
+ }
66
+ files["components/Layout.sinth"] = `import { Navbar, Content } from "sinth:ui"
67
+
68
+ component Layout(str current = "/") {
69
+ Navbar(brand: "${name}") {
70
+ NavLink(href: "/", ariaCurrent: current == "/" ? "page" : null) { "Home" }
71
+ NavLink(href: "/about", ariaCurrent: current == "/about" ? "page" : null) { "About" }
72
+ }
73
+ Main {
74
+ Content {
75
+ $slot
76
+ }
77
+ }
78
+ Footer(class: "site-footer") {
79
+ Content {
80
+ Small { "© " + new Date().getFullYear() + " ${name}. Built with Sinth." }
81
+ }
82
+ }
83
+
84
+ style {
85
+ main { padding: "3rem 0" }
86
+ .site-footer {
87
+ borderTop: "1px solid var(--ui-border)"
88
+ padding: "1.5rem 0"
89
+ color: "var(--ui-muted)"
90
+ }
91
+ }
92
+ }
93
+ `;
94
+ files["pages/index.sinth"] = `import { Layout } from "../components/Layout.sinth"
95
+ import { Button, Card, Columns, Field, Badge, Alert } from "sinth:ui"
96
+
97
+ title = "${name}"
98
+ descr = "A fast website built with Sinth."
99
+
100
+ var num count = 0
101
+ var str name = ""
102
+ var str[] features = ["Reactive by default", "Zero-config builds", "Deploy anywhere"]
103
+
104
+ computed str greeting = name.trim() ? "Hello, " + name.trim() + "!" : "Hello, stranger!"
105
+
106
+ Layout(current: "/") {
107
+ Badge(tone: "accent") { "Sinth ${version}" }
108
+ Heading(level: 1) { greeting }
109
+ Paragraph(class: "lead") { "Edit pages/index.sinth and save. Your changes appear instantly, state included." }
110
+
111
+ Columns(min: "15rem") {
112
+ Card(title: "Counter") {
113
+ Paragraph { "You clicked " + count + (count == 1 ? " time." : " times.") }
114
+ Button(onClick: count += 1) { "Click me" }
115
+ }
116
+ Card(title: "Two-way binding") {
117
+ Field(label: "Your name", value: name, placeholder: "Ada Lovelace")
118
+ }
119
+ }
120
+
121
+ Heading(level: 2) { "Why Sinth?" }
122
+ Ul {
123
+ for feature in features {
124
+ Li { feature }
125
+ }
126
+ }
127
+
128
+ if count >= 10 {
129
+ Alert(tone: "success", title: "Nice!") { "You clicked ten times. State survives hot reloads too." }
130
+ }
131
+ }
132
+
133
+ style {
134
+ .lead {
135
+ fontSize: "1.15rem"
136
+ color: "var(--ui-muted)"
137
+ maxWidth: "40rem"
138
+ }
139
+ }
140
+ `;
141
+ files["pages/about.sinth"] = `page
142
+
143
+ import { Layout } from "../components/Layout.sinth"
144
+
145
+ title = "About | ${name}"
146
+ descr = "About this site."
147
+
148
+ Layout(current: "/about") {
149
+ Heading(level: 1) { "About" }
150
+ Paragraph { "This page is static, so Sinth ships it without any JavaScript." }
151
+ }
152
+ `;
153
+ files["pages/404.sinth"] = `page
154
+
155
+ import { Layout } from "../components/Layout.sinth"
156
+ import { Button } from "sinth:ui"
157
+
158
+ title = "Page not found"
159
+ robots = "noindex"
160
+
161
+ Layout {
162
+ Heading(level: 1) { "Page not found" }
163
+ Paragraph { "The page you are looking for does not exist." }
164
+ Button(href: "/") { "Back home" }
165
+ }
166
+ `;
167
+ return files;
168
+ }
169
+ function pageTemplate(title) {
170
+ return `title = "${title}"
171
+
172
+ Main {
173
+ Heading(level: 1) { "${title}" }
174
+ }
175
+ `;
176
+ }
177
+ function componentTemplate(name) {
178
+ const cls = name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
179
+ return `component ${name}(str title = "${name}") {
180
+ Div(class: "${cls}") {
181
+ Heading(level: 3) { title }
182
+ $slot
183
+ }
184
+
185
+ style {
186
+ .${cls} {
187
+ padding: "1rem"
188
+ borderRadius: "12px"
189
+ }
190
+ }
191
+ }
192
+ `;
193
+ }
@@ -0,0 +1,28 @@
1
+ import { Diagnostic } from "../compiler/diagnostics";
2
+ export declare const c: {
3
+ bold: (s: string) => string;
4
+ dim: (s: string) => string;
5
+ red: (s: string) => string;
6
+ green: (s: string) => string;
7
+ yellow: (s: string) => string;
8
+ blue: (s: string) => string;
9
+ magenta: (s: string) => string;
10
+ cyan: (s: string) => string;
11
+ gray: (s: string) => string;
12
+ violet: (s: string) => string;
13
+ underline: (s: string) => string;
14
+ };
15
+ export declare const colorEnabled: boolean;
16
+ export declare function brand(label: string, version: string): string;
17
+ export declare const log: {
18
+ info: (msg: string) => void;
19
+ success: (msg: string) => void;
20
+ warn: (msg: string) => void;
21
+ error: (msg: string) => void;
22
+ step: (msg: string) => void;
23
+ blank: () => void;
24
+ };
25
+ export declare function printDiagnostic(d: Diagnostic): void;
26
+ export declare function formatBytes(bytes: number): string;
27
+ export declare function formatMs(ms: number): string;
28
+ export declare function table(rows: string[][], gap?: number): string;