claude-code-templates 1.17.0 → 1.17.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +42 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-templates",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "CLI tool to setup Claude Code configurations with framework-specific commands, automation hooks and MCP Servers for your projects",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -747,22 +747,12 @@ async function installIndividualHook(hookName, targetDir, options) {
747
747
  console.log(chalk.yellow('📝 Existing .claude/settings.json found, merging hook configurations...'));
748
748
  }
749
749
 
750
- // Check for conflicts before merging
750
+ // Check for conflicts before merging (simplified for new array format)
751
751
  const conflicts = [];
752
752
 
753
- // Check for conflicting hooks
754
- if (existingConfig.hooks && hookConfig.hooks) {
755
- ['PreToolUse', 'PostToolUse'].forEach(hookType => {
756
- if (existingConfig.hooks[hookType] && hookConfig.hooks[hookType]) {
757
- Object.keys(hookConfig.hooks[hookType]).forEach(toolName => {
758
- if (existingConfig.hooks[hookType][toolName] &&
759
- existingConfig.hooks[hookType][toolName] !== hookConfig.hooks[hookType][toolName]) {
760
- conflicts.push(`Hook "${hookType}.${toolName}" (current: "${existingConfig.hooks[hookType][toolName]}", new: "${hookConfig.hooks[hookType][toolName]}")`);
761
- }
762
- });
763
- }
764
- });
765
- }
753
+ // For the new array format, we'll allow appending rather than conflict detection
754
+ // This is because Claude Code's array format naturally supports multiple hooks
755
+ // Conflicts are less likely and generally hooks can coexist
766
756
 
767
757
  // Ask user about conflicts if any exist and not in silent mode
768
758
  if (conflicts.length > 0 && !options.silent) {
@@ -787,26 +777,47 @@ async function installIndividualHook(hookName, targetDir, options) {
787
777
  return;
788
778
  }
789
779
 
790
- // Deep merge configurations
780
+ // Deep merge configurations with proper hook array structure
791
781
  const mergedConfig = {
792
- ...existingConfig,
793
- ...hookConfig
782
+ ...existingConfig
794
783
  };
795
784
 
796
- // Deep merge hooks specifically (only if no conflicts or user approved overwrite)
797
- if (existingConfig.hooks && hookConfig.hooks) {
798
- mergedConfig.hooks = {
799
- ...existingConfig.hooks,
800
- ...hookConfig.hooks
801
- };
802
-
803
- // Deep merge hook types (PreToolUse, PostToolUse)
804
- ['PreToolUse', 'PostToolUse'].forEach(hookType => {
805
- if (existingConfig.hooks[hookType] && hookConfig.hooks[hookType]) {
806
- mergedConfig.hooks[hookType] = {
807
- ...existingConfig.hooks[hookType],
808
- ...hookConfig.hooks[hookType]
809
- };
785
+ // Initialize hooks structure if it doesn't exist
786
+ if (!mergedConfig.hooks) {
787
+ mergedConfig.hooks = {};
788
+ }
789
+
790
+ // Merge hook configurations properly (Claude Code expects arrays)
791
+ if (hookConfig.hooks) {
792
+ Object.keys(hookConfig.hooks).forEach(hookType => {
793
+ if (!mergedConfig.hooks[hookType]) {
794
+ // If hook type doesn't exist, just copy the array
795
+ mergedConfig.hooks[hookType] = hookConfig.hooks[hookType];
796
+ } else {
797
+ // If hook type exists, append to the array (Claude Code format)
798
+ if (Array.isArray(hookConfig.hooks[hookType])) {
799
+ // New format: array of hook objects
800
+ if (!Array.isArray(mergedConfig.hooks[hookType])) {
801
+ // Convert old format to new format
802
+ mergedConfig.hooks[hookType] = [];
803
+ }
804
+ // Append new hooks to existing array
805
+ mergedConfig.hooks[hookType] = mergedConfig.hooks[hookType].concat(hookConfig.hooks[hookType]);
806
+ } else {
807
+ // Old format compatibility: convert to new format
808
+ console.log(chalk.yellow(`⚠️ Converting old hook format to new Claude Code format for ${hookType}`));
809
+ if (!Array.isArray(mergedConfig.hooks[hookType])) {
810
+ mergedConfig.hooks[hookType] = [];
811
+ }
812
+ // Add old format hook as a single matcher
813
+ mergedConfig.hooks[hookType].push({
814
+ matcher: "*",
815
+ hooks: [{
816
+ type: "command",
817
+ command: hookConfig.hooks[hookType]
818
+ }]
819
+ });
820
+ }
810
821
  }
811
822
  });
812
823
  }