@@ -2,9 +2,9 @@ import _ from 'lodash';
22import fs from 'fs' ;
33import path from 'path' ;
44import { promisify } from 'util' ;
5- import mkdirp from 'mkdirp' ;
6- import fetch from 'node-fetch' ;
5+ import { mkdirp } from 'mkdirp' ;
76import { fileURLToPath } from 'url' ;
7+ import api from './githubAPI.mjs' ;
88
99import yamlHeadmatter from './yaml-headmatter.mjs' ;
1010import processReadme from './process-readme.mjs' ;
@@ -13,7 +13,6 @@ const __filename = fileURLToPath(import.meta.url);
1313const __dirname = path . dirname ( __filename ) ;
1414
1515const writeFile = promisify ( fs . writeFile ) ;
16- const rename = promisify ( fs . rename ) ;
1716const readFile = promisify ( fs . readFile ) ;
1817const cwd = process . cwd ( ) ;
1918
@@ -32,28 +31,35 @@ const loaderGroup = {
3231 'style-loader' : 'CSS' ,
3332 'stylus-loader' : 'CSS' ,
3433} ;
34+ const communityPackages = [ {
35+ name : 'svg-chunk-webpack-plugin' ,
36+ contributors : [ 'yoriiis' , 'alexander-akait' ]
37+ } ] ;
3538
3639async function main ( ) {
3740 for ( const type of types ) {
3841 const outputDir = pathMap [ type ] ;
3942
4043 await mkdirp ( outputDir ) ;
4144
45+ /** @type string[] */
4246 const repos = JSON . parse (
4347 await readFile ( path . resolve ( __dirname , `../../repositories/${ type } .json` ) )
4448 ) ;
4549
4650 for ( const repo of repos ) {
47- const [ , packageName ] = repo . split ( '/' ) ;
48- const url = `https://raw.githubusercontent.com/${ repo } /master/README.md` ;
51+ const [ owner , packageName ] = repo . split ( '/' ) ;
52+
53+ const response = await api . repos . get ( {
54+ owner,
55+ repo : packageName ,
56+ } ) ;
57+
58+ const defaultBranch = response . data . default_branch ;
59+ const url = `https://raw.githubusercontent.com/${ repo } /${ defaultBranch } /README.md` ;
4960 const htmlUrl = `https://github.com/${ repo } ` ;
50- const editUrl = `${ htmlUrl } /edit/master/README.md` ;
51- < << << << HEAD
61+ const editUrl = `${ htmlUrl } /edit/${ defaultBranch } /README.md` ;
5262 const fileName = path . resolve ( outputDir , `_${ packageName } .mdx` ) ;
53- = === ===
54- const fileName = path . resolve ( outputDir , `${ packageName } .mdx` ) ;
55- const mdxFileName = path . resolve ( outputDir , `${ packageName } .mdx` ) ;
56- > >>> >>> d054d4656cbfb5228fc96f5de26d4f0ce349f742
5763
5864 let title = packageName ;
5965
@@ -67,27 +73,29 @@ async function main() {
6773 let headmatter ;
6874
6975 if ( type === 'plugins' ) {
76+ let group = 'webpack contrib' ;
77+ let contributors = [ ] ;
78+ const packageFromCommunity = communityPackages . find ( ( item ) => item . name === packageName ) ;
79+ if ( packageFromCommunity ) {
80+ group = 'Community' ;
81+ contributors = packageFromCommunity . contributors ;
82+ }
7083 headmatter = yamlHeadmatter ( {
7184 title : title ,
72- group : 'webpack contrib' ,
85+ group,
86+ contributors,
7387 source : url ,
7488 edit : editUrl ,
7589 repo : htmlUrl ,
76- << < << << HEAD
77- thirdParty : true
78- = = === ==
79- >>> >>> > d054d4656cbfb5228fc96f5de26d4f0ce349f742
90+ thirdParty : true ,
8091 } ) ;
8192 } else {
8293 let basic = {
8394 title : title ,
8495 source : url ,
8596 edit : editUrl ,
8697 repo : htmlUrl ,
87- << < << << HEAD
88- thirdParty : true
89- = = === ==
90- >>> >>> > d054d4656cbfb5228fc96f5de26d4f0ce349f742
98+ thirdParty : true ,
9199 } ;
92100
93101 if ( loaderGroup [ packageName ] ) {
@@ -96,12 +104,16 @@ async function main() {
96104 headmatter = yamlHeadmatter ( basic ) ;
97105 }
98106
99- const response = await fetch ( url ) ;
100- const content = await response . text ( ) ;
107+ const { data : content } = await api . repos . getReadme ( {
108+ owner,
109+ repo : packageName ,
110+ mediaType : {
111+ format : 'raw' ,
112+ } ,
113+ } ) ;
101114 const body = processReadme ( content , { source : url } ) ;
102115 await writeFile ( fileName , headmatter + body ) ;
103- await rename ( fileName , mdxFileName ) ;
104- console . log ( 'Generated:' , path . relative ( cwd , mdxFileName ) ) ;
116+ console . log ( 'Generated:' , path . relative ( cwd , fileName ) ) ;
105117 }
106118 }
107119}
0 commit comments