cs-devtest
v1.1.5
Published
Automatic Husky + Gitleaks + SonarQube setup for any JS/TS project
Maintainers
Readme
cs-setup
A robust, zero-config CLI package that automatically secures and standardizes your projects. By simply installing this package, it automatically configures Husky, Gitleaks, ESLint, SonarQube, Smoke Testing, and Newman API Testing natively hooked into your Git workflow.
🚀 Features
🛡️ Pre-Commit Hook (Code Quality & Security)
Whenever you run git commit, the following checks run automatically on your staged files:
- ESLint: Auto-lints all staged
.js,.jsx,.ts,.tsx,.mjs,.cjsfiles. - Gitleaks: Scans staged files for hardcoded secrets and credentials. Blocks the commit if any secrets are detected.
- Coverage & SonarQube: Attempts to generate test coverage (via Jest/Vitest) and then runs a SonarQube scan. If the Quality Gate fails, the commit is blocked.
🧪 Pre-Push Hook (CI Pipeline)
Whenever you run git push, a compulsory local CI pipeline runs:
- Smoke Test: Automatically boots up your server and waits for it to be accessible.
- Newman API Tests: Automatically runs Postman collections against your locally running server. Blocks the push if any tests fail.
- Branch Guard: Automatically detects branch deletions (e.g.,
git push origin --delete) and skips CI checks to allow instant deletion.
📦 Installation
<<<<<<< HEAD
To strictly use pnpm i (or any other package manager) and bypass pnpm 10's strict security firewalls without any extra commands, you must copy and paste the following snippet into your project's package.json.
- Open your
package.json. - Add the dependency using the HTTPS URL (to avoid SSH permission errors).
- Add the pnpm configuration block (to allow the package to setup the
.githubfolders automatically). ======= To install and initialize the setup in your project, add it as adevDependency:
5a9b41b61a0ab34f079eca1241b7405eceb0dda3
{
"devDependencies": {
<<<<<<< HEAD
"cs-setup": "git+https://github.com/Creolestudios/DevOps-standards.git"
},
"pnpm": {
"onlyBuiltDependencies": [
"cs-setup"
]
=======
"cs-setup": "github:HUSAINTRIVEDI52/pkg#m-main"
>>>>>>> 5a9b41b61a0ab34f079eca1241b7405eceb0dda3
}
}<<<<<<< HEAD
Once the above is in your package.json, simply type:
pnpm i(This also works perfectly for npm i or yarn without any modifications.)
======= Then, run:
npm install5a9b41b61a0ab34f079eca1241b7405eceb0dda3
🔄 Updating to Latest Version
If new features or fixes (like updated Git hook templates or new dependencies) are added to the cs-setup package, follow these steps to sync your project:
- Pull the latest code:
npm install github:HUSAINTRIVEDI52/pkg#m-main - Sync hooks and scripts:
npx cs-setup check-hooks
This will automatically update your .husky/ files, refresh your scripts/run-ci-checks.sh, and install any new required dependencies (like Vitest coverage tools).
⚙️ Manual Initialization
If the automatic setup didn't trigger, or if you want to re-run the initialization:
npx cs-setup initTo verify and restore your hooks without a full initialization:
npx cs-setup check-hooks📋 Configuration Details
SonarQube
A sonar-project.properties file is generated in your project root. You must edit this file to provide your SonarQube credentials:
sonar.host.url: Your SonarQube server URL.sonar.login: Your SonarQube token.
Postman / Newman
Save your Postman collections in your repository with the .postman_collection.json extension. The CI script will automatically find and execute them against your local server.
Monorepo Support
The package automatically detects if your Node project is in a subdirectory of the Git repository. The hooks will automatically cd into the correct project folder before running checks.
❌ Troubleshooting
- Hooks aren't running? Ensure you have initialized a Git repository (
git init) before installing. You can manually runnpx cs-setup check-hooksto restore them. - Missing Vitest Coverage? If your smoke tests fail due to a missing
@vitest/coverage-v8dependency, runnpx cs-setup check-hooksto install it automatically. - Server fails to start in CI? Ensure your
package.jsonhas a validstartordevscript.
