locadot 1.5.1 → 1.5.5
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/dist/constants/index.js +16 -0
- package/dist/index.js +47 -12
- package/dist/lib/commands.js +21 -2
- package/dist/utils/startup.js +134 -0
- package/package.json +2 -1
package/dist/constants/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const appdata_path_1 = __importDefault(require("appdata-path"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
8
9
|
const PACKAGE_PATH = (0, appdata_path_1.default)("locadot");
|
|
9
10
|
const LOGS = path_1.default.join(PACKAGE_PATH, ".locadot.log");
|
|
10
11
|
const LOCK_FILE = path_1.default.join(PACKAGE_PATH, ".locadot.lock");
|
|
@@ -16,6 +17,21 @@ Constants.paths = {
|
|
|
16
17
|
REGISTRY_FILE: REGISTRY_FILE,
|
|
17
18
|
LOGS: LOGS,
|
|
18
19
|
};
|
|
20
|
+
Constants.platform = () => {
|
|
21
|
+
const currentPlatform = os_1.default.platform();
|
|
22
|
+
if (currentPlatform === "win32") {
|
|
23
|
+
return "windows";
|
|
24
|
+
}
|
|
25
|
+
else if (currentPlatform === "darwin") {
|
|
26
|
+
return "mac";
|
|
27
|
+
}
|
|
28
|
+
else if (currentPlatform === "linux") {
|
|
29
|
+
return "linux";
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return "unknown";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
19
35
|
Constants.proxyInfo = {
|
|
20
36
|
invalidHost: "❌ Invalid domain. Please use a valid localhost domain like dev.localhost, localhost, test.localhost, etc.",
|
|
21
37
|
hostExist: "❌ Domain already in use. Please choose another domain or stop the existing instance.",
|
package/dist/index.js
CHANGED
|
@@ -21,23 +21,31 @@ program
|
|
|
21
21
|
.requiredOption("-p, --port <port>", "Local port to forward to")
|
|
22
22
|
.action(async (options) => {
|
|
23
23
|
await commands_1.default.add(options);
|
|
24
|
+
process.exit(0);
|
|
24
25
|
});
|
|
25
26
|
program
|
|
26
27
|
.command("update")
|
|
27
28
|
.requiredOption("-h, --host <host>", "Domain to map must be ends with localhost. Example: dev.localhost, localhost, test.localhost, etc.")
|
|
28
29
|
.requiredOption("-p, --port <port>", "Local port to forward to")
|
|
29
30
|
.description("Update a domain")
|
|
30
|
-
.action(async (options) =>
|
|
31
|
+
.action(async (options) => {
|
|
32
|
+
await commands_1.default.update(options);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
31
35
|
program
|
|
32
36
|
.command("remove")
|
|
33
37
|
.requiredOption("-h, --host <host>", "Host must ends with localhost. Example: dev.localhost, localhost, test.localhost, etc.")
|
|
34
38
|
.description("Remove a domain")
|
|
35
|
-
.action(async (options) =>
|
|
39
|
+
.action(async (options) => {
|
|
40
|
+
await commands_1.default.remove(options);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
});
|
|
36
43
|
program
|
|
37
44
|
.command("host")
|
|
38
45
|
.description("Show all hosts")
|
|
39
|
-
.action(() => {
|
|
40
|
-
commands_1.default.getRegistry();
|
|
46
|
+
.action(async () => {
|
|
47
|
+
await commands_1.default.getRegistry();
|
|
48
|
+
process.exit(0);
|
|
41
49
|
});
|
|
42
50
|
program
|
|
43
51
|
.command("watch:logs")
|
|
@@ -48,38 +56,65 @@ program
|
|
|
48
56
|
program
|
|
49
57
|
.command("clear:logs")
|
|
50
58
|
.description("Clear logs")
|
|
51
|
-
.action(() => {
|
|
52
|
-
commands_1.default.clearLogs();
|
|
59
|
+
.action(async () => {
|
|
60
|
+
await commands_1.default.clearLogs();
|
|
61
|
+
process.exit(0);
|
|
53
62
|
});
|
|
54
63
|
program
|
|
55
64
|
.command("clear:hosts")
|
|
56
65
|
.description("Clear all host file.")
|
|
57
|
-
.action(() => {
|
|
58
|
-
commands_1.default.clearHosts();
|
|
66
|
+
.action(async () => {
|
|
67
|
+
await commands_1.default.clearHosts();
|
|
68
|
+
process.exit(0);
|
|
59
69
|
});
|
|
60
70
|
program
|
|
61
71
|
.command("path")
|
|
62
72
|
.description("Show configuration paths.")
|
|
63
73
|
.action(() => {
|
|
64
74
|
commands_1.default.configPath();
|
|
75
|
+
process.exit(0);
|
|
65
76
|
});
|
|
66
77
|
program
|
|
67
78
|
.command("path:logs")
|
|
68
79
|
.description("Show logs path file.")
|
|
69
80
|
.action(() => {
|
|
70
81
|
commands_1.default.logPath();
|
|
82
|
+
process.exit(0);
|
|
71
83
|
});
|
|
72
84
|
program
|
|
73
85
|
.command("path:hosts")
|
|
74
86
|
.description("Show hosts path file.")
|
|
75
|
-
.action(() => {
|
|
76
|
-
commands_1.default.hostPath();
|
|
87
|
+
.action(async () => {
|
|
88
|
+
await commands_1.default.hostPath();
|
|
89
|
+
process.exit(0);
|
|
90
|
+
});
|
|
91
|
+
program
|
|
92
|
+
.command("startup:enable")
|
|
93
|
+
.description("Enable locadot on reboot.")
|
|
94
|
+
.action(async () => {
|
|
95
|
+
await commands_1.default.enableStartup();
|
|
96
|
+
process.exit(0);
|
|
97
|
+
});
|
|
98
|
+
program
|
|
99
|
+
.command("startup:disable")
|
|
100
|
+
.description("Disable locadot on reboot.")
|
|
101
|
+
.action(async () => {
|
|
102
|
+
await commands_1.default.disableStartup();
|
|
103
|
+
process.exit(0);
|
|
104
|
+
});
|
|
105
|
+
program
|
|
106
|
+
.command("startup:status")
|
|
107
|
+
.description("Check locadot status on reboot.")
|
|
108
|
+
.action(async () => {
|
|
109
|
+
await commands_1.default.statusStartup();
|
|
110
|
+
process.exit(0);
|
|
77
111
|
});
|
|
78
112
|
program
|
|
79
113
|
.command("restart")
|
|
80
114
|
.description("Restart locadot")
|
|
81
|
-
.action(() => {
|
|
82
|
-
commands_1.default.restart();
|
|
115
|
+
.action(async () => {
|
|
116
|
+
await commands_1.default.restart();
|
|
117
|
+
process.exit(0);
|
|
83
118
|
});
|
|
84
119
|
program
|
|
85
120
|
.command("stop")
|
package/dist/lib/commands.js
CHANGED
|
@@ -7,6 +7,7 @@ const localhost_1 = __importDefault(require("./localhost"));
|
|
|
7
7
|
const proxy_1 = __importDefault(require("../proxy"));
|
|
8
8
|
const locadot_file_1 = __importDefault(require("./locadot-file"));
|
|
9
9
|
const constants_1 = __importDefault(require("../constants"));
|
|
10
|
+
const startup_1 = __importDefault(require("../utils/startup"));
|
|
10
11
|
class Commands {
|
|
11
12
|
static async add(argv) {
|
|
12
13
|
if (!localhost_1.default.isValidLocalhostDomain(argv.host)) {
|
|
@@ -88,9 +89,9 @@ class Commands {
|
|
|
88
89
|
}
|
|
89
90
|
catch (error) { }
|
|
90
91
|
}
|
|
91
|
-
static clearLogs() {
|
|
92
|
+
static async clearLogs() {
|
|
92
93
|
try {
|
|
93
|
-
locadot_file_1.default.clearLogs();
|
|
94
|
+
await locadot_file_1.default.clearLogs();
|
|
94
95
|
console.log("☑️ Logs successfully cleared.");
|
|
95
96
|
}
|
|
96
97
|
catch (error) { }
|
|
@@ -105,5 +106,23 @@ class Commands {
|
|
|
105
106
|
console.log(constants_1.default.paths.REGISTRY_FILE);
|
|
106
107
|
console.log(constants_1.default.paths.LOGS);
|
|
107
108
|
}
|
|
109
|
+
static async enableStartup() {
|
|
110
|
+
try {
|
|
111
|
+
await startup_1.default.enable();
|
|
112
|
+
}
|
|
113
|
+
catch (error) { }
|
|
114
|
+
}
|
|
115
|
+
static async disableStartup() {
|
|
116
|
+
try {
|
|
117
|
+
await startup_1.default.disable();
|
|
118
|
+
}
|
|
119
|
+
catch (error) { }
|
|
120
|
+
}
|
|
121
|
+
static async statusStartup() {
|
|
122
|
+
try {
|
|
123
|
+
await startup_1.default.status();
|
|
124
|
+
}
|
|
125
|
+
catch (error) { }
|
|
126
|
+
}
|
|
108
127
|
}
|
|
109
128
|
exports.default = Commands;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const sudo_prompt_1 = __importDefault(require("@expo/sudo-prompt"));
|
|
11
|
+
const constants_1 = __importDefault(require("../constants"));
|
|
12
|
+
const locadot_file_1 = __importDefault(require("../lib/locadot-file"));
|
|
13
|
+
const SERVICE_NAME = "reboot-locadot";
|
|
14
|
+
const { command, path: commandArgs } = locadot_file_1.default.getStartProxyFile();
|
|
15
|
+
const sudoOptions = {
|
|
16
|
+
name: "Locadot",
|
|
17
|
+
};
|
|
18
|
+
function execSudo(cmd) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
sudo_prompt_1.default.exec(cmd, sudoOptions, (error, stdout, stderr) => {
|
|
21
|
+
if (error)
|
|
22
|
+
return reject(error);
|
|
23
|
+
if (stderr)
|
|
24
|
+
console.error(stderr);
|
|
25
|
+
if (stdout)
|
|
26
|
+
console.log(stdout);
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
class Startup {
|
|
32
|
+
static async enable() {
|
|
33
|
+
const platform = constants_1.default.platform();
|
|
34
|
+
let cmd = "";
|
|
35
|
+
switch (platform) {
|
|
36
|
+
case "windows":
|
|
37
|
+
cmd = `schtasks /Create /TN "${SERVICE_NAME}" /TR "${command} ${commandArgs.join(" ")}" /SC ONSTART /F`;
|
|
38
|
+
break;
|
|
39
|
+
case "linux":
|
|
40
|
+
const cronLine = `@reboot ${command} ${commandArgs.join(" ")}`;
|
|
41
|
+
cmd = `crontab -l | grep -v '${commandArgs[0]}' | { cat; echo '${cronLine}'; } | crontab -`;
|
|
42
|
+
break;
|
|
43
|
+
case "mac":
|
|
44
|
+
const plistPath = path_1.default.join(os_1.default.homedir(), "Library", "LaunchAgents", "com.local.reboot.plist");
|
|
45
|
+
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
46
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
47
|
+
<plist version="1.0">
|
|
48
|
+
<dict>
|
|
49
|
+
<key>Label</key>
|
|
50
|
+
<string>com.local.reboot</string>
|
|
51
|
+
<key>ProgramArguments</key>
|
|
52
|
+
<array>
|
|
53
|
+
<string>${command}</string>
|
|
54
|
+
${commandArgs.map((arg) => `<string>${arg}</string>`).join("\n ")}
|
|
55
|
+
</array>
|
|
56
|
+
<key>RunAtLoad</key>
|
|
57
|
+
<true/>
|
|
58
|
+
</dict>
|
|
59
|
+
</plist>`;
|
|
60
|
+
fs_1.default.writeFileSync(plistPath, plist);
|
|
61
|
+
cmd = `launchctl load "${plistPath}"`;
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
throw new Error("Unknown platform");
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
await execSudo(cmd);
|
|
68
|
+
console.log("✅ Reboot task enabled.");
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error("❌ Failed to enable reboot task:", err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
static async disable() {
|
|
75
|
+
const platform = constants_1.default.platform();
|
|
76
|
+
let cmd = "";
|
|
77
|
+
switch (platform) {
|
|
78
|
+
case "windows":
|
|
79
|
+
cmd = `schtasks /Delete /TN "${SERVICE_NAME}" /F`;
|
|
80
|
+
break;
|
|
81
|
+
case "linux":
|
|
82
|
+
cmd = `crontab -l | grep -v '${commandArgs[0]}' | crontab -`;
|
|
83
|
+
break;
|
|
84
|
+
case "mac":
|
|
85
|
+
const plistPath = path_1.default.join(os_1.default.homedir(), "Library", "LaunchAgents", "com.local.reboot.plist");
|
|
86
|
+
cmd = `launchctl unload "${plistPath}" && rm "${plistPath}"`;
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
throw new Error("Unknown platform");
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await execSudo(cmd);
|
|
93
|
+
console.log("✅ Reboot task disabled.");
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
console.error("❌ Failed to disable reboot task:", err);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
static async status() {
|
|
100
|
+
const platform = constants_1.default.platform();
|
|
101
|
+
try {
|
|
102
|
+
switch (platform) {
|
|
103
|
+
case "linux": {
|
|
104
|
+
const output = (0, child_process_1.execSync)("crontab -l", { encoding: "utf-8" });
|
|
105
|
+
console.log(output.includes(commandArgs[0]) ? "enabled" : "disabled");
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "windows": {
|
|
109
|
+
try {
|
|
110
|
+
const output = (0, child_process_1.execSync)(`schtasks /Query /TN "${SERVICE_NAME}"`, {
|
|
111
|
+
encoding: "utf-8",
|
|
112
|
+
});
|
|
113
|
+
console.log(output.includes(SERVICE_NAME) ? "enabled" : "disabled");
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
console.log("disabled");
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "mac": {
|
|
121
|
+
const plistPath = path_1.default.join(os_1.default.homedir(), "Library", "LaunchAgents", "com.local.reboot.plist");
|
|
122
|
+
console.log(fs_1.default.existsSync(plistPath) ? "enabled" : "disabled");
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
throw new Error("Unknown platform");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
console.error("❌ Failed to check status:", err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.default = Startup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locadot",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "Secure your local development environment with HTTPS and custom domains like dev.localhost.",
|
|
5
5
|
"homepage": "https://www.npmjs.com/package/locadot",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"url": "https://github.com/avinashid/locadot/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@expo/sudo-prompt": "^9.3.2",
|
|
32
33
|
"@types/http-proxy": "^1.17.16",
|
|
33
34
|
"@types/yargs": "^17.0.33",
|
|
34
35
|
"appdata-path": "^1.0.0",
|