@luxkit/cli 1.0.4 โ 1.0.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/README.md +23 -9
- package/dist/index.js +109 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
| Feature | Description |
|
|
30
30
|
| :------------------------- | :----------------------------------------------------------------------------- |
|
|
31
|
-
| ๐ฏ **One Command Setup** | `lux fmt web` generates all linting & formatting configs instantly
|
|
31
|
+
| ๐ฏ **One Command Setup** | `lux fmt web` generates all linting & formatting configs instantly |
|
|
32
32
|
| ๐ง **5 Fmt Presets** | `web` ยท `electron` ยท `uniapp` ยท `node` ยท `nest` โ each with curated rules |
|
|
33
33
|
| ๐ฅ๏ธ **6 VSCode Presets** | `web` ยท `electron` ยท `uniapp` ยท `node` ยท `nest` ยท `go` โ settings + extensions |
|
|
34
34
|
| ๐ **Smart Merge** | Preset wins for linting keys; user wins for personal preferences |
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
| ๐ **Fuzzy Matching** | Typo a preset name? Levenshtein distance finds the closest match |
|
|
38
38
|
| ๐งช **Dry Run** | Preview all changes with `--dry-run` before writing anything |
|
|
39
39
|
| ๐ **Script Injection** | Auto-injects `<pm> lint` / `<pm> format` scripts into package.json |
|
|
40
|
+
| ๐ **Proxy Management** | Persistent proxy config with `set` / `unset` โ copy to CMD / PowerShell / Bash |
|
|
41
|
+
| ๐ **Self-Update** | `lux update` checks and installs the latest version automatically |
|
|
40
42
|
|
|
41
43
|
<br />
|
|
42
44
|
|
|
@@ -63,14 +65,20 @@ lux vscode list
|
|
|
63
65
|
|
|
64
66
|
### CLI Commands
|
|
65
67
|
|
|
66
|
-
| Command
|
|
67
|
-
|
|
|
68
|
-
| `lux fmt <preset>`
|
|
69
|
-
| `lux fmt list`
|
|
70
|
-
| `lux vscode <preset>`
|
|
71
|
-
| `lux vscode list`
|
|
72
|
-
| `lux
|
|
73
|
-
| `lux
|
|
68
|
+
| Command | Description |
|
|
69
|
+
| :-------------------------- | :------------------------------------------------- |
|
|
70
|
+
| `lux fmt <preset>` | Initialize formatting config files |
|
|
71
|
+
| `lux fmt list` | List available fmt presets |
|
|
72
|
+
| `lux vscode <preset>` | Initialize VSCode workspace settings |
|
|
73
|
+
| `lux vscode list` | List available VSCode presets |
|
|
74
|
+
| `lux set <key=value> [...]` | Persist proxy env vars (e.g. `https_proxy=http://127.0.0.1:7890`) |
|
|
75
|
+
| `lux unset` | Clear all stored proxy configuration |
|
|
76
|
+
| `lux show env` | Display stored proxy environment variables |
|
|
77
|
+
| `lux vpn cmd` | Copy CMD proxy commands to clipboard |
|
|
78
|
+
| `lux vpn pw` | Copy PowerShell proxy commands to clipboard |
|
|
79
|
+
| `lux vpn bash` | Copy Bash proxy commands to clipboard |
|
|
80
|
+
| `lux update` | Update `@luxkit/cli` to the latest version |
|
|
81
|
+
| `lux update --check` | Check for available updates without installing |
|
|
74
82
|
|
|
75
83
|
<br />
|
|
76
84
|
|
|
@@ -155,6 +163,12 @@ bun code:check:all # lint + format + spell check
|
|
|
155
163
|
|
|
156
164
|
<br />
|
|
157
165
|
|
|
166
|
+
### ๐ค Support
|
|
167
|
+
|
|
168
|
+
If you have any questions or run into issues, feel free to [open an issue](https://github.com/TTT1231/lux/issues) on GitHub.
|
|
169
|
+
|
|
170
|
+
<br />
|
|
171
|
+
|
|
158
172
|
### ๐ License
|
|
159
173
|
|
|
160
174
|
[ISC](https://opensource.org/licenses/ISC) โ Free to use, modify, and distribute.
|
package/dist/index.js
CHANGED
|
@@ -915,6 +915,62 @@ async function injectScripts(scripts, opts, pm) {
|
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
917
|
|
|
918
|
+
// src/utils/config.ts
|
|
919
|
+
import fs2 from "fs";
|
|
920
|
+
import os from "os";
|
|
921
|
+
import path5 from "path";
|
|
922
|
+
var CONFIG_DIR = ".lux";
|
|
923
|
+
var ENV_FILE = "env.txt";
|
|
924
|
+
function getEnvConfigPath() {
|
|
925
|
+
return path5.join(os.homedir(), CONFIG_DIR, ENV_FILE);
|
|
926
|
+
}
|
|
927
|
+
function getEnvConfig() {
|
|
928
|
+
let content;
|
|
929
|
+
try {
|
|
930
|
+
content = fs2.readFileSync(getEnvConfigPath(), "utf-8");
|
|
931
|
+
} catch {
|
|
932
|
+
return {};
|
|
933
|
+
}
|
|
934
|
+
const result = {};
|
|
935
|
+
for (const line of content.split("\n")) {
|
|
936
|
+
const trimmed = line.trim();
|
|
937
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
938
|
+
const eqIndex = trimmed.indexOf("=");
|
|
939
|
+
if (eqIndex === -1) continue;
|
|
940
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
941
|
+
const value = trimmed.slice(eqIndex + 1).trim();
|
|
942
|
+
if (key) result[key] = value;
|
|
943
|
+
}
|
|
944
|
+
return result;
|
|
945
|
+
}
|
|
946
|
+
function setEnvConfig(data) {
|
|
947
|
+
const lines = Object.entries(data).filter(([, v]) => v !== "").map(([k, v]) => `${k}=${v}`);
|
|
948
|
+
writeFile(getEnvConfigPath(), lines.join("\n") + "\n");
|
|
949
|
+
}
|
|
950
|
+
function clearEnvConfig() {
|
|
951
|
+
try {
|
|
952
|
+
fs2.unlinkSync(getEnvConfigPath());
|
|
953
|
+
} catch {
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// src/commands/show.ts
|
|
958
|
+
function handleShowEnv() {
|
|
959
|
+
const config = getEnvConfig();
|
|
960
|
+
const entries = Object.entries(config);
|
|
961
|
+
if (entries.length === 0) {
|
|
962
|
+
logger.log("No env config.");
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
for (const [key, value] of entries) {
|
|
966
|
+
logger.log(`${key}=${value}`);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
function registerShowCommand(program2) {
|
|
970
|
+
const show = program2.command("show");
|
|
971
|
+
show.command("env").description("Display stored proxy environment variables").action(() => handleShowEnv());
|
|
972
|
+
}
|
|
973
|
+
|
|
918
974
|
// src/utils/execFileNoThrow.ts
|
|
919
975
|
import { exec } from "child_process";
|
|
920
976
|
import { promisify } from "util";
|
|
@@ -1747,59 +1803,78 @@ function registerVscodeCommand(program2) {
|
|
|
1747
1803
|
|
|
1748
1804
|
// src/commands/vpn.ts
|
|
1749
1805
|
import { spawnSync } from "child_process";
|
|
1750
|
-
var
|
|
1751
|
-
function buildCommands(shell,
|
|
1806
|
+
var ALLOWED_KEYS = ["https_proxy", "http_proxy", "all_proxy"];
|
|
1807
|
+
function buildCommands(shell, env) {
|
|
1808
|
+
const entries = Object.entries(env).map(([k, v]) => `${k}=${v}`);
|
|
1752
1809
|
if (shell === "cmd") {
|
|
1753
|
-
return
|
|
1754
|
-
`set https_proxy=${httpProxy}`,
|
|
1755
|
-
`set http_proxy=${httpProxy}`,
|
|
1756
|
-
`set all_proxy=${socksProxy}`
|
|
1757
|
-
].join("\r\n");
|
|
1810
|
+
return entries.map((e) => `set ${e}`).join(" && ");
|
|
1758
1811
|
}
|
|
1759
1812
|
if (shell === "bash") {
|
|
1760
|
-
return
|
|
1761
|
-
`export https_proxy=${httpProxy}`,
|
|
1762
|
-
`export http_proxy=${httpProxy}`,
|
|
1763
|
-
`export all_proxy=${socksProxy}`
|
|
1764
|
-
].join("\n");
|
|
1813
|
+
return entries.map((e) => `export ${e}`).join(" && ");
|
|
1765
1814
|
}
|
|
1766
|
-
return
|
|
1767
|
-
`$env:https_proxy="${httpProxy}"`,
|
|
1768
|
-
`$env:http_proxy="${httpProxy}"`,
|
|
1769
|
-
`$env:all_proxy="${socksProxy}"`
|
|
1770
|
-
].join("\r\n");
|
|
1815
|
+
return entries.map((e) => `$env:${e}`).join(" ; ");
|
|
1771
1816
|
}
|
|
1772
1817
|
function copyToClipboard(text) {
|
|
1773
1818
|
const result = spawnSync("clip", [], { input: text, stdio: ["pipe", "ignore", "ignore"] });
|
|
1774
1819
|
return result.status === 0;
|
|
1775
1820
|
}
|
|
1776
|
-
function parseProxy(proxy) {
|
|
1777
|
-
const url = new URL(proxy.includes("://") ? proxy : `http://${proxy}`);
|
|
1778
|
-
return {
|
|
1779
|
-
httpProxy: url.href,
|
|
1780
|
-
socksProxy: `socks5://${url.hostname}:${url.port}`
|
|
1781
|
-
};
|
|
1782
|
-
}
|
|
1783
1821
|
var SHELL_LABELS = {
|
|
1784
1822
|
cmd: "CMD",
|
|
1785
1823
|
pw: "PowerShell",
|
|
1786
1824
|
bash: "Bash"
|
|
1787
1825
|
};
|
|
1788
|
-
function handleCopy(shell
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1826
|
+
function handleCopy(shell) {
|
|
1827
|
+
const config = getEnvConfig();
|
|
1828
|
+
if (Object.keys(config).length === 0) {
|
|
1829
|
+
logger.warn("No proxy configured. Run `lux set https_proxy=<address>` to configure.");
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
const commands = buildCommands(shell, config);
|
|
1791
1833
|
if (copyToClipboard(commands)) {
|
|
1792
1834
|
logger.log(`Copied to clipboard \u2014 paste in ${SHELL_LABELS[shell]}`);
|
|
1793
1835
|
} else {
|
|
1794
1836
|
logger.error("Failed to copy to clipboard");
|
|
1795
|
-
|
|
1837
|
+
logger.log(commands);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
function isValidKey(key) {
|
|
1841
|
+
return ALLOWED_KEYS.includes(key);
|
|
1842
|
+
}
|
|
1843
|
+
function handleSet(args) {
|
|
1844
|
+
if (args.length === 0) {
|
|
1845
|
+
logger.log("Usage: lux set <key=value> [key=value ...]");
|
|
1846
|
+
return;
|
|
1847
|
+
}
|
|
1848
|
+
const existing = getEnvConfig();
|
|
1849
|
+
const merged = { ...existing };
|
|
1850
|
+
for (const arg of args) {
|
|
1851
|
+
if (!arg.includes("=")) {
|
|
1852
|
+
logger.error(
|
|
1853
|
+
`Invalid format: "${arg}". Use key=value (e.g. https_proxy=http://127.0.0.1:7890)`
|
|
1854
|
+
);
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
const eqIndex = arg.indexOf("=");
|
|
1858
|
+
const key = arg.slice(0, eqIndex);
|
|
1859
|
+
const value = arg.slice(eqIndex + 1);
|
|
1860
|
+
if (!isValidKey(key)) {
|
|
1861
|
+
logger.error(`Invalid key: "${key}". Allowed keys: ${ALLOWED_KEYS.join(", ")}`);
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
merged[key] = value;
|
|
1796
1865
|
}
|
|
1866
|
+
setEnvConfig(merged);
|
|
1867
|
+
logger.success("Set successfully");
|
|
1868
|
+
}
|
|
1869
|
+
function handleUnset() {
|
|
1870
|
+
clearEnvConfig();
|
|
1871
|
+
logger.success("Proxy configuration cleared");
|
|
1797
1872
|
}
|
|
1798
1873
|
function registerVpnCommand(program2) {
|
|
1799
1874
|
const vpn = program2.command("vpn");
|
|
1800
|
-
vpn.command("cmd").description("Copy CMD proxy commands to clipboard").
|
|
1801
|
-
vpn.command("pw").description("Copy PowerShell proxy commands to clipboard").
|
|
1802
|
-
vpn.command("bash").description("Copy Bash proxy commands to clipboard").
|
|
1875
|
+
vpn.command("cmd").description("Copy CMD proxy commands to clipboard").action(() => handleCopy("cmd"));
|
|
1876
|
+
vpn.command("pw").description("Copy PowerShell proxy commands to clipboard").action(() => handleCopy("pw"));
|
|
1877
|
+
vpn.command("bash").description("Copy Bash proxy commands to clipboard").action(() => handleCopy("bash"));
|
|
1803
1878
|
}
|
|
1804
1879
|
|
|
1805
1880
|
// src/index.ts
|
|
@@ -1807,5 +1882,8 @@ program.name("lux").description("One-click project formatting & VSCode config CL
|
|
|
1807
1882
|
registerFmtCommand(program);
|
|
1808
1883
|
registerVscodeCommand(program);
|
|
1809
1884
|
registerVpnCommand(program);
|
|
1885
|
+
registerShowCommand(program);
|
|
1810
1886
|
registerUpdateCommand(program);
|
|
1887
|
+
program.command("set").description("Set proxy env vars using key=value pairs").argument("[args...]", "key=value pairs (e.g. https_proxy=http://127.0.0.1:7890)").action((args) => handleSet(args));
|
|
1888
|
+
program.command("unset").description("Clear stored proxy configuration").action(() => handleUnset());
|
|
1811
1889
|
program.parse();
|