2022-12-29 21:50:56 -05:00
/ * *
2023-01-17 04:52:54 -05:00
* This script runs a task to check alteration files sequence :
* Newest files should come last .
2022-12-29 21:50:56 -05:00
* /
2022-12-29 22:08:09 -05:00
import { execSync } from "child_process" ;
2022-12-29 21:50:56 -05:00
const alterationFilePrefix = "packages/schemas/alterations/" ;
const allAlterations = execSync ( "pnpm cli db alter list" , {
encoding : "utf-8" ,
} )
. split ( "\n" )
. filter ( ( filename ) => Boolean ( filename ) )
. map ( ( filename ) => filename . replace ( ".js" , "" ) ) ;
2023-02-24 00:31:09 -05:00
const diffFiles = execSync ( "git diff HEAD~1 HEAD --name-only --diff-filter=ACR" , {
2022-12-29 21:50:56 -05:00
encoding : "utf-8" ,
} ) ;
const committedAlterations = diffFiles
. split ( "\n" )
2024-01-11 01:38:37 -05:00
. filter ( ( filename ) =>
filename . startsWith ( alterationFilePrefix ) &&
! filename . slice ( alterationFilePrefix . length ) . includes ( "/" )
)
2022-12-29 21:50:56 -05:00
. map ( ( filename ) =>
filename . replace ( alterationFilePrefix , "" ) . replace ( ".ts" , "" )
) ;
for ( const alteration of committedAlterations ) {
const index = allAlterations . indexOf ( alteration ) ;
if ( index < allAlterations . length - committedAlterations . length ) {
throw new Error (
2023-01-18 00:12:57 -05:00
` Wrong alteration sequence for committed file: ${ alteration } \n All timestamps of committed alteration files should be greater than the biggest one in the base branch. `
2022-12-29 21:50:56 -05:00
) ;
}
2024-01-11 01:38:37 -05:00
console . log ( ` ✅ ${ alteration } ` ) ;
2022-12-29 21:50:56 -05:00
}