1+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
13import { Octokit } from "@octokit/rest" ;
2- import YAML from "yaml" ;
3- import fs from "fs" ;
4+ import * as YAML from "yaml" ;
5+ import * as fs from "fs" ;
6+ import { join , extname } from "path" ;
47
58function pad ( number : number ) {
69 if ( number < 10 ) {
@@ -12,8 +15,13 @@ function pad(number: number) {
1215// Modified version of the toISOString polyfill from https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
1316// because I couldn't find a function which outputs the dates like it happened on ruby
1417// but the diff from the TS output and the ruby output should be as low as possible
15- // @ts -expect-error
16- Date . prototype . toRubyString = function ( ) {
18+ declare global {
19+ interface Date {
20+ toRubyString ( ) : string ;
21+ }
22+ }
23+
24+ Date . prototype . toRubyString = function ( this : Date ) {
1725 return (
1826 this . getUTCFullYear ( ) +
1927 "-" +
@@ -31,59 +39,57 @@ Date.prototype.toRubyString = function () {
3139} ;
3240
3341const client = new Octokit ( {
34- auth : process . env . GITHUB_TOKEN || "" ,
42+ auth : process . env . GITHUB_TOKEN ?? "" ,
3543} ) ;
3644
3745function walk ( directory : string , filepaths : string [ ] = [ ] ) : string [ ] {
3846 const files = fs . readdirSync ( directory ) ;
39- for ( let filename of files ) {
40- const filepath = require ( "path" ) . join ( directory , filename ) ;
47+ for ( const filename of files ) {
48+ const filepath = join ( directory , filename ) ;
4149 if ( fs . statSync ( filepath ) . isDirectory ( ) ) {
4250 walk ( filepath , filepaths ) ;
43- } else if ( require ( "path" ) . extname ( filename ) === ".md" ) {
51+ } else if ( extname ( filename ) === ".md" ) {
4452 filepaths . push ( filepath ) ;
4553 }
4654 }
4755 return filepaths ;
4856}
4957
50- const files = walk ( require ( "path" ) . join ( __dirname , ".." , "_apps" ) ) ;
58+ const files = walk ( join ( __dirname , ".." , "_apps" ) ) ;
5159
52- files . forEach ( async ( path ) => {
53- let data : string = "" ;
60+ for ( const path of files ) {
61+ let data = "" ;
5462 try {
5563 try {
5664 // @ts -expect-error
57- data = fs
58- . readFileSync ( path )
59- . toString ( )
60- . match ( / ^ - - - ( ( (? ! - - - ) .| [ \r \n ] ) * ) [ \r \n ] - - - $ / m) [ 0 ] ;
65+ data = / ^ - - - ( ( (? ! - - - ) .| [ \r \n ] ) * ) [ \r \n ] - - - $ / m. exec (
66+ fs . readFileSync ( path ) . toString ( ) ,
67+ ) [ 0 ] ;
6168 } catch {
6269 console . error ( `Error parsing ${ path } ` ) ;
6370 console . log ( data ) ;
6471 process . exit ( 1 ) ;
6572 }
66- let app = YAML . parse ( data . replaceAll ( "---" , "" ) ) ;
73+ const app = YAML . parse ( data . replaceAll ( "---" , "" ) ) ;
6774 console . log ( `Syncing ${ app . title } ` ) ;
6875
69- const repoName = app [ " repository" ] . split ( "/" ) ;
76+ const repoName = app . repository . split ( "/" ) ;
7077 const repo = await client . rest . repos . get ( {
7178 owner : repoName [ 0 ] ,
7279 repo : repoName [ 1 ] ,
7380 } ) ;
7481 app . stars = repo . data . stargazers_count ;
75- //@ts -expect-error
7682 app . updated = new Date ( repo . data . pushed_at ) . toRubyString ( ) ;
7783
7884 if ( app . host ) {
7985 const statsFromServer = await fetch ( app . host + "/probot/stats" ) ;
8086 if ( statsFromServer . status === 200 ) {
81- let stats : Record < string , unknown > = YAML . parse (
82- await statsFromServer . text ( )
87+ const stats : Record < string , unknown > = YAML . parse (
88+ await statsFromServer . text ( ) ,
8389 ) ;
8490 if ( stats . popular ) {
85- app . organizations = ( < Array < unknown > > stats . popular ) . map (
86- ( org : any ) => org . login
91+ app . organizations = ( stats . popular as unknown [ ] ) . map (
92+ ( org : any ) => org . login as string ,
8793 ) ;
8894 }
8995 }
@@ -93,7 +99,7 @@ files.forEach(async (path) => {
9399 content = content . replace (
94100 data ,
95101 `---
96- ${ YAML . stringify ( app ) } ---`
102+ ${ YAML . stringify ( app ) } ---`,
97103 ) ;
98104 fs . writeFileSync ( path , content ) ;
99105 console . log ( `Done for ${ app . title } ` ) ;
@@ -107,4 +113,4 @@ ${YAML.stringify(app)}---`
107113 console . log ( e ) ;
108114 process . exit ( 1 ) ;
109115 }
110- } ) ;
116+ }
0 commit comments