@binaryandthread/cli 0.3.0 → 0.3.1
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/bin.js +48 -11
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-RDJJLYXB.js → chunk-VDOFLQ2P.js} +5 -5
- package/dist/chunk-VDOFLQ2P.js.map +1 -0
- package/dist/{chunk-OVG37IIX.js → chunk-ZNDKXHMV.js} +1 -1
- package/dist/chunk-ZNDKXHMV.js.map +1 -0
- package/dist/{config-FXGCWC6Y.js → config-GVEB4R7I.js} +2 -2
- package/dist/{interactive-DJXIUVBM.js → interactive-JALKLT56.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-OVG37IIX.js.map +0 -1
- package/dist/chunk-RDJJLYXB.js.map +0 -1
- /package/dist/{config-FXGCWC6Y.js.map → config-GVEB4R7I.js.map} +0 -0
- /package/dist/{interactive-DJXIUVBM.js.map → interactive-JALKLT56.js.map} +0 -0
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
forgetConfig,
|
|
6
6
|
loadConfig,
|
|
7
7
|
saveConfig
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZNDKXHMV.js";
|
|
9
9
|
import {
|
|
10
10
|
makePrompts
|
|
11
11
|
} from "./chunk-AAN4VWP3.js";
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
versionLine,
|
|
54
54
|
warn,
|
|
55
55
|
working
|
|
56
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-VDOFLQ2P.js";
|
|
57
57
|
import {
|
|
58
58
|
__require
|
|
59
59
|
} from "./chunk-7OCVIDC7.js";
|
|
@@ -62,6 +62,26 @@ import {
|
|
|
62
62
|
import { spawn } from "child_process";
|
|
63
63
|
import { Command } from "commander";
|
|
64
64
|
|
|
65
|
+
// src/locale.ts
|
|
66
|
+
function detectRegionFromLocale(env) {
|
|
67
|
+
const raw = (env.LC_ALL || env.LC_MESSAGES || env.LANG || "").trim();
|
|
68
|
+
const m = /^[A-Za-z]{2,3}[_-]([A-Za-z]{2})(?:[.@]|$)/.exec(raw);
|
|
69
|
+
return m ? m[1].toLowerCase() : null;
|
|
70
|
+
}
|
|
71
|
+
function resolveEffectiveRegion(flag, saved, env) {
|
|
72
|
+
if (flag && flag.trim()) {
|
|
73
|
+
return { region: flag.trim().toLowerCase(), source: "flag" };
|
|
74
|
+
}
|
|
75
|
+
if (saved && saved.trim()) {
|
|
76
|
+
return { region: saved.trim().toLowerCase(), source: "config" };
|
|
77
|
+
}
|
|
78
|
+
const fromLocale = detectRegionFromLocale(env);
|
|
79
|
+
if (fromLocale) {
|
|
80
|
+
return { region: fromLocale, source: "locale" };
|
|
81
|
+
}
|
|
82
|
+
return { region: void 0, source: void 0 };
|
|
83
|
+
}
|
|
84
|
+
|
|
65
85
|
// src/client-config.ts
|
|
66
86
|
function resolveClientConfig(env = process.env) {
|
|
67
87
|
const baseUrl = env.BT_API_URL || env.MEDUSA_BACKEND_URL || BT_DEFAULT_STORE_URL;
|
|
@@ -82,7 +102,7 @@ function makeLogger(debug, write = (s) => process.stderr.write(s)) {
|
|
|
82
102
|
}
|
|
83
103
|
|
|
84
104
|
// src/version.ts
|
|
85
|
-
var VERSION = "0.3.
|
|
105
|
+
var VERSION = "0.3.1";
|
|
86
106
|
|
|
87
107
|
// src/eggs.ts
|
|
88
108
|
function teapot() {
|
|
@@ -223,6 +243,7 @@ import * as fs from "fs";
|
|
|
223
243
|
import * as path from "path";
|
|
224
244
|
var CACHE_FILE = "update-check.json";
|
|
225
245
|
var CHECK_INTERVAL_MS = 6 * 60 * 60 * 1e3;
|
|
246
|
+
var NOTICE_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
226
247
|
var REGISTRY_LATEST = "https://registry.npmjs.org/@binaryandthread/cli/latest";
|
|
227
248
|
var FETCH_TIMEOUT_MS = 2e3;
|
|
228
249
|
function parseSemver(v) {
|
|
@@ -254,9 +275,14 @@ function maybeNotifyUpdate(deps) {
|
|
|
254
275
|
const now = deps.now ?? Date.now();
|
|
255
276
|
const read = deps.readCache ?? readUpdateCache;
|
|
256
277
|
const refresh = deps.refresh ?? ((n) => void fetchLatestIntoCache(n));
|
|
278
|
+
const markNotified = deps.markNotified ?? markNotifiedInCache;
|
|
257
279
|
const cache = read();
|
|
258
280
|
const line = updateNoticeLine(deps.current, cache?.latest);
|
|
259
|
-
|
|
281
|
+
const canNotify = cache?.lastNotified === void 0 || now - cache.lastNotified >= NOTICE_INTERVAL_MS;
|
|
282
|
+
if (line && canNotify) {
|
|
283
|
+
deps.write(line + "\n");
|
|
284
|
+
markNotified(now);
|
|
285
|
+
}
|
|
260
286
|
if (!cache || now - cache.lastCheck > CHECK_INTERVAL_MS) {
|
|
261
287
|
refresh(now);
|
|
262
288
|
}
|
|
@@ -268,12 +294,22 @@ function readUpdateCache() {
|
|
|
268
294
|
try {
|
|
269
295
|
const j = JSON.parse(fs.readFileSync(cachePath(), "utf8"));
|
|
270
296
|
if (j && typeof j.latest === "string" && typeof j.lastCheck === "number") {
|
|
271
|
-
|
|
297
|
+
const cache = { latest: j.latest, lastCheck: j.lastCheck };
|
|
298
|
+
if (typeof j.lastNotified === "number") {
|
|
299
|
+
cache.lastNotified = j.lastNotified;
|
|
300
|
+
}
|
|
301
|
+
return cache;
|
|
272
302
|
}
|
|
273
303
|
} catch {
|
|
274
304
|
}
|
|
275
305
|
return null;
|
|
276
306
|
}
|
|
307
|
+
function markNotifiedInCache(now) {
|
|
308
|
+
const cache = readUpdateCache();
|
|
309
|
+
if (cache) {
|
|
310
|
+
writeUpdateCache({ ...cache, lastNotified: now });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
277
313
|
function writeUpdateCache(c) {
|
|
278
314
|
try {
|
|
279
315
|
fs.mkdirSync(configDir(), { recursive: true });
|
|
@@ -439,7 +475,7 @@ async function runBrowse(client, config, args) {
|
|
|
439
475
|
lines.push(" peek at next \u2192 bt browse --branch=next");
|
|
440
476
|
} else {
|
|
441
477
|
lines.push(header(style, "bt browse \u2014 in stock"));
|
|
442
|
-
lines.push(regionLine(rr, style));
|
|
478
|
+
lines.push(regionLine(rr, style, config.region_source));
|
|
443
479
|
lines.push(...layoutRows(rows, style));
|
|
444
480
|
for (const d of drops) {
|
|
445
481
|
const dt = (d.title ?? d.handle ?? d.id).toString();
|
|
@@ -478,7 +514,7 @@ function registerBrowse(program, makeClient2, loadConfig2) {
|
|
|
478
514
|
program.command("browse").alias("ls").description("list what's in stock on a branch.").option("--branch <branch>", "main (live) or next (terminal-only drops)").option("--pick", "opt into the arrow-key picker (default is the numbered table \u2014 use bt stage <n>)").option("--plain", "force the static table (the default; kept for back-compat)").action(async (opts) => {
|
|
479
515
|
const { json, brand } = resolveOutput(program);
|
|
480
516
|
if (opts.pick && !json && brand.color && process.stdout.isTTY && process.stdin.isTTY) {
|
|
481
|
-
const { runInteractiveBrowse } = await import("./interactive-
|
|
517
|
+
const { runInteractiveBrowse } = await import("./interactive-JALKLT56.js");
|
|
482
518
|
const handled = await runInteractiveBrowse(makeClient2(), loadConfig2(), { branch: opts.branch, brand });
|
|
483
519
|
if (handled) return;
|
|
484
520
|
}
|
|
@@ -973,7 +1009,7 @@ function registerCheckout(program, makeClient2, loadConfig2) {
|
|
|
973
1009
|
const { makePrompts: makePrompts2 } = await import("./prompts-DDVV5RE6.js");
|
|
974
1010
|
const { openCheckout } = await import("./browser-WCNC4AWS.js");
|
|
975
1011
|
const { pollUntilPlaced } = await import("./poll-O3VUD5WV.js");
|
|
976
|
-
const { saveConfig: saveConfig2 } = await import("./config-
|
|
1012
|
+
const { saveConfig: saveConfig2 } = await import("./config-GVEB4R7I.js");
|
|
977
1013
|
const client = makeClient2();
|
|
978
1014
|
const print = json ? () => {
|
|
979
1015
|
} : (line) => process.stdout.write(line + "\n");
|
|
@@ -1748,7 +1784,7 @@ function registerBuy(program, makeClient2, loadConfig2) {
|
|
|
1748
1784
|
const { makePrompts: makePrompts2 } = await import("./prompts-DDVV5RE6.js");
|
|
1749
1785
|
const { openCheckout } = await import("./browser-WCNC4AWS.js");
|
|
1750
1786
|
const { pollUntilPlaced } = await import("./poll-O3VUD5WV.js");
|
|
1751
|
-
const { saveConfig: saveConfig2 } = await import("./config-
|
|
1787
|
+
const { saveConfig: saveConfig2 } = await import("./config-GVEB4R7I.js");
|
|
1752
1788
|
const client = makeClient2();
|
|
1753
1789
|
const print = json ? () => {
|
|
1754
1790
|
} : (line) => process.stdout.write(line + "\n");
|
|
@@ -1808,7 +1844,7 @@ function runConfig(args, deps) {
|
|
|
1808
1844
|
function registerConfig(program) {
|
|
1809
1845
|
program.command("config").argument("[sub]", "get | set", "get").argument("[key]", "config key").argument("[value]", "value (for set)").description("view or set local prefs (email, region, defaults). the auth token is never stored here.").action(async (sub, key, value) => {
|
|
1810
1846
|
const { json } = resolveOutput(program);
|
|
1811
|
-
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await import("./config-
|
|
1847
|
+
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await import("./config-GVEB4R7I.js");
|
|
1812
1848
|
const res = runConfig({ sub, key, value, json }, { load: loadConfig2, save: saveConfig2 });
|
|
1813
1849
|
printResult(res, json);
|
|
1814
1850
|
});
|
|
@@ -2010,7 +2046,8 @@ function registerCommands(program) {
|
|
|
2010
2046
|
const effectiveConfig = () => {
|
|
2011
2047
|
const saved = loadConfig();
|
|
2012
2048
|
const flag = program.opts().region;
|
|
2013
|
-
|
|
2049
|
+
const { region, source } = resolveEffectiveRegion(flag, saved.region, process.env);
|
|
2050
|
+
return { ...saved, region, region_source: source };
|
|
2014
2051
|
};
|
|
2015
2052
|
registerInit(program);
|
|
2016
2053
|
registerBrowse(program, makeClient, effectiveConfig);
|