Skip to content

Commit af963f0

Browse files
Merge pull request #8 from n8bird-oss/feature/lint-format
Added lint and format to the main codebase
2 parents dc1d44c + 4a7e305 commit af963f0

10 files changed

Lines changed: 1615 additions & 437 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '18'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run linting
26+
run: npm run lint
27+
28+
- name: Run formatting check
29+
run: npm run format -- --check

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ node_modules/
33
npm-debug.log
44
yarn-debug.log
55
yarn-error.log
6-
package-lock.json
76
.pnpm-debug.log
87

8+
# Package manager lockfiles (keep package-lock.json, ignore others)
9+
yarn.lock
10+
pnpm-lock.yaml
11+
.pnpm-store/
12+
913
# Bun
1014
.pnpm/
1115
bun.lockb

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"tabWidth": 2,
6+
"printWidth": 80
7+
}

CONTRIBUTING.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ We welcome contributions to the Backend-Starter-CLI project! Whether it's fixing
55
## How to Contribute
66

77
1. **Fork the Repository**
8-
98
- Navigate to the [Backend-Starter-CLI repository](https://github.com/abdullah4tech/backend-starter-cli) and click the "Fork" button.
109

1110
2. **Clone Your Fork**
12-
1311
- Clone your forked repository to your local machine:
1412
```bash
1513
git clone https://github.com/<your-username>/backend-starter-cli.git
1614
```
1715

1816
3. **Set Up the Project**
19-
2017
- Install dependencies:
2118
```bash
2219
npm install
@@ -27,26 +24,22 @@ We welcome contributions to the Backend-Starter-CLI project! Whether it's fixing
2724
```
2825

2926
4. **Create a Branch**
30-
3127
- Create a new branch for your contribution:
3228
```bash
3329
git checkout -b feature/your-feature-name
3430
```
3531

3632
5. **Make Changes**
37-
3833
- Implement your changes, adhering to the project's coding standards.
3934
- If you're fixing a bug or adding a feature, write tests to ensure your changes work as expected.
4035

4136
6. **Run Tests**
42-
4337
- Verify your changes by running the test suite:
4438
```bash
4539
npm test
4640
```
4741

4842
7. **Commit Your Changes**
49-
5043
- Write clear and concise commit messages following the format:
5144
```bash
5245
feat: add feature description
@@ -59,14 +52,12 @@ We welcome contributions to the Backend-Starter-CLI project! Whether it's fixing
5952
```
6053

6154
8. **Push Your Branch**
62-
6355
- Push your changes to your forked repository:
6456
```bash
6557
git push origin feature/your-feature-name
6658
```
6759

6860
9. **Submit a Pull Request**
69-
7061
- Navigate to the original [Backend-Starter-CLI repository](https://github.com/abdullah4tech/backend-starter-cli) and click on "New Pull Request."
7162
- Provide a detailed description of your changes and link to any relevant issues.
7263

@@ -89,7 +80,6 @@ If you encounter a bug or have a feature request, please [open an issue](https:/
8980
Feel free to reach out for help or discussions:
9081
9182
- Email: abdullahmu4life@gmail.com
92-
- Twitter: [abdullah4tech_](https://twitter.com/Abdullah's) X account handle
83+
- Twitter: [abdullah4tech\_](https://twitter.com/Abdullah's) X account handle
9384

9485
Thank you for contributing to Backend-Starter-CLI! Your efforts help make this project better for everyone.
95-

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ To use the `backend-starter` CLI, first ensure you have [Node.js](https://nodejs
2828
### Global Installation
2929

3030
Install the package globally using npm:
31+
3132
```bash
3233
npm install -g backend-starter-cli
3334
```
3435

3536
Now you can use the CLI anywhere with:
37+
3638
```bash
3739
backend-starter-cli
3840
```
3941

4042
### One-Time Use with NPX
4143

4244
Alternatively, you can use it without installation via npx:
45+
4346
```bash
4447
npx backend-starter-cli
4548
```
@@ -51,11 +54,13 @@ npx backend-starter-cli
5154
### Starting a New Project
5255

5356
Run the CLI and follow the interactive prompts:
57+
5458
```bash
5559
backend-starter-cli
5660
```
5761

5862
You will be asked to provide the following details:
63+
5964
- **Project Name**: The name of your new project.
6065
- **Initialize Git**: Whether to initialize a Git repository.
6166
- **Framework**: Select your preferred backend framework.
@@ -64,10 +69,13 @@ You will be asked to provide the following details:
6469
### Example Workflow
6570

6671
#### 1. Scaffold a Project
72+
6773
```bash
6874
backend-starter-cli
6975
```
70-
*Example prompt interaction:*
76+
77+
_Example prompt interaction:_
78+
7179
```
7280
? Enter your project name: my-awesome-backend
7381
? Do you want to Initialize git? (Y/n) Yes
@@ -79,24 +87,39 @@ backend-starter-cli
7987
```
8088

8189
#### 2. Navigate to Your New Project
90+
8291
```bash
8392
cd my-awesome-backend
8493
```
8594

8695
#### 3. Install Dependencies
87-
If you didn't install dependencies during setup, you can do so manually:
96+
97+
Install dependencies using your preferred package manager:
98+
8899
```bash
100+
# Using npm
89101
npm install
102+
103+
# Using yarn
104+
yarn install
105+
106+
# Using pnpm
107+
pnpm install
108+
109+
# Using bun
110+
bun install
90111
```
91112

92113
#### 4. Start Building 🚀
114+
93115
Start coding with your generated boilerplate!
94116

95117
---
96118

97119
## Project Structure
98120

99121
Below is an example structure of a project generated with the **Express** framework:
122+
100123
```
101124
my-awesome-backend/
102125
├── .env # Environment variables
@@ -109,8 +132,8 @@ my-awesome-backend/
109132

110133
## Requirements
111134

112-
- Node.js >= 20.0.0
113-
- npm >= 10.0.0 or higher
135+
- Node.js >= 16.0.0
136+
- Any package manager (npm, yarn, pnpm, or bun)
114137

115138
---
116139

bin/index.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
'use strict';
22

33
import inquirer from 'inquirer';
44
import chalk from 'chalk';
@@ -51,7 +51,8 @@ async function setupProject() {
5151
{
5252
type: 'confirm',
5353
name: 'createEnvFile',
54-
message: 'Do you want to create an .env file for your database configuration?',
54+
message:
55+
'Do you want to create an .env file for your database configuration?',
5556
default: true,
5657
},
5758
]);
@@ -62,7 +63,9 @@ async function setupProject() {
6263

6364
// Create project directory
6465
if (fs.existsSync(projectPath)) {
65-
console.log(chalk.red(`Directory "${projectName}" already exists! Exiting.`));
66+
console.log(
67+
chalk.red(`Directory "${projectName}" already exists! Exiting.`)
68+
);
6669
process.exit(1);
6770
}
6871
fs.mkdirSync(projectPath);
@@ -84,22 +87,22 @@ async function setupProject() {
8487
dev: 'node index.js',
8588
start: 'node index.js',
8689
format: 'prettier --write *.js',
87-
lint: 'eslint *.js --fix'
90+
lint: 'eslint *.js --fix',
8891
},
8992
dependencies: {},
9093
devDependencies: {
91-
"prettier": "latest",
92-
"eslint": "latest"
94+
prettier: 'latest',
95+
eslint: 'latest',
9396
},
9497
type: 'module',
9598
keywords: [],
96-
author: "",
97-
license: "ISC",
99+
author: '',
100+
license: 'ISC',
98101
description: '',
99102
};
100103

101-
dependencies[framework].forEach(dep => {
102-
packageJson.dependencies[dep] = "latest"; // Add framework dependencies
104+
dependencies[framework].forEach((dep) => {
105+
packageJson.dependencies[dep] = 'latest'; // Add framework dependencies
103106
});
104107

105108
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
@@ -137,7 +140,10 @@ app.listen(3000, () => {
137140
});
138141
`,
139142
};
140-
fs.writeFileSync(path.join(projectPath, 'index.js'), boilerplate[framework]);
143+
fs.writeFileSync(
144+
path.join(projectPath, 'index.js'),
145+
boilerplate[framework]
146+
);
141147

142148
if (addDatabase) {
143149
const envContent = `
@@ -153,8 +159,11 @@ DB_NAME=database_name
153159

154160
// Git initialization
155161
if (versionControl) {
156-
execSync(`git init ${projectName} > /dev/null 2>&1`)
157-
fs.writeFileSync(path.join(projectPath, '.gitignore'), 'node_modules\n.env\n');
162+
execSync(`git init ${projectName} > /dev/null 2>&1`);
163+
fs.writeFileSync(
164+
path.join(projectPath, '.gitignore'),
165+
'node_modules\n.env\n'
166+
);
158167
}
159168

160169
// Write Prettier configuration
@@ -184,7 +193,7 @@ DB_NAME=database_name
184193
semi: ['error', 'always'],
185194
},
186195
};
187-
196+
188197
fs.writeFileSync(
189198
path.join(projectPath, '.prettierrc.json'),
190199
JSON.stringify(prettierConfig, null, 2)
@@ -195,7 +204,7 @@ DB_NAME=database_name
195204
JSON.stringify(eslintConfig, null, 2)
196205
);
197206

198-
console.log(chalk.white(`\nScaffolding project in ${projectPath}`))
207+
console.log(chalk.white(`\nScaffolding project in ${projectPath}`));
199208

200209
console.log(`
201210
Done. Now run:

eslint.config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js';
2+
3+
export default [
4+
js.configs.recommended,
5+
{
6+
files: ['**/*.js', '**/*.mjs'],
7+
languageOptions: {
8+
ecmaVersion: 2022,
9+
sourceType: 'module',
10+
globals: {
11+
console: 'readonly',
12+
process: 'readonly',
13+
Buffer: 'readonly',
14+
__dirname: 'readonly',
15+
__filename: 'readonly',
16+
},
17+
},
18+
rules: {
19+
'no-unused-vars': 'warn',
20+
'no-console': 'off',
21+
'prefer-const': 'error',
22+
'no-var': 'error',
23+
},
24+
},
25+
{
26+
ignores: ['node_modules/**', 'dist/**', 'build/**'],
27+
},
28+
];

0 commit comments

Comments
 (0)