@@ -20,8 +20,8 @@ const argv = yargs(hideBin(process.argv))
2020// we need to update the toml file to have a feature on - default=['injective']
2121// editing and writing the toml file before building the contract for injective
2222function injectivePreSetup ( contractTomlFilePath : string ) {
23- const tomlContentStr = readFileSync ( contractTomlFilePath , "utf-8" ) ;
24- const parsedToml = toml . parse ( tomlContentStr ) ;
23+ const originalTomlContentStr = readFileSync ( contractTomlFilePath , "utf-8" ) ;
24+ const parsedToml = toml . parse ( originalTomlContentStr ) ;
2525
2626 // add injective feature to the cargo.toml
2727 // @ts -ignore
@@ -38,19 +38,11 @@ function injectivePreSetup(contractTomlFilePath: string) {
3838 } ) ;
3939
4040 writeFileSync ( contractTomlFilePath , updatedToml ) ;
41- }
4241
43- // we are using `git restore` to restore the toml file to it's original content.
44- // we can also remove a feature from parsedToml and stringify it as above.
45- // But stringifying it gives us an output with different indentation
46- // and other such edits.
47- function injectivePostCleanup ( contractTomlFilePath : string ) {
48- exec ( `git restore ${ contractTomlFilePath } ` , ( error , _stdout , _stderr ) => {
49- if ( error !== null )
50- console . log (
51- "Error restoring cargo.toml file. Please restore it manually."
52- ) ;
53- } ) ;
42+ // after contract compilation we need to reset the original content of the toml file
43+ return function injectivePostCleanup ( ) {
44+ writeFileSync ( contractTomlFilePath , originalTomlContentStr ) ;
45+ } ;
5446}
5547
5648function build ( ) {
@@ -61,22 +53,24 @@ function build() {
6153
6254 const contractTomlFilePath = "../contracts/pyth/Cargo.toml" ;
6355
64- if ( argv . injective === true ) injectivePreSetup ( contractTomlFilePath ) ;
56+ let cleanup = ( ) => { } ;
57+ if ( argv . injective === true )
58+ cleanup = injectivePreSetup ( contractTomlFilePath ) ;
6559
6660 const buildCommand = `
6761 docker run --rm -v "$(cd ..; pwd)":/code \
6862 -v $(cd ../../../wormhole_attester; pwd):/wormhole_attester \
6963 --mount type=volume,source="$(basename "$(cd ..; pwd)")_cache",target=/code/target \
7064 --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
71- cosmwasm/workspace-optimizer-arm64 :0.12.11
65+ cosmwasm/workspace-optimizer:0.12.11
7266 ` ;
7367
7468 // build contract by running the command
7569 exec ( buildCommand , ( _error , stdout , stderr ) => {
7670 console . log ( stdout ) ;
7771 console . log ( stderr ) ;
7872
79- if ( argv . injective === true ) injectivePostCleanup ( contractTomlFilePath ) ;
73+ cleanup ( ) ;
8074 } ) ;
8175}
8276
0 commit comments