1+ import { execSync } from 'node:child_process'
12import { writeFile } from 'node:fs/promises'
23import { createRequire } from 'node:module'
34import { resolve } from 'node:path'
45import { fileURLToPath } from 'node:url'
6+
57import axios from 'axios'
68
9+ function githubToken ( ) {
10+ if ( process . env . GH_TOKEN ) return process . env . GH_TOKEN
11+ if ( process . env . GITHUB_TOKEN ) return process . env . GITHUB_TOKEN
12+ try {
13+ return execSync ( 'gh auth token' , {
14+ encoding : 'utf8' ,
15+ stdio : [ 'ignore' , 'pipe' , 'ignore' ] ,
16+ } ) . trim ( )
17+ } catch {
18+ return undefined
19+ }
20+ }
21+
722const require = createRequire ( import . meta. url )
823const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) )
924
1025const {
1126 dashboard : { repo } ,
1227} = require ( './package.json' )
28+
1329const Package = require ( './package.json' )
30+
1431const endpoint = `https://api.github.com/repos/${ repo } /releases/latest`
1532
1633const latestVersion = async ( ) => {
34+ const token = githubToken ( )
1735 const res = await axios
1836 . get ( endpoint , {
1937 headers : {
2038 'User-Agent' :
2139 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' ,
22- Authorization : process . env . GH_TOKEN
23- ? `Bearer ${ process . env . GH_TOKEN } `
24- : undefined ,
40+ ...( token ? { Authorization : `Bearer ${ token } ` } : { } ) ,
2541 } ,
2642 } )
2743 . catch ( ( error ) => {
@@ -40,7 +56,7 @@ async function main() {
4056 JSON . stringify ( Package , null , 2 ) ,
4157 )
4258
43- console . log ( 'Updated version to' , version )
59+ console . info ( 'Updated version to' , version )
4460}
4561
4662main ( )
0 commit comments