@nitronjs/framework 0.1.2 → 0.1.22

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/cli/create.js +57 -14
  2. package/package.json +1 -1
package/cli/create.js CHANGED
@@ -32,6 +32,27 @@ function logStep(message, status = "pending") {
32
32
  console.log(` ${icons[status]} ${message}`);
33
33
  }
34
34
 
35
+ function startSpinner(message) {
36
+ if (!process.stdout.isTTY) {
37
+ return () => {};
38
+ }
39
+
40
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
41
+ let i = 0;
42
+ const line = () => ` ${COLORS.yellow}${frames[i]}${COLORS.reset} ${message}`;
43
+
44
+ process.stdout.write(line());
45
+ const timer = setInterval(() => {
46
+ i = (i + 1) % frames.length;
47
+ process.stdout.write(`\r${line()}`);
48
+ }, 120);
49
+
50
+ return () => {
51
+ clearInterval(timer);
52
+ process.stdout.write(`\r${" ".repeat(message.length + 4)}\r`);
53
+ };
54
+ }
55
+
35
56
  function printBanner() {
36
57
  console.log();
37
58
  log("███╗ ██╗██╗████████╗██████╗ ██████╗ ███╗ ██╗ ██╗███████╗", COLORS.cyan);
@@ -133,6 +154,11 @@ function updatePackageJson(projectPath, projectName) {
133
154
 
134
155
  function updateEnvFile(projectPath) {
135
156
  const envPath = path.join(projectPath, ".env");
157
+ const envExamplePath = path.join(projectPath, ".env.example");
158
+
159
+ if (!fs.existsSync(envPath) && fs.existsSync(envExamplePath)) {
160
+ fs.copyFileSync(envExamplePath, envPath);
161
+ }
136
162
 
137
163
  if (fs.existsSync(envPath)) {
138
164
  let content = fs.readFileSync(envPath, "utf-8");
@@ -145,19 +171,30 @@ function updateEnvFile(projectPath) {
145
171
  function runNpmInstall(projectPath) {
146
172
  return new Promise((resolve, reject) => {
147
173
  const isWindows = process.platform === "win32";
148
- const npm = isWindows ? "npm.cmd" : "npm";
174
+ const npm = isWindows ? (process.env.ComSpec || "cmd.exe") : "npm";
175
+ const npmArgs = isWindows ? ["/d", "/s", "/c", "npm", "install"] : ["install"];
149
176
 
150
- const child = spawn(npm, ["install"], {
177
+ const child = spawn(npm, npmArgs, {
151
178
  cwd: projectPath,
152
- stdio: "inherit",
153
- shell: isWindows
179
+ stdio: ["ignore", "pipe", "pipe"]
180
+ });
181
+
182
+ let output = "";
183
+ child.stdout.on("data", (data) => {
184
+ output += data.toString();
185
+ });
186
+
187
+ child.stderr.on("data", (data) => {
188
+ output += data.toString();
154
189
  });
155
190
 
156
191
  child.on("close", (code) => {
157
192
  if (code === 0) {
158
193
  resolve();
159
194
  } else {
160
- reject(new Error(`npm install failed with code ${code}`));
195
+ const error = new Error(`npm install failed with code ${code}`);
196
+ error.output = output.trim();
197
+ reject(error);
161
198
  }
162
199
  });
163
200
 
@@ -180,19 +217,19 @@ function printSuccess(projectName) {
180
217
  console.log();
181
218
  log(` ${COLORS.dim}1.${COLORS.reset} ${COLORS.cyan}cd ${projectName}${COLORS.reset}`);
182
219
  log(` ${COLORS.dim}2.${COLORS.reset} Configure your ${COLORS.yellow}.env${COLORS.reset} file`);
183
- log(` ${COLORS.dim}3.${COLORS.reset} ${COLORS.cyan}njs migrate${COLORS.reset}`);
184
- log(` ${COLORS.dim}4.${COLORS.reset} ${COLORS.cyan}njs dev${COLORS.reset}`);
220
+ log(` ${COLORS.dim}3.${COLORS.reset} ${COLORS.cyan}npm run migrate${COLORS.reset}`);
221
+ log(` ${COLORS.dim}4.${COLORS.reset} ${COLORS.cyan}npm run dev${COLORS.reset}`);
185
222
  console.log();
186
223
 
187
224
  log(`${COLORS.bold}Useful commands:${COLORS.reset}`);
188
225
  console.log();
189
- log(` ${COLORS.cyan}njs dev${COLORS.reset} ${COLORS.dim}Start development server${COLORS.reset}`);
190
- log(` ${COLORS.cyan}njs build${COLORS.reset} ${COLORS.dim}Build for production${COLORS.reset}`);
191
- log(` ${COLORS.cyan}njs start${COLORS.reset} ${COLORS.dim}Start production server${COLORS.reset}`);
192
- log(` ${COLORS.cyan}njs migrate${COLORS.reset} ${COLORS.dim}Run database migrations${COLORS.reset}`);
193
- log(` ${COLORS.cyan}njs seed${COLORS.reset} ${COLORS.dim}Run database seeders${COLORS.reset}`);
194
- log(` ${COLORS.cyan}njs make:controller${COLORS.reset} ${COLORS.dim}Create a new controller${COLORS.reset}`);
195
- log(` ${COLORS.cyan}njs make:model${COLORS.reset} ${COLORS.dim}Create a new model${COLORS.reset}`);
226
+ log(` ${COLORS.cyan}npm run dev${COLORS.reset} ${COLORS.dim}Start development server${COLORS.reset}`);
227
+ log(` ${COLORS.cyan}npm run build${COLORS.reset} ${COLORS.dim}Build for production${COLORS.reset}`);
228
+ log(` ${COLORS.cyan}npm run start${COLORS.reset} ${COLORS.dim}Start production server${COLORS.reset}`);
229
+ log(` ${COLORS.cyan}npm run migrate${COLORS.reset} ${COLORS.dim}Run database migrations${COLORS.reset}`);
230
+ log(` ${COLORS.cyan}npm run seed${COLORS.reset} ${COLORS.dim}Run database seeders${COLORS.reset}`);
231
+ log(` ${COLORS.cyan}npm run make:controller${COLORS.reset} ${COLORS.dim}Create a new controller${COLORS.reset}`);
232
+ log(` ${COLORS.cyan}npm run make:model${COLORS.reset} ${COLORS.dim}Create a new model${COLORS.reset}`);
196
233
  console.log();
197
234
 
198
235
  log(`${COLORS.dim}Documentation: https://nitronjs.dev/docs${COLORS.reset}`);
@@ -246,11 +283,17 @@ export default async function create(projectName, options = {}) {
246
283
  logStep("APP_KEY generated", "success");
247
284
 
248
285
  logStep("Installing dependencies (this may take a moment)...", "running");
286
+ const stopSpinner = startSpinner("Installing dependencies...");
249
287
  try {
250
288
  await runNpmInstall(projectPath);
289
+ stopSpinner();
251
290
  logStep("Dependencies installed", "success");
252
291
  } catch (error) {
292
+ stopSpinner();
253
293
  logStep("Failed to install dependencies", "error");
294
+ if (error.output) {
295
+ log(`${COLORS.dim}${error.output}${COLORS.reset}`);
296
+ }
254
297
  log(`${COLORS.yellow}Please run 'npm install' manually in the project directory${COLORS.reset}`);
255
298
  }
256
299
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitronjs/framework",
3
- "version": "0.1.2",
3
+ "version": "0.1.22",
4
4
  "description": "NitronJS is a modern and extensible Node.js MVC framework built on Fastify. It focuses on clean architecture, modular structure, and developer productivity, offering built-in routing, middleware, configuration management, CLI tooling, and native React integration for scalable full-stack applications.",
5
5
  "bin": {
6
6
  "njs": "./cli/njs.js"