@@ -3,44 +3,49 @@ const fileIn = process.argv[2];
3
3
const fileOut = process . argv [ 3 ] ;
4
4
5
5
if ( ! fileIn ) {
6
- console . error ( 'Invalid input' ) ;
6
+ console . error ( 'Invalid input' ) ;
7
7
}
8
8
9
9
fs . readFile ( fileIn , 'utf8' , ( err , data ) => {
10
- if ( err ) {
11
- console . error ( 'Error reading file:' , err ) ;
12
- return ;
10
+ if ( err ) {
11
+ console . error ( 'Error reading file:' , err ) ;
12
+ return ;
13
+ }
14
+
15
+ try {
16
+ const jsonData = JSON . parse ( data ) ;
17
+ if ( typeof jsonData . storageLayout == 'undefined' || jsonData . ast . absolutePath == 'undefined' ) {
18
+ return ;
13
19
}
14
20
15
- try {
16
- const jsonData = JSON . parse ( data ) ;
17
- if ( typeof jsonData . storageLayout == 'undefined' ) {
18
- return ;
19
- }
21
+ if ( jsonData . storageLayout . storage . length == 0 ) {
22
+ return ;
23
+ }
20
24
21
- if ( jsonData . storageLayout . storage . length == 0 ) {
22
- return ;
23
- }
25
+ // Skip generating storage layout for files locate in the directory "src"
26
+ if ( ! jsonData . ast . absolutePath . startsWith ( 'src' ) ) {
27
+ return ;
28
+ }
24
29
25
- const outputData = jsonData . storageLayout . storage
26
- . map ( ( { contract, label, offset, slot, type : typeId } ) => {
27
- const typeObj = jsonData . storageLayout . types [ typeId ] ;
28
- const typeLabel = typeObj . label ;
29
- const numberOfBytes = typeObj . numberOfBytes ;
30
- return `${ contract } :${ label } (storage_slot: ${ slot } ) (offset: ${ offset } ) (type: ${ typeLabel } ) (numberOfBytes: ${ numberOfBytes } )` ;
31
- } )
32
- . join ( '\n' ) ;
33
- if ( ! fileOut ) {
34
- console . log ( outputData ) ;
35
- } else {
36
- fs . writeFile ( fileOut , outputData , 'utf-8' , err => {
37
- if ( err ) {
38
- console . error ( 'Error writing file:' , err ) ;
39
- return ;
40
- }
41
- } ) ;
30
+ const outputData = jsonData . storageLayout . storage
31
+ . map ( ( { contract, label, offset, slot, type : typeId } ) => {
32
+ const typeObj = jsonData . storageLayout . types [ typeId ] ;
33
+ const typeLabel = typeObj . label ;
34
+ const numberOfBytes = typeObj . numberOfBytes ;
35
+ return `${ contract } :${ label } (storage_slot: ${ slot } ) (offset: ${ offset } ) (type: ${ typeLabel } ) (numberOfBytes: ${ numberOfBytes } )` ;
36
+ } )
37
+ . join ( '\n' ) ;
38
+ if ( ! fileOut ) {
39
+ console . log ( outputData ) ;
40
+ } else {
41
+ fs . writeFile ( fileOut , outputData , 'utf-8' , err => {
42
+ if ( err ) {
43
+ console . error ( 'Error writing file:' , err ) ;
44
+ return ;
42
45
}
43
- } catch ( err ) {
44
- console . error ( 'Error parsing JSON:' , err ) ;
46
+ } ) ;
45
47
}
48
+ } catch ( err ) {
49
+ console . error ( 'Error parsing JSON:' , err ) ;
50
+ }
46
51
} ) ;
0 commit comments