@kabran-tecnologia/kabran-config 1.10.0 → 1.12.0

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.
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Kabran Configuration File
3
+ *
4
+ * This file customizes the behavior of kabran-config validators and tools.
5
+ * All settings are optional - defaults are applied for any missing values.
6
+ *
7
+ * @see https://github.com/kabran-owner/kabran-config
8
+ */
9
+
10
+ /** @type {import('@kabran-tecnologia/kabran-config/core/config-loader').KabranConfig} */
11
+ export default {
12
+ /**
13
+ * README Validator Configuration
14
+ *
15
+ * Customize which sections are required and recommended in your README.md
16
+ */
17
+ readme: {
18
+ // Sections that MUST be present (validation fails if missing)
19
+ required: ['Installation', 'Usage', 'License'],
20
+
21
+ // Sections that SHOULD be present (warning if missing)
22
+ recommended: ['Development', 'Testing', 'Contributing'],
23
+ },
24
+
25
+ /**
26
+ * Environment Validator Configuration
27
+ *
28
+ * Customize how environment variable usage is detected
29
+ */
30
+ env: {
31
+ // Require .env.example file if env vars are detected
32
+ requireExample: true,
33
+
34
+ // Patterns to search for when detecting env var usage
35
+ detectPatterns: [
36
+ 'process.env', // Node.js
37
+ 'import.meta.env', // Vite/ESM
38
+ 'Deno.env', // Deno
39
+ 'os.getenv', // Python
40
+ '$_ENV', // PHP
41
+ ],
42
+ },
43
+
44
+ /**
45
+ * Quality Standard Validator Configuration
46
+ *
47
+ * Customize the location of your quality standard documentation
48
+ */
49
+ quality: {
50
+ // Path to quality standard file (relative to project root)
51
+ standardPath: 'docs/quality/001-quality-standard.md',
52
+ },
53
+ };
@@ -1,388 +0,0 @@
1
- # CI/CD Migration Guide
2
-
3
- This guide helps you migrate existing CI/CD scripts to use `@kabran-owner/kabran-config` standardized scripts.
4
-
5
- ## Before/After Comparison
6
-
7
- ### Before (Old Pattern)
8
-
9
- ```bash
10
- # scripts/ci.sh - 250 lines mixing logic + config
11
- #!/usr/bin/env bash
12
- set -euo pipefail
13
-
14
- # Define colors
15
- RED='\033[0;31m'
16
- GREEN='\033[0;32m'
17
- # ...
18
-
19
- # Define logging functions
20
- log_info() { ... }
21
- log_error() { ... }
22
- # ...
23
-
24
- # Define execution function
25
- run_step() { ... }
26
-
27
- # CI steps (project-specific)
28
- run_step "lint" "pnpm lint:ci"
29
- run_step "test" "pnpm test:ci"
30
- # ...
31
-
32
- # Generate JSON output
33
- echo "CI_RESULT_JSON: ..."
34
- ```
35
-
36
- ### After (New Pattern)
37
-
38
- ```bash
39
- # scripts/ci.sh - 15 lines (wrapper)
40
- #!/usr/bin/env bash
41
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
42
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
43
- RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/ci/ci-runner.sh"
44
-
45
- export PROJECT_ROOT="$PROJECT_ROOT"
46
- export CI_CONFIG_FILE="$SCRIPT_DIR/ci-config.sh"
47
- exec bash "$RUNNER" "$@"
48
- ```
49
-
50
- ```bash
51
- # scripts/ci-config.sh - 60 lines (config only)
52
- #!/usr/bin/env bash
53
- PROJECT_NAME="my-project"
54
- PM="pnpm"
55
-
56
- ci_steps() {
57
- run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
58
- run_step "test" "cd '$PROJECT_ROOT' && $PM test:ci" || FAILED=1
59
- run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
60
- return $FAILED
61
- }
62
- ```
63
-
64
- ## Migration Steps
65
-
66
- ### Step 1: Install kabran-config
67
-
68
- ```bash
69
- npm install --save-dev @kabran-owner/kabran-config@^1.5.0
70
- ```
71
-
72
- ### Step 2: Extract Configuration
73
-
74
- 1. Identify your CI steps in existing `scripts/ci.sh`
75
- 2. Create `scripts/ci-config.sh` with only config
76
- 3. Move step definitions to `ci_steps()` function
77
-
78
- **Example extraction:**
79
-
80
- ```bash
81
- # OLD scripts/ci.sh
82
- run_step "format-check" "pnpm format:check"
83
- run_step "lint" "pnpm lint:ci"
84
- run_step "typecheck" "pnpm type-check"
85
-
86
- # NEW scripts/ci-config.sh
87
- ci_steps() {
88
- run_step "format-check" "cd '$PROJECT_ROOT' && $PM format:check" || FAILED=1
89
- run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
90
- run_step "typecheck" "cd '$PROJECT_ROOT' && $PM type-check" || FAILED=1
91
- return $FAILED
92
- }
93
- ```
94
-
95
- ### Step 3: Replace Wrapper
96
-
97
- ```bash
98
- # Backup old script
99
- mv scripts/ci.sh scripts/ci.sh.backup
100
-
101
- # Create new wrapper
102
- cat > scripts/ci.sh << 'EOF'
103
- #!/usr/bin/env bash
104
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
105
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
106
- RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/ci/ci-runner.sh"
107
-
108
- export PROJECT_ROOT="$PROJECT_ROOT"
109
- export CI_CONFIG_FILE="$SCRIPT_DIR/ci-config.sh"
110
- exec bash "$RUNNER" "$@"
111
- EOF
112
-
113
- chmod +x scripts/ci.sh
114
- ```
115
-
116
- ### Step 4: Test Locally
117
-
118
- ```bash
119
- # Dry run
120
- CI_VERBOSE=true bash scripts/ci.sh
121
-
122
- # Check JSON output
123
- cat .workspace/ci-result.json | jq .
124
- ```
125
-
126
- ### Step 5: Validate in CI
127
-
128
- Push to a test branch and verify GitHub Actions / bash-worker works correctly.
129
-
130
- ## Common Pitfalls
131
-
132
- ### Path Issues
133
-
134
- ❌ **Wrong:**
135
- ```bash
136
- run_step "lint" "pnpm lint:ci" # Runs in wrong directory
137
- ```
138
-
139
- ✅ **Correct:**
140
- ```bash
141
- run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci"
142
- ```
143
-
144
- ### Exit Code Handling
145
-
146
- ❌ **Wrong:**
147
- ```bash
148
- ci_steps() {
149
- run_step "build" "pnpm build" # Doesn't track failure
150
- }
151
- ```
152
-
153
- ✅ **Correct:**
154
- ```bash
155
- ci_steps() {
156
- run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
157
- return $FAILED
158
- }
159
- ```
160
-
161
- ### Missing PM Variable
162
-
163
- ❌ **Wrong:**
164
- ```bash
165
- # ci-config.sh without PM
166
- ci_steps() {
167
- run_step "lint" "npm run lint" # Hardcoded npm
168
- }
169
- ```
170
-
171
- ✅ **Correct:**
172
- ```bash
173
- PM="npm" # Or pnpm, yarn
174
-
175
- ci_steps() {
176
- run_step "lint" "cd '$PROJECT_ROOT' && $PM run lint"
177
- }
178
- ```
179
-
180
- ## Rollback Procedure
181
-
182
- If migration fails:
183
-
184
- ```bash
185
- # Restore old script
186
- mv scripts/ci.sh.backup scripts/ci.sh
187
-
188
- # Remove kabran-config (optional)
189
- npm uninstall @kabran-owner/kabran-config
190
- ```
191
-
192
- ## Project-Specific Examples
193
-
194
- ### Tricket (Monorepo with pnpm)
195
-
196
- ```bash
197
- #!/usr/bin/env bash
198
- PROJECT_NAME="tricket-monorepo"
199
- PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
200
- PM="pnpm"
201
-
202
- ci_steps() {
203
- run_step "format-check" "cd '$PROJECT_ROOT' && $PM format:check" || FAILED=1
204
- run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
205
- run_step "typecheck" "cd '$PROJECT_ROOT' && $PM type-check" || FAILED=1
206
- run_step "test" "cd '$PROJECT_ROOT' && $PM test:ci" || FAILED=1
207
- run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
208
- return $FAILED
209
- }
210
-
211
- ci_metadata() {
212
- jq -n \
213
- --arg node_version "$(node --version)" \
214
- --arg pm_version "$($PM --version)" \
215
- --arg steps "format-check,lint,typecheck,test,build" \
216
- '{
217
- node_version: $node_version,
218
- pnpm_version: $pm_version,
219
- steps_completed: ($steps | split(","))
220
- }'
221
- }
222
- ```
223
-
224
- ### CIE (Multi-Component with Doppler)
225
-
226
- ```bash
227
- #!/usr/bin/env bash
228
- PROJECT_NAME="cie-monorepo"
229
- PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
230
- FRONTEND_DIR="$PROJECT_ROOT/frontend"
231
- CMS_DIR="$PROJECT_ROOT/cms"
232
- WEBSITE_DIR="$PROJECT_ROOT/website"
233
- PM="npm"
234
-
235
- ci_steps() {
236
- # Frontend
237
- log_section "PART 1: FRONTEND CI (React + Vite)"
238
- run_step "frontend-format" "cd '$FRONTEND_DIR' && $PM run format:ci" || FAILED=1
239
- run_step "frontend-lint" "cd '$FRONTEND_DIR' && $PM run lint" || FAILED=1
240
- run_step "frontend-typecheck" "cd '$FRONTEND_DIR' && $PM run type-check" || FAILED=1
241
- run_step "frontend-test" "cd '$FRONTEND_DIR' && $PM run test:ci" "$FRONTEND_DIR/test-results.json" || FAILED=1
242
- run_step "frontend-build" "cd '$FRONTEND_DIR' && $PM run build" || FAILED=2
243
-
244
- # CMS
245
- log_section "PART 2: CMS CI (Next.js + PayloadCMS)"
246
- run_step "cms-typecheck" "cd '$CMS_DIR' && $PM run typecheck" || FAILED=1
247
- run_step "cms-build" "cd '$CMS_DIR' && doppler run -- $PM run build" || FAILED=2
248
-
249
- # Website
250
- log_section "PART 3: WEBSITE CI (React + Vite)"
251
- run_step "website-format" "cd '$WEBSITE_DIR' && $PM run format:ci" || FAILED=1
252
- run_step "website-lint" "cd '$WEBSITE_DIR' && $PM run lint" || FAILED=1
253
- run_step "website-typecheck" "cd '$WEBSITE_DIR' && $PM run type-check" || FAILED=1
254
- run_step "website-test" "cd '$WEBSITE_DIR' && $PM run test:ci" "$WEBSITE_DIR/test-results.json" || FAILED=1
255
- run_step "website-build" "cd '$WEBSITE_DIR' && $PM run build" || FAILED=2
256
-
257
- return $FAILED
258
- }
259
- ```
260
-
261
- ### Kabran-app (with Supabase)
262
-
263
- ```bash
264
- #!/usr/bin/env bash
265
- PROJECT_NAME="kabran-app"
266
- PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
267
- SUPABASE_DIR="$PROJECT_ROOT/supabase"
268
- PM="npm"
269
-
270
- SUPABASE_STARTED=false
271
-
272
- cleanup_supabase() {
273
- if [ "$SUPABASE_STARTED" = "true" ]; then
274
- log_warn "Cleaning up Supabase containers..."
275
- cd "$PROJECT_ROOT" 2>/dev/null && supabase stop 2>/dev/null || true
276
- fi
277
- }
278
-
279
- trap cleanup_supabase EXIT
280
-
281
- has_migrations_changed() {
282
- local base_branch="${CI_BASE_BRANCH:-main}"
283
-
284
- if ! git rev-parse --git-dir > /dev/null 2>&1; then
285
- return 1
286
- fi
287
-
288
- git fetch origin "$base_branch" --quiet 2>/dev/null || true
289
-
290
- if git diff --name-only "origin/${base_branch}...HEAD" 2>/dev/null | grep -qE "^(supabase/migrations/|supabase/functions/)"; then
291
- return 0
292
- fi
293
-
294
- return 1
295
- }
296
-
297
- ci_steps() {
298
- # Frontend CI
299
- log_section "PART 1: FRONTEND CI"
300
- run_step "lint" "cd '$PROJECT_ROOT' && $PM run lint -w @kabran/web -- --max-warnings=0" || FAILED=1
301
- run_step "typecheck" "cd '$PROJECT_ROOT' && $PM run type-check" || FAILED=1
302
- run_step "test" "cd '$PROJECT_ROOT' && $PM run test -w @kabran/web -- run" || FAILED=1
303
- run_step "build" "cd '$PROJECT_ROOT' && $PM run build" || FAILED=2
304
-
305
- # Database CI (Conditional)
306
- if has_migrations_changed; then
307
- log_section "PART 2: DATABASE CI (Supabase Migrations)"
308
-
309
- if ! run_step "supabase-start" "cd '$PROJECT_ROOT' && supabase start"; then
310
- FAILED=2
311
- supabase stop 2>/dev/null || true
312
- else
313
- SUPABASE_STARTED=true
314
-
315
- run_step "supabase-migrations" "cd '$PROJECT_ROOT' && supabase db reset --linked=false" || FAILED=1
316
-
317
- if ! run_step "supabase-stop" "cd '$PROJECT_ROOT' && supabase stop"; then
318
- log_warn "Failed to stop Supabase cleanly"
319
- fi
320
- SUPABASE_STARTED=false
321
- fi
322
- else
323
- log_info "No migrations/functions changed, skipping database CI"
324
- fi
325
-
326
- return $FAILED
327
- }
328
- ```
329
-
330
- ## Deploy Migration
331
-
332
- ### Before
333
-
334
- ```bash
335
- # scripts/deploy.sh - 300+ lines
336
- # (manual JSON parsing, stack execution, etc.)
337
- ```
338
-
339
- ### After
340
-
341
- ```bash
342
- # scripts/deploy.sh - 15 lines
343
- #!/usr/bin/env bash
344
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
345
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
346
- RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/deploy/deploy-runner.sh"
347
-
348
- export PROJECT_ROOT="$PROJECT_ROOT"
349
- export SCRIPT_DIR="$SCRIPT_DIR"
350
- export DEPLOY_CONFIG_FILE="$SCRIPT_DIR/deploy.json"
351
-
352
- exec bash "$RUNNER" "$@"
353
- ```
354
-
355
- ```json
356
- {
357
- "project": "my-project",
358
- "version": "1.0.0",
359
- "stacks": [
360
- {
361
- "name": "api",
362
- "type": "backend",
363
- "path": "../apps/api/docker",
364
- "script": "api-deploy.sh",
365
- "condition": {
366
- "type": "path_changed",
367
- "paths": ["apps/api/", "packages/"]
368
- }
369
- }
370
- ],
371
- "settings": {
372
- "timeout_seconds": 300,
373
- "skip_unchanged": true
374
- }
375
- }
376
- ```
377
-
378
- ## Support
379
-
380
- Issues? Check:
381
- 1. kabran-config README.md
382
- 2. Example configs in this migration guide
383
- 3. Create issue in nexus repo
384
-
385
- ---
386
-
387
- **Version:** 1.5.0
388
- **Last Updated:** 2026-01-12