ht-skills 0.2.2 → 0.2.4
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/lib/cli.js +48 -17
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -242,7 +242,7 @@ function summarizePreviewErrors(preview) {
|
|
|
242
242
|
async function promptToOpenBrowser(url, deps = {}) {
|
|
243
243
|
const ask = deps.ask || null;
|
|
244
244
|
if (ask) {
|
|
245
|
-
await ask(
|
|
245
|
+
await ask("Press ENTER to open in the browser...\n");
|
|
246
246
|
return;
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -259,12 +259,38 @@ async function promptToOpenBrowser(url, deps = {}) {
|
|
|
259
259
|
output: process.stdout,
|
|
260
260
|
});
|
|
261
261
|
try {
|
|
262
|
-
await rl.question(
|
|
262
|
+
await rl.question("Press ENTER to open in the browser...\n");
|
|
263
263
|
} finally {
|
|
264
264
|
rl.close();
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
function startLoginWaitingIndicator(deps = {}) {
|
|
269
|
+
const isInteractive = typeof deps.isInteractive === "boolean"
|
|
270
|
+
? deps.isInteractive
|
|
271
|
+
: Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
272
|
+
|
|
273
|
+
if (!isInteractive || !process.stdout.isTTY) {
|
|
274
|
+
return () => {};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const frames = ["|", "/", "-", "\\"];
|
|
278
|
+
let frameIndex = 0;
|
|
279
|
+
process.stdout.write("Waiting for browser sign-in... ");
|
|
280
|
+
const timer = setInterval(() => {
|
|
281
|
+
const frame = frames[frameIndex % frames.length];
|
|
282
|
+
frameIndex += 1;
|
|
283
|
+
process.stdout.write(`\rWaiting for browser sign-in... ${frame}`);
|
|
284
|
+
}, 120);
|
|
285
|
+
|
|
286
|
+
return () => {
|
|
287
|
+
clearInterval(timer);
|
|
288
|
+
process.stdout.write("\r");
|
|
289
|
+
process.stdout.clearLine(0);
|
|
290
|
+
process.stdout.cursorTo(0);
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
268
294
|
function formatInstallError(error, { slug, version = null, registry, stage = "resolve" }) {
|
|
269
295
|
const rawMessage = String(error?.message || "Install failed").trim();
|
|
270
296
|
const status = Number(error?.status || 0);
|
|
@@ -1279,33 +1305,38 @@ async function cmdLogin(flags, deps = {}) {
|
|
|
1279
1305
|
throw new Error("registry did not return a usable CLI login flow");
|
|
1280
1306
|
}
|
|
1281
1307
|
|
|
1282
|
-
log(`
|
|
1308
|
+
log(`Authenticate your account at:\n${browserUrl}`);
|
|
1283
1309
|
await promptToOpenBrowser(browserUrl, deps);
|
|
1284
1310
|
|
|
1285
1311
|
try {
|
|
1286
1312
|
await Promise.resolve(openBrowser(browserUrl));
|
|
1287
|
-
log(`Opened browser for ${registry}. Complete sign-in to continue...`);
|
|
1288
1313
|
} catch (error) {
|
|
1289
1314
|
log(`Open this URL in your browser and sign in:\n${browserUrl}`);
|
|
1290
1315
|
}
|
|
1291
1316
|
|
|
1292
1317
|
const expiresAtMs = Date.parse(started.expires_at || "") || (Date.now() + timeoutMs);
|
|
1293
1318
|
const deadline = Math.min(Date.now() + timeoutMs, expiresAtMs);
|
|
1319
|
+
const stopIndicator = startLoginWaitingIndicator(deps);
|
|
1294
1320
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1321
|
+
try {
|
|
1322
|
+
while (Date.now() <= deadline) {
|
|
1323
|
+
await sleep(pollIntervalMs);
|
|
1324
|
+
const status = await requestJsonImpl(pollUrl);
|
|
1325
|
+
if (status.status === "approved") {
|
|
1326
|
+
await setStoredRegistryAuth(registry, {
|
|
1327
|
+
token: status.token,
|
|
1328
|
+
user: status.user || null,
|
|
1329
|
+
tokenExpiresAt: status.token_expires_at || null,
|
|
1330
|
+
savedAt: new Date().toISOString(),
|
|
1331
|
+
}, { homeDir });
|
|
1332
|
+
const userLabel = status.user?.name || status.user?.email || status.user?.id || "user";
|
|
1333
|
+
stopIndicator();
|
|
1334
|
+
log(`Signed in to ${registry} as ${userLabel}.`);
|
|
1335
|
+
return status;
|
|
1336
|
+
}
|
|
1308
1337
|
}
|
|
1338
|
+
} finally {
|
|
1339
|
+
stopIndicator();
|
|
1309
1340
|
}
|
|
1310
1341
|
|
|
1311
1342
|
throw new Error(`Timed out waiting for browser sign-in at ${registry}`);
|