localssl-cli 0.1.1 → 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/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.3",
4
4
  "description": "One-command local HTTPS setup for teams",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "scripts": {
15
15
  "start": "node bin/localssl.js",
16
- "test": "node -e \"console.log('No tests yet')\""
16
+ "test": "node -e \"console.log('No tests yet')\"",
17
+ "postinstall": "node src/postinstall.js"
17
18
  },
18
19
  "keywords": [
19
20
  "https",
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 };
@@ -0,0 +1,60 @@
1
+ const path = require('path');
2
+ const fs = require('fs-extra');
3
+
4
+ function ensureHook(scripts, hookName, targetCommand, baseScriptName) {
5
+ if (!scripts[baseScriptName]) {
6
+ return false;
7
+ }
8
+
9
+ const current = scripts[hookName];
10
+ if (!current) {
11
+ scripts[hookName] = targetCommand;
12
+ return true;
13
+ }
14
+
15
+ if (current.includes('localssl-cli use') || current.includes('localssl use')) {
16
+ return false;
17
+ }
18
+
19
+ scripts[hookName] = `${targetCommand} && ${current}`;
20
+ return true;
21
+ }
22
+
23
+ async function run() {
24
+ if (process.env.LOCALSSL_SKIP_POSTINSTALL === '1') {
25
+ return;
26
+ }
27
+
28
+ const packageRoot = path.resolve(__dirname, '..');
29
+ const initCwd = path.resolve(process.env.INIT_CWD || process.cwd());
30
+ if (initCwd === packageRoot) {
31
+ return;
32
+ }
33
+
34
+ const targetPackageJsonPath = path.join(initCwd, 'package.json');
35
+ if (!(await fs.pathExists(targetPackageJsonPath))) {
36
+ return;
37
+ }
38
+
39
+ let targetPackage;
40
+ try {
41
+ targetPackage = await fs.readJson(targetPackageJsonPath);
42
+ } catch {
43
+ return;
44
+ }
45
+
46
+ targetPackage.scripts = targetPackage.scripts || {};
47
+
48
+ let changed = false;
49
+ changed = ensureHook(targetPackage.scripts, 'predev', 'localssl-cli use', 'dev') || changed;
50
+ changed = ensureHook(targetPackage.scripts, 'prestart', 'localssl-cli use', 'start') || changed;
51
+
52
+ if (!changed) {
53
+ return;
54
+ }
55
+
56
+ await fs.writeJson(targetPackageJsonPath, targetPackage, { spaces: 2 });
57
+ console.log('localssl-cli: added predev/prestart HTTPS setup hooks');
58
+ }
59
+
60
+ run().catch(() => {});
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 };