@@ -7,6 +7,9 @@ import process from 'node:process';
77const start = performance . now ( ) ;
88console . log ( '[sync-packages] start' ) ;
99
10+ let skipGithubStars = false ;
11+ let logsAtTheEnd : String [ ] = [ ] ;
12+
1013const packages = [
1114 ...PACKAGES_META . FEATURED . flatMap ( ( pkg ) => pkg . packages ) ,
1215 ...PACKAGES_META . SV_ADD . packages
@@ -52,7 +55,7 @@ if (jsonNotNeeded.length > 0) {
5255}
5356
5457// PART 3: refresh data
55- registryJsonFiles = fs . readdirSync ( registryFolder ) ; // .slice(0, 1);
58+ registryJsonFiles = fs . readdirSync ( registryFolder ) ; //.slice(0, 1);
5659
5760const batch = 10 ;
5861for ( let i = 0 ; i < registryJsonFiles . length ; i += batch ) {
@@ -69,10 +72,18 @@ theEnd(0);
6972// HELPERS
7073
7174function theEnd ( val : number ) {
72- console . log ( `[sync-packages] exit(${ val } ) - took: ${ ( performance . now ( ) - start ) . toFixed ( 0 ) } ms` ) ;
75+ const msg = [ '[sync-packages]' ] ;
76+ if ( val > 0 ) {
77+ msg . push ( `exit(${ val } ) - ` ) ;
78+ }
79+ msg . push ( `took: ${ ( performance . now ( ) - start ) . toFixed ( 0 ) } ms` ) ;
80+ console . log ( msg . join ( ' ' ) ) ;
81+ if ( logsAtTheEnd . length > 0 ) {
82+ console . log ( '[sync-packages] Report:' ) ;
83+ console . log ( ` - ${ logsAtTheEnd . join ( '\n - ' ) } ` ) ;
84+ }
7385 process . exit ( val ) ;
7486}
75-
7687async function fetchData ( pkg : string ) {
7788 const [ npmInfo , npmDlInfo ] = await Promise . all ( [
7889 fetch ( `https://registry.npmjs.org/${ pkg } ` ) . then ( ( r ) => r . json ( ) ) ,
@@ -84,7 +95,8 @@ async function fetchData(pkg: string) {
8495 const raw_repo_url = npmInfo . repository ?. url ?? '' ;
8596 const repo_url = raw_repo_url ?. replace ( / ^ g i t \+ / , '' ) . replace ( / \. g i t $ / , '' ) ;
8697 if ( ! repo_url ) {
87- console . error ( `repo_url not found for ${ pkg } ` ) ;
98+ // console.error(`repo_url not found for ${pkg}`);
99+ logsAtTheEnd . push ( `repo_url not found for ${ pkg } ` ) ;
88100 }
89101 const git_org = repo_url ?. split ( '/' ) [ 3 ] ;
90102 const git_repo = repo_url ?. split ( '/' ) [ 4 ] ;
@@ -95,12 +107,15 @@ async function fetchData(pkg: string) {
95107 const version = npmInfo [ 'dist-tags' ] . latest ;
96108 const updated = npmInfo . time [ version ] ;
97109
98- let github_stars = 0 ;
99- if ( git_org && git_repo ) {
100- const githubInfo = await fetch ( `https://api.github.com/repos/${ git_org } /${ git_repo } ` ) . then (
101- ( r ) => r . json ( )
102- ) ;
103- github_stars = githubInfo . stargazers_count ;
110+ let github_stars : number | undefined = undefined ;
111+ if ( git_org && git_repo && ! skipGithubStars ) {
112+ const res = await fetch ( `https://api.github.com/repos/${ git_org } /${ git_repo } ` ) ;
113+ const resJson = await res . json ( ) ;
114+ if ( resJson . message && resJson . message . startsWith ( 'API rate limit exceeded' ) ) {
115+ skipGithubStars = true ;
116+ } else {
117+ github_stars = resJson . stargazers_count ;
118+ }
104119 }
105120
106121 return {
@@ -121,7 +136,7 @@ async function fetchData(pkg: string) {
121136}
122137
123138async function refreshJson ( fullPath : string ) {
124- console . log ( `Working on :` , fullPath ) ;
139+ console . log ( `Refreshing :` , fullPath ) ;
125140
126141 const currentJson = JSON . parse ( fs . readFileSync ( fullPath , 'utf-8' ) ) ;
127142 const newData = await fetchData ( currentJson . name ) ;
0 commit comments