@@ -2,79 +2,25 @@ import child_process from "node:child_process";
22import fs from "node:fs/promises" ;
33import util from "node:util" ;
44
5- async function main ( ) {
6- const dgDir = `${ process . cwd ( ) } /node_modules/@lido/dual-governance` ;
7- const gitmodulesPath = `${ dgDir } /.gitmodules` ;
8-
9- const gitmodulesExists = await checkFileExists ( gitmodulesPath ) ;
10- if ( ! gitmodulesExists ) {
11- console . log ( `.gitmodules file not found at ${ gitmodulesPath } ` ) ;
12- return ;
13- }
14-
15- console . log ( `.gitmodules file found at ${ gitmodulesPath } ` ) ;
16-
17- const gitmodulesFile = ( await fs . readFile ( gitmodulesPath ) ) . toString ( ) . replaceAll ( / \t / g, "" ) ;
5+ const DG_REPOSITORY_URL = "https://github.com/lidofinance/dual-governance.git" ;
6+ const DG_REPOSITORY_BRANCH = "feature/scratch-deploy-support" ; // TODO: use release branch
7+ const DG_INSTALL_DIR = `${ process . cwd ( ) } /dg` ;
188
19- const submodules = parseGitmodules ( gitmodulesFile ) ;
20- console . log ( submodules ) ;
21-
22- await fs . rm ( `${ dgDir } /lib` , { force : true , recursive : true } ) ;
9+ async function main ( ) {
10+ console . log ( "Delete DG folder" , DG_INSTALL_DIR ) ;
11+ await fs . rm ( DG_INSTALL_DIR , { force : true , recursive : true } ) ;
2312
24- await cloneSubmodules ( submodules ) ;
13+ console . log ( "Clone DG repo to" , DG_INSTALL_DIR ) ;
14+ await runCommand (
15+ `git clone --branch ${ DG_REPOSITORY_BRANCH } --single-branch ${ DG_REPOSITORY_URL } ${ DG_INSTALL_DIR } ` ,
16+ process . cwd ( ) ,
17+ ) ;
2518
2619 console . log ( "Building DualGovernance contracts" ) ;
27- await runForgeBuild ( dgDir ) ;
20+ await runForgeBuild ( DG_INSTALL_DIR ) ;
2821
2922 console . log ( "Running unit tests" ) ;
30- await runUnitTests ( dgDir ) ;
31- }
32-
33- type GitSubmodule = {
34- path : string ;
35- url : string ;
36- branch ?: string ;
37- } ;
38-
39- /**
40- * @param {String } gitmodulesFile .gitmodules file content
41- */
42- function parseGitmodules ( gitmodulesFile : string ) {
43- const submoduleSectionRe = / \[ s u b m o d u l e ( \s + ) ( ' | " ) ( .+ ) ( ' | " ) \] ( [ ^ \[ ] + ) / gm;
44- const submodulePropertyRe = / ( p a t h ) ( .+ ) | ( u r l ) ( .+ ) | ( b r a n c h ) ( .+ ) / g;
45- const submodulesList = [ ...gitmodulesFile . matchAll ( submoduleSectionRe ) ] ;
46- const result : Record < string , GitSubmodule > = { } ;
47-
48- if ( ! submodulesList . length ) {
49- return result ;
50- }
51-
52- submodulesList . forEach ( ( submoduleText ) => {
53- const item : GitSubmodule = {
54- path : "" ,
55- url : ""
56- } ;
57- const submodulePropertiesList = [ ...( submoduleText [ 5 ] || "" ) . matchAll ( submodulePropertyRe ) ] ;
58- submodulePropertiesList . forEach ( ( conf ) => {
59- const [ key = "" , value = "" ] = ( conf [ 0 ] ?? "" ) . split ( "=" ) ;
60- const pureKey = key . trim ( ) as "path" | "url" | "branch" ;
61- if ( pureKey ) {
62- item [ pureKey ] = value . trim ( ) ;
63- }
64- } ) ;
65- result [ item . path ] = item ;
66- } )
67- return result ;
68- }
69-
70- async function cloneSubmodules ( submodules : Record < string , GitSubmodule > ) {
71- for ( const key of Object . keys ( submodules ) ) {
72- let branch = submodules [ key ] . branch || "" ;
73- if ( branch . length && branch . indexOf ( "tag" ) != - 1 ) {
74- branch = branch . replace ( "tags/" , "" ) ;
75- }
76- await runCommand ( `git clone ${ branch . length ? `--branch ${ branch } ` : "" } --single-branch ${ submodules [ key ] . url } ${ process . cwd ( ) } /node_modules/@lido/dual-governance/${ submodules [ key ] . path } ` , process . cwd ( ) ) ;
77- }
23+ await runUnitTests ( DG_INSTALL_DIR ) ;
7824}
7925
8026async function runForgeBuild ( workingDirectory : string ) {
@@ -97,12 +43,6 @@ async function runCommand(command: string, workingDirectory: string) {
9743 }
9844}
9945
100- async function checkFileExists ( path : string ) {
101- return fs . access ( path )
102- . then ( ( ) => true )
103- . catch ( ( ) => false ) ;
104- }
105-
10646main ( )
10747 . then ( ( ) => process . exit ( 0 ) )
10848 . catch ( ( error ) => {
0 commit comments