@@ -20,8 +20,8 @@ const argv = yargs(hideBin(process.argv))
20
20
// we need to update the toml file to have a feature on - default=['injective']
21
21
// editing and writing the toml file before building the contract for injective
22
22
function 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 ) ;
25
25
26
26
// add injective feature to the cargo.toml
27
27
// @ts -ignore
@@ -38,19 +38,11 @@ function injectivePreSetup(contractTomlFilePath: string) {
38
38
} ) ;
39
39
40
40
writeFileSync ( contractTomlFilePath , updatedToml ) ;
41
- }
42
41
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
+ } ;
54
46
}
55
47
56
48
function build ( ) {
@@ -61,22 +53,24 @@ function build() {
61
53
62
54
const contractTomlFilePath = "../contracts/pyth/Cargo.toml" ;
63
55
64
- if ( argv . injective === true ) injectivePreSetup ( contractTomlFilePath ) ;
56
+ let cleanup = ( ) => { } ;
57
+ if ( argv . injective === true )
58
+ cleanup = injectivePreSetup ( contractTomlFilePath ) ;
65
59
66
60
const buildCommand = `
67
61
docker run --rm -v "$(cd ..; pwd)":/code \
68
62
-v $(cd ../../../wormhole_attester; pwd):/wormhole_attester \
69
63
--mount type=volume,source="$(basename "$(cd ..; pwd)")_cache",target=/code/target \
70
64
--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
72
66
` ;
73
67
74
68
// build contract by running the command
75
69
exec ( buildCommand , ( _error , stdout , stderr ) => {
76
70
console . log ( stdout ) ;
77
71
console . log ( stderr ) ;
78
72
79
- if ( argv . injective === true ) injectivePostCleanup ( contractTomlFilePath ) ;
73
+ cleanup ( ) ;
80
74
} ) ;
81
75
}
82
76
0 commit comments