localssl-cli 0.1.1 → 0.1.2

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/bin/localssl.js CHANGED
@@ -9,13 +9,15 @@ const { renew } = require('../src/renew');
9
9
  const { removeAll } = require('../src/remove');
10
10
  const { trustTeam } = require('../src/trust');
11
11
  const { isCI, err } = require('../src/utils');
12
+ const packageJson = require('../package.json');
12
13
 
13
14
  const program = new Command();
14
15
 
15
16
  program
16
17
  .name('localssl')
17
18
  .description('One-command local HTTPS setup')
18
- .version('0.1.0');
19
+ .version(packageJson.version)
20
+ .option('-o, --open', 'open HTTPS URL in your default browser');
19
21
 
20
22
  program
21
23
  .command('init')
@@ -26,7 +28,8 @@ program
26
28
  .command('use')
27
29
  .description('Generate per-project certificate and configure framework')
28
30
  .argument('[hosts...]', 'additional hosts')
29
- .action(runGuard(async (hosts) => useProject(hosts || [])));
31
+ .option('-o, --open', 'open HTTPS URL in your default browser')
32
+ .action(runGuard(async (hosts, options) => useProject(hosts || [], { open: !!options.open })));
30
33
 
31
34
  program
32
35
  .command('status')
@@ -64,7 +67,8 @@ program
64
67
  .action(runGuard(removeAll));
65
68
 
66
69
  program.action(runGuard(async () => {
67
- await useProject([]);
70
+ const opts = program.opts();
71
+ await useProject([], { open: !!opts.open });
68
72
  }));
69
73
 
70
74
  program.parseAsync(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "localssl-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "One-command local HTTPS setup for teams",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
package/src/open.js ADDED
@@ -0,0 +1,21 @@
1
+ const { execFile } = require('child_process');
2
+
3
+ function openBrowser(url) {
4
+ return new Promise((resolve) => {
5
+ if (process.platform === 'win32') {
6
+ execFile('powershell', ['-NoProfile', '-Command', `Start-Process '${url}'`], { windowsHide: true }, (error) => {
7
+ resolve(!error);
8
+ });
9
+ return;
10
+ }
11
+
12
+ if (process.platform === 'darwin') {
13
+ execFile('open', [url], (error) => resolve(!error));
14
+ return;
15
+ }
16
+
17
+ execFile('xdg-open', [url], (error) => resolve(!error));
18
+ });
19
+ }
20
+
21
+ module.exports = { openBrowser };
package/src/use.js CHANGED
@@ -4,8 +4,23 @@ const { configureFramework } = require('./frameworks');
4
4
  const { ensureGitignore } = require('./gitignore');
5
5
  const { syncCurrentMachine, trustTeamCertificates } = require('./team');
6
6
  const { step, info } = require('./utils');
7
+ const { openBrowser } = require('./open');
7
8
 
8
- async function useProject(hostsArg = []) {
9
+ function defaultPortForFramework(framework) {
10
+ if (framework === 'Vite') return 5173;
11
+ if (framework === 'Next.js') return 3000;
12
+ if (framework === 'Create React App') return 3000;
13
+ if (framework === 'Webpack Dev Server') return 8080;
14
+ return 3000;
15
+ }
16
+
17
+ function buildOpenUrl(hosts, framework) {
18
+ const host = hosts.includes('localhost') ? 'localhost' : hosts[0] || 'localhost';
19
+ const port = defaultPortForFramework(framework);
20
+ return `https://${host}:${port}`;
21
+ }
22
+
23
+ async function useProject(hostsArg = [], options = {}) {
9
24
  info('Setting up local HTTPS for this project...');
10
25
 
11
26
  const total = 4;
@@ -31,10 +46,19 @@ async function useProject(hostsArg = []) {
31
46
 
32
47
  const teamConfig = await syncCurrentMachine(hosts);
33
48
  const trusted = await trustTeamCertificates(teamConfig);
49
+ const openUrl = buildOpenUrl(hosts, frameworkResult.framework);
34
50
 
35
51
  info('Done. Start your dev server — HTTPS is ready.');
36
52
  info('Run: npm run dev');
53
+ info(`Open: ${openUrl}`);
37
54
  info(`Team CAs trusted: ${trusted}`);
55
+
56
+ if (options.open) {
57
+ const opened = await openBrowser(openUrl);
58
+ if (opened) {
59
+ info('Browser opened ✓');
60
+ }
61
+ }
38
62
  }
39
63
 
40
64
  module.exports = { useProject };