Skip to content

Commit b773ba2

Browse files
committed
set up to publish on npm
1 parent 9cbfa28 commit b773ba2

File tree

4 files changed

+130
-54
lines changed

4 files changed

+130
-54
lines changed

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.github/
2+
node_modules/
3+
demo_secret.txt
4+
.DS_Store
5+
coverage/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Shivam Sharma
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 87 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,117 @@
11
# CodeGuardian — Sensitive Data Scanner
22

3-
A small Node.js CLI that scans your repository for commonly leaked secrets before you push.
3+
Lightweight CLI to scan repositories for accidentally committed secrets (API keys, tokens, private keys). This short guide starts with how to use CodeGuardian in your project, how to integrate it into CI, and then explains the feature set and configuration.
44

5-
Features
6-
- CLI scanner using configurable regex rules
7-
- Sample Husky pre-commit hook
8-
- Optional CI mode (exit non-zero when findings are present)
5+
## How developers use CodeGuardian.
96

10-
Quick start
11-
1. Install dependencies:
7+
---
128

13-
```bash
14-
npm install
15-
```
16-
17-
2. (Optional) Install husky hooks (manual steps)
9+
Installation (two quick ways):
1810

19-
Note: this project no longer runs `husky install` automatically during `npm install` — the `prepare` script was removed to avoid install-time failures on machines that don't have Husky installed. If you want local pre-commit hooks, install and enable Husky manually:
11+
- Run directly with npx (no install required):
2012

2113
```bash
22-
# install husky as a dev dependency
23-
npm install --save-dev husky
14+
npx @shivarm/codeguardian
15+
```
2416

25-
# install husky hooks into .husky/
26-
npx husky install
17+
- Install as a dev dependency (recommended for team projects):
2718

28-
# add a pre-commit hook that runs CodeGuardian on staged files and fails the commit
29-
npx husky add .husky/pre-commit "npx codeguardian --staged --ci"
19+
```bash
20+
npm install --save-dev @shivarm/codeguardian
3021
```
3122

32-
3. Run the scanner on the repo:
23+
Basic commands:
24+
25+
- Scan entire repository:
3326

3427
```bash
3528
npx codeguardian
3629
```
3730

38-
Config
39-
Drop a `.codeguardianrc.json` in the repo with the following shape:
31+
- Scan only staged files (fast; good for pre-commit hooks):
4032

41-
```json
42-
{
43-
"rules": [
44-
{ "name": "Example", "pattern": "AKIA[0-9A-Z]{16}", "flags": "g" }
45-
]
46-
}
33+
```bash
34+
npx codeguardian --staged
4735
```
4836

49-
You can also add an `ignoreFiles` array of globs or paths to skip scanning noisy files (for example lockfiles or build outputs). Example `.codeguardianrc.json`:
37+
- CI mode (exit non-zero on findings):
5038

51-
```json
52-
{
53-
"ignoreFiles": [
54-
"package-lock.json",
55-
"yarn.lock",
56-
"pnpm-lock.yaml",
57-
"dist/**",
58-
"node_modules/**"
59-
],
60-
"rules": [
61-
{ "name": "AWS Access Key ID", "pattern": "AKIA[0-9A-Z]{16}", "flags": "g" },
62-
{ "name": "Simple API key assignment", "pattern": "api_key\\s*[=:\\s]\\s*([A-Za-z0-9_\\-]{8,})", "flags": "gi" }
63-
]
64-
}
39+
```bash
40+
npx codeguardian --ci
6541
```
6642

67-
To run the scanner with a custom config file use `--config`:
43+
Custom config (optional):
6844

6945
```bash
7046
npx codeguardian --config .codeguardianrc.json
7147
```
7248

73-
CI Integration
74-
Run `npx codeguardian --ci` in your CI pipeline and fail the build if any findings are present.
49+
## How to integrate with CI (GitHub Actions).
50+
51+
---
52+
53+
Use the built-in workflow `.github/workflows/codeguardian.yml` or add a step to your pipeline to run the scanner in CI mode. Example snippet:
54+
55+
```yaml
56+
on:
57+
push:
58+
branches: [main]
59+
pull_request:
60+
branches: [main]
61+
62+
jobs:
63+
scan:
64+
name: Run CodeGuardian
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v5
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v5
72+
with:
73+
node-version: "22"
74+
cache: "npm"
75+
76+
- name: Install dependencies
77+
run: npm install
78+
79+
- name: Run CodeGuardian scanner (CI mode)
80+
run: npx codeguardian --ci
81+
```
82+
83+
When run with `--ci` the CLI exits with a non-zero code if any findings are detected — this will fail the job and block merges until issues are resolved.
84+
85+
## What CodeGuardian offers
86+
87+
---
88+
89+
- Rule-based scanning: configure regex rules (name, pattern, flags) to detect secrets.
90+
- `ignoreFiles`: glob list to skip noisy files (lockfiles, build artifacts).
91+
- Staged-file scanning: run only what will be committed (fast pre-commit checks).
92+
- Husky integration: optional pre-commit hooks to block commits locally.
93+
- CI-ready: `--ci` mode for failing pipelines on findings.
94+
95+
## Developer guide & advanced configuration
7596

76-
Notes
77-
Notes
78-
- The default ruleset (in `default-config.json`) is a starting point — tune it for your project to reduce false positives.
79-
- The scanner respects `.gitignore` and ignores `node_modules` and `.git` by default. Additionally, CodeGuardian now ignores common lockfiles by default (e.g. `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`) to reduce noisy matches from integrity/hash lines.
97+
---
98+
99+
## CLI options
100+
101+
- `-c, --config <path>` — path to JSON config file (default: `.codeguardianrc.json`)
102+
- `-s, --staged` — only scan staged files
103+
- `--ci` — CI mode: exit non-zero when findings exist
104+
- `-v, --verbose` — verbose output
105+
106+
## Config file (`.codeguardianrc.json`)
107+
108+
Minimal shape:
109+
110+
```json
111+
{
112+
"ignoreFiles": ["package-lock.json", "yarn.lock", "dist/**"],
113+
"rules": [{ "name": "AWS Access Key ID", "pattern": "AKIA[0-9A-Z]{16}", "flags": "g" }]
114+
}
115+
```
80116

81-
If you want to ignore additional files from scanning (beyond `.gitignore` and the default lockfiles), add them to your `.codeguardianrc.json`.
117+
Rules are JavaScript regular expressions expressed as strings. `flags` is optional (for example `gi`). The scanner will try to compile each rule. invalid patterns are skipped.

package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "codeguardian",
3-
"version": "0.1.0",
2+
"name": "@shivarm/codeguardian",
3+
"version": "1.0.0",
44
"description": "CLI to scan repos for sensitive secrets before pushing",
55
"main": "src/index.js",
66
"type": "module",
@@ -16,12 +16,26 @@
1616
"pre-commit",
1717
"husky"
1818
],
19-
"author": "",
19+
"author": "Shivam Sharma <[email protected]>",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/shivarm/code-guardian.git"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/shivarm/code-guardian/issues"
26+
},
27+
"homepage": "https://github.com/shivarm/code-guardian#readme",
2028
"license": "MIT",
29+
"publishConfig": {
30+
"access": "public"
31+
},
2132
"dependencies": {
2233
"chalk": "^5.3.0",
2334
"commander": "^11.0.0",
2435
"fast-glob": "^3.3.2",
2536
"ignore": "^5.2.0"
37+
},
38+
"engines": {
39+
"node": ">=18.0.0"
2640
}
2741
}

0 commit comments

Comments
 (0)