github-labels-template 0.8.0-patch.30e7740 → 0.8.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/dist/index.js +4 -163
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { defineCommand as
|
|
4
|
+
import { defineCommand as defineCommand7, runMain } from "citty";
|
|
5
5
|
|
|
6
6
|
// src/commands/apply.ts
|
|
7
7
|
import { defineCommand } from "citty";
|
|
@@ -1230,17 +1230,13 @@ var check_default = defineCommand6({
|
|
|
1230
1230
|
}
|
|
1231
1231
|
});
|
|
1232
1232
|
|
|
1233
|
-
// src/commands/update.ts
|
|
1234
|
-
import { defineCommand as defineCommand7 } from "citty";
|
|
1235
|
-
import { execSync } from "child_process";
|
|
1236
|
-
|
|
1237
1233
|
// src/ui/banner.ts
|
|
1238
1234
|
import figlet from "figlet";
|
|
1239
1235
|
import pc8 from "picocolors";
|
|
1240
1236
|
// package.json
|
|
1241
1237
|
var package_default = {
|
|
1242
1238
|
name: "github-labels-template",
|
|
1243
|
-
version: "0.8.0
|
|
1239
|
+
version: "0.8.0",
|
|
1244
1240
|
description: "A CLI tool to apply a curated GitHub labels template to any repository using gh CLI.",
|
|
1245
1241
|
type: "module",
|
|
1246
1242
|
bin: {
|
|
@@ -1304,19 +1300,6 @@ function getVersion() {
|
|
|
1304
1300
|
function getAuthor() {
|
|
1305
1301
|
return package_default.author ?? "unknown";
|
|
1306
1302
|
}
|
|
1307
|
-
function showUpdateBanner(latestVersion) {
|
|
1308
|
-
const current = getVersion();
|
|
1309
|
-
const inner1 = ` Update available: v${current} → v${latestVersion} `;
|
|
1310
|
-
const inner2 = ` Run ${pc8.bold("ghlt update")} to upgrade. `;
|
|
1311
|
-
const visibleLen = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
1312
|
-
const width = Math.max(visibleLen(inner1), visibleLen(inner2));
|
|
1313
|
-
const line = "─".repeat(width);
|
|
1314
|
-
console.log(pc8.yellow(`┌${line}┐`));
|
|
1315
|
-
console.log(pc8.yellow("│") + pc8.bold(` Update available: v${current} → v${latestVersion} `) + " ".repeat(width - visibleLen(inner1)) + pc8.yellow("│"));
|
|
1316
|
-
console.log(pc8.yellow("│") + ` Run ${pc8.bold("ghlt update")} to upgrade. ` + " ".repeat(width - visibleLen(inner2)) + pc8.yellow("│"));
|
|
1317
|
-
console.log(pc8.yellow(`└${line}┘`));
|
|
1318
|
-
console.log();
|
|
1319
|
-
}
|
|
1320
1303
|
function showBanner(minimal = false) {
|
|
1321
1304
|
console.log(pc8.cyan(`
|
|
1322
1305
|
` + LOGO));
|
|
@@ -1331,151 +1314,10 @@ function showBanner(minimal = false) {
|
|
|
1331
1314
|
console.log();
|
|
1332
1315
|
}
|
|
1333
1316
|
|
|
1334
|
-
// src/utils/updater.ts
|
|
1335
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync } from "fs";
|
|
1336
|
-
import { join } from "path";
|
|
1337
|
-
import { homedir } from "os";
|
|
1338
|
-
var CACHE_DIR = join(homedir(), ".ghlt");
|
|
1339
|
-
var CACHE_FILE = join(CACHE_DIR, "update-check.json");
|
|
1340
|
-
var CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
1341
|
-
var REGISTRY_URL = "https://registry.npmjs.org/github-labels-template/latest";
|
|
1342
|
-
function isNewerVersion(latest, current) {
|
|
1343
|
-
const parse = (v) => v.replace(/^v/, "").split(".").map(Number);
|
|
1344
|
-
const [lMaj, lMin, lPatch] = parse(latest);
|
|
1345
|
-
const [cMaj, cMin, cPatch] = parse(current);
|
|
1346
|
-
if (lMaj !== cMaj)
|
|
1347
|
-
return lMaj > cMaj;
|
|
1348
|
-
if (lMin !== cMin)
|
|
1349
|
-
return lMin > cMin;
|
|
1350
|
-
return lPatch > cPatch;
|
|
1351
|
-
}
|
|
1352
|
-
function readCache(cacheFile = CACHE_FILE) {
|
|
1353
|
-
try {
|
|
1354
|
-
if (!existsSync2(cacheFile))
|
|
1355
|
-
return null;
|
|
1356
|
-
const raw = readFileSync2(cacheFile, "utf-8");
|
|
1357
|
-
return JSON.parse(raw);
|
|
1358
|
-
} catch {
|
|
1359
|
-
return null;
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
function writeCache(data, cacheFile = CACHE_FILE) {
|
|
1363
|
-
try {
|
|
1364
|
-
const dir = join(cacheFile, "..");
|
|
1365
|
-
if (!existsSync2(dir))
|
|
1366
|
-
mkdirSync(dir, { recursive: true });
|
|
1367
|
-
writeFileSync2(cacheFile, JSON.stringify(data), "utf-8");
|
|
1368
|
-
} catch {}
|
|
1369
|
-
}
|
|
1370
|
-
async function fetchLatestVersion() {
|
|
1371
|
-
try {
|
|
1372
|
-
const res = await fetch(REGISTRY_URL);
|
|
1373
|
-
if (!res.ok)
|
|
1374
|
-
return null;
|
|
1375
|
-
const data = await res.json();
|
|
1376
|
-
return data.version ?? null;
|
|
1377
|
-
} catch {
|
|
1378
|
-
return null;
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
function refreshCacheInBackground(cacheFile = CACHE_FILE) {
|
|
1382
|
-
fetchLatestVersion().then((version) => {
|
|
1383
|
-
if (version) {
|
|
1384
|
-
writeCache({ lastChecked: Date.now(), latestVersion: version }, cacheFile);
|
|
1385
|
-
}
|
|
1386
|
-
}).catch(() => {});
|
|
1387
|
-
}
|
|
1388
|
-
function checkForUpdate(cacheFile = CACHE_FILE) {
|
|
1389
|
-
if (process.env.CI === "true" || process.env.CI === "1")
|
|
1390
|
-
return null;
|
|
1391
|
-
if (process.env.NO_UPDATE_NOTIFIER)
|
|
1392
|
-
return null;
|
|
1393
|
-
if (process.argv.includes("--no-update-notifier"))
|
|
1394
|
-
return null;
|
|
1395
|
-
const cache = readCache(cacheFile);
|
|
1396
|
-
const now = Date.now();
|
|
1397
|
-
const isStale = !cache || now - cache.lastChecked > CACHE_TTL_MS;
|
|
1398
|
-
if (isStale) {
|
|
1399
|
-
refreshCacheInBackground(cacheFile);
|
|
1400
|
-
}
|
|
1401
|
-
if (cache?.latestVersion && isNewerVersion(cache.latestVersion, getVersion())) {
|
|
1402
|
-
return cache.latestVersion;
|
|
1403
|
-
}
|
|
1404
|
-
return null;
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// src/commands/update.ts
|
|
1408
|
-
function detectPackageManager() {
|
|
1409
|
-
try {
|
|
1410
|
-
execSync("bun --version", { stdio: "ignore" });
|
|
1411
|
-
return "bun";
|
|
1412
|
-
} catch {
|
|
1413
|
-
return "npm";
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
function getUpdateCommand(pm) {
|
|
1417
|
-
if (pm === "bun")
|
|
1418
|
-
return "bun add -g github-labels-template";
|
|
1419
|
-
return "npm install -g github-labels-template";
|
|
1420
|
-
}
|
|
1421
|
-
var update_default = defineCommand7({
|
|
1422
|
-
meta: {
|
|
1423
|
-
name: "update",
|
|
1424
|
-
description: "Update ghlt to the latest published version"
|
|
1425
|
-
},
|
|
1426
|
-
args: {
|
|
1427
|
-
check: {
|
|
1428
|
-
type: "boolean",
|
|
1429
|
-
default: false,
|
|
1430
|
-
description: "Only check if an update is available without installing"
|
|
1431
|
-
},
|
|
1432
|
-
"dry-run": {
|
|
1433
|
-
type: "boolean",
|
|
1434
|
-
default: false,
|
|
1435
|
-
description: "Alias for --check — report availability without updating"
|
|
1436
|
-
}
|
|
1437
|
-
},
|
|
1438
|
-
async run({ args }) {
|
|
1439
|
-
const current = getVersion();
|
|
1440
|
-
info(`Current version: v${current}`);
|
|
1441
|
-
const latest = await fetchLatestVersion();
|
|
1442
|
-
if (!latest) {
|
|
1443
|
-
error("Could not fetch the latest version. Check your internet connection.");
|
|
1444
|
-
process.exit(1);
|
|
1445
|
-
}
|
|
1446
|
-
info(`Latest version: v${latest}`);
|
|
1447
|
-
writeCache({ lastChecked: Date.now(), latestVersion: latest });
|
|
1448
|
-
if (!isNewerVersion(latest, current)) {
|
|
1449
|
-
success("Already on the latest version.");
|
|
1450
|
-
return;
|
|
1451
|
-
}
|
|
1452
|
-
if (args.check || args["dry-run"]) {
|
|
1453
|
-
info(`Update available: v${current} → v${latest}`);
|
|
1454
|
-
info(`Run 'ghlt update' to upgrade.`);
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
info("Updating ghlt...");
|
|
1458
|
-
try {
|
|
1459
|
-
const pm = detectPackageManager();
|
|
1460
|
-
const cmd = getUpdateCommand(pm);
|
|
1461
|
-
execSync(cmd, { stdio: "inherit" });
|
|
1462
|
-
success(`ghlt updated to v${latest}`);
|
|
1463
|
-
} catch {
|
|
1464
|
-
error("Update failed. Try running the update command manually:");
|
|
1465
|
-
console.log(` npm install -g github-labels-template`);
|
|
1466
|
-
process.exit(1);
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
|
|
1471
1317
|
// src/index.ts
|
|
1472
1318
|
var isHelp = process.argv.includes("--help") || process.argv.includes("-h");
|
|
1473
1319
|
showBanner(isHelp);
|
|
1474
|
-
var
|
|
1475
|
-
if (availableUpdate) {
|
|
1476
|
-
showUpdateBanner(availableUpdate);
|
|
1477
|
-
}
|
|
1478
|
-
var main = defineCommand8({
|
|
1320
|
+
var main = defineCommand7({
|
|
1479
1321
|
meta: {
|
|
1480
1322
|
name: "ghlt",
|
|
1481
1323
|
version: getVersion(),
|
|
@@ -1494,8 +1336,7 @@ var main = defineCommand8({
|
|
|
1494
1336
|
migrate: migrate_default,
|
|
1495
1337
|
generate: generate_default,
|
|
1496
1338
|
list: list_default,
|
|
1497
|
-
check: check_default
|
|
1498
|
-
update: update_default
|
|
1339
|
+
check: check_default
|
|
1499
1340
|
},
|
|
1500
1341
|
run({ args }) {
|
|
1501
1342
|
if (args.version) {
|