Skip to content

Commit e4b49c0

Browse files
authored
Merge pull request #1 from DevKaliper/feat/development
Feat/development
2 parents d635094 + eeaa2c1 commit e4b49c0

38 files changed

Lines changed: 5719 additions & 1 deletion

.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 2022,
6+
"sourceType": "module",
7+
"project": "./tsconfig.json"
8+
},
9+
"plugins": ["@typescript-eslint"],
10+
"extends": [
11+
"eslint:recommended",
12+
"plugin:@typescript-eslint/recommended",
13+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
14+
"prettier"
15+
],
16+
"rules": {
17+
"@typescript-eslint/no-explicit-any": "error",
18+
"@typescript-eslint/explicit-function-return-type": "off",
19+
"@typescript-eslint/explicit-module-boundary-types": "off",
20+
"@typescript-eslint/no-unused-vars": [
21+
"error",
22+
{ "argsIgnorePattern": "^_" }
23+
],
24+
"no-console": "off"
25+
},
26+
"env": {
27+
"node": true,
28+
"es2022": true
29+
}
30+
}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
node_modules/
3+
dist/
4+
build/
5+
coverage/
6+
.env
7+
.env.local
8+
.env.*.local
9+
.idea/
10+
.vscode/
11+
.DS_Store
12+
*.log
13+
*.tmp

.npmignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
src
3+
__tests__
4+
tsconfig.json
5+
.eslintrc.json
6+
.prettierrc.json
7+
vitest.config.ts
8+
*.test.ts
9+
*.spec.ts
10+
.gitignore
11+
.github

.prettierrc.json

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

CHANGELOG.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2026-02-17
9+
10+
### Added
11+
12+
#### Core Features
13+
- `diff` command - Compare environment variables between two sources
14+
- `check` command - Validate environment against baseline (e.g., .env.example)
15+
- `audit` command - Detect security issues and suspicious values
16+
17+
#### Parsers
18+
- `.env` file parser with support for standard dotenv format
19+
- `.env.example` parser that extracts variable names even without values
20+
- Docker Compose parser that extracts environment variables from all services
21+
- Vercel configuration parser (vercel.json)
22+
- Railway configuration parser (railway.toml)
23+
- Git integration - load .env files from any git reference (branches, commits)
24+
25+
#### Audit Rules
26+
- `SECRET_IN_PLAIN` - Detects plaintext passwords and weak secrets (error)
27+
- `LOCALHOST_IN_PROD` - Flags localhost/127.0.0.1 in production variables (warn)
28+
- `EMPTY_SECRET` - Identifies secret variables with empty values (error)
29+
- `WEAK_DEFAULT` - Catches common weak defaults like "password", "changeme" (warn)
30+
- `MISSING_REQUIRED` - Reports variables present in baseline but missing in target (error)
31+
32+
#### Output Formats
33+
- Plain text output with optional color support
34+
- JSON output for programmatic consumption
35+
- Markdown output for documentation and reports
36+
- Value masking option (--no-values) for sensitive information
37+
38+
#### CLI Options
39+
- `--format` - Choose output format (text, json, markdown)
40+
- `--only-missing` - Show only added/removed variables
41+
- `--only-changed` - Show only changed variables
42+
- `--no-values` - Mask variable values in output
43+
- `--baseline` - Specify custom baseline file for check command
44+
- `--severity` - Filter audit results by severity (warn, error)
45+
46+
#### Integration Sources
47+
- File paths: `./path/to/.env`
48+
- Git references: `main:.env`, `HEAD~1:.env`
49+
- Docker Compose: `compose:./docker-compose.yml`
50+
- Vercel: `vercel:./vercel.json`
51+
- Railway: `railway:./railway.toml`
52+
53+
#### Developer Experience
54+
- TypeScript strict mode
55+
- Comprehensive unit tests (31 tests across 6 test suites)
56+
- ESLint + Prettier configuration
57+
- Vitest for fast testing
58+
- Full code coverage tracking
59+
- Example fixtures for testing
60+
- Demo script showcasing all features
61+
62+
#### Documentation
63+
- Comprehensive README with usage examples
64+
- EXAMPLES.md with real-world use cases
65+
- CONTRIBUTING.md with development guidelines
66+
- Inline code documentation
67+
- MIT License
68+
69+
### Technical Details
70+
- Node.js 20+ required
71+
- TypeScript 5.3+
72+
- ES2022 modules
73+
- Functional programming style
74+
- Named exports only
75+
- No default exports
76+
- Zero external API dependencies
77+
- Fast execution with minimal overhead
78+
79+
[1.0.0]: https://github.com/DevKaliper/env-diff-cli/releases/tag/v1.0.0

CONTRIBUTING.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# Contributing to envdiff
2+
3+
Thank you for considering contributing to envdiff! This document provides guidelines and instructions for contributing.
4+
5+
## Development Setup
6+
7+
1. **Fork and clone the repository**
8+
```bash
9+
git clone https://github.com/YOUR_USERNAME/env-diff-cli.git
10+
cd env-diff-cli
11+
```
12+
13+
2. **Install dependencies**
14+
```bash
15+
npm install
16+
```
17+
18+
3. **Build the project**
19+
```bash
20+
npm run build
21+
```
22+
23+
4. **Run tests**
24+
```bash
25+
npm test
26+
```
27+
28+
## Project Structure
29+
30+
```
31+
src/
32+
cli.ts # Commander setup, command registration
33+
commands/
34+
diff.ts # diff two env sources
35+
check.ts # validate against a baseline
36+
audit.ts # suspicious value detection
37+
parsers/
38+
dotenv.ts # .env and .env.example
39+
compose.ts # docker-compose.yml environment blocks
40+
vercel.ts # vercel.json + .vercel/output
41+
railway.ts # railway.toml
42+
core/
43+
differ.ts # diff logic, set operations on variable maps
44+
auditor.ts # suspicious value rules
45+
reporter.ts # format output (text | json | markdown)
46+
types.ts # shared types
47+
__tests__/ # unit tests
48+
fixtures/ # test data
49+
```
50+
51+
## Code Style
52+
53+
- **TypeScript strict mode** - All code must pass strict type checking
54+
- **Functional style** - Prefer pure functions over classes
55+
- **Named exports only** - No default exports
56+
- **Async/await** - Use async functions for all I/O operations
57+
- **No `any` type** - Use `unknown` and narrow explicitly
58+
- **ESLint + Prettier** - Code must pass linting and formatting checks
59+
60+
Run formatting and linting:
61+
```bash
62+
npm run format
63+
npm run lint
64+
```
65+
66+
## Adding New Features
67+
68+
### Adding a New Parser
69+
70+
To add support for a new configuration format:
71+
72+
1. Create a new parser in `src/parsers/yourformat.ts`
73+
2. Implement the parser function that returns `Promise<EnvMap>`
74+
3. Add test fixtures in `src/__tests__/fixtures/`
75+
4. Write unit tests in `src/__tests__/yourformat.test.ts`
76+
5. Update the `loadSource` function in `src/commands/diff.ts`
77+
6. Update README.md and EXAMPLES.md with usage examples
78+
79+
Example parser structure:
80+
```typescript
81+
import { readFile } from 'fs/promises'
82+
import type { EnvMap } from '../types.js'
83+
import { ParseError } from '../types.js'
84+
85+
export async function parseYourFormat(filePath: string): Promise<EnvMap> {
86+
try {
87+
const content = await readFile(filePath, 'utf-8')
88+
// Parse content and return EnvMap
89+
return {}
90+
} catch (error) {
91+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
92+
return {}
93+
}
94+
throw new ParseError(`Failed to parse: ${filePath}`)
95+
}
96+
}
97+
```
98+
99+
### Adding a New Audit Rule
100+
101+
To add a new security audit rule:
102+
103+
1. Add the rule to the `rules` array in `src/core/auditor.ts`
104+
2. Write tests in `src/__tests__/auditor.test.ts` (positive and negative cases)
105+
3. Update README.md with the new rule description
106+
107+
Example rule:
108+
```typescript
109+
{
110+
id: 'YOUR_RULE_ID',
111+
severity: 'warn' | 'error',
112+
match: (key: string, value: string) => {
113+
// Return true if the rule should trigger
114+
return false
115+
}
116+
}
117+
```
118+
119+
## Testing
120+
121+
### Running Tests
122+
123+
```bash
124+
# Run all tests
125+
npm test
126+
127+
# Run tests once (no watch mode)
128+
npm run test:run
129+
130+
# Run with coverage
131+
npm run test:coverage
132+
```
133+
134+
### Writing Tests
135+
136+
- Place tests in `src/__tests__/`
137+
- Use descriptive test names
138+
- Test both positive and negative cases
139+
- Use fixtures in `src/__tests__/fixtures/` for test data
140+
- Avoid mocking the filesystem - use real files in temp directories
141+
142+
Example test:
143+
```typescript
144+
import { describe, it, expect } from 'vitest'
145+
import { yourFunction } from '../your-module.js'
146+
147+
describe('yourFunction', () => {
148+
it('should handle valid input', () => {
149+
const result = yourFunction('input')
150+
expect(result).toBe('expected')
151+
})
152+
153+
it('should throw on invalid input', () => {
154+
expect(() => yourFunction('')).toThrow()
155+
})
156+
})
157+
```
158+
159+
## Pull Request Process
160+
161+
1. **Create a feature branch**
162+
```bash
163+
git checkout -b feature/your-feature-name
164+
```
165+
166+
2. **Make your changes**
167+
- Write clean, well-documented code
168+
- Add tests for new functionality
169+
- Update documentation as needed
170+
171+
3. **Test your changes**
172+
```bash
173+
npm run lint
174+
npm run format:check
175+
npm run test:run
176+
npm run build
177+
```
178+
179+
4. **Commit your changes**
180+
```bash
181+
git add .
182+
git commit -m "feat: add your feature description"
183+
```
184+
185+
5. **Push to your fork**
186+
```bash
187+
git push origin feature/your-feature-name
188+
```
189+
190+
6. **Create a Pull Request**
191+
- Provide a clear description of the changes
192+
- Link to any related issues
193+
- Ensure all CI checks pass
194+
195+
## Commit Message Convention
196+
197+
Follow conventional commits:
198+
199+
- `feat:` - New feature
200+
- `fix:` - Bug fix
201+
- `docs:` - Documentation changes
202+
- `test:` - Adding or updating tests
203+
- `refactor:` - Code refactoring
204+
- `perf:` - Performance improvements
205+
- `chore:` - Maintenance tasks
206+
207+
Examples:
208+
```
209+
feat: add support for Kubernetes ConfigMaps
210+
fix: handle empty environment files correctly
211+
docs: update installation instructions
212+
test: add tests for audit rules
213+
```
214+
215+
## Questions or Issues?
216+
217+
- Open an issue for bugs or feature requests
218+
- Start a discussion for questions or ideas
219+
- Check existing issues before creating new ones
220+
221+
## License
222+
223+
By contributing, you agree that your contributions will be licensed under the MIT License.

0 commit comments

Comments
 (0)