@@ -7,6 +7,9 @@ import process from 'node:process';
7
7
const start = performance . now ( ) ;
8
8
console . log ( '[sync-packages] start' ) ;
9
9
10
+ let skipGithubStars = false ;
11
+ let logsAtTheEnd : String [ ] = [ ] ;
12
+
10
13
const packages = [
11
14
...PACKAGES_META . FEATURED . flatMap ( ( pkg ) => pkg . packages ) ,
12
15
...PACKAGES_META . SV_ADD . packages
@@ -52,7 +55,7 @@ if (jsonNotNeeded.length > 0) {
52
55
}
53
56
54
57
// PART 3: refresh data
55
- registryJsonFiles = fs . readdirSync ( registryFolder ) ; // .slice(0, 1);
58
+ registryJsonFiles = fs . readdirSync ( registryFolder ) ; //.slice(0, 1);
56
59
57
60
const batch = 10 ;
58
61
for ( let i = 0 ; i < registryJsonFiles . length ; i += batch ) {
@@ -69,10 +72,18 @@ theEnd(0);
69
72
// HELPERS
70
73
71
74
function 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
+ }
73
85
process . exit ( val ) ;
74
86
}
75
-
76
87
async function fetchData ( pkg : string ) {
77
88
const [ npmInfo , npmDlInfo ] = await Promise . all ( [
78
89
fetch ( `https://registry.npmjs.org/${ pkg } ` ) . then ( ( r ) => r . json ( ) ) ,
@@ -84,7 +95,8 @@ async function fetchData(pkg: string) {
84
95
const raw_repo_url = npmInfo . repository ?. url ?? '' ;
85
96
const repo_url = raw_repo_url ?. replace ( / ^ g i t \+ / , '' ) . replace ( / \. g i t $ / , '' ) ;
86
97
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 } ` ) ;
88
100
}
89
101
const git_org = repo_url ?. split ( '/' ) [ 3 ] ;
90
102
const git_repo = repo_url ?. split ( '/' ) [ 4 ] ;
@@ -95,12 +107,15 @@ async function fetchData(pkg: string) {
95
107
const version = npmInfo [ 'dist-tags' ] . latest ;
96
108
const updated = npmInfo . time [ version ] ;
97
109
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
+ }
104
119
}
105
120
106
121
return {
@@ -121,7 +136,7 @@ async function fetchData(pkg: string) {
121
136
}
122
137
123
138
async function refreshJson ( fullPath : string ) {
124
- console . log ( `Working on :` , fullPath ) ;
139
+ console . log ( `Refreshing :` , fullPath ) ;
125
140
126
141
const currentJson = JSON . parse ( fs . readFileSync ( fullPath , 'utf-8' ) ) ;
127
142
const newData = await fetchData ( currentJson . name ) ;
0 commit comments