@@ -7,81 +7,73 @@ const DIR = process.cwd();
7
7
/**
8
8
* Build SDK, and Functions
9
9
*/
10
- export default function setup ( testRunId : string , nodeVersion : string , firebaseAdmin : string ) {
10
+ export default function setup ( testRunId : string , firebaseAdmin : string ) {
11
11
buildSdk ( testRunId ) ;
12
- createPackageJson ( testRunId , nodeVersion , firebaseAdmin ) ;
12
+ createRequirementsTxt ( testRunId , firebaseAdmin ) ;
13
13
installDependencies ( ) ;
14
- buildFunctions ( ) ;
15
14
}
16
15
17
16
function buildSdk ( testRunId : string ) {
18
17
console . log ( "Building SDK..." ) ;
19
18
process . chdir ( path . join ( DIR , ".." ) ) ; // go up to root
20
19
21
- // remove existing firebase-functions-*.tgz files
22
- const files = fs . readdirSync ( "." ) ;
23
- files . forEach ( ( file ) => {
24
- if ( file . match ( / ^ f i r e b a s e - f u n c t i o n s - .* \. t g z $ / ) ) {
25
- fs . rmSync ( file ) ;
26
- }
27
- } ) ;
20
+ // remove existing build
21
+ fs . rmdirSync ( "dist" , { recursive : true } ) ;
22
+
28
23
// build the package
29
- execSync ( "npm run build:pack" , { stdio : "inherit" } ) ;
24
+ execSync ( "python -m pip install --upgrade build" , { stdio : "inherit" } ) ;
25
+ execSync ( "python -m build -s" , { stdio : "inherit" } ) ;
30
26
31
27
// move the generated tarball package to functions
32
28
const generatedFile = fs
33
- . readdirSync ( ". " )
34
- . find ( ( file ) => file . match ( / ^ f i r e b a s e - f u n c t i o n s - .* \. t g z $ / ) ) ;
29
+ . readdirSync ( "dist " )
30
+ . find ( ( file ) => file . match ( / ^ f i r e b a s e _ f u n c t i o n s - .* \. t a r \. g z $ / ) ) ;
35
31
36
32
if ( generatedFile ) {
37
33
const targetPath = path . join (
38
- "integration_test " ,
34
+ "integration_tests " ,
39
35
"functions" ,
40
- `firebase-functions- ${ testRunId } .tgz `
36
+ `firebase_functions_ ${ testRunId } .tar.gz `
41
37
) ;
42
- fs . renameSync ( generatedFile , targetPath ) ;
38
+ fs . renameSync ( path . join ( "dist" , generatedFile ) , targetPath ) ;
43
39
console . log ( "SDK moved to" , targetPath ) ;
44
40
}
45
41
46
42
process . chdir ( DIR ) ; // go back to integration_test
47
43
}
48
44
49
- function createPackageJson ( testRunId : string , nodeVersion : string , firebaseAdmin : string ) {
45
+ function createRequirementsTxt ( testRunId : string , firebaseAdmin : string ) {
50
46
console . log ( "Creating package.json..." ) ;
51
- const packageJsonTemplatePath = `${ DIR } /package.json .template` ;
52
- const packageJsonPath = `${ DIR } /functions/package.json ` ;
47
+ const requirementsTemplatePath = `${ DIR } /requirements.txt .template` ;
48
+ const requirementsPath = `${ DIR } /functions/requirements.txt ` ;
53
49
54
- fs . copyFileSync ( packageJsonTemplatePath , packageJsonPath ) ;
50
+ fs . copyFileSync ( requirementsTemplatePath , requirementsPath ) ;
55
51
56
- let packageJsonContent = fs . readFileSync ( packageJsonPath , "utf8" ) ;
57
- packageJsonContent = packageJsonContent . replace (
58
- / _ _ S D K _ T A R B A L L _ _ / g,
59
- `firebase-functions-${ testRunId } .tgz`
52
+ let requirementsContent = fs . readFileSync ( requirementsPath , "utf8" ) ;
53
+ requirementsContent = requirementsContent . replace (
54
+ / _ _ L O C A L _ F I R E B A S E _ F U N C T I O N S _ _ / g,
55
+ `firebase_functions_${ testRunId } .tar.gz`
56
+ ) ;
57
+ requirementsContent = requirementsContent . replace (
58
+ / _ _ F I R E B A S E _ A D M I N _ _ / g,
59
+ firebaseAdmin
60
60
) ;
61
- packageJsonContent = packageJsonContent . replace ( / _ _ N O D E _ V E R S I O N _ _ / g, nodeVersion ) ;
62
- packageJsonContent = packageJsonContent . replace ( / _ _ F I R E B A S E _ A D M I N _ _ / g, firebaseAdmin ) ;
63
61
64
- fs . writeFileSync ( packageJsonPath , packageJsonContent ) ;
62
+ fs . writeFileSync ( requirementsPath , requirementsContent ) ;
65
63
}
66
64
67
65
function installDependencies ( ) {
68
66
console . log ( "Installing dependencies..." ) ;
69
67
const functionsDir = "functions" ;
70
68
process . chdir ( functionsDir ) ; // go to functions
71
69
72
- const modulePath = path . join ( "node_modules" , "firebase-functions ") ;
73
- if ( fs . existsSync ( modulePath ) ) {
74
- execSync ( `rm -rf ${ modulePath } ` , { stdio : "inherit" } ) ;
70
+ const venvPath = path . join ( "venv " ) ;
71
+ if ( fs . existsSync ( venvPath ) ) {
72
+ execSync ( `rm -rf ${ venvPath } ` , { stdio : "inherit" } ) ;
75
73
}
76
74
77
- execSync ( "npm install" , { stdio : "inherit" } ) ;
75
+ execSync ( "python3 -m venv venv" , { stdio : "inherit" } ) ;
76
+ execSync ( "source venv/bin/activate" , { stdio : "inherit" } ) ;
77
+ execSync ( "python3 -m pip install -r requirements.txt" , { stdio : "inherit" } ) ;
78
78
process . chdir ( "../" ) ; // go back to integration_test
79
79
}
80
-
81
- function buildFunctions ( ) {
82
- console . log ( "Building functions..." ) ;
83
- process . chdir ( path . join ( DIR , "functions" ) ) ; // go to functions
84
-
85
- execSync ( "npm run build" , { stdio : "inherit" } ) ;
86
- process . chdir ( DIR ) ; // go back to integration_test
87
- }
0 commit comments