@@ -14,51 +14,37 @@ module.exports = function (FirebaseService, ExpressGenerator, Config, Q) {
14
14
//Fetch the project from firebase
15
15
var project_promise = FirebaseService . retrieveProject ( project_id ) ;
16
16
return result = project_promise . then ( function ( project ) {
17
- var functions = project . artifacts . Functions ;
18
- // read GitHub credential from Config file in Config directory
19
- var deploymentInfo = {
20
- repoName : Config . github [ "repoName" ] ,
21
- token : Config . github [ "token" ] ,
22
- firstName : Config . github [ "firstName" ] ,
23
- lastName : Config . github [ "lastName" ] ,
24
- email : Config . github [ "email" ] ,
25
- userId : Config . github [ "username" ] ,
26
-
27
- } ;
28
- //if in the client request deployment info are inserted, it overwrite the deployment info, otherwise it reads data from the Config file
29
- if ( project . deploymentInfo && project . deploymentInfo !== 'undefined' && project . deploymentInfo . gitUserId !== "" && project . deploymentInfo . gitToken !== "" && project . deploymentInfo . gitRepoName !== "" &&
30
- project . deploymentInfo . firstName !== "" && project . deploymentInfo . lastName !== "" && project . deploymentInfo . gitEmail !== "" ) {
31
- console . log ( "it used the client request github credential" ) ;
32
- for ( var credential in project . deploymentInfo ) {
33
- deploymentInfo . userId = project . deploymentInfo [ credential ] . gitUserName ;
34
- deploymentInfo . token = project . deploymentInfo [ credential ] . gitToken ;
35
- deploymentInfo . firstName = project . deploymentInfo [ credential ] . gitUserFirstName ;
36
- deploymentInfo . lastName = project . deploymentInfo [ credential ] . gitUserLastName ;
37
- deploymentInfo . email = project . deploymentInfo [ credential ] . gitEmail ;
38
- deploymentInfo . repoName = project . deploymentInfo [ credential ] . gitRepoName ;
17
+ if ( project != null ) {
18
+ var functions = project . artifacts . Functions ;
19
+ // read GitHub credential from Config file in Config directory
20
+ var deploymentInfo = {
21
+ repoName : Config . github [ "repoName" ] ,
22
+ token : Config . github [ "token" ] ,
23
+ firstName : Config . github [ "firstName" ] ,
24
+ lastName : Config . github [ "lastName" ] ,
25
+ email : Config . github [ "email" ] ,
26
+ userId : Config . github [ "username" ] ,
27
+
28
+ } ;
29
+ //if in the client request deployment info are inserted, it overwrite the deployment info, otherwise it reads data from the Config file
30
+ if ( project . deploymentInfo && project . deploymentInfo !== 'undefined' && project . deploymentInfo . gitUserId !== "" && project . deploymentInfo . gitToken !== "" && project . deploymentInfo . gitRepoName !== "" &&
31
+ project . deploymentInfo . firstName !== "" && project . deploymentInfo . lastName !== "" && project . deploymentInfo . gitEmail !== "" ) {
32
+ console . log ( "it used the client request github credential" ) ;
33
+ for ( var credential in project . deploymentInfo ) {
34
+ deploymentInfo . userId = project . deploymentInfo [ credential ] . gitUserName ;
35
+ deploymentInfo . token = project . deploymentInfo [ credential ] . gitToken ;
36
+ deploymentInfo . firstName = project . deploymentInfo [ credential ] . gitUserFirstName ;
37
+ deploymentInfo . lastName = project . deploymentInfo [ credential ] . gitUserLastName ;
38
+ deploymentInfo . email = project . deploymentInfo [ credential ] . gitEmail ;
39
+ deploymentInfo . repoName = project . deploymentInfo [ credential ] . gitRepoName ;
40
+ }
39
41
}
40
- }
41
- var isComplete = false ;
42
-
43
- //Check if all the end points are complete
44
- for ( var func in functions ) {
45
- if ( functions [ func ] . isApiArtifact ) {
46
- isComplete = functions [ func ] . isComplete ;
47
- }
48
- }
49
- //if end points are complete, create a template express app
50
- if ( isComplete ) {
51
- //if the template is created, add the code and routing
52
- // if (ExpressGenerator.createEndPints(project_id, path, port)) {
53
-
54
42
ExpressGenerator . createDir ( rootPath + '/' + project_id ) ;
55
43
//return new Promise(function (resolve, reject) {
56
- var resultTmp = initGit ( project_id , rootPath + '/' + project_id , deploymentInfo , functions ) ;
44
+ var resultTmp = initGit ( project_id , rootPath + '/' + project_id , deploymentInfo , functions ) ;
57
45
58
- // });
59
46
return true ;
60
- }
61
- else {
47
+ } else {
62
48
return false ;
63
49
}
64
50
}
@@ -69,6 +55,7 @@ module.exports = function (FirebaseService, ExpressGenerator, Config, Q) {
69
55
70
56
71
57
}
58
+
72
59
// it pull the code from repo then add 2 files to the repo and push it back
73
60
function initGit ( project_id , projectPath , deploymentInfo , functions ) {
74
61
// return new Promise(function (resolve, reject) {
@@ -97,13 +84,13 @@ module.exports = function (FirebaseService, ExpressGenerator, Config, Q) {
97
84
Git . init ( )
98
85
. then ( function ( res ) {
99
86
console . log ( "user name set" ) ;
100
- return Git . direct ( 'config user.name "' + deploymentInfo . firstName + ' ' + deploymentInfo . firstName + '"' ) ; //Set user name for the repo commits
87
+ return Git . direct ( 'config user.name "' + deploymentInfo . firstName + ' ' + deploymentInfo . firstName + '"' ) ; //Set user name for the repo commits
101
88
102
89
} ) . then ( function ( res ) {
103
90
console . log ( res ) ;
104
91
console . log ( "mail set" ) ;
105
92
return Git . direct ( 'config user.email "' + deploymentInfo . email + '"' ) ; //Set user email for repo commits
106
- } ) . then ( function ( res ) {
93
+ } ) . then ( function ( res ) {
107
94
// console.log("user name set");
108
95
109
96
return Git . pull ( 'https://' + deploymentInfo . token + '@github.com/' + deploymentInfo . userId + '/' + deploymentInfo . repoName + '.git/ master --allow-unrelated-histories' ) ; //Create a remote named origin
@@ -148,26 +135,26 @@ module.exports = function (FirebaseService, ExpressGenerator, Config, Q) {
148
135
}
149
136
150
137
151
- function buildMicroserviceFiles ( project_id , functions ) {
138
+ function buildMicroserviceFiles ( project_id , functions ) {
152
139
var code = '' ;
153
140
var routes = '' ;
154
141
var exports = 'module.exports = {' ;
155
142
156
143
//create a single object with code from all complete functions
157
144
for ( var func in functions ) {
158
- if ( functions [ func ] . isComplete ) {
159
- code += "\n\n\n" + functions [ func ] . header + '\n' + functions [ func ] . code ;
160
- exports += "\n" + functions [ func ] . name + ":" + functions [ func ] . name + "," ;
161
- }
145
+ // if (functions[func].isComplete) {
146
+ code += "\n\n\n" + functions [ func ] . header + '\n' + functions [ func ] . code ;
147
+ exports += "\n" + functions [ func ] . name + ":" + functions [ func ] . name + "," ;
148
+ // }
162
149
}
163
150
exports = exports . substr ( 0 , exports . length - 1 ) + " }" ;
164
151
//Create the file with all the functions in the project
165
- ExpressGenerator . createServiceFile ( project_id , rootPath , code + "\n" + exports + "\n" + "//" + new Date ( ) ) ;
152
+ ExpressGenerator . createServiceFile ( project_id , rootPath , code + "\n" + exports + "\n" + "//" + new Date ( ) ) ;
166
153
167
154
//create both get and post handlers for each end point
168
155
169
156
for ( var func in functions ) {
170
- if ( functions [ func ] . isApiArtifact && functions [ func ] . isComplete ) {
157
+ if ( functions [ func ] . isApiArtifact /* && functions[func].isComplete*/ ) {
171
158
var get_parameters = '' ;
172
159
var post_parameters = '' ;
173
160
//Generate all parameters to be passed
0 commit comments