cloudflare-tunnel-kit 0.1.2 → 0.1.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/README.md CHANGED
@@ -35,40 +35,52 @@ The toolkit does not concatenate user input into shell commands, print secrets t
35
35
 
36
36
  ## Installation
37
37
 
38
- Install the package after it is published:
38
+ Install the package in the project that needs a tunnel:
39
39
 
40
40
  ```bash
41
41
  npm install --save-dev cloudflare-tunnel-kit
42
42
  ```
43
43
 
44
- For a source checkout:
44
+ The package exposes the `cf-tunnel` binary locally. Run it through `npx` so no global installation is required:
45
45
 
46
46
  ```bash
47
- npm install
48
- npm run build
49
- node ./dist/cli/main.js --help
47
+ npx cf-tunnel
48
+ npx cf-tunnel ui
49
+ ```
50
+
51
+ You can also add project scripts:
52
+
53
+ ```json
54
+ {
55
+ "scripts": {
56
+ "tunnel": "cf-tunnel",
57
+ "tunnel:ui": "cf-tunnel ui"
58
+ }
59
+ }
50
60
  ```
51
61
 
62
+ Then run `npm run tunnel` or `npm run tunnel:ui`.
63
+
52
64
  ## CLI usage
53
65
 
54
66
  Check the local environment:
55
67
 
56
68
  ```bash
57
- cf-tunnel doctor
69
+ npx cf-tunnel doctor
58
70
  ```
59
71
 
60
- Run `cf-tunnel` or `cf-tunnel init` without options to start the interactive text-only wizard. It asks for each value, validates before execution, prints a command preview, and asks for confirmation.
72
+ Run `npx cf-tunnel` without options to start the interactive text-only wizard. It asks for each value, validates before execution, prints a command preview, and asks for confirmation.
61
73
 
62
74
  Preview a Quick Tunnel without starting `cloudflared`:
63
75
 
64
76
  ```bash
65
- cf-tunnel quick --url http://127.0.0.1:8000 --dry-run
77
+ npx cf-tunnel quick --url http://127.0.0.1:8000 --dry-run
66
78
  ```
67
79
 
68
80
  Preview a named tunnel:
69
81
 
70
82
  ```bash
71
- cf-tunnel create \
83
+ npx cf-tunnel create \
72
84
  --url http://127.0.0.1:8000 \
73
85
  --name my-project \
74
86
  --hostname tunnel.example.com \
@@ -78,39 +90,22 @@ cf-tunnel create \
78
90
  Lifecycle commands:
79
91
 
80
92
  ```text
81
- cf-tunnel start --name my-project
82
- cf-tunnel stop --name my-project
83
- cf-tunnel status --name my-project
93
+ npx cf-tunnel start --name my-project
94
+ npx cf-tunnel stop --name my-project
95
+ npx cf-tunnel status --name my-project
84
96
  ```
85
97
 
86
98
  `--yes` does not bypass validation or Laravel `.env` confirmation.
87
99
 
88
- ## Makefile shortcuts
89
-
90
- The repository includes a small Makefile for discoverable commands:
91
-
92
- ```bash
93
- make setup
94
- make help
95
- make init
96
- make ui
97
- make quick URL=http://127.0.0.1:8000
98
- make create NAME=law-firm URL=http://127.0.0.1:8000
99
- make doctor
100
- make test
101
- ```
102
-
103
- `make quick` and `make create` use `--dry-run` by default. Review the plan, then use the CLI to execute and confirm the operation explicitly.
104
-
105
100
  ## Live UI
106
101
 
107
102
  Start the local UI:
108
103
 
109
104
  ```bash
110
- cf-tunnel ui
105
+ npx cf-tunnel ui
111
106
  ```
112
107
 
113
- Open the URL printed in the terminal, usually `http://127.0.0.1:<port>`. The wizard includes profile selection, local URL input, tunnel name, validation, plan preview, confirmation, execution, and a button to copy a redacted AI-help prompt.
108
+ The command prints startup progress, chooses an available loopback port, and opens the browser automatically. If the browser cannot be opened, copy the printed `http://127.0.0.1:<port>` URL. Use `npx cf-tunnel ui --no-open` when you only want the URL.
114
109
 
115
110
  The UI binds to loopback by default and does not send the copied prompt anywhere.
116
111
 
@@ -119,8 +114,8 @@ The UI binds to loopback by default and does not send the copied prompt anywhere
119
114
  The custom profile makes no framework assumptions:
120
115
 
121
116
  ```bash
122
- cf-tunnel quick --profile custom --url http://127.0.0.1:3000 --dry-run
123
- cf-tunnel create --profile custom --url http://127.0.0.1:8000 --name billing --dry-run
117
+ npx cf-tunnel quick --profile custom --url http://127.0.0.1:3000 --dry-run
118
+ npx cf-tunnel create --profile custom --url http://127.0.0.1:8000 --name billing --hostname billing.example.com --dry-run
124
119
  ```
125
120
 
126
121
  ## Laravel profile
@@ -130,10 +125,11 @@ The Laravel adapter checks for `artisan` and Laravel evidence in `composer.json`
130
125
  Every mapping is shown as a diff and requires explicit confirmation. If `.env` is missing or ambiguous, the adapter stops with a remediation message instead of guessing.
131
126
 
132
127
  ```bash
133
- cf-tunnel create \
128
+ npx cf-tunnel create \
134
129
  --profile laravel \
135
130
  --url http://127.0.0.1:8000 \
136
131
  --name law-firm \
132
+ --hostname law.example.com \
137
133
  --dry-run
138
134
  ```
139
135
 
@@ -214,6 +210,8 @@ An already-published `name@version` cannot be published again. See the [npm publ
214
210
 
215
211
  ## Development
216
212
 
213
+ These commands are only for contributors working from a source checkout. Projects that install the npm package do not need this repository's Makefile.
214
+
217
215
  ```bash
218
216
  npm install
219
217
  npm test
package/dist/cli/main.js CHANGED
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
2
3
  import { createServer } from '../ui/server.js';
3
4
  import { createTunnelPlan, executeTunnelPlan } from '../index.js';
4
5
  import { createLaravelPlan } from '../index.js';
6
+ import { launchBrowser } from '../providers/browser.js';
5
7
  import { runWizard } from './wizard.js';
6
8
  const args = process.argv.slice(2);
7
9
  const command = args[0] ?? 'init';
10
+ const packageVersion = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
8
11
  const value = (name) => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : undefined; };
9
- function help() { console.log(`cloudflare-tunnel-kit 0.1.0\n\nUsage: cf-tunnel <command> [options]\n\nCommands: init create quick start stop status doctor ui\nOptions: --url URL --name NAME --hostname HOST --profile custom|laravel --config PATH --dry-run --yes --no-open`); }
12
+ function help() { console.log(`cloudflare-tunnel-kit ${packageVersion}\n\nUsage from an installed project:\n npx cf-tunnel\n npx cf-tunnel ui\n\nCommands: init create quick start stop status doctor ui\nOptions: --url URL --name NAME --hostname HOST --profile custom|laravel --config PATH --dry-run --yes --no-open`); }
10
13
  async function main() {
11
14
  if (command === 'init') {
12
15
  if (args.length === 1)
@@ -15,8 +18,24 @@ async function main() {
15
18
  if (command === 'help' || command === '--help')
16
19
  return help();
17
20
  if (command === 'ui') {
21
+ console.log('Starting Cloudflare Tunnel Kit UI on this machine...');
18
22
  const server = createServer();
19
- server.listen(0, '127.0.0.1', () => { const a = server.address(); console.log(`UI ready at http://127.0.0.1:${a.port}`); });
23
+ server.once('error', error => {
24
+ console.error(`Unable to start the local UI: ${error.message}`);
25
+ console.error('Check whether local server processes are allowed, then run `npx cf-tunnel ui` again.');
26
+ process.exitCode = 1;
27
+ });
28
+ server.listen(0, '127.0.0.1', async () => {
29
+ const address = server.address();
30
+ if (!address || typeof address === 'string')
31
+ return;
32
+ const url = `http://127.0.0.1:${address.port}`;
33
+ console.log(`UI ready at ${url}`);
34
+ if (!args.includes('--no-open')) {
35
+ const result = await launchBrowser(url);
36
+ console.log(result.message);
37
+ }
38
+ });
20
39
  return;
21
40
  }
22
41
  if (command === 'doctor') {
package/dist/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from './providers/command-runner.js';
13
13
  export * from './providers/cloudflared.js';
14
14
  export * from './providers/git-safety.js';
15
15
  export * from './providers/process-supervisor.js';
16
+ export * from './providers/browser.js';
package/dist/index.js CHANGED
@@ -13,3 +13,4 @@ export * from './providers/command-runner.js';
13
13
  export * from './providers/cloudflared.js';
14
14
  export * from './providers/git-safety.js';
15
15
  export * from './providers/process-supervisor.js';
16
+ export * from './providers/browser.js';
@@ -0,0 +1,9 @@
1
+ export declare function launchBrowser(url: string, options?: {
2
+ platform?: string;
3
+ run?: (executable: string, args: string[]) => Promise<{
4
+ exitCode: number;
5
+ }>;
6
+ }): Promise<{
7
+ opened: boolean;
8
+ message: string;
9
+ }>;
@@ -0,0 +1,17 @@
1
+ import { runCommand } from './command-runner.js';
2
+ export async function launchBrowser(url, options = {}) {
3
+ const platform = options.platform ?? process.platform;
4
+ const run = options.run ?? ((executable, args) => runCommand({ executable, args, timeoutMs: 10_000 }));
5
+ const command = platform === 'darwin'
6
+ ? ['open', [url]]
7
+ : platform === 'win32'
8
+ ? ['cmd.exe', ['/c', 'start', '', url]]
9
+ : ['xdg-open', [url]];
10
+ try {
11
+ const result = await run(command[0], [...command[1]]);
12
+ if (result.exitCode === 0)
13
+ return { opened: true, message: `Opened ${url}` };
14
+ }
15
+ catch { }
16
+ return { opened: false, message: `Open this URL manually: ${url}` };
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-tunnel-kit",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Safe, reusable Cloudflare Tunnel setup for custom and Laravel projects.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -34,6 +34,6 @@
34
34
  },
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "better-sqlite3": "^13.0.3"
37
+ "better-sqlite3": "^12.11.1"
38
38
  }
39
39
  }