import { ExecSyncOptions } from 'child_process' ; import * as fs from 'fs-extra' ; import { homedir } from 'os' ; import { join } from 'path' ; const userHome = homedir ( ) ; export const values = { myNameIs : 'yalc' , ignoreFileName : '.yalcignore' , myNameIsCapitalized : 'Yalc' , lockfileName : 'yalc.lock' , yalcPackagesFolder : '.yalc' , prescript : 'preyalc' , postscript : 'postyalc' , installationsFile : 'installations.json' , } ; export interface UpdatePackagesOptions { safe ? : boolean ; workingDir : string ; } export { publishPackage } from './publish' ; export { updatePackages } from './update' ; export { checkManifest } from './check' ; export { removePackages } from './remove' ; export { addPackages } from './add' ; export * from './pkg' ; export * from './pm' ; export interface YalcGlobal { yalcStoreMainDir : string ; } export const yalcGlobal = global as any ; export function getStoreMainDir ( ) { if ( yalcGlobal . yalcStoreMainDir ) { return yalcGlobal . yalcStoreMainDir ; } if ( process . platform === 'win32' && process . env . LOCALAPPDATA ) { return join ( process . env . LOCALAPPDATA , values . myNameIsCapitalized ) ; } return join ( userHome , '.' + values . myNameIs ) ; } export function getStorePackagesDir ( ) { return join ( getStoreMainDir ( ) , 'packages' ) ; } export const getPackageStoreDir = ( packageName , version = '' ) => join ( getStorePackagesDir ( ) , packageName , version ) ; export const execLoudOptions = { stdio : 'inherit' } as ExecSyncOptions ; const signatureFileName = 'yalc.sig' ; export const readSignatureFile = ( workingDir ) => { const signatureFilePath = join ( workingDir , signatureFileName ) ; try { const fileData = fs . readFileSync ( signatureFilePath , 'utf-8' ) ; return fileData ; } catch ( e ) { return '' ; } } ; export const readIgnoreFile = ( workingDir ) => { const filePath = join ( workingDir , values . ignoreFileName ) ; try { const fileData = fs . readFileSync ( filePath , 'utf-8' ) ; return fileData ; } catch ( e ) { return '' ; } } ; export const writeSignatureFile = ( workingDir , signature ) => { const signatureFilePath = join ( workingDir , signatureFileName ) ; try { fs . writeFileSync ( signatureFilePath , signature ) ; } catch ( e ) { console . error ( 'Could not write signature file' ) ; throw e ; } } ;