@kuratchi/js 0.0.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.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @kuratchi/js
2
+
3
+ Cloudflare Workers-native web framework with a compiler, runtime, and CLI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @kuratchi/js
9
+ ```
10
+
11
+ ## CLI
12
+
13
+ ```bash
14
+ npx kuratchi create my-app
15
+ npx kuratchi build
16
+ npx kuratchi watch
17
+ ```
18
+
19
+ ## Runtime APIs
20
+
21
+ ```ts
22
+ import { createApp, defineConfig } from '@kuratchi/js';
23
+ import { getCtx, getEnv } from '@kuratchi/js/runtime/context.js';
24
+ import { kuratchiDO, doRpc } from '@kuratchi/js/runtime/do.js';
25
+ ```
26
+
27
+
28
+
29
+
package/dist/cli.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry point — kuratchi build | watch | create
4
+ */
5
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry point — kuratchi build | watch | create
4
+ */
5
+ import { compile } from './compiler/index.js';
6
+ import * as path from 'node:path';
7
+ import * as fs from 'node:fs';
8
+ const args = process.argv.slice(2);
9
+ const command = args[0];
10
+ const projectDir = process.cwd();
11
+ switch (command) {
12
+ case 'build':
13
+ runBuild();
14
+ break;
15
+ case 'watch':
16
+ case 'dev':
17
+ runWatch();
18
+ break;
19
+ case 'create':
20
+ runCreate();
21
+ break;
22
+ default:
23
+ console.log(`
24
+ KuratchiJS CLI
25
+
26
+ Usage:
27
+ kuratchi create [name] Scaffold a new KuratchiJS project
28
+ kuratchi build Compile routes once
29
+ kuratchi watch Compile routes + watch for changes
30
+ `);
31
+ process.exit(1);
32
+ }
33
+ async function runCreate() {
34
+ const { create } = await import('./create.js');
35
+ const remaining = args.slice(1);
36
+ const flags = remaining.filter(a => a.startsWith('-'));
37
+ const positional = remaining.filter(a => !a.startsWith('-'));
38
+ await create(positional[0], flags);
39
+ }
40
+ function runBuild(isDev = false) {
41
+ console.log('[kuratchi] Compiling...');
42
+ try {
43
+ const outFile = compile({ projectDir, isDev });
44
+ console.log(`[kuratchi] Built → ${path.relative(projectDir, outFile)}`);
45
+ }
46
+ catch (err) {
47
+ console.error(`[kuratchi] Build failed: ${err.message}`);
48
+ process.exit(1);
49
+ }
50
+ }
51
+ function runWatch() {
52
+ runBuild(true);
53
+ const routesDir = path.join(projectDir, 'src', 'routes');
54
+ const layoutFile = path.join(projectDir, 'src', 'routes', 'layout.html');
55
+ const watchDirs = [routesDir].filter(d => fs.existsSync(d));
56
+ let rebuildTimeout = null;
57
+ const triggerRebuild = () => {
58
+ if (rebuildTimeout)
59
+ clearTimeout(rebuildTimeout);
60
+ rebuildTimeout = setTimeout(() => {
61
+ console.log('[kuratchi] File changed, rebuilding...');
62
+ try {
63
+ compile({ projectDir, isDev: true });
64
+ console.log('[kuratchi] Rebuilt.');
65
+ }
66
+ catch (err) {
67
+ console.error(`[kuratchi] Rebuild failed: ${err.message}`);
68
+ }
69
+ }, 100);
70
+ };
71
+ for (const dir of watchDirs) {
72
+ fs.watch(dir, { recursive: true }, triggerRebuild);
73
+ }
74
+ if (fs.existsSync(layoutFile)) {
75
+ fs.watch(layoutFile, triggerRebuild);
76
+ }
77
+ console.log('[kuratchi] Watching for changes...');
78
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Compiler — scans a project's routes/ directory, parses .html files,
3
+ * and generates a single Worker entry point.
4
+ */
5
+ export { parseFile } from './parser.js';
6
+ export { compileTemplate, generateRenderFunction } from './template.js';
7
+ export interface CompileOptions {
8
+ /** Absolute path to the project root */
9
+ projectDir: string;
10
+ /** Output file path (default: .kuratchi/worker.js) */
11
+ outFile?: string;
12
+ /** Whether this is a dev build (sets __kuratchi_DEV__ global) */
13
+ isDev?: boolean;
14
+ }
15
+ export interface CompiledRoute {
16
+ /** Route pattern (e.g., '/todos', '/blog/:slug') */
17
+ pattern: string;
18
+ /** Relative file path from routes/ (e.g., 'todos', 'blog/[slug]') */
19
+ filePath: string;
20
+ /** Whether it has a load function */
21
+ hasLoad: boolean;
22
+ /** Whether it has actions */
23
+ hasActions: boolean;
24
+ /** Whether it has RPC functions */
25
+ hasRpc: boolean;
26
+ }
27
+ /**
28
+ * Compile a project's src/routes/ into .kuratchi/routes.js
29
+ *
30
+ * The generated module exports { app } — an object with a fetch() method
31
+ * that handles routing, load functions, form actions, and rendering.
32
+ * The project's src/index.ts imports this and re-exports it as the Worker default.
33
+ */
34
+ export declare function compile(options: CompileOptions): string;