@arvoretech/hub 0.19.0 → 0.20.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 +56 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3875,7 +3875,9 @@ import { readFileSync } from "fs";
|
|
|
3875
3875
|
import { join as join17, dirname } from "path";
|
|
3876
3876
|
import { fileURLToPath } from "url";
|
|
3877
3877
|
import chalk15 from "chalk";
|
|
3878
|
+
import ora from "ora";
|
|
3878
3879
|
var PACKAGE_NAME = "@arvoretech/hub";
|
|
3880
|
+
var RELEASES_URL = "https://hub.arvore.com.br/api/releases.json";
|
|
3879
3881
|
function getCurrentVersion() {
|
|
3880
3882
|
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
3881
3883
|
const pkgPath = join17(__dirname2, "..", "package.json");
|
|
@@ -3888,6 +3890,24 @@ async function getLatestVersion() {
|
|
|
3888
3890
|
const data = await res.json();
|
|
3889
3891
|
return data.version;
|
|
3890
3892
|
}
|
|
3893
|
+
function compareVersions(a, b) {
|
|
3894
|
+
const pa = a.split(".").map(Number);
|
|
3895
|
+
const pb = b.split(".").map(Number);
|
|
3896
|
+
for (let i = 0; i < 3; i++) {
|
|
3897
|
+
if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
3898
|
+
}
|
|
3899
|
+
return 0;
|
|
3900
|
+
}
|
|
3901
|
+
async function getReleasesBetween(from, to) {
|
|
3902
|
+
try {
|
|
3903
|
+
const res = await fetch(RELEASES_URL, { signal: AbortSignal.timeout(5e3) });
|
|
3904
|
+
if (!res.ok) return [];
|
|
3905
|
+
const releases = await res.json();
|
|
3906
|
+
return releases.filter((r) => compareVersions(r.version, from) > 0 && compareVersions(r.version, to) <= 0).sort((a, b) => compareVersions(a.version, b.version));
|
|
3907
|
+
} catch {
|
|
3908
|
+
return [];
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3891
3911
|
function detectPackageManager() {
|
|
3892
3912
|
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
3893
3913
|
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
@@ -3921,47 +3941,61 @@ function buildInstallCommand(pm) {
|
|
|
3921
3941
|
return `npm install -g ${PACKAGE_NAME}@latest`;
|
|
3922
3942
|
}
|
|
3923
3943
|
}
|
|
3944
|
+
var typeColors = {
|
|
3945
|
+
feat: chalk15.green,
|
|
3946
|
+
fix: chalk15.yellow,
|
|
3947
|
+
refactor: chalk15.magenta,
|
|
3948
|
+
chore: chalk15.dim
|
|
3949
|
+
};
|
|
3950
|
+
function formatChangeType(type) {
|
|
3951
|
+
const color = typeColors[type] ?? chalk15.dim;
|
|
3952
|
+
return color(type.toUpperCase().padEnd(8));
|
|
3953
|
+
}
|
|
3924
3954
|
var updateCommand = new Command16("update").description("Update hub CLI to the latest version").option("--check", "Only check for updates without installing").action(async (opts) => {
|
|
3925
3955
|
const currentVersion = getCurrentVersion();
|
|
3926
|
-
|
|
3927
|
-
Current version: ${currentVersion}`));
|
|
3956
|
+
const checkSpinner = ora({ text: "Checking for updates...", color: "cyan" }).start();
|
|
3928
3957
|
let latestVersion;
|
|
3929
3958
|
try {
|
|
3930
3959
|
latestVersion = await getLatestVersion();
|
|
3931
3960
|
} catch (err) {
|
|
3932
|
-
|
|
3933
|
-
`));
|
|
3961
|
+
checkSpinner.fail(`Failed to check for updates: ${err.message}`);
|
|
3934
3962
|
return;
|
|
3935
3963
|
}
|
|
3936
|
-
console.log(chalk15.blue(` Latest version: ${latestVersion}`));
|
|
3937
3964
|
if (currentVersion === latestVersion) {
|
|
3938
|
-
|
|
3965
|
+
checkSpinner.succeed(chalk15.green(`Already on the latest version (${currentVersion})`));
|
|
3939
3966
|
return;
|
|
3940
3967
|
}
|
|
3941
|
-
|
|
3942
|
-
|
|
3968
|
+
checkSpinner.succeed(`Update available: ${chalk15.dim(currentVersion)} \u2192 ${chalk15.green(latestVersion)}`);
|
|
3969
|
+
const releases = await getReleasesBetween(currentVersion, latestVersion);
|
|
3970
|
+
if (releases.length > 0) {
|
|
3971
|
+
console.log();
|
|
3972
|
+
console.log(chalk15.cyan(" Releases included:"));
|
|
3973
|
+
for (const release of releases) {
|
|
3974
|
+
const date = (/* @__PURE__ */ new Date(release.date + "T00:00:00")).toLocaleDateString("pt-BR");
|
|
3975
|
+
console.log();
|
|
3976
|
+
console.log(` ${chalk15.green("\u25CF")} ${chalk15.white.bold(`v${release.version}`)} ${chalk15.dim(`\u2014 ${release.title}`)} ${chalk15.dim(`(${date})`)}`);
|
|
3977
|
+
for (const change of release.changes) {
|
|
3978
|
+
console.log(` ${formatChangeType(change.type)} ${chalk15.dim(change.title)}`);
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3981
|
+
console.log();
|
|
3982
|
+
console.log(chalk15.dim(` Full notes: https://hub.arvore.com.br/releases`));
|
|
3983
|
+
}
|
|
3943
3984
|
const pm = detectPackageManager();
|
|
3944
3985
|
if (opts.check) {
|
|
3945
3986
|
console.log(chalk15.dim(`
|
|
3946
|
-
Run 'hub update'
|
|
3987
|
+
Run 'hub update' to install.
|
|
3947
3988
|
`));
|
|
3948
3989
|
return;
|
|
3949
3990
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
Updating with ${pm}...
|
|
3953
|
-
`));
|
|
3954
|
-
console.log(chalk15.dim(` $ ${installCmd}
|
|
3955
|
-
`));
|
|
3991
|
+
console.log();
|
|
3992
|
+
const installSpinner = ora({ text: `Updating with ${pm}...`, color: "cyan" }).start();
|
|
3956
3993
|
try {
|
|
3957
|
-
execSync12(
|
|
3958
|
-
|
|
3959
|
-
Updated to ${latestVersion} successfully.
|
|
3960
|
-
`));
|
|
3994
|
+
execSync12(buildInstallCommand(pm), { stdio: "pipe" });
|
|
3995
|
+
installSpinner.succeed(chalk15.green(`Updated to ${latestVersion}`));
|
|
3961
3996
|
} catch {
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
console.log(chalk15.dim(` $ ${installCmd}
|
|
3997
|
+
installSpinner.fail("Update failed");
|
|
3998
|
+
console.log(chalk15.dim(` Try running manually: ${buildInstallCommand(pm)}
|
|
3965
3999
|
`));
|
|
3966
4000
|
}
|
|
3967
4001
|
});
|