File tree Expand file tree Collapse file tree 4 files changed +47
-51
lines changed
Expand file tree Collapse file tree 4 files changed +47
-51
lines changed Original file line number Diff line number Diff line change 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" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11import yargs from "yargs" ;
22import { hideBin } from "yargs/helpers" ;
3- // import { checkVersionMiddleware } from "./helpers/checkNpmVersion .ts";
3+ import { checkVersionMiddleware } from "./helpers/checkVersion .ts" ;
44import { globalOptions } from "./helpers/options.ts" ;
55import initCommand from "./handlers/init/index.ts" ;
66import 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 )
You can’t perform that action at this time.
0 commit comments