import { Asset , BinaConfig } from "../types" ; import { archive_ext } from "./archive_ext" ; const isArchive = ( filepath ) => { return archive_ext . some ( ( ext ) => filepath . endsWith ( ext ) ) ; } ; const getOS = ( name ) => { if ( /windows/i . test ( name ) ) { return "windows" ; } if ( /linux/i . test ( name ) ) { return "linux" ; } if ( /(mac|darwin|apple)/i . test ( name ) ) { return "darwin" ; } return "unknown" ; } ; const getARCH = ( name ) => { if ( /amd64/ . test ( name ) ) { return "amd64" ; } if ( /x64/i . test ( name ) ) { return "amd64" ; } if ( /x86_64/ . test ( name ) ) { return "amd64" ; } if ( /x86/i . test ( name ) ) { return "386" ; } if ( /(arm64|aarch)/i . test ( name ) ) { return "arm64" ; } if ( /(386|686)/ . test ( name ) ) { return "386" ; } if ( /arm/ . test ( name ) ) { return "armv7" ; } return "unknown" ; } ; export const generateConfig = ( repo , assets ) : BinaConfig => { const config = { platforms : { } } ; for ( const asset of assets ) { const platform = `${ getOS ( asset . name ) }-${ getARCH ( asset . name ) }` ; if ( isArchive ( asset . name ) && ! config . platforms [ platform ] ) { config . platforms [ platform ] = { asset : asset . name , file : repo . name , } ; } } return config ; } ;