@constela/cli 0.2.4 → 0.3.0

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 (2) hide show
  1. package/dist/index.js +78 -0
  2. package/package.json +4 -3
package/dist/index.js CHANGED
@@ -79,10 +79,88 @@ async function compileCommand(inputPath, options) {
79
79
  console.log(`Compiled ${inputPath} \u2192 ${outputPath}`);
80
80
  }
81
81
 
82
+ // src/commands/dev.ts
83
+ import { createDevServer } from "@constela/start";
84
+ async function devCommand(options) {
85
+ const port = options.port ? parseInt(options.port, 10) : 3e3;
86
+ if (Number.isNaN(port)) {
87
+ console.error("Error: Invalid port number");
88
+ process.exit(1);
89
+ }
90
+ const host = options.host ?? "localhost";
91
+ try {
92
+ const server = await createDevServer({ port, host });
93
+ await server.listen();
94
+ console.log(`Development server running at http://${host}:${server.port}`);
95
+ process.on("SIGINT", async () => {
96
+ console.log("\nShutting down server...");
97
+ await server.close();
98
+ process.exit(0);
99
+ });
100
+ process.on("SIGTERM", async () => {
101
+ await server.close();
102
+ process.exit(0);
103
+ });
104
+ } catch (err) {
105
+ const error = err;
106
+ console.error(`Error: Failed to start development server - ${error.message}`);
107
+ process.exit(1);
108
+ }
109
+ }
110
+
111
+ // src/commands/build.ts
112
+ import { build } from "@constela/start";
113
+ async function buildCommand(options) {
114
+ const outDir = options.outDir ?? "dist";
115
+ try {
116
+ console.log("Building for production...");
117
+ const result = await build({ outDir });
118
+ console.log("Build completed: " + result.outDir);
119
+ if (result.routes.length > 0) {
120
+ console.log("Routes: " + result.routes.join(", "));
121
+ }
122
+ } catch (err) {
123
+ const error = err;
124
+ console.error("Error: Build failed - " + error.message);
125
+ process.exit(1);
126
+ }
127
+ }
128
+
129
+ // src/commands/start.ts
130
+ import { createDevServer as createDevServer2 } from "@constela/start";
131
+ async function startCommand(options) {
132
+ const port = options.port ? parseInt(options.port, 10) : 3e3;
133
+ if (Number.isNaN(port)) {
134
+ console.error("Error: Invalid port number");
135
+ process.exit(1);
136
+ }
137
+ try {
138
+ const server = await createDevServer2({ port, host: "0.0.0.0" });
139
+ await server.listen();
140
+ console.log(`Production server running at http://0.0.0.0:${server.port}`);
141
+ process.on("SIGINT", async () => {
142
+ console.log("\nShutting down server...");
143
+ await server.close();
144
+ process.exit(0);
145
+ });
146
+ process.on("SIGTERM", async () => {
147
+ await server.close();
148
+ process.exit(0);
149
+ });
150
+ } catch (err) {
151
+ const error = err;
152
+ console.error(`Error: Failed to start production server - ${error.message}`);
153
+ process.exit(1);
154
+ }
155
+ }
156
+
82
157
  // src/index.ts
83
158
  var program = new Command();
84
159
  program.name("constela").description("Constela UI framework CLI").version("0.1.0");
85
160
  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);
163
+ program.command("start").description("Start production server").option("-p, --port <number>", "Port number (default: 3000)").action(startCommand);
86
164
  if (process.argv.length <= 2) {
87
165
  program.outputHelp();
88
166
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/cli",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tools for Constela UI framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,8 +19,9 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "commander": "^12.0.0",
22
- "@constela/compiler": "0.4.0",
23
- "@constela/core": "0.4.0"
22
+ "@constela/core": "0.4.0",
23
+ "@constela/start": "0.2.0",
24
+ "@constela/compiler": "0.4.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^20.10.0",