@constela/cli 0.3.8 → 0.3.10

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 (3) hide show
  1. package/README.md +177 -0
  2. package/dist/index.js +39 -11
  3. package/package.json +3 -3
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @constela/cli
2
+
3
+ Command-line tools for the Constela UI framework.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @constela/cli
9
+ ```
10
+
11
+ Or use with npx:
12
+
13
+ ```bash
14
+ npx constela <command>
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### constela compile
20
+
21
+ Compiles a Constela DSL file to a program.
22
+
23
+ ```bash
24
+ constela compile <input> [options]
25
+ ```
26
+
27
+ **Arguments:**
28
+ - `<input>` - Input DSL file (JSON)
29
+
30
+ **Options:**
31
+ - `-o, --out <path>` - Output file path
32
+ - `--pretty` - Pretty-print JSON output
33
+
34
+ **Examples:**
35
+
36
+ ```bash
37
+ # Compile to stdout
38
+ constela compile app.json
39
+
40
+ # Compile to file
41
+ constela compile app.json --out dist/app.compiled.json
42
+
43
+ # Pretty-print output
44
+ constela compile app.json --pretty
45
+ ```
46
+
47
+ ### constela dev
48
+
49
+ Starts the development server with hot reload.
50
+
51
+ ```bash
52
+ constela dev [options]
53
+ ```
54
+
55
+ **Options:**
56
+ - `-p, --port <number>` - Server port (default: 3000)
57
+ - `--host <string>` - Server host (default: localhost)
58
+
59
+ **Examples:**
60
+
61
+ ```bash
62
+ # Default settings
63
+ constela dev
64
+
65
+ # Custom port
66
+ constela dev --port 8080
67
+
68
+ # Accessible from network
69
+ constela dev --host 0.0.0.0
70
+ ```
71
+
72
+ ### constela build
73
+
74
+ Builds the application for production.
75
+
76
+ ```bash
77
+ constela build [options]
78
+ ```
79
+
80
+ **Options:**
81
+ - `-o, --outDir <path>` - Output directory (default: dist)
82
+
83
+ **Examples:**
84
+
85
+ ```bash
86
+ # Default output to dist/
87
+ constela build
88
+
89
+ # Custom output directory
90
+ constela build --outDir build
91
+ ```
92
+
93
+ **Output:**
94
+ - Static HTML files for each route
95
+ - Bundled runtime JavaScript
96
+ - Copied public assets
97
+
98
+ ### constela start
99
+
100
+ Starts the production server.
101
+
102
+ ```bash
103
+ constela start [options]
104
+ ```
105
+
106
+ **Options:**
107
+ - `-p, --port <number>` - Server port (default: 3000)
108
+
109
+ **Examples:**
110
+
111
+ ```bash
112
+ # Default settings
113
+ constela start
114
+
115
+ # Custom port
116
+ constela start --port 8080
117
+ ```
118
+
119
+ The server binds to `0.0.0.0` by default for deployment compatibility.
120
+
121
+ ## Project Structure
122
+
123
+ The CLI expects the following project structure:
124
+
125
+ ```
126
+ project/
127
+ src/
128
+ pages/ # Page files (.json, .ts)
129
+ index.json # / route
130
+ about.json # /about route
131
+ users/
132
+ [id].json # /users/:id route
133
+ layouts/ # Layout files (optional)
134
+ default.json
135
+ docs.json
136
+ public/ # Static assets
137
+ styles/
138
+ images/
139
+ content/ # Content files (optional)
140
+ blog/
141
+ *.mdx
142
+ ```
143
+
144
+ ## Configuration
145
+
146
+ Create a `constela.config.ts` file in your project root:
147
+
148
+ ```typescript
149
+ import type { ConstelaConfig } from '@constela/start';
150
+
151
+ export default {
152
+ adapter: 'node', // 'cloudflare' | 'vercel' | 'deno' | 'node'
153
+ ssg: {
154
+ routes: ['/about', '/contact'],
155
+ },
156
+ } satisfies ConstelaConfig;
157
+ ```
158
+
159
+ ## Exit Codes
160
+
161
+ | Code | Description |
162
+ |------|-------------|
163
+ | 0 | Success |
164
+ | 1 | Compilation error |
165
+ | 1 | Server startup failed |
166
+ | 1 | Build failed |
167
+
168
+ ## Signals
169
+
170
+ The `start` command handles graceful shutdown:
171
+
172
+ - `SIGINT` (Ctrl+C) - Graceful shutdown
173
+ - `SIGTERM` - Graceful shutdown
174
+
175
+ ## License
176
+
177
+ MIT
package/dist/index.js CHANGED
@@ -80,18 +80,34 @@ async function compileCommand(inputPath, options) {
80
80
  }
81
81
 
82
82
  // src/commands/dev.ts
83
- import { createDevServer } from "@constela/start";
83
+ import { createDevServer, loadConfig, resolveConfig } from "@constela/start";
84
84
  async function devCommand(options) {
85
- const port = options.port ? parseInt(options.port, 10) : 3e3;
86
- if (Number.isNaN(port)) {
85
+ const port = options.port ? parseInt(options.port, 10) : void 0;
86
+ if (options.port !== void 0 && Number.isNaN(port)) {
87
87
  console.error("Error: Invalid port number");
88
88
  process.exit(1);
89
89
  }
90
- const host = options.host ?? "localhost";
91
90
  try {
92
- const server = await createDevServer({ port, host });
91
+ const fileConfig = await loadConfig(process.cwd());
92
+ const resolvedConfig = await resolveConfig(fileConfig, {
93
+ port,
94
+ host: options.host,
95
+ routesDir: options.routesDir,
96
+ publicDir: options.publicDir,
97
+ layoutsDir: options.layoutsDir
98
+ });
99
+ const serverPort = resolvedConfig.dev?.port ?? port ?? 3e3;
100
+ const serverHost = resolvedConfig.dev?.host ?? options.host ?? "localhost";
101
+ const server = await createDevServer({
102
+ port: serverPort,
103
+ host: serverHost,
104
+ ...resolvedConfig.routesDir && { routesDir: resolvedConfig.routesDir },
105
+ ...resolvedConfig.publicDir && { publicDir: resolvedConfig.publicDir },
106
+ ...resolvedConfig.layoutsDir && { layoutsDir: resolvedConfig.layoutsDir },
107
+ ...resolvedConfig.css && { css: resolvedConfig.css }
108
+ });
93
109
  await server.listen();
94
- console.log(`Development server running at http://${host}:${server.port}`);
110
+ console.log(`Development server running at http://${serverHost}:${server.port}`);
95
111
  process.on("SIGINT", async () => {
96
112
  console.log("\nShutting down server...");
97
113
  await server.close();
@@ -109,12 +125,24 @@ async function devCommand(options) {
109
125
  }
110
126
 
111
127
  // src/commands/build.ts
112
- import { build } from "@constela/start";
128
+ import { build, loadConfig as loadConfig2, resolveConfig as resolveConfig2 } from "@constela/start";
113
129
  async function buildCommand(options) {
114
- const outDir = options.outDir ?? "dist";
115
130
  try {
116
131
  console.log("Building for production...");
117
- const result = await build({ outDir });
132
+ const fileConfig = await loadConfig2(process.cwd());
133
+ const resolvedConfig = await resolveConfig2(fileConfig, {
134
+ outDir: options.outDir,
135
+ routesDir: options.routesDir,
136
+ publicDir: options.publicDir,
137
+ layoutsDir: options.layoutsDir
138
+ });
139
+ const result = await build({
140
+ outDir: resolvedConfig.build?.outDir ?? options.outDir ?? "dist",
141
+ routesDir: resolvedConfig.routesDir,
142
+ publicDir: resolvedConfig.publicDir,
143
+ layoutsDir: resolvedConfig.layoutsDir,
144
+ css: resolvedConfig.css
145
+ });
118
146
  console.log("Build completed: " + result.outDir);
119
147
  if (result.routes.length > 0) {
120
148
  console.log("Routes: " + result.routes.join(", "));
@@ -158,8 +186,8 @@ async function startCommand(options) {
158
186
  var program = new Command();
159
187
  program.name("constela").description("Constela UI framework CLI").version("0.1.0");
160
188
  program.command("compile <input>").description("Compile a Constela DSL file").option("-o, --out <path>", "Output file path").option("--pretty", "Pretty-print JSON output").action(compileCommand);
161
- program.command("dev").description("Start development server").option("-p, --port <number>", "Port number (default: 3000)").option("--host <string>", "Host address").action(devCommand);
162
- program.command("build").description("Build for production").option("-o, --outDir <path>", "Output directory (default: dist)").action(buildCommand);
189
+ program.command("dev").description("Start development server").option("-p, --port <number>", "Port number (default: 3000)").option("--host <string>", "Host address").option("--routesDir <path>", "Routes directory").option("--publicDir <path>", "Public directory").option("--layoutsDir <path>", "Layouts directory").action(devCommand);
190
+ program.command("build").description("Build for production").option("-o, --outDir <path>", "Output directory (default: dist)").option("--routesDir <path>", "Routes directory").option("--publicDir <path>", "Public directory").option("--layoutsDir <path>", "Layouts directory").action(buildCommand);
163
191
  program.command("start").description("Start production server").option("-p, --port <number>", "Port number (default: 3000)").action(startCommand);
164
192
  if (process.argv.length <= 2) {
165
193
  program.outputHelp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/cli",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "CLI tools for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,9 +19,9 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "commander": "^12.0.0",
22
- "@constela/compiler": "0.7.0",
23
22
  "@constela/core": "0.7.0",
24
- "@constela/start": "1.2.1"
23
+ "@constela/compiler": "0.7.0",
24
+ "@constela/start": "1.2.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^20.10.0",