Skip to content

Commit 630bdde

Browse files
feat: enhance project setup with ESLint integration and configuration
1 parent a0104a5 commit 630bdde

File tree

4 files changed

+74
-3
lines changed

4 files changed

+74
-3
lines changed

src/orchestrator.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ import { setupEnv } from "./tasks/setupEnv.js";
66
import { addAuth } from "./tasks/addAuth.js";
77
import { addMulter } from "./tasks/addMulter.js";
88
import { configureScripts } from "./tasks/configureScripts.js";
9-
import { configurePackageJson } from './tasks/configurePackageJson.js';
9+
import { configurePackageJson } from "./tasks/configurePackageJson.js";
10+
import { setupESLintConfig } from "./tasks/setupESLint.js";
1011

1112
export async function orchestrateSetup() {
1213
console.log("🚀 Welcome to create-node-backend!");
1314

1415
const projectName = await askQuestion("Project name: ");
1516
const useAuth = await askQuestion("Include auth? (y/n): ");
1617
const useMulter = await askQuestion("Include Multer (file uploads)? (y/n): ");
18+
const useLint = await askQuestion("Use ESLint? (y/n): ");
1719

1820
await setupNpm(projectName);
19-
await installDependencies(useAuth, useMulter);
21+
await installDependencies(useAuth, useMulter, useLint);
2022
await setupFolderStructure(projectName);
2123
await setupEnv(projectName);
24+
2225
if (useAuth.toLowerCase() === "y") await addAuth(projectName);
2326
if (useMulter.toLowerCase() === "y") await addMulter(projectName);
27+
2428
await configureScripts(projectName);
2529
await configurePackageJson(projectName);
30+
if (useLint.toLowerCase() === "y") await setupESLintConfig(projectName);
2631

2732
console.log(`👉 Project "${projectName}" created!`);
2833
console.log(`👉 Run: cd ${projectName} && npm run dev`);

src/tasks/configurePackageJson.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export async function configurePackageJson(projectName) {
1212
packageJson.scripts = {
1313
...packageJson.scripts,
1414
dev: "nodemon src/index.js",
15+
lint: "eslint .",
16+
"lint:fix": "eslint . --fix",
1517
};
1618

1719
// Write back to package.json

src/tasks/installDependencies.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from "child_process";
22

3-
export async function installDependencies(useAuth, useMulter) {
3+
export async function installDependencies(useAuth, useMulter, useLint) {
44
console.log("📥 Installing core dependencies...");
55
execSync("npm install express dotenv", { stdio: "inherit" });
66

@@ -14,6 +14,16 @@ export async function installDependencies(useAuth, useMulter) {
1414
execSync("npm install multer", { stdio: "inherit" });
1515
}
1616

17+
console.log("📦 Installing dev dependencies...");
18+
19+
execSync("npm install --save-dev nodemon", { stdio: "inherit" });
20+
if (useLint.toLowerCase() === "y") {
21+
console.log("🔍 Installing ESLint...");
22+
execSync("npm install --save-dev eslint eslint-plugin-n eslint-plugin-promise", {
23+
stdio: "inherit",
24+
});
25+
}
26+
1727
console.log("⚙️ Installing dev dependencies...");
1828
execSync("npm install --save-dev nodemon", { stdio: "inherit" });
1929
}

src/tasks/setupESLint.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
export async function setupESLintConfig() {
5+
const eslintConfigContent = `
6+
import eslintPluginNode from 'eslint-plugin-n';
7+
import eslintPluginPromise from 'eslint-plugin-promise';
8+
9+
/** @type {import("eslint").Linter.FlatConfig} */
10+
export default [
11+
{
12+
files: ["**/*.js"],
13+
languageOptions: {
14+
ecmaVersion: "latest",
15+
sourceType: "module",
16+
},
17+
plugins: {
18+
node: eslintPluginNode,
19+
promise: eslintPluginPromise,
20+
},
21+
rules: {
22+
// Best practices
23+
"no-unused-vars": ["warn"],
24+
"no-console": "off",
25+
"eqeqeq": ["error", "always"],
26+
"curly": ["error", "all"],
27+
28+
// Style
29+
"indent": ["error", 2],
30+
"quotes": ["error", "single"],
31+
"semi": ["error", "always"],
32+
"comma-dangle": ["error", "always-multiline"],
33+
34+
// Node.js-specific
35+
"node/callback-return": "warn",
36+
"node/handle-callback-err": "warn",
37+
"node/no-mixed-requires": "warn",
38+
"node/no-new-require": "warn",
39+
40+
// Promise-specific
41+
"promise/always-return": "warn",
42+
"promise/no-return-wrap": "warn",
43+
},
44+
},
45+
];
46+
`;
47+
48+
fs.writeFileSync(
49+
path.join(process.cwd(), "eslint.config.js"),
50+
eslintConfigContent.trim()
51+
);
52+
53+
console.log("✅ ESLint v9+ configuration (eslint.config.js) created!");
54+
}

0 commit comments

Comments
 (0)