claude-code-templates 1.26.2 → 1.26.3

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/chats-mobile.js +41 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-templates",
3
- "version": "1.26.2",
3
+ "version": "1.26.3",
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": {
@@ -1187,6 +1187,12 @@ class ChatsMobile {
1187
1187
  * Stop the server
1188
1188
  */
1189
1189
  async stop() {
1190
+ // Prevent multiple stop calls
1191
+ if (this.isStopped) {
1192
+ return;
1193
+ }
1194
+ this.isStopped = true;
1195
+
1190
1196
  if (this.cloudflaredProcess) {
1191
1197
  try {
1192
1198
  this.cloudflaredProcess.kill('SIGTERM');
@@ -1195,26 +1201,28 @@ class ChatsMobile {
1195
1201
  this.log('warn', chalk.yellow('⚠️ Error stopping Cloudflare Tunnel:', error.message));
1196
1202
  }
1197
1203
  }
1198
-
1204
+
1199
1205
  if (this.webSocketServer) {
1200
1206
  try {
1207
+ console.log(chalk.gray('🔌 Closing WebSocket server...'));
1201
1208
  await this.webSocketServer.close();
1202
- this.log('info', chalk.gray('🌐 WebSocket server stopped'));
1209
+ console.log(chalk.green(' WebSocket server closed'));
1203
1210
  } catch (error) {
1204
1211
  this.log('warn', chalk.yellow('⚠️ Error stopping WebSocket server:', error.message));
1205
1212
  }
1206
1213
  }
1207
-
1214
+
1208
1215
  if (this.httpServer) {
1209
1216
  await new Promise((resolve) => {
1210
1217
  this.httpServer.close(resolve);
1211
1218
  });
1212
1219
  }
1213
-
1220
+
1214
1221
  if (this.fileWatcher) {
1222
+ console.log(chalk.gray('🛑 Stopping file watchers...'));
1215
1223
  await this.fileWatcher.stop();
1216
1224
  }
1217
-
1225
+
1218
1226
  console.log(chalk.gray('🛑 Chats Mobile server stopped'));
1219
1227
  }
1220
1228
  }
@@ -1245,14 +1253,35 @@ async function startChatsMobile(options = {}) {
1245
1253
  }
1246
1254
 
1247
1255
  console.log(chalk.gray('Press Ctrl+C to stop'));
1248
-
1249
- // Handle graceful shutdown
1250
- process.on('SIGINT', async () => {
1256
+
1257
+ // Handle graceful shutdown - remove existing listeners first to prevent duplicates
1258
+ const shutdownHandler = async () => {
1259
+ if (chatsMobile.isShuttingDown) return; // Prevent multiple shutdown attempts
1260
+ chatsMobile.isShuttingDown = true;
1261
+
1251
1262
  console.log(chalk.yellow('\n🛑 Shutting down...'));
1252
- await chatsMobile.stop();
1253
- process.exit(0);
1254
- });
1255
-
1263
+
1264
+ // Remove this specific handler to prevent it from being called again
1265
+ process.removeListener('SIGINT', shutdownHandler);
1266
+ process.removeListener('SIGTERM', shutdownHandler);
1267
+
1268
+ try {
1269
+ await chatsMobile.stop();
1270
+ process.exit(0);
1271
+ } catch (error) {
1272
+ console.error(chalk.red('❌ Error during shutdown:'), error);
1273
+ process.exit(1);
1274
+ }
1275
+ };
1276
+
1277
+ // Remove any existing SIGINT/SIGTERM listeners to prevent duplicates
1278
+ process.removeAllListeners('SIGINT');
1279
+ process.removeAllListeners('SIGTERM');
1280
+
1281
+ // Add the new handler
1282
+ process.on('SIGINT', shutdownHandler);
1283
+ process.on('SIGTERM', shutdownHandler);
1284
+
1256
1285
  } catch (error) {
1257
1286
  console.error(chalk.red('❌ Failed to start Chats Mobile:'), error);
1258
1287
  process.exit(1);