Skip to content

Commit 93afc62

Browse files
committed
re implement version check, decrease version to force rerelease
1 parent 87d6eeb commit 93afc62

File tree

4 files changed

+47
-51
lines changed

4 files changed

+47
-51
lines changed

packages/cli/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"express": "npm:express@^5.1.0",
1010
"glob": "npm:glob@^11.0.2",
1111
"http-proxy-middleware": "npm:http-proxy-middleware@^3.0.5",
12+
"octokit": "npm:octokit@^4.1.3",
1213
"tree-sitter": "npm:tree-sitter@^0.22.4",
1314
"tree-sitter-c-sharp": "npm:tree-sitter-c-sharp@^0.23.1",
1415
"tree-sitter-python": "npm:tree-sitter-python@^0.23.6",

packages/cli/src/cli/helpers/checkNpmVersion.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import localPackageJson from "../../../../../deno.json" with { type: "json" };
2+
import process from "node:process";
3+
import { Octokit } from "octokit";
4+
5+
export async function checkVersionMiddleware() {
6+
const currentVersion = localPackageJson.version;
7+
8+
const owner = "nanoapi-io";
9+
const repo = "napi";
10+
11+
const octokit = new Octokit();
12+
13+
try {
14+
const release = await octokit.rest.repos.getLatestRelease({
15+
owner,
16+
repo,
17+
});
18+
19+
const tagName = release.data.tag_name;
20+
21+
const latestVersion = tagName.replace(/^v/, "");
22+
23+
if (currentVersion !== latestVersion) {
24+
console.error(
25+
`
26+
You are using version ${currentVersion}.
27+
The latest version is ${latestVersion}.
28+
Please update to the latest version.
29+
30+
You can update the version by running one of the following commands:
31+
32+
You can get the latest version here: ${release.data.html_url}
33+
`,
34+
);
35+
process.exit(1);
36+
}
37+
} catch (err) {
38+
console.warn(
39+
`Failed to fetch latest version, ignoring version check. Error: ${err}`,
40+
);
41+
}
42+
}

packages/cli/src/cli/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import yargs from "yargs";
22
import { hideBin } from "yargs/helpers";
3-
// import { checkVersionMiddleware } from "./helpers/checkNpmVersion.ts";
3+
import { checkVersionMiddleware } from "./helpers/checkVersion.ts";
44
import { globalOptions } from "./helpers/options.ts";
55
import initCommand from "./handlers/init/index.ts";
66
import auditCommand from "./handlers/audit/index.ts";
@@ -14,9 +14,9 @@ export function initCli() {
1414

1515
yargs(hideBin(process.argv))
1616
.scriptName("napi")
17-
// .middleware(async () => {
18-
// await checkVersionMiddleware();
19-
// })
17+
.middleware(async () => {
18+
await checkVersionMiddleware();
19+
})
2020
.options(globalOptions)
2121
.command(initCommand)
2222
.command(auditCommand)

0 commit comments

Comments
 (0)