1
1
import { execSync } from 'child_process' ;
2
- import { cpSync } from 'fs' ;
3
- import fs from 'fs/promises' ;
4
- import path , { join , dirname } from 'path' ;
2
+ import { cpSync , mkdirSync , rmSync , readFileSync , writeFileSync } from 'fs' ;
3
+ import { join , dirname } from 'path' ;
5
4
import { fileURLToPath } from 'url' ;
6
5
7
6
// eslint-disable-next-line @typescript-eslint/naming-convention
8
7
export const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
9
8
9
+ export const binPath = join ( __dirname , '../forc-binaries/forc' ) ;
10
+
10
11
const platforms = {
11
12
darwin : {
12
13
arm64 : 'darwin_arm64' ,
@@ -18,10 +19,6 @@ const platforms = {
18
19
} ,
19
20
} ;
20
21
21
- const binPath = join ( __dirname , '../forc-binaries/forc' ) ;
22
-
23
- export default binPath ;
24
-
25
22
export const getPkgPlatform = ( ) => {
26
23
if ( process . platform !== 'darwin' && process . platform !== 'linux' ) {
27
24
throw new Error (
@@ -36,28 +33,28 @@ export const getPkgPlatform = () => {
36
33
return platforms [ process . platform ] [ process . arch ] ;
37
34
} ;
38
35
39
- const versionFilePath = path . join ( __dirname , '../VERSION' ) ;
36
+ const versionFilePath = join ( __dirname , '../VERSION' ) ;
40
37
41
- export const getCurrentVersion = async ( ) => {
42
- const versionContents = await fs . readFile ( versionFilePath , 'utf8' ) ;
38
+ export const getCurrentVersion = ( ) => {
39
+ const versionContents = readFileSync ( versionFilePath , 'utf8' ) ;
43
40
const forcVersion = versionContents . match ( / ^ .+ $ / m) ?. [ 0 ] || versionContents ;
44
41
return forcVersion ;
45
42
} ;
46
43
47
- export const setCurrentVersion = async ( version ) => {
48
- await fs . writeFile ( versionFilePath , version ) ;
44
+ export const setCurrentVersion = ( version ) => {
45
+ writeFileSync ( versionFilePath , version ) ;
49
46
} ;
50
47
51
48
export const isGitBranch = ( versionFileContents ) => versionFileContents . indexOf ( 'git:' ) !== - 1 ;
52
49
53
50
const swayRepoUrl = 'https://github.com/fuellabs/sway.git' ;
54
51
55
52
export const buildFromGitBranch = ( branchName ) => {
56
- fs . rmSync ( 'sway-repo' , { recursive : true , force : true } ) ;
57
- fs . rmSync ( 'forc-binaries' , { recursive : true , force : true } ) ;
53
+ rmSync ( 'sway-repo' , { recursive : true , force : true } ) ;
54
+ rmSync ( 'forc-binaries' , { recursive : true , force : true } ) ;
58
55
execSync ( `git clone --branch ${ branchName } ${ swayRepoUrl } sway-repo` ) ;
59
56
execSync ( `cd sway-repo && cargo build` ) ;
60
- fs . mkdirSync ( 'forc-binaries' ) ;
57
+ mkdirSync ( 'forc-binaries' ) ;
61
58
cpSync ( 'sway-repo/target/debug/forc' , 'forc-binaries' ) ;
62
59
cpSync ( 'sway-repo/target/debug/forc-deploy' , 'forc-binaries' ) ;
63
60
cpSync ( 'sway-repo/target/debug/forc-doc' , 'forc-binaries' ) ;
@@ -66,5 +63,5 @@ export const buildFromGitBranch = (branchName) => {
66
63
cpSync ( 'sway-repo/target/debug/forc-run' , 'forc-binaries' ) ;
67
64
cpSync ( 'sway-repo/target/debug/forc-submit' , 'forc-binaries' ) ;
68
65
cpSync ( 'sway-repo/target/debug/forc-tx' , 'forc-binaries' ) ;
69
- fs . rmSync ( 'sway-repo' , { recursive : true , force : true } ) ;
66
+ rmSync ( 'sway-repo' , { recursive : true , force : true } ) ;
70
67
} ;
0 commit comments