elegance-js 3.0.0 → 3.0.2
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 +90 -0
- package/bin/export.js +42 -0
- package/package.json +7 -4
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Elegance
|
|
2
|
+
|
|
3
|
+
Elegance is a TypeScript framework for web applications. It provides file‑system routing, reactive state, server‑side rendering, and client‑side interactivity in a single codebase.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Ridiculous speed: Up to ~24x faster build times compared to Next.JS, and up to ~1400x raw RPS on API Routes.
|
|
8
|
+
- Optimized: 4KB client runtime
|
|
9
|
+
- File‑system routing: pages and API endpoints are defined by the directory structure.
|
|
10
|
+
- TSX support: use TSX with no runtime overhead.
|
|
11
|
+
- Server & Client hybrid: You can write server & client-code in 1 file with no issues.
|
|
12
|
+
- Reactive: atoms and components with automatic dependency tracking.
|
|
13
|
+
- Dynamic rendering: opt into per‑request rendering or statically enumerate paths.
|
|
14
|
+
- Server Actions: Inline API routes into your page files for faster development times.
|
|
15
|
+
- Middleware: scoped request processing with the ability to pass data to downstream handlers.
|
|
16
|
+
- Built‑in bundling: code splitting and advanced dead‑code elimination (DCE).
|
|
17
|
+
- API routes: define `GET`, `POST`, `PUT`, `DELETE`, and `OPTIONS` handlers.
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx create-elegance-app my-app
|
|
23
|
+
cd my-app
|
|
24
|
+
npx elegance
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Visit `http://localhost:3000` to see the default page.
|
|
28
|
+
|
|
29
|
+
## Example
|
|
30
|
+
|
|
31
|
+
A simple counter:
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
const counter = state(0);
|
|
35
|
+
|
|
36
|
+
export default function CounterPage() {
|
|
37
|
+
return div(
|
|
38
|
+
button({
|
|
39
|
+
onClick: () => counter.value++,
|
|
40
|
+
},
|
|
41
|
+
`Counter: ${counter.value}`
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A reusable component version:
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
const Counter = component({
|
|
51
|
+
atoms: {
|
|
52
|
+
counter: 0,
|
|
53
|
+
},
|
|
54
|
+
view(_, { counter }) {
|
|
55
|
+
return button({
|
|
56
|
+
onClick: () => counter.value++,
|
|
57
|
+
},
|
|
58
|
+
`Counter: ${counter.value}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default function Page() {
|
|
64
|
+
return Counter();
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Project Structure
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
my-app/
|
|
72
|
+
├── pages/
|
|
73
|
+
│ ├── page.tsx # / (home)
|
|
74
|
+
│ ├── about/
|
|
75
|
+
│ │ └── page.tsx # /about
|
|
76
|
+
│ ├── api/
|
|
77
|
+
│ │ └── route.ts # /api/*
|
|
78
|
+
│ ├── [slug]/
|
|
79
|
+
│ │ └── page.tsx # dynamic routes
|
|
80
|
+
│ └── middleware.ts # global middleware
|
|
81
|
+
└── ...
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
Full documentation is available via [Our Website](https://elegance.js.org/)
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
package/bin/export.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn, ChildProcess } from "node:child_process";
|
|
3
|
+
import { join, dirname } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const BUILD_PROD_ENTRY = join(__dirname, "build", "prod.js");
|
|
10
|
+
|
|
11
|
+
const MODE = process.argv.includes("-prod") ? "prod" : "dev";
|
|
12
|
+
|
|
13
|
+
function spawnTs(entry, extraEnv = {}) {
|
|
14
|
+
return spawn("node", ["--import", "ts-arc/register", entry], {
|
|
15
|
+
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
16
|
+
env: {
|
|
17
|
+
...process.env,
|
|
18
|
+
ELEGANCE_DEV_MODE: MODE,
|
|
19
|
+
ARGS: JSON.stringify(process.argv.slice(2)),
|
|
20
|
+
...extraEnv,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function spawnBuild() {
|
|
26
|
+
return spawnTs(BUILD_PROD_ENTRY);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function runBuild() {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const build = spawnBuild();
|
|
32
|
+
|
|
33
|
+
build.once("exit", (code) => {
|
|
34
|
+
if (code === 0 || code === null) resolve();
|
|
35
|
+
else reject(new Error(`Build process exited with code ${code}`));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
(async () => {
|
|
41
|
+
await runBuild();
|
|
42
|
+
})();
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elegance-js",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/user-utils.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"bootstrap": "./bin/bootstrap.js",
|
|
8
|
-
"elegance": "./bin/run.js"
|
|
8
|
+
"elegance": "./bin/run.js",
|
|
9
|
+
"export": "./bin/export.js"
|
|
9
10
|
},
|
|
10
|
-
"files": [
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
11
14
|
"scripts": {
|
|
12
15
|
"lint": "oxlint ./src --fix -D unused-variable -D unused-import",
|
|
13
16
|
"build": "esbuild './src/*.ts' './src/**/*.ts' --outdir=./dist --outbase=./src --format=esm --platform=node --bundle=false && tsc --emitDeclarationOnly && node scripts/fix-imports.js"
|
|
@@ -62,4 +65,4 @@
|
|
|
62
65
|
"oxlint": "^1.68.0",
|
|
63
66
|
"typescript": "^5.0.0"
|
|
64
67
|
}
|
|
65
|
-
}
|
|
68
|
+
}
|