1
- require ( " dotenv" ) . config ( ) ;
1
+ require ( ' dotenv' ) . config ( ) ;
2
2
3
3
const CacheAsset = require ( "@11ty/eleventy-cache-assets" ) ;
4
4
const fastglob = require ( "fast-glob" ) ;
@@ -30,7 +30,7 @@ async function githubRequest(user, repo) {
30
30
issues : "" ,
31
31
} ;
32
32
33
- if ( ! process . env . GITHUB_READ_TOKEN ) {
33
+ if ( process . env . ELEVENTY_ENV == 'dev' || ! process . env . GITHUB_READ_TOKEN ) {
34
34
return errorData ;
35
35
}
36
36
@@ -55,22 +55,22 @@ async function githubRequest(user, repo) {
55
55
const fetchOptions = {
56
56
method : "POST" ,
57
57
headers : {
58
- Authorization : `bearer ${ process . env . GITHUB_READ_TOKEN } ` ,
58
+ " Authorization" : `bearer ${ process . env . GITHUB_READ_TOKEN } `
59
59
} ,
60
- body : JSON . stringify ( { query } ) ,
60
+ body : JSON . stringify ( { query } )
61
61
} ;
62
62
const opts = {
63
63
duration : "1401m" , // 23.5 hours
64
64
type : "json" ,
65
- fetchOptions,
65
+ fetchOptions
66
66
} ;
67
67
68
68
let req ;
69
69
try {
70
70
req = await CacheAsset ( url , opts ) ;
71
- if ( req . errors && req . errors . length ) {
72
- console . log ( "GitHub Data Source Error from API" , req . errors ) ;
73
- if ( req . errors . filter ( ( e ) => e . type === "RATE_LIMITED" ) . length > 0 ) {
71
+ if ( req . errors && req . errors . length ) {
72
+ console . log ( "GitHub Data Source Error from API" , req . errors ) ;
73
+ if ( req . errors . filter ( e => e . type === "RATE_LIMITED" ) . length > 0 ) {
74
74
throw new Error ( "Failing the build due to GitHub API rate limiting." ) ;
75
75
}
76
76
return errorData ;
@@ -80,31 +80,31 @@ async function githubRequest(user, repo) {
80
80
stars : req . data . repository . stargazers . totalCount ,
81
81
forks : req . data . repository . forks . totalCount ,
82
82
issues : req . data . repository . issues . totalCount ,
83
- } ;
84
- } catch ( e ) {
85
- console . log ( "GitHub Data Source Error" , e ) ;
83
+ }
84
+ } catch ( e ) {
85
+ console . log ( "GitHub Data Source Error" , e ) ;
86
86
87
87
return errorData ;
88
88
}
89
89
}
90
90
91
91
async function getReposFromMarkdown ( glob ) {
92
92
// Starters
93
- let ssgs = await fastglob ( glob , {
94
- caseSensitiveMatch : false ,
93
+ let ssgs = await fastglob ( glob , {
94
+ caseSensitiveMatch : false
95
95
} ) ;
96
96
97
97
let repos = [ ] ;
98
- for ( let ssg of ssgs ) {
98
+ for ( let ssg of ssgs ) {
99
99
let matter = graymatter . read ( ssg ) ;
100
100
let fullRepo = matter . data . repo ;
101
- if ( fullRepo ) {
101
+ if ( fullRepo ) {
102
102
let split = fullRepo . split ( "/" ) ;
103
103
let user = split [ 0 ] ;
104
104
let repo = split [ 1 ] ;
105
-
106
- if ( ! matter . data . repohost || matter . data . repohost === "github" ) {
107
- if ( matter . data . disabled ) {
105
+
106
+ if ( ! matter . data . repohost || matter . data . repohost === "github" ) {
107
+ if ( matter . data . disabled ) {
108
108
continue ;
109
109
}
110
110
repos . push ( { user, repo } ) ;
@@ -115,24 +115,18 @@ async function getReposFromMarkdown(glob) {
115
115
return repos ;
116
116
}
117
117
118
- module . exports = async function ( ) {
118
+ module . exports = async function ( ) {
119
119
let data = { } ;
120
120
121
121
let ssgRepos = await getReposFromMarkdown ( "./src/site/generators/*.md" ) ;
122
- for ( let entry of ssgRepos ) {
123
- data [ `${ entry . user } /${ entry . repo } ` ] = await githubRequest (
124
- entry . user ,
125
- entry . repo
126
- ) ;
122
+ for ( let entry of ssgRepos ) {
123
+ data [ `${ entry . user } /${ entry . repo } ` ] = await githubRequest ( entry . user , entry . repo ) ;
127
124
}
128
125
129
126
let cmsRepos = await getReposFromMarkdown ( "./src/site/headless-cms/*.md" ) ;
130
- for ( let entry of cmsRepos ) {
131
- data [ `${ entry . user } /${ entry . repo } ` ] = await githubRequest (
132
- entry . user ,
133
- entry . repo
134
- ) ;
127
+ for ( let entry of cmsRepos ) {
128
+ data [ `${ entry . user } /${ entry . repo } ` ] = await githubRequest ( entry . user , entry . repo ) ;
135
129
}
136
130
137
131
return data ;
138
- } ;
132
+ } ;
0 commit comments