oltc-selector 2.1.0 → 2.2.0
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 +2 -1
- package/bin/oltc.js +101 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
填工况,给出 2025 目录里**最低满足**的型号。网页和 `oltc` CLI 共用同一份 `selectOltc` 引擎。
|
|
4
4
|
|
|
5
|
-
**CLI:** `npx -y oltc-selector@2.
|
|
5
|
+
**CLI:** `npx -y oltc-selector@2.2.0`,命令是 `oltc`。Agent 技能包另放,不在这个仓库里。
|
|
6
6
|
**网页:** [oltc-selector.vercel.app](https://oltc-selector.vercel.app/) · [GitHub Pages](https://erict16.github.io/oltc-selector/)
|
|
7
7
|
|
|
8
8
|
私人辅助,不是厂家官网。型号是起点,出 OS 前要工程确认。
|
|
@@ -52,6 +52,7 @@ oltc --mva 125 --kind auto --hv 225 --mv 115 --tap junction
|
|
|
52
52
|
| `--oil` / `--vacuum` | Switching medium | vacuum (on-load) |
|
|
53
53
|
| `--contact` | OCTC contact e.g. `6x5` | |
|
|
54
54
|
| `--json` | Machine output | |
|
|
55
|
+
| `--no-update-check` | Skip the daily npm check. A newer version only prints a notice on stderr; nothing is installed. `OLTC_NO_UPDATE_CHECK=1` or `CI=1` also skip it. | check on |
|
|
55
56
|
|
|
56
57
|
`--structure auto` and omitting `--octc` match the web first paint: on-load, in-tank vacuum, minimum-adequate ranking.
|
|
57
58
|
|
package/bin/oltc.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// lib/appVersion.ts
|
|
4
|
+
var APP_VERSION = "2.2.0";
|
|
5
|
+
|
|
3
6
|
// lib/decimal.ts
|
|
4
7
|
var GROUPED = /^\d{1,3}([,,]\d{3})+$/;
|
|
5
8
|
var PLAIN = /^\d*\.?\d*$/;
|
|
@@ -2159,7 +2162,7 @@ function num(raw, flag) {
|
|
|
2159
2162
|
}
|
|
2160
2163
|
throw new CliError(`Invalid number for ${flag}: ${raw}`);
|
|
2161
2164
|
}
|
|
2162
|
-
function parseCliArgs(
|
|
2165
|
+
function parseCliArgs(argv2) {
|
|
2163
2166
|
const out = {
|
|
2164
2167
|
conn: "Y",
|
|
2165
2168
|
kind: "two_winding",
|
|
@@ -2176,14 +2179,14 @@ function parseCliArgs(argv) {
|
|
|
2176
2179
|
given: /* @__PURE__ */ new Set()
|
|
2177
2180
|
};
|
|
2178
2181
|
const take = (i, flag) => {
|
|
2179
|
-
const v =
|
|
2182
|
+
const v = argv2[i + 1];
|
|
2180
2183
|
if (v == null || v.startsWith("-")) {
|
|
2181
2184
|
throw new CliError(`Missing value for ${flag}`);
|
|
2182
2185
|
}
|
|
2183
2186
|
return [v, i + 1];
|
|
2184
2187
|
};
|
|
2185
|
-
for (let i = 0; i <
|
|
2186
|
-
const a =
|
|
2188
|
+
for (let i = 0; i < argv2.length; i++) {
|
|
2189
|
+
const a = argv2[i];
|
|
2187
2190
|
if (a === "-h" || a === "--help") {
|
|
2188
2191
|
out.help = true;
|
|
2189
2192
|
continue;
|
|
@@ -2192,6 +2195,9 @@ function parseCliArgs(argv) {
|
|
|
2192
2195
|
out.json = true;
|
|
2193
2196
|
continue;
|
|
2194
2197
|
}
|
|
2198
|
+
if (a === "--no-update-check") {
|
|
2199
|
+
continue;
|
|
2200
|
+
}
|
|
2195
2201
|
if (a === "--octc") {
|
|
2196
2202
|
out.given.add("octc");
|
|
2197
2203
|
out.octc = true;
|
|
@@ -2462,6 +2468,9 @@ Flags:
|
|
|
2462
2468
|
--contact OCTC contact e.g. 6x5.
|
|
2463
2469
|
--phases I|II|III. Default III.
|
|
2464
2470
|
--json Machine-readable result (still no prices).
|
|
2471
|
+
--no-update-check Skip the daily check for a newer version. The check only
|
|
2472
|
+
prints a notice on stderr; it never installs anything.
|
|
2473
|
+
OLTC_NO_UPDATE_CHECK=1 or CI=1 also turn it off.
|
|
2465
2474
|
-h, --help This text.
|
|
2466
2475
|
|
|
2467
2476
|
Defaults match the web first paint: on-load, in-tank vacuum, structure auto,
|
|
@@ -2793,12 +2802,12 @@ function formatCliJson(input, args) {
|
|
|
2793
2802
|
};
|
|
2794
2803
|
return JSON.stringify(payload, null, 2) + "\n";
|
|
2795
2804
|
}
|
|
2796
|
-
function runCli(
|
|
2805
|
+
function runCli(argv2, io = {
|
|
2797
2806
|
stdout: (s) => process.stdout.write(s),
|
|
2798
2807
|
stderr: (s) => process.stderr.write(s)
|
|
2799
2808
|
}) {
|
|
2800
2809
|
try {
|
|
2801
|
-
const args = parseCliArgs(
|
|
2810
|
+
const args = parseCliArgs(argv2);
|
|
2802
2811
|
if (args.help) {
|
|
2803
2812
|
io.stdout(CLI_HELP);
|
|
2804
2813
|
return 0;
|
|
@@ -2813,6 +2822,91 @@ function runCli(argv, io = {
|
|
|
2813
2822
|
}
|
|
2814
2823
|
}
|
|
2815
2824
|
|
|
2825
|
+
// lib/updateCheck.ts
|
|
2826
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2827
|
+
import { homedir } from "node:os";
|
|
2828
|
+
import path from "node:path";
|
|
2829
|
+
var UPDATE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
2830
|
+
var REGISTRY_LATEST = "https://registry.npmjs.org/oltc-selector/latest";
|
|
2831
|
+
function isNewer(latest, current) {
|
|
2832
|
+
const parse = (v) => {
|
|
2833
|
+
const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(v.trim());
|
|
2834
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
2835
|
+
};
|
|
2836
|
+
const a = parse(latest);
|
|
2837
|
+
const b = parse(current);
|
|
2838
|
+
if (!a || !b) return false;
|
|
2839
|
+
for (let i = 0; i < 3; i++) {
|
|
2840
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
2841
|
+
}
|
|
2842
|
+
return false;
|
|
2843
|
+
}
|
|
2844
|
+
function updateNotice(latest, current) {
|
|
2845
|
+
return `
|
|
2846
|
+
\u6709\u65B0\u7248\u672C oltc-selector ${latest}\uFF08\u5F53\u524D ${current}\uFF09\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u66F4\u65B0\u3002
|
|
2847
|
+
\u9700\u8981\u65F6\u8FD0\u884C\uFF1Anpm i -g oltc-selector@latest\uFF0C\u6216\u7528 npx -y oltc-selector@latest\u3002
|
|
2848
|
+
`;
|
|
2849
|
+
}
|
|
2850
|
+
function updateCheckEnabled(argv2, env) {
|
|
2851
|
+
if (argv2.includes("--no-update-check")) return false;
|
|
2852
|
+
if (env.OLTC_NO_UPDATE_CHECK || env.NO_UPDATE_NOTIFIER || env.CI) return false;
|
|
2853
|
+
return true;
|
|
2854
|
+
}
|
|
2855
|
+
function defaultCacheFile(env) {
|
|
2856
|
+
const base = env.XDG_CACHE_HOME || path.join(homedir(), ".cache");
|
|
2857
|
+
return path.join(base, "oltc-selector", "update-check.json");
|
|
2858
|
+
}
|
|
2859
|
+
async function fetchLatest(timeoutMs) {
|
|
2860
|
+
const res = await fetch(REGISTRY_LATEST, {
|
|
2861
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
2862
|
+
headers: { accept: "application/json" }
|
|
2863
|
+
});
|
|
2864
|
+
if (!res.ok) return null;
|
|
2865
|
+
const body = await res.json();
|
|
2866
|
+
return typeof body.version === "string" ? body.version : null;
|
|
2867
|
+
}
|
|
2868
|
+
function readCache(file2) {
|
|
2869
|
+
try {
|
|
2870
|
+
const c = JSON.parse(readFileSync(file2, "utf8"));
|
|
2871
|
+
return typeof c.checkedAt === "number" ? c : null;
|
|
2872
|
+
} catch {
|
|
2873
|
+
return null;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
function writeCache(file2, c) {
|
|
2877
|
+
try {
|
|
2878
|
+
mkdirSync(path.dirname(file2), { recursive: true });
|
|
2879
|
+
writeFileSync(file2, JSON.stringify(c) + "\n");
|
|
2880
|
+
} catch {
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
async function checkForUpdate(opts) {
|
|
2884
|
+
const now = opts.now ?? Date.now();
|
|
2885
|
+
try {
|
|
2886
|
+
let latest;
|
|
2887
|
+
const cached = readCache(opts.cacheFile);
|
|
2888
|
+
if (cached && now - cached.checkedAt < UPDATE_TTL_MS) {
|
|
2889
|
+
latest = cached.latest;
|
|
2890
|
+
} else {
|
|
2891
|
+
latest = await (opts.fetchLatest ?? fetchLatest)(opts.timeoutMs ?? 1500).catch(
|
|
2892
|
+
() => cached?.latest ?? null
|
|
2893
|
+
);
|
|
2894
|
+
writeCache(opts.cacheFile, { checkedAt: now, latest });
|
|
2895
|
+
}
|
|
2896
|
+
return latest && isNewer(latest, opts.current) ? updateNotice(latest, opts.current) : null;
|
|
2897
|
+
} catch {
|
|
2898
|
+
return null;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2816
2902
|
// scripts/oltc.ts
|
|
2817
|
-
var
|
|
2903
|
+
var argv = process.argv.slice(2);
|
|
2904
|
+
var code = runCli(argv);
|
|
2905
|
+
if (updateCheckEnabled(argv, process.env)) {
|
|
2906
|
+
const notice = await checkForUpdate({
|
|
2907
|
+
current: APP_VERSION,
|
|
2908
|
+
cacheFile: defaultCacheFile(process.env)
|
|
2909
|
+
});
|
|
2910
|
+
if (notice) process.stderr.write(notice);
|
|
2911
|
+
}
|
|
2818
2912
|
process.exit(code);
|