Skip to content

Commit

Permalink
fix: better prompt for upgrader (#18)
Browse files Browse the repository at this point in the history
better prompt for upgrader
  • Loading branch information
sylc committed Jul 30, 2023
1 parent ad977b8 commit 9e045fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"program": "${workspaceFolder}/cli.ts",
"args": ["--upgrade"],
"cwd": "${workspaceFolder}",
"runtimeExecutable": "C:\\Users\\sylva\\.deno\\bin\\deno.EXE",
"runtimeArgs": [
"run",
"--inspect-wait",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
1 change: 0 additions & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ await new Command()
await upgrader({
packageName: "dkill",
currentVersion: vJson.version,
denoLand: true,
});
return;
}
Expand Down
49 changes: 28 additions & 21 deletions src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,34 @@ async function fetchNewFlags(url: string) {
export async function upgrader(config: {
packageName: string;
currentVersion: string;
denoLand?: boolean;
}) {
// try to find the install script
console.log("Run ONE of the below commands");
if (config.denoLand) {
const versions = await (
await fetch(
`https://cdn.deno.land/${config.packageName}/meta/versions.json`,
)
).json();
if (config.currentVersion !== versions.latest) {
const newFlags = await fetchNewFlags(
`https://deno.land/x/${config.packageName}@${versions.latest}/version.ts`,
);
console.log(
`deno.land: deno install -f ${
newFlags.join(" ")
} https://deno.land/x/${config.packageName}@${versions.latest}/cli.ts`,
);
} else {
console.log("Already up to date from deno.land");
}
// try to find the latest version
console.log("Looking up latest version");
const versions = await (
await fetch(
`https://cdn.deno.land/${config.packageName}/meta/versions.json`,
)
).json();
// We do not consider the < comparison because
// it is unlikely to eb > (not doing canary release)
// so if not equal, it must be lower version
if (config.currentVersion !== versions.latest) {
const newFlags = await fetchNewFlags(
`https://deno.land/x/${config.packageName}@${versions.latest}/version.ts`,
);

console.log(
`Current version: ${config.currentVersion}; latest Version: ${versions.latest}`,
);
console.log("Run the below command to update:");
console.log(
`deno install -f ${
newFlags.join(" ")
} https://deno.land/x/${config.packageName}@${versions.latest}/cli.ts`,
);
} else {
console.log(
`Local version ${config.currentVersion} is the most recent release`,
);
}
}

0 comments on commit 9e045fd

Please sign in to comment.