@fatsolutions/ganchos 1.0.5 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/configs/cairo/Scarb.fmt.toml +11 -0
- package/configs/cairo/install.js +7 -0
- package/configs/cairo/install.ts +10 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +3 -2
- package/hooks/pre-commit/cairo.sh +71 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @fatsolutions/ganchos
|
|
2
|
+
|
|
3
|
+
Git Hook Manager for Polyglot Monorepos.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @fatsolutions/ganchos
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Setup
|
|
12
|
+
|
|
13
|
+
Add your desired languages to `package.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"ganchos": {
|
|
18
|
+
"languages": ["typescript", "python", "cairo"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The hooks will be automatically installed on `pnpm install` via the postinstall bootstrap.
|
|
24
|
+
|
|
25
|
+
## Manual Setup
|
|
26
|
+
|
|
27
|
+
If you prefer manual control, skip the `ganchos` field in `package.json` and use the CLI:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Enable languages
|
|
31
|
+
pnpm ganchos enable typescript python cairo
|
|
32
|
+
|
|
33
|
+
# Install the hooks
|
|
34
|
+
pnpm ganchos install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## CLI Commands
|
|
38
|
+
|
|
39
|
+
| Command | Description |
|
|
40
|
+
|---------|-------------|
|
|
41
|
+
| `ganchos install` | Install git hooks based on configuration |
|
|
42
|
+
| `ganchos generate` | Generate hook content to stdout (for inspection) |
|
|
43
|
+
| `ganchos list` | List configured and available languages |
|
|
44
|
+
| `ganchos enable <languages...>` | Enable one or more languages |
|
|
45
|
+
| `ganchos disable <languages...>` | Disable one or more languages |
|
|
46
|
+
|
|
47
|
+
## Supported Languages
|
|
48
|
+
|
|
49
|
+
- **javascript** - ESLint, Prettier
|
|
50
|
+
- **typescript** - TypeScript compiler, ESLint, Prettier
|
|
51
|
+
- **python** - Black, isort, flake8, mypy *(work in progress)*
|
|
52
|
+
- **cairo** - scarb fmt, scarb lint
|
|
53
|
+
|
|
54
|
+
## How It Works
|
|
55
|
+
|
|
56
|
+
1. Configuration is stored in `.ganchos.json` (auto-generated, added to `.git/info/exclude`)
|
|
57
|
+
2. Language-specific hook scripts are located in `hooks/pre-commit/`
|
|
58
|
+
3. On commit, the pre-commit hook runs checks for all enabled languages on staged files
|
|
59
|
+
4. Auto-fixable issues (formatting) are fixed automatically; you'll be prompted to review and commit again
|
|
60
|
+
|
|
61
|
+
## Language-Specific Requirements
|
|
62
|
+
|
|
63
|
+
### JavaScript/TypeScript
|
|
64
|
+
- `eslint` and `prettier` available via `npx`
|
|
65
|
+
|
|
66
|
+
### Python
|
|
67
|
+
- Optional: `black`, `isort`, `flake8`, `mypy` installed in your environment
|
|
68
|
+
|
|
69
|
+
### Cairo (Starknet)
|
|
70
|
+
- `scarb` installed ([installation guide](https://docs.swmansion.com/scarb/))
|
|
71
|
+
- `Scarb.toml` present in project root or package directories
|
|
72
|
+
|
|
73
|
+
## Monorepo Support
|
|
74
|
+
|
|
75
|
+
Ganchos detects `packages/` subdirectories and runs language tools from the appropriate project roots:
|
|
76
|
+
- Looks for `package.json`, `tsconfig.json`, `pyproject.toml`, `Scarb.toml` in package directories
|
|
77
|
+
- Falls back to root-level configuration when appropriate
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
Contributions are welcome! Feel free to open issues or submit pull requests.
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
GPL-2.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "fmt_hook"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
|
|
5
|
+
[tool.fmt]
|
|
6
|
+
sort-module-level-items = true
|
|
7
|
+
max-line-length = 100
|
|
8
|
+
tab-size = 4
|
|
9
|
+
breaking-behaviour = { tuple = "LineByLine", fixed_array = "SingleBreakPoint", macro_call = "SingleBreakPoint" }
|
|
10
|
+
merge-use-items = true
|
|
11
|
+
allow-duplicate-uses = false
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const dependencies: Record<string, string> = {
|
|
2
|
+
};
|
|
3
|
+
|
|
4
|
+
export const configFiles: string[] = [
|
|
5
|
+
"Scarb.fmt.toml",
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export function getInstallCommand(_deps: Record<string, string>, _projectRoot: string): string {
|
|
9
|
+
return "echo \"Installed cairo deps\""
|
|
10
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface FatHooksConfig {
|
|
|
11
11
|
version: string;
|
|
12
12
|
languages: LanguageConfig[];
|
|
13
13
|
}
|
|
14
|
-
declare const SUPPORTED_LANGUAGES: readonly ["javascript", "typescript", "python"];
|
|
14
|
+
declare const SUPPORTED_LANGUAGES: readonly ["javascript", "typescript", "python", "cairo"];
|
|
15
15
|
type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
|
|
16
16
|
declare const DEFAULT_CONFIG: FatHooksConfig;
|
|
17
17
|
|
package/dist/types/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const SUPPORTED_LANGUAGES = ["javascript", "typescript", "python"];
|
|
1
|
+
const SUPPORTED_LANGUAGES = ["javascript", "typescript", "python", "cairo"];
|
|
2
2
|
const DEFAULT_CONFIG = {
|
|
3
3
|
version: "1.0.0",
|
|
4
4
|
languages: [
|
|
5
5
|
{ name: "javascript", enabled: false },
|
|
6
6
|
{ name: "typescript", enabled: false },
|
|
7
|
-
{ name: "python", enabled: false }
|
|
7
|
+
{ name: "python", enabled: false },
|
|
8
|
+
{ name: "cairo", enabled: false }
|
|
8
9
|
]
|
|
9
10
|
};
|
|
10
11
|
export {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Cairo pre-commit hook
|
|
2
|
+
echo "Running Cairo checks..."
|
|
3
|
+
|
|
4
|
+
SCARB_FMT_MANIFEST="Scarb.fmt.toml"
|
|
5
|
+
|
|
6
|
+
# Check if scarb is installed
|
|
7
|
+
if ! command -v scarb >/dev/null 2>&1; then
|
|
8
|
+
echo "Error: scarb is not installed. Please install it from https://docs.swmansion.com/scarb/"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
# Check if there are any Cairo files to check
|
|
13
|
+
CAIRO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.cairo$' || true)
|
|
14
|
+
if [ -n "$CAIRO_FILES" ]; then
|
|
15
|
+
echo "Checking Cairo files: $CAIRO_FILES"
|
|
16
|
+
|
|
17
|
+
# Get unique package directories from modified files
|
|
18
|
+
PACKAGES=$(echo "$CAIRO_FILES" | grep '^packages/' | cut -d'/' -f1-2 | sort -u || true)
|
|
19
|
+
|
|
20
|
+
# Check if we have root-level Cairo files
|
|
21
|
+
ROOT_CAIRO_FILES=$(echo "$CAIRO_FILES" | grep -v '^packages/' || true)
|
|
22
|
+
|
|
23
|
+
# Run scarb fmt per package directory (if they have Scarb.toml)
|
|
24
|
+
for package_dir in $PACKAGES; do
|
|
25
|
+
PACKAGE_CAIRO_FILES=$(echo "$CAIRO_FILES" | grep "^$package_dir/" || true)
|
|
26
|
+
if [ -n "$PACKAGE_CAIRO_FILES" ]; then
|
|
27
|
+
if [ -f "$package_dir/Scarb.toml" ]; then
|
|
28
|
+
# Get relative paths for files in this package
|
|
29
|
+
RELATIVE_FILES=$(echo "$PACKAGE_CAIRO_FILES" | sed "s|^$package_dir/||")
|
|
30
|
+
|
|
31
|
+
echo " Running scarb fmt in $package_dir..."
|
|
32
|
+
(cd "$package_dir" && echo "$RELATIVE_FILES" | xargs scarb --manifest-path "$SCARB_FMT_MANIFEST" fmt) || {
|
|
33
|
+
echo "scarb fmt failed in $package_dir. Please fix the issues before committing."
|
|
34
|
+
exit 1
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
echo " Running scarb lint in $package_dir..."
|
|
38
|
+
(cd "$package_dir" && scarb lint) || {
|
|
39
|
+
echo "scarb lint failed in $package_dir. Run 'cd $package_dir && scarb lint --fix' to fix lint issues."
|
|
40
|
+
exit 1
|
|
41
|
+
}
|
|
42
|
+
fi
|
|
43
|
+
fi
|
|
44
|
+
done
|
|
45
|
+
|
|
46
|
+
# Run scarb fmt and lint from root for root-level Cairo files (if Scarb.toml exists at root)
|
|
47
|
+
if [ -n "$ROOT_CAIRO_FILES" ] && [ -f "Scarb.toml" ]; then
|
|
48
|
+
echo " Running scarb fmt in root..."
|
|
49
|
+
echo "$ROOT_CAIRO_FILES" | xargs scarb --manifest-path "$SCARB_FMT_MANIFEST" fmt || {
|
|
50
|
+
echo "scarb fmt failed. Please fix the issues before committing."
|
|
51
|
+
exit 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
echo " Running scarb lint in root..."
|
|
55
|
+
scarb lint || {
|
|
56
|
+
echo "scarb lint failed. Run 'scarb lint --fix' to fix lint issues."
|
|
57
|
+
exit 1
|
|
58
|
+
}
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
# Check if files were modified by auto-fix
|
|
62
|
+
MODIFIED=$(echo "$CAIRO_FILES" | xargs git diff --name-only)
|
|
63
|
+
if [ -n "$MODIFIED" ]; then
|
|
64
|
+
echo ""
|
|
65
|
+
echo "The following files were auto-fixed:"
|
|
66
|
+
echo "$MODIFIED" | sed 's/^/ /'
|
|
67
|
+
echo ""
|
|
68
|
+
echo "Please review the changes and commit again."
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
fi
|