1
- const { execSync} = require ( "child_process" ) ;
1
+ const { execSync, spawnSync } = require ( "child_process" ) ;
2
2
const path = require ( "path" ) ;
3
3
const process = require ( "process" ) ;
4
4
const fs = require ( "fs" ) ;
@@ -40,7 +40,8 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
40
40
return ;
41
41
}
42
42
43
- const header = " Creating metadata for package browser... " ;
43
+ const header = " Creating metadata for package browser. This will take a while. " ;
44
+ console . log ( ) ;
44
45
console . log ( "=" . repeat ( header . length ) ) ;
45
46
console . log ( header ) ;
46
47
console . log ( "=" . repeat ( header . length ) ) ;
@@ -60,7 +61,7 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
60
61
this . __deleteFolderRecursiveSync ( targetDir ) ;
61
62
}
62
63
fs . mkdirSync ( targetDir ) ;
63
- console . log ( `>>> Starting compilation of all compatible packages. This might take a while .` ) ;
64
+ console . log ( `>>> Starting compilation of all compatible packages.. .` ) ;
64
65
let stdout = execSync ( `qx pkg list --uris-only` ) ;
65
66
let packages =
66
67
stdout
@@ -75,7 +76,7 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
75
76
`Creating container application...`
76
77
) ;
77
78
for ( let pkg of packages ) {
78
- this . __addCmd ( `cd ${ containerPath } && qx pkg install ${ pkg } ` , `Installing ${ pkg } ...` ) ;
79
+ this . __addCmd ( `qx pkg install ${ pkg } ` , `Installing ${ pkg } ...` , containerPath ) ;
79
80
}
80
81
await this . __executeCommands ( ) ;
81
82
const packages_dir = path . join ( containerPath , "qx_packages" ) ;
@@ -105,8 +106,9 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
105
106
}
106
107
// compile the application
107
108
this . __addCmd (
108
- `cd ${ pkg_dir } && qx pkg migrate && qx compile --target=${ targetType } --warnAsError=false --feedback=0 --force 2>&1` ,
109
+ `qx pkg migrate 2>&1 && qx compile --target=${ targetType } --warnAsError=false --feedback=0 --force 2>&1` ,
109
110
`Compiling ${ manifest . info . name } v${ manifest . info . version } ...` ,
111
+ pkg_dir ,
110
112
( stdout , stderr ) => {
111
113
let compilation_log = stdout + "\n\n" + stderr ;
112
114
packages_data [ index ] . data = {
@@ -121,17 +123,18 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
121
123
if (targetType === "build") {
122
124
this.__deleteFolderRecursiveSync(path.join(outputPath, "transpiled"));
123
125
}
124
- */
126
+ */
125
127
console . log ( `>>> Moving generated applications from ${ outputPath } to ${ appTgtPath } ` ) ;
126
128
fs . renameSync ( outputPath , appTgtPath ) ;
127
129
// inform client that we have one or more application demos
128
130
packages_data [ index ] . data . applications = compileData . applications ;
129
131
} ,
130
132
error => {
131
- console . error ( error . message ) ;
133
+ let compilation_log = error . message + "\n\n" + error . stderr . toString ( ) + "\n\n" + error . stdout . toString ( ) ;
134
+ console . error ( compilation_log ) ;
132
135
packages_data [ index ] . data = {
133
136
problems : true ,
134
- compilation_log : error . message + "\n\n" + error . stderr . toString ( ) + "\n\n" + error . stdout . toString ( )
137
+ compilation_log
135
138
} ;
136
139
}
137
140
) ;
@@ -158,29 +161,35 @@ qx.Class.define("qxl.packagebrowser.compile.LibraryApi", {
158
161
* Adds a command to the command queue
159
162
* @param {String } cmd The CLI command
160
163
* @param {String|undefined } info An explanatory text for the log, defaults to the CLI command
161
- * @param {Function } onSuccess
164
+ * @param {String|undefined } cwd
165
+ * If given, the working directory in which the commands will be executed
166
+ * @param {Function|undefined } onSuccess
162
167
* A function that is executed when the command has succesfully terminated.
163
168
* Receives the output of the command
164
- * @param {Function } onFail
169
+ * @param {Function|undefined } onFail
165
170
* A function that is executed when the command has finished with a non-zero
166
171
* exit code or an error has been thrown in the onSuccess function. Receives
167
172
* an error object.
168
173
* @private
169
174
*/
170
- __addCmd ( cmd , info , onSuccess , onFail ) {
175
+ __addCmd ( cmd , info , cwd , onSuccess , onFail ) {
171
176
this . __cmds = this . __cmds || [ ] ;
172
- this . __cmds . push ( [ cmd , info , onSuccess , onFail ] ) ;
177
+ this . __cmds . push ( [ cmd , info , cwd , onSuccess , onFail ] ) ;
173
178
} ,
174
179
175
180
/**
176
181
* Executes the commands in the queue.
177
182
* @private
178
183
*/
179
184
async __executeCommands ( ) {
180
- for ( let [ cmd , info , onSuccess , onFail ] of this . __cmds ) {
185
+ for ( let [ cmd , info , cwd , onSuccess , onFail ] of this . __cmds ) {
181
186
console . log ( ">>> " + ( info || `Executing '${ cmd } '` ) ) ;
187
+ const options = { } ;
188
+ if ( cwd ) {
189
+ options . cwd = cwd ;
190
+ }
182
191
try {
183
- let stdout = execSync ( cmd ) ;
192
+ let stdout = execSync ( cmd , options ) ;
184
193
stdout = stdout . toString ( ) . trim ( ) ;
185
194
if ( stdout ) {
186
195
console . log ( stdout ) ;
0 commit comments