import path from 'path' ; import fs from 'fs' ; import Debug from 'debug' ; import { HYPERMERGE_PATH , HYPERFILE_PATH } from '../renderer/constants' ; const log = Debug ( 'HyperfileMigration' ) ; migrateHyperfileData ( ) ; function migrateHyperfileData ( ) { try { const destinationDir = HYPERMERGE_PATH ; const sourceDir = HYPERFILE_PATH ; const migratedSourceDir = `${ sourceDir }_premigration_ledger` ; fs . mkdirSync ( migratedSourceDir ) ; const filenames = fs . readdirSync ( sourceDir ) ; filenames . forEach ( ( filename ) => { const source = path . join ( sourceDir , filename ) ; let destination ; if ( filename === 'ledger' ) { destination = path . join ( migratedSourceDir , filename ) ; } else { destination = path . join ( destinationDir , filename ) ; } fs . renameSync ( source , destination ) ; } ) ; fs . rmdirSync ( sourceDir ) ; log ( 'Hyperfile data migrated' ) ; } catch ( _err ) { log ( `Hyperfile data not migrated. Reason: \n${ _err }` ) ; } }