localssl-cli 0.1.8 → 0.1.9
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 +3 -1
- package/package.json +1 -1
- package/src/frameworks/angular.js +97 -0
- package/src/frameworks/detect.js +1 -0
- package/src/frameworks/index.js +6 -0
- package/src/postinstall.js +2 -1
- package/src/use.js +1 -0
package/README.md
CHANGED
|
@@ -48,7 +48,8 @@ Then run your app as usual (`npm run dev` / `npm start`).
|
|
|
48
48
|
|
|
49
49
|
- Adds `predev: "localssl-cli use"` if `dev` exists
|
|
50
50
|
- Adds `prestart: "localssl-cli use"` if `start` exists
|
|
51
|
-
-
|
|
51
|
+
- Adds `preserve: "localssl-cli use"` if `serve` exists
|
|
52
|
+
- If pre-hooks already exist, prepends `localssl-cli use && ...`
|
|
52
53
|
- Skips if already configured
|
|
53
54
|
|
|
54
55
|
Disable this behavior:
|
|
@@ -119,6 +120,7 @@ Best-effort cleanup:
|
|
|
119
120
|
## Framework support
|
|
120
121
|
|
|
121
122
|
- **Vite**: injects HTTPS cert/key in `vite.config.*`
|
|
123
|
+
- **Angular (`ng serve`)**: updates `start/dev/serve` scripts with `--ssl`, `--ssl-cert`, `--ssl-key` and updates `angular.json` serve options when available
|
|
122
124
|
- **Next.js**: updates `dev` script with `--experimental-https` flags
|
|
123
125
|
- **Create React App**: writes HTTPS vars to `.env.local`
|
|
124
126
|
- **Express**: creates `localssl.js` helper exporting HTTPS options
|
package/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const { PROJECT_DIR } = require('../utils');
|
|
4
|
+
|
|
5
|
+
function addHttpsFlagsToNgServe(script, certPath, keyPath) {
|
|
6
|
+
if (!/\bng\s+serve\b/.test(script)) {
|
|
7
|
+
return { changed: false, value: script };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (/--ssl\b/.test(script) || /--ssl-cert\b/.test(script) || /--ssl-key\b/.test(script)) {
|
|
11
|
+
return { changed: false, value: script };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const cert = certPath.replace(/\\/g, '/');
|
|
15
|
+
const key = keyPath.replace(/\\/g, '/');
|
|
16
|
+
const value = `${script} --ssl true --ssl-cert \"${cert}\" --ssl-key \"${key}\"`;
|
|
17
|
+
return { changed: true, value };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function configureAngularScripts(certPath, keyPath) {
|
|
21
|
+
const packageJsonPath = path.join(PROJECT_DIR, 'package.json');
|
|
22
|
+
if (!(await fs.pathExists(packageJsonPath))) {
|
|
23
|
+
return { updated: false, details: 'package.json not found' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const pkg = await fs.readJson(packageJsonPath).catch(() => ({}));
|
|
27
|
+
pkg.scripts = pkg.scripts || {};
|
|
28
|
+
|
|
29
|
+
let changed = false;
|
|
30
|
+
for (const scriptName of ['start', 'dev', 'serve']) {
|
|
31
|
+
const current = pkg.scripts[scriptName];
|
|
32
|
+
if (!current) continue;
|
|
33
|
+
|
|
34
|
+
const result = addHttpsFlagsToNgServe(current, certPath, keyPath);
|
|
35
|
+
if (result.changed) {
|
|
36
|
+
pkg.scripts[scriptName] = result.value;
|
|
37
|
+
changed = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (changed) {
|
|
42
|
+
await fs.writeJson(packageJsonPath, pkg, { spaces: 2 });
|
|
43
|
+
return { updated: true, details: 'package.json ng serve scripts updated' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { updated: false, details: 'ng serve scripts already configured' };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function configureAngularJson(certPath, keyPath) {
|
|
50
|
+
const angularJsonPath = path.join(PROJECT_DIR, 'angular.json');
|
|
51
|
+
if (!(await fs.pathExists(angularJsonPath))) {
|
|
52
|
+
return { updated: false, details: 'angular.json not found' };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const angular = await fs.readJson(angularJsonPath).catch(() => ({}));
|
|
56
|
+
const projects = angular.projects || {};
|
|
57
|
+
const defaultProject = angular.defaultProject || Object.keys(projects)[0];
|
|
58
|
+
if (!defaultProject || !projects[defaultProject]) {
|
|
59
|
+
return { updated: false, details: 'angular project config not found' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const project = projects[defaultProject];
|
|
63
|
+
const serve = project.architect?.serve || project.targets?.serve;
|
|
64
|
+
if (!serve) {
|
|
65
|
+
return { updated: false, details: 'serve target not found' };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
serve.options = serve.options || {};
|
|
69
|
+
const cert = certPath.replace(/\\/g, '/');
|
|
70
|
+
const key = keyPath.replace(/\\/g, '/');
|
|
71
|
+
|
|
72
|
+
const already = serve.options.ssl === true && serve.options.sslCert === cert && serve.options.sslKey === key;
|
|
73
|
+
if (already) {
|
|
74
|
+
return { updated: false, details: 'angular.json already configured' };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
serve.options.ssl = true;
|
|
78
|
+
serve.options.sslCert = cert;
|
|
79
|
+
serve.options.sslKey = key;
|
|
80
|
+
|
|
81
|
+
await fs.writeJson(angularJsonPath, angular, { spaces: 2 });
|
|
82
|
+
return { updated: true, details: 'angular.json serve options updated' };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function configureAngular(certPath, keyPath) {
|
|
86
|
+
const scriptResult = await configureAngularScripts(certPath, keyPath);
|
|
87
|
+
const jsonResult = await configureAngularJson(certPath, keyPath);
|
|
88
|
+
|
|
89
|
+
if (scriptResult.updated || jsonResult.updated) {
|
|
90
|
+
const details = [scriptResult.details, jsonResult.details].filter((x) => !/already configured|not found/.test(x)).join('; ') || 'Angular HTTPS configured';
|
|
91
|
+
return { updated: true, details };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { updated: false, details: `${scriptResult.details}; ${jsonResult.details}` };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
module.exports = { configureAngular };
|
package/src/frameworks/detect.js
CHANGED
|
@@ -11,6 +11,7 @@ async function detectFramework() {
|
|
|
11
11
|
const pkg = await fs.readJson(packageJsonPath).catch(() => ({}));
|
|
12
12
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
13
13
|
|
|
14
|
+
if (deps['@angular/cli'] || await fs.pathExists(path.join(PROJECT_DIR, 'angular.json'))) return 'angular';
|
|
14
15
|
if (deps.vite) return 'vite';
|
|
15
16
|
if (deps.next) return 'nextjs';
|
|
16
17
|
if (deps['react-scripts']) return 'cra';
|
package/src/frameworks/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const { configureNext } = require('./nextjs');
|
|
|
4
4
|
const { configureCra } = require('./cra');
|
|
5
5
|
const { configureExpress } = require('./express');
|
|
6
6
|
const { configureWebpack } = require('./webpack');
|
|
7
|
+
const { configureAngular } = require('./angular');
|
|
7
8
|
|
|
8
9
|
async function configureFramework(certPath, keyPath) {
|
|
9
10
|
const framework = await detectFramework();
|
|
@@ -13,6 +14,11 @@ async function configureFramework(certPath, keyPath) {
|
|
|
13
14
|
return { framework: 'Vite', ...result };
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
if (framework === 'angular') {
|
|
18
|
+
const result = await configureAngular(certPath, keyPath);
|
|
19
|
+
return { framework: 'Angular', ...result };
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
if (framework === 'nextjs') {
|
|
17
23
|
const result = await configureNext(certPath, keyPath);
|
|
18
24
|
return { framework: 'Next.js', ...result };
|
package/src/postinstall.js
CHANGED
|
@@ -48,13 +48,14 @@ async function run() {
|
|
|
48
48
|
let changed = false;
|
|
49
49
|
changed = ensureHook(targetPackage.scripts, 'predev', 'localssl-cli use', 'dev') || changed;
|
|
50
50
|
changed = ensureHook(targetPackage.scripts, 'prestart', 'localssl-cli use', 'start') || changed;
|
|
51
|
+
changed = ensureHook(targetPackage.scripts, 'preserve', 'localssl-cli use', 'serve') || changed;
|
|
51
52
|
|
|
52
53
|
if (!changed) {
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
await fs.writeJson(targetPackageJsonPath, targetPackage, { spaces: 2 });
|
|
57
|
-
console.log('localssl-cli: added predev/prestart HTTPS setup hooks');
|
|
58
|
+
console.log('localssl-cli: added predev/prestart/preserve HTTPS setup hooks');
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
run().catch(() => {});
|
package/src/use.js
CHANGED
|
@@ -8,6 +8,7 @@ const { openBrowser } = require('./open');
|
|
|
8
8
|
|
|
9
9
|
function defaultPortForFramework(framework) {
|
|
10
10
|
if (framework === 'Vite') return 5173;
|
|
11
|
+
if (framework === 'Angular') return 4200;
|
|
11
12
|
if (framework === 'Next.js') return 3000;
|
|
12
13
|
if (framework === 'Create React App') return 3000;
|
|
13
14
|
if (framework === 'Webpack Dev Server') return 8080;
|