@ifecodes/backend-template 1.0.0 → 1.0.7

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/bin/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import { execSync } from "child_process";
@@ -205,12 +205,26 @@ if (!isInMicroserviceProject) {
205
205
  // Install husky and setup at root level
206
206
  if (config.projectType === "microservice") {
207
207
  console.log("\n📦 Installing Husky at root level...\n");
208
- execSync("npm install", { cwd: target, stdio: "inherit" });
209
- console.log("\n🔧 Setting up Husky...\n");
210
- execSync("npm run prepare", { cwd: target, stdio: "inherit" });
208
+ try {
209
+ execSync("npm install", { cwd: target, stdio: "inherit" });
210
+ console.log("\n🔧 Setting up Husky...\n");
211
+ execSync("npm run prepare", { cwd: target, stdio: "inherit" });
212
+ } catch (error) {
213
+ console.log("\n⚠️ Husky setup skipped (dependencies not installed)\n");
214
+ }
211
215
  } else if (config.projectType === "monolith") {
212
- console.log("\n🔧 Setting up Husky...\n");
213
- execSync("npm run prepare", { cwd: target, stdio: "inherit" });
216
+ // Only setup Husky if node_modules exists (dependencies installed successfully)
217
+ const nodeModulesPath = path.join(target, "node_modules");
218
+ if (fs.existsSync(nodeModulesPath)) {
219
+ console.log("\n🔧 Setting up Husky...\n");
220
+ try {
221
+ execSync("npm run prepare", { cwd: target, stdio: "inherit" });
222
+ } catch (error) {
223
+ console.log("\n⚠️ Husky setup failed (run 'npm run prepare' manually after fixing dependencies)\n");
224
+ }
225
+ } else {
226
+ console.log("\n⚠️ Husky setup skipped (run 'npm install && npm run prepare' to set up git hooks)\n");
227
+ }
214
228
  }
215
229
  }
216
230
 
@@ -118,13 +118,6 @@ export const setupService = async (
118
118
  const appPath = path.join(serviceRoot, "src/app.ts");
119
119
  let content = fs.readFileSync(appPath, "utf8");
120
120
  content = content.replace("/*__IMPORTS__*/", imports.join("\n"));
121
- // import env if cors is selected
122
- if (res.features && res.features.includes("cors")) {
123
- envContent = envContent.replace(
124
- "/*__ENV_CORS__*/",
125
- "import { ENV } from '@/config';"
126
- );
127
- }
128
121
  content = content.replace("/*__MIDDLEWARE__*/", middlewares.join("\n"));
129
122
  fs.writeFileSync(appPath, content);
130
123
 
@@ -176,6 +169,18 @@ export const setupService = async (
176
169
  if (fs.existsSync(envPath)) {
177
170
  let envContent = fs.readFileSync(envPath, "utf8");
178
171
 
172
+ // Import ENV in app.ts if CORS is selected
173
+ if (res.features && res.features.includes("cors")) {
174
+ let appContent = fs.readFileSync(appPath, "utf8");
175
+ if (!appContent.includes("import { ENV } from")) {
176
+ appContent = appContent.replace(
177
+ "/*__IMPORTS__*/",
178
+ "import { ENV } from '@/config';\n/*__IMPORTS__*/"
179
+ );
180
+ fs.writeFileSync(appPath, appContent);
181
+ }
182
+ }
183
+
179
184
  // Add ALLOWED_ORIGIN if CORS is selected
180
185
  if (res.features && res.features.includes("cors")) {
181
186
  envContent = envContent.replace(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ifecodes/backend-template",
3
- "version": "1.0.0",
3
+ "version": "1.0.7",
4
4
  "description": "Production-ready Express + TypeScript backend generator with optional features and microservice support",
5
5
  "bin": {
6
6
  "ifecodes-template": "bin/cli.js"
@@ -1,6 +1,5 @@
1
1
  import express from "express";
2
2
  /*__IMPORTS__*/
3
- /*__ENV_CORS__*/
4
3
 
5
4
  const app = express();
6
5