File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ function convertToRawURL ( url , suffix = null ) {
2+ url = url . replace ( 'https://github.com/' , '' ) ;
3+ const parts = url . split ( '/' ) ;
4+ const owner = parts [ 0 ] ;
5+ const repoName = parts [ 1 ] ;
6+ const branch = 'HEAD' ;
7+ let path = parts [ 2 ] ? "/" + parts [ 2 ] : '' ;
8+ if ( suffix ) {
9+ path += "/" + suffix ;
10+ }
11+ return `https://raw.githubusercontent.com/${ owner } /${ repoName } /${ branch } ${ path } ` ;
12+ }
13+
14+ async function findLicenseURL ( url ) {
15+ const licenseFileURL = convertToRawURL ( url , 'LICENSE' ) ;
16+ // Fetch the license file
17+ const licenseResponse = await fetch ( licenseFileURL ) ;
18+ if ( licenseResponse . ok ) {
19+ const licenseText = await licenseResponse . text ( ) ;
20+ // Get the first line of the license file
21+ const license = licenseText . split ( '\n' ) [ 0 ] ;
22+ return license ;
23+ }
24+ return null ;
25+ }
26+
27+ if ( process . argv . length < 3 ) {
28+ console . error ( 'Usage: node find-license.mjs <GitHub URL>' ) ;
29+ process . exit ( 1 ) ;
30+ }
31+
32+ const license = await findLicenseURL ( process . argv [ 2 ] ) ;
33+ if ( license ) console . log ( license ) ;
You can’t perform that action at this time.
0 commit comments