import path from 'path' ; import fs from 'fs' ; import { execSync } from 'child_process' ; import { Dictionary } from './types' ; export const isValidProjectName = ( projectName ) : boolean => /^[$A-Z_][0-9A-Z_$]*$/i . test ( projectName ) && projectName . toLowerCase ( ) !== 'react' ; export const yarnExists = ( ) : boolean => { try { execSync ( 'yarn --version' , { stdio : 'ignore' } ) ; return true ; } catch { return false ; } } ; export const sortKeys = ( obj ) : Dictionary => Object . keys ( obj ) . sort ( ( a , b ) => a . localeCompare ( b ) ) . reduce ( ( res , key ) => ( { ... res , [ key ] : obj [ key ] } ) , { } ) ; export const getVersion = ( ) : string => JSON . parse ( fs . readFileSync ( path . resolve ( __dirname , '..' , 'package.json' ) , { encoding : 'utf8' , } ) ) . version ;