@abyrd9/harbor-cli 0.0.2 → 0.0.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.
package/dist/index.js CHANGED
@@ -292,6 +292,16 @@ async function generateCaddyFile() {
292
292
  try {
293
293
  const config = await readHarborConfig();
294
294
  let caddyfileContent = '';
295
+ // Check if any services need a Caddyfile
296
+ const needsCaddyfile = config.services.some(svc => svc.port && svc.subdomain);
297
+ if (!needsCaddyfile) {
298
+ // If no services need a Caddyfile, remove it if it exists
299
+ if (fileExists('Caddyfile')) {
300
+ await fs.promises.unlink('Caddyfile');
301
+ console.log('Removed Caddyfile as no services require subdomains');
302
+ }
303
+ return;
304
+ }
295
305
  for (const svc of config.services) {
296
306
  if (!svc.port || !svc.subdomain) {
297
307
  continue;
@@ -320,8 +330,9 @@ async function runServices() {
320
330
  process.exit(1);
321
331
  }
322
332
  // Load and validate config
333
+ let config;
323
334
  try {
324
- const config = await readHarborConfig();
335
+ config = await readHarborConfig();
325
336
  const validationError = validateConfig(config);
326
337
  if (validationError) {
327
338
  console.log(`❌ Invalid harbor.json configuration: ${validationError}`);
@@ -332,16 +343,18 @@ async function runServices() {
332
343
  console.error('Error reading config:', err);
333
344
  process.exit(1);
334
345
  }
335
- if (!fileExists('Caddyfile')) {
336
- console.log('❌ No Caddyfile found');
337
- console.log('\nTo initialize a new Harbor project, please use:');
346
+ // Check if any services need a Caddyfile
347
+ const needsCaddyfile = config.services.some(svc => svc.port && svc.subdomain);
348
+ if (needsCaddyfile && !fileExists('Caddyfile')) {
349
+ console.log('❌ No Caddyfile found, but some services require subdomains');
350
+ console.log('\nTo generate the Caddyfile:');
338
351
  console.log(' harbor anchor');
339
- console.log('\nOr to generate just the Caddyfile:');
340
- console.log(' harbor moor');
341
352
  process.exit(1);
342
353
  }
343
- // Stop any existing Caddy process
344
- await stopCaddy();
354
+ // Stop any existing Caddy process if we need it
355
+ if (needsCaddyfile) {
356
+ await stopCaddy();
357
+ }
345
358
  // Ensure scripts exist and are executable
346
359
  await ensureScriptsExist();
347
360
  // Execute the script directly using spawn to handle I/O streams
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyrd9/harbor-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A CLI tool for managing local development services with automatic subdomain routing",
5
5
  "type": "module",
6
6
  "bin": {
package/scripts/dev.sh CHANGED
@@ -68,13 +68,28 @@ tmux set-option -g 'status-format[0]' ''
68
68
  echo "Creating window for interactive shell"
69
69
  tmux rename-window -t local-dev-test:0 'Terminal'
70
70
 
71
- # Create a new window for Caddy (now on index 1)
72
- echo "Creating window for Caddy"
73
- tmux new-window -t local-dev-test:1 -n 'Caddy'
74
- tmux send-keys -t local-dev-test:1 'caddy run' C-m
71
+ # Check if any services need Caddy
72
+ needs_caddy=false
73
+ jq -c '.services[]' harbor.json | while read service; do
74
+ subdomain=$(echo $service | jq -r '.subdomain // empty')
75
+ port=$(echo $service | jq -r '.port // empty')
76
+ if [ ! -z "$subdomain" ] && [ ! -z "$port" ]; then
77
+ needs_caddy=true
78
+ break
79
+ fi
80
+ done
81
+
82
+ window_index=1 # Start from index 1
83
+
84
+ # Create a new window for Caddy if needed
85
+ if [ "$needs_caddy" = true ]; then
86
+ echo "Creating window for Caddy"
87
+ tmux new-window -t local-dev-test:1 -n 'Caddy'
88
+ tmux send-keys -t local-dev-test:1 'caddy run' C-m
89
+ window_index=2 # Start services from index 2
90
+ fi
75
91
 
76
92
  # Create windows dynamically based on harbor.json
77
- window_index=2 # Start from index 2 since we have Terminal and Caddy
78
93
  jq -c '.services[]' harbor.json | while read service; do
79
94
  name=$(echo $service | jq -r '.name')
80
95
  path=$(echo $service | jq -r '.path')