autoworkflow 1.1.0 → 2.0.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.
package/lib/install.js DELETED
@@ -1,600 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * autoworkflow - Auto-Install Script
4
- *
5
- * This runs automatically when the package is installed.
6
- * Sets up Git hooks and creates default config.
7
- */
8
-
9
- const fs = require('fs');
10
- const path = require('path');
11
- const { execSync } = require('child_process');
12
-
13
- // Colors for output
14
- const c = {
15
- reset: '\x1b[0m',
16
- green: '\x1b[32m',
17
- yellow: '\x1b[33m',
18
- blue: '\x1b[34m',
19
- red: '\x1b[31m',
20
- };
21
-
22
- function log(color, message) {
23
- console.log(`${color}${message}${c.reset}`);
24
- }
25
-
26
- function findProjectRoot() {
27
- // Start from where npm install was run (not node_modules)
28
- let dir = process.env.INIT_CWD || process.cwd();
29
-
30
- // Walk up to find package.json (project root)
31
- while (dir !== path.dirname(dir)) {
32
- if (fs.existsSync(path.join(dir, 'package.json'))) {
33
- // Make sure it's not our own package.json
34
- const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
35
- if (pkg.name !== 'autoworkflow') {
36
- return dir;
37
- }
38
- }
39
- dir = path.dirname(dir);
40
- }
41
-
42
- return process.env.INIT_CWD || process.cwd();
43
- }
44
-
45
- function isGitRepo(dir) {
46
- return fs.existsSync(path.join(dir, '.git'));
47
- }
48
-
49
- function ensureHuskyDir(projectRoot) {
50
- const huskyDir = path.join(projectRoot, '.husky');
51
- if (!fs.existsSync(huskyDir)) {
52
- fs.mkdirSync(huskyDir, { recursive: true });
53
- }
54
-
55
- // Create husky internal dir
56
- const huskyInternalDir = path.join(huskyDir, '_');
57
- if (!fs.existsSync(huskyInternalDir)) {
58
- fs.mkdirSync(huskyInternalDir, { recursive: true });
59
- }
60
-
61
- return huskyDir;
62
- }
63
-
64
- function createPreCommitHook(huskyDir, projectRoot) {
65
- const hookPath = path.join(huskyDir, 'pre-commit');
66
-
67
- // Check if hook already exists
68
- if (fs.existsSync(hookPath)) {
69
- log(c.yellow, ' ⚠ Pre-commit hook already exists, skipping...');
70
- return;
71
- }
72
-
73
- const hookContent = `#!/bin/bash
74
- # ============================================
75
- # autoworkflow - Pre-Commit Hook
76
- # ============================================
77
- # Auto-generated. Modify enforce.config.json to customize.
78
- # ============================================
79
-
80
- npx autoworkflow run
81
- `;
82
-
83
- fs.writeFileSync(hookPath, hookContent);
84
- fs.chmodSync(hookPath, '755');
85
- log(c.green, ' ✓ Created pre-commit hook');
86
- }
87
-
88
- function createCommitMsgHook(huskyDir) {
89
- const hookPath = path.join(huskyDir, 'commit-msg');
90
-
91
- if (fs.existsSync(hookPath)) {
92
- log(c.yellow, ' ⚠ Commit-msg hook already exists, skipping...');
93
- return;
94
- }
95
-
96
- const hookContent = `#!/bin/bash
97
- # ============================================
98
- # autoworkflow - Commit Message Hook
99
- # ============================================
100
-
101
- npx autoworkflow commit-msg "$1"
102
- `;
103
-
104
- fs.writeFileSync(hookPath, hookContent);
105
- fs.chmodSync(hookPath, '755');
106
- log(c.green, ' ✓ Created commit-msg hook');
107
- }
108
-
109
- function createDefaultConfig(projectRoot) {
110
- const configPath = path.join(projectRoot, 'enforce.config.json');
111
-
112
- if (fs.existsSync(configPath)) {
113
- log(c.yellow, ' ⚠ Config file already exists, skipping...');
114
- return;
115
- }
116
-
117
- const defaultConfig = {
118
- version: '1.0.0',
119
- rules: {
120
- 'no-todo-comments': {
121
- enabled: true,
122
- blocking: true,
123
- patterns: ['TODO', 'FIXME', 'XXX', 'HACK']
124
- },
125
- 'no-console-logs': {
126
- enabled: true,
127
- blocking: true,
128
- allow: ['warn', 'error']
129
- },
130
- 'typescript': {
131
- enabled: true,
132
- blocking: true,
133
- command: 'npx tsc --noEmit'
134
- },
135
- 'eslint': {
136
- enabled: true,
137
- blocking: true,
138
- autoFix: true,
139
- command: 'npx eslint . --max-warnings 0',
140
- fixCommand: 'npx eslint . --fix'
141
- },
142
- 'circular-deps': {
143
- enabled: true,
144
- blocking: true,
145
- paths: ['src/']
146
- }
147
- },
148
- fixLoop: {
149
- enabled: true,
150
- maxAttempts: 5,
151
- autoFixRules: ['eslint']
152
- },
153
- commitMessage: {
154
- enabled: true,
155
- pattern: '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\\(.+\\))?: .{1,72}$'
156
- }
157
- };
158
-
159
- fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
160
- log(c.green, ' ✓ Created enforce.config.json');
161
- }
162
-
163
- function initializeHusky(projectRoot) {
164
- try {
165
- // Initialize husky
166
- execSync('npx husky', { cwd: projectRoot, stdio: 'ignore' });
167
- log(c.green, ' ✓ Initialized husky');
168
- } catch (error) {
169
- // Husky might already be initialized, that's okay
170
- }
171
- }
172
-
173
- function updatePackageJson(projectRoot) {
174
- const pkgPath = path.join(projectRoot, 'package.json');
175
-
176
- if (!fs.existsSync(pkgPath)) {
177
- log(c.yellow, ' ⚠ No package.json found');
178
- return;
179
- }
180
-
181
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
182
-
183
- // Add prepare script for husky if not exists
184
- if (!pkg.scripts) {
185
- pkg.scripts = {};
186
- }
187
-
188
- if (!pkg.scripts.prepare) {
189
- pkg.scripts.prepare = 'husky';
190
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
191
- log(c.green, ' ✓ Added prepare script to package.json');
192
- }
193
- }
194
-
195
- function createClaudeMd(projectRoot) {
196
- const claudePath = path.join(projectRoot, 'CLAUDE.md');
197
-
198
- if (fs.existsSync(claudePath)) {
199
- log(c.yellow, ' ⚠ CLAUDE.md already exists, skipping...');
200
- return;
201
- }
202
-
203
- const claudeContent = `# CLAUDE.md - AI Workflow Instructions
204
-
205
- > **MANDATORY**: Follow this workflow for ALL coding tasks.
206
-
207
- ## Workflow
208
-
209
- \`\`\`
210
- 1. ANALYZE → Read relevant files first
211
- 2. PLAN → Show plan + suggestions
212
- 3. CONFIRM → "Should I proceed?" (wait for approval)
213
- 4. IMPLEMENT → Make changes (after approval)
214
- 5. VERIFY → Run checks (autoworkflow handles this on commit)
215
- 6. COMMIT → Conventional commit format required
216
- \`\`\`
217
-
218
- ---
219
-
220
- ## Blocking Rules (Enforced by autoworkflow)
221
-
222
- These rules are **automatically enforced** on every commit:
223
-
224
- | Rule | Blocking | Auto-Fix |
225
- |------|----------|----------|
226
- | No TODO/FIXME comments | ⛔ YES | NO |
227
- | No console.log statements | ⛔ YES | NO |
228
- | TypeScript errors | ⛔ YES | NO |
229
- | ESLint errors | ⛔ YES | YES (auto-fix loop) |
230
- | Circular dependencies | ⛔ YES | NO |
231
- | Conventional commits | ⛔ YES | NO |
232
-
233
- ---
234
-
235
- ## Suggestions System
236
-
237
- For EVERY new feature, include suggestions after your plan:
238
-
239
- \`\`\`
240
- 💡 **Suggestions for Feature Completeness:**
241
-
242
- 🔴 **Required** (must implement):
243
- - [ ] Error handling for [specific case]
244
- - [ ] Loading state for [async operation]
245
- - [ ] Input validation for [field]
246
-
247
- 🟡 **Recommended** (improves quality):
248
- - [ ] Handle edge case: [scenario]
249
- - [ ] Add accessibility: [aria labels]
250
-
251
- 🟢 **Optional** (nice to have):
252
- - [ ] Add tests
253
- - [ ] Performance optimization
254
-
255
- **Which suggestions should I include?** (all/required/none)
256
- \`\`\`
257
-
258
- ---
259
-
260
- ## Confirmation Checkpoints
261
-
262
- ### Before Implementation
263
- \`\`\`
264
- ## Task: [description]
265
-
266
- ### Plan
267
- 1. [Change 1]
268
- 2. [Change 2]
269
-
270
- 💡 Suggestions: [list]
271
-
272
- **Should I proceed?**
273
- \`\`\`
274
-
275
- ### Before Commit
276
- \`\`\`
277
- ✅ All checks will run automatically via autoworkflow.
278
- **Should I commit with message: "type: description"?**
279
- \`\`\`
280
-
281
- ---
282
-
283
- ## Commit Message Format
284
-
285
- Must follow conventional commits:
286
-
287
- \`\`\`bash
288
- # Valid formats
289
- feat: add user authentication
290
- fix(api): resolve timeout issue
291
- docs: update readme
292
-
293
- # Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
294
- \`\`\`
295
-
296
- ---
297
-
298
- ## Rules
299
-
300
- 1. **Ask before implementing** - Plan first, wait for approval
301
- 2. **No console.log** - Use proper logging or remove
302
- 3. **No TODO comments** - Complete the work or create an issue
303
- 4. **Fix all errors** - TypeScript and ESLint must pass
304
- 5. **One feature at a time** - Complete fully before next
305
- 6. **Use conventional commits** - type(scope): description
306
- `;
307
-
308
- fs.writeFileSync(claudePath, claudeContent);
309
- log(c.green, ' ✓ Created CLAUDE.md');
310
- }
311
-
312
- function createVSCodeSettings(projectRoot) {
313
- const vscodeDir = path.join(projectRoot, '.vscode');
314
- const settingsPath = path.join(vscodeDir, 'settings.json');
315
-
316
- // Create .vscode directory if it doesn't exist
317
- if (!fs.existsSync(vscodeDir)) {
318
- fs.mkdirSync(vscodeDir, { recursive: true });
319
- }
320
-
321
- if (fs.existsSync(settingsPath)) {
322
- log(c.yellow, ' ⚠ .vscode/settings.json already exists, skipping...');
323
- return;
324
- }
325
-
326
- const settings = {
327
- // Editor - Format & Fix on Save
328
- "editor.formatOnSave": true,
329
- "editor.formatOnPaste": true,
330
- "editor.codeActionsOnSave": {
331
- "source.fixAll.eslint": "explicit",
332
- "source.organizeImports": "explicit",
333
- "source.removeUnusedImports": "explicit"
334
- },
335
- "editor.defaultFormatter": "esbenp.prettier-vscode",
336
- "editor.tabSize": 2,
337
- "editor.insertSpaces": true,
338
- "editor.detectIndentation": false,
339
- "editor.bracketPairColorization.enabled": true,
340
- "editor.guides.bracketPairs": true,
341
- "editor.linkedEditing": true,
342
- "editor.suggest.preview": true,
343
- "editor.inlineSuggest.enabled": true,
344
-
345
- // TypeScript - Use workspace version, strict checking
346
- "typescript.tsdk": "node_modules/typescript/lib",
347
- "typescript.enablePromptUseWorkspaceTsdk": true,
348
- "typescript.validate.enable": true,
349
- "typescript.suggestionActions.enabled": true,
350
- "typescript.preferences.importModuleSpecifier": "relative",
351
- "typescript.updateImportsOnFileMove.enabled": "always",
352
- "typescript.suggest.completeFunctionCalls": true,
353
-
354
- // JavaScript
355
- "javascript.updateImportsOnFileMove.enabled": "always",
356
- "javascript.suggest.completeFunctionCalls": true,
357
-
358
- // ESLint
359
- "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
360
- "eslint.codeActionsOnSave.mode": "all",
361
- "eslint.run": "onType",
362
-
363
- // Prettier
364
- "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
365
- "[typescriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
366
- "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
367
- "[javascriptreact]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
368
- "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
369
- "[jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
370
- "[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
371
- "[css]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
372
- "[scss]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
373
- "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
374
-
375
- // Files
376
- "files.autoSave": "onFocusChange",
377
- "files.trimTrailingWhitespace": true,
378
- "files.insertFinalNewline": true,
379
- "files.trimFinalNewlines": true,
380
- "files.associations": {
381
- "*.css": "tailwindcss"
382
- },
383
- "files.exclude": {
384
- "**/node_modules": true,
385
- "**/.git": true,
386
- "**/dist": true,
387
- "**/.next": true,
388
- "**/coverage": true
389
- },
390
-
391
- // Search
392
- "search.exclude": {
393
- "**/node_modules": true,
394
- "**/dist": true,
395
- "**/coverage": true,
396
- "**/.next": true,
397
- "**/package-lock.json": true
398
- },
399
-
400
- // Tailwind CSS
401
- "tailwindCSS.experimental.classRegex": [
402
- ["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
403
- ["cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
404
- ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
405
- ],
406
- "tailwindCSS.includeLanguages": {
407
- "typescript": "javascript",
408
- "typescriptreact": "javascript"
409
- },
410
-
411
- // Terminal
412
- "terminal.integrated.defaultProfile.osx": "zsh",
413
- "terminal.integrated.scrollback": 10000,
414
-
415
- // Git
416
- "git.enableSmartCommit": true,
417
- "git.confirmSync": false,
418
- "git.autofetch": true,
419
-
420
- // Explorer
421
- "explorer.confirmDelete": false,
422
- "explorer.confirmDragAndDrop": false,
423
- "explorer.compactFolders": false
424
- };
425
-
426
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
427
- log(c.green, ' ✓ Created .vscode/settings.json');
428
- }
429
-
430
- function createVSCodeTasks(projectRoot) {
431
- const vscodeDir = path.join(projectRoot, '.vscode');
432
- const tasksPath = path.join(vscodeDir, 'tasks.json');
433
-
434
- // Create .vscode directory if it doesn't exist
435
- if (!fs.existsSync(vscodeDir)) {
436
- fs.mkdirSync(vscodeDir, { recursive: true });
437
- }
438
-
439
- if (fs.existsSync(tasksPath)) {
440
- log(c.yellow, ' ⚠ .vscode/tasks.json already exists, skipping...');
441
- return;
442
- }
443
-
444
- const tasks = {
445
- "version": "2.0.0",
446
- "tasks": [
447
- {
448
- "label": "Autoworkflow: Run Checks",
449
- "type": "shell",
450
- "command": "npx autoworkflow run",
451
- "group": {
452
- "kind": "build",
453
- "isDefault": true
454
- },
455
- "presentation": {
456
- "reveal": "always",
457
- "panel": "shared",
458
- "clear": true
459
- },
460
- "problemMatcher": ["$tsc", "$eslint-stylish"]
461
- },
462
- {
463
- "label": "Autoworkflow: TypeScript Check",
464
- "type": "shell",
465
- "command": "npx tsc --noEmit",
466
- "group": "build",
467
- "presentation": {
468
- "reveal": "always",
469
- "panel": "shared"
470
- },
471
- "problemMatcher": "$tsc"
472
- },
473
- {
474
- "label": "Autoworkflow: ESLint Fix",
475
- "type": "shell",
476
- "command": "npx eslint . --fix",
477
- "group": "build",
478
- "presentation": {
479
- "reveal": "always",
480
- "panel": "shared"
481
- },
482
- "problemMatcher": "$eslint-stylish"
483
- },
484
- {
485
- "label": "Autoworkflow: List Rules",
486
- "type": "shell",
487
- "command": "npx autoworkflow list",
488
- "group": "build",
489
- "presentation": {
490
- "reveal": "always",
491
- "panel": "shared"
492
- },
493
- "problemMatcher": []
494
- },
495
- {
496
- "label": "Dev Server",
497
- "type": "shell",
498
- "command": "npm run dev",
499
- "group": "build",
500
- "isBackground": true,
501
- "presentation": {
502
- "reveal": "always",
503
- "panel": "dedicated"
504
- },
505
- "problemMatcher": []
506
- },
507
- {
508
- "label": "Quick Commit",
509
- "type": "shell",
510
- "command": "git add -A && git commit -m '${input:commitMessage}'",
511
- "group": "build",
512
- "presentation": {
513
- "reveal": "always",
514
- "panel": "shared"
515
- },
516
- "problemMatcher": []
517
- }
518
- ],
519
- "inputs": [
520
- {
521
- "id": "commitMessage",
522
- "type": "promptString",
523
- "description": "Commit message (e.g., 'feat: add dark mode')"
524
- }
525
- ]
526
- };
527
-
528
- fs.writeFileSync(tasksPath, JSON.stringify(tasks, null, 2));
529
- log(c.green, ' ✓ Created .vscode/tasks.json');
530
- }
531
-
532
- function main() {
533
- console.log('');
534
- log(c.blue, '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
535
- log(c.blue, '🔧 autoworkflow - Setting up...');
536
- log(c.blue, '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
537
- console.log('');
538
-
539
- const projectRoot = findProjectRoot();
540
-
541
- // Skip if we're in the package itself
542
- if (projectRoot.includes('node_modules')) {
543
- return;
544
- }
545
-
546
- log(c.blue, `Project root: ${projectRoot}`);
547
- console.log('');
548
-
549
- // Check if it's a git repo
550
- if (!isGitRepo(projectRoot)) {
551
- log(c.yellow, '⚠ Not a git repository. Initialize git first:');
552
- log(c.yellow, ' git init');
553
- console.log('');
554
- return;
555
- }
556
-
557
- // Setup husky
558
- const huskyDir = ensureHuskyDir(projectRoot);
559
- initializeHusky(projectRoot);
560
-
561
- // Create hooks
562
- createPreCommitHook(huskyDir, projectRoot);
563
- createCommitMsgHook(huskyDir);
564
-
565
- // Create config
566
- createDefaultConfig(projectRoot);
567
-
568
- // Update package.json
569
- updatePackageJson(projectRoot);
570
-
571
- // Create CLAUDE.md for AI workflow
572
- createClaudeMd(projectRoot);
573
-
574
- // Create VSCode settings and tasks
575
- createVSCodeSettings(projectRoot);
576
- createVSCodeTasks(projectRoot);
577
-
578
- console.log('');
579
- log(c.green, '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
580
- log(c.green, '✅ Setup complete!');
581
- log(c.green, '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
582
- console.log('');
583
- log(c.blue, 'Enforcement is now active. Just commit as usual:');
584
- console.log(' git add .');
585
- console.log(' git commit -m "feat: your feature"');
586
- console.log('');
587
- log(c.blue, 'Files created:');
588
- console.log(' • enforce.config.json - Rule configuration');
589
- console.log(' • CLAUDE.md - AI workflow instructions');
590
- console.log(' • .vscode/settings.json - Editor settings');
591
- console.log(' • .vscode/tasks.json - Quick tasks (Cmd+Shift+B)');
592
- console.log('');
593
- log(c.blue, 'CLI commands: npx autoworkflow --help');
594
- console.log('');
595
- }
596
-
597
- // Only run if this is the actual install (not during npm pack)
598
- if (!process.env.npm_config_ignore_scripts) {
599
- main();
600
- }