copyhub-cli 1.0.3 → 1.0.4

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/.env.example CHANGED
@@ -1,4 +1,5 @@
1
- # Copy to .env and fill in values. CopyHub reads .env when you run the CLI from the current directory.
1
+ # Copy to `.env` (project folder), `~/.copyhub/.env`, or both. CopyHub merges these without relying on cwd alone:
2
+ # package dir `.env` → ~/.copyhub/.env → current working directory `.env` (later wins). Shell-exported vars always win.
2
3
  #
3
4
  # Google Cloud Console → APIs: enable "Google Sheets API" on the SAME project as your OAuth client ID
4
5
  # (if sync fails with project=..., open the Enable link in the log or Library → Google Sheets API → Enable).
package/README.md CHANGED
@@ -120,7 +120,7 @@ copyhub start
120
120
 
121
121
  - **Recommended for first setup:** run **`copyhub login`** with no secrets configured — your browser opens a **localhost wizard** where you paste **Client ID** and **Client secret** (the same values as `COPYHUB_GOOGLE_CLIENT_ID` / `COPYHUB_GOOGLE_CLIENT_SECRET`); they are stored in `~/.copyhub/config.json`.
122
122
 
123
- - Copy `.env.example` to `.env` and set `COPYHUB_GOOGLE_CLIENT_ID`, `COPYHUB_GOOGLE_CLIENT_SECRET`, and optionally `COPYHUB_OAUTH_REDIRECT_PORT` (default **19999**).
123
+ - Copy `.env.example` to **`~/.copyhub/.env`** and/or a `.env` in your project folder and set `COPYHUB_GOOGLE_CLIENT_ID`, `COPYHUB_GOOGLE_CLIENT_SECRET`, and optionally `COPYHUB_OAUTH_REDIRECT_PORT` (default **19999**). This works even with **`npm install -g`** when your shell is not in the repo directory.
124
124
 
125
125
  - Or run **`copyhub config`**:
126
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copyhub-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "CopyHub — clipboard, local history, Google Sheets sync (OAuth). Windows, macOS, Linux.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
2
+ import { loadCopyhubEnv } from './load-env.js';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { program } from 'commander';
@@ -33,6 +33,8 @@ import { ensureDir } from './storage.js';
33
33
  import { runCopyhubDaemon } from './start-daemon-logic.js';
34
34
  import { wipeCopyhubDirectory } from './wipe-data.js';
35
35
 
36
+ loadCopyhubEnv();
37
+
36
38
  const CLI_JS = fileURLToPath(new URL('./cli.js', import.meta.url));
37
39
 
38
40
  program.name('copyhub').description(
@@ -0,0 +1,39 @@
1
+ import dotenv from 'dotenv';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { DIR } from './paths.js';
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+
9
+ /**
10
+ * Merge `.env` files into `process.env` without overwriting shell-exported vars.
11
+ * Order (later wins among files only): package directory → ~/.copyhub/.env → cwd.
12
+ * Fixes global `copyhub login` when cwd has no `.env` (dotenv/config default looks only at cwd).
13
+ */
14
+ export function loadCopyhubEnv() {
15
+ const pkgRoot = join(__dirname, '..');
16
+ const paths = [
17
+ join(pkgRoot, '.env'),
18
+ join(DIR, '.env'),
19
+ join(process.cwd(), '.env'),
20
+ ];
21
+
22
+ /** @type {Record<string, string>} */
23
+ const merged = {};
24
+ for (const p of paths) {
25
+ if (!existsSync(p)) continue;
26
+ try {
27
+ const raw = readFileSync(p, 'utf8');
28
+ Object.assign(merged, dotenv.parse(raw));
29
+ } catch {
30
+ /* ignore unreadable or malformed .env */
31
+ }
32
+ }
33
+
34
+ for (const [key, value] of Object.entries(merged)) {
35
+ if (process.env[key] === undefined) {
36
+ process.env[key] = value;
37
+ }
38
+ }
39
+ }
package/ui/main.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import 'dotenv/config';
2
1
  import path from 'node:path';
3
2
  import { fileURLToPath } from 'node:url';
4
3
  import {
@@ -12,6 +11,7 @@ import {
12
11
  Menu,
13
12
  nativeImage,
14
13
  } from 'electron';
14
+ import { loadCopyhubEnv } from '../src/load-env.js';
15
15
  import { readRecentHistorySync } from '../src/storage.js';
16
16
  import {
17
17
  loadOverlayAcceleratorFromConfigSync,
@@ -20,6 +20,8 @@ import {
20
20
  import { loadTokens } from '../src/tokens.js';
21
21
  import { fetchOverlayDailyTabRows } from '../src/sheet-overlay-history.js';
22
22
 
23
+ loadCopyhubEnv();
24
+
23
25
  const gotLock = app.requestSingleInstanceLock();
24
26
  if (!gotLock) {
25
27
  app.quit();