localssl-cli 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/package.json +3 -2
- package/src/postinstall.js +60 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "localssl-cli",
|
|
3
|
-
"version": "0.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",
|
|
@@ -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(() => {});
|