@@ -3,7 +3,8 @@ import * as child from 'child_process';
3
3
import * as jsonforms from '@jsonforms/core' ;
4
4
import { writeFile , readFile } from 'fs' ;
5
5
6
- export function cloneAndInstall ( repo : String , path : string ) {
6
+ / * *
7
+ export function cloneAndInstall ( repo : String , path : string , callback : ( result : string , type ?: string ) => void ) {
7
8
var url = '' ;
8
9
switch ( repo ) {
9
10
case 'example' :
@@ -14,32 +15,34 @@ export function cloneAndInstall(repo: String, path: string) {
14
15
break ;
15
16
}
16
17
const git = simplegit ( ) ;
17
- console . log ( 'Starting to clone repo' ) ;
18
+ callback ( 'Starting to clone repo' ) ;
18
19
git . clone ( url , path )
19
- . then ( function ( ) {
20
- console . log ( 'Finished to clone repo' ) ;
21
- console . log ( 'Running npm install' ) ;
22
- child . exec ( ' cd /${path} && npm install' , ( error , stdout , stderr ) => {
23
- if ( error ) {
24
- console . error ( `exec error: ${ error } ` ) ;
25
- return ;
26
- }
27
- console . log ( `stdout: ${ stdout } ` ) ;
28
- console . log ( `stderr: ${ stderr } ` ) ;
29
- } ) ;
30
- } )
31
- . catch ( ( err : any ) => console . error ( 'failed: ' , err ) ) ;
20
+ . then ( function ( ) {
21
+ callback ( 'Finished to clone repo' ) ;
22
+ callback ( 'Running npm install' ) ;
23
+ child . exec ( ` cd /${ path } | npm install` , ( error , stdout , stderr ) => {
24
+ if ( error ) {
25
+ callback ( `exec error: ${ error } ` , 'err' ) ;
26
+ return ;
27
+ }
28
+ callback ( `stdout: ${ stdout } ` ) ;
29
+ callback ( `stderr: ${ stderr } ` , 'err' ) ;
30
+ } ) ;
31
+ } )
32
+ . catch ( ( err : any ) => { callback ( err . message , ' err' ) } ) ;
32
33
}
33
34
34
- export function generateUISchema ( path : string ) {
35
+ / * *
36
+ export function generateUISchema ( path : string , callback : ( result : string , type ?: string ) => void ) {
35
37
readFile ( path , 'utf8' , ( err , data ) => {
36
- if ( err ) throw err ;
38
+ if ( err ) callback ( err . message , ' err' ) ;
37
39
var content = JSON . parse ( data ) ;
38
40
var jsonSchema = jsonforms . generateJsonSchema ( content ) ;
39
41
var jsonUISchema = jsonforms . generateDefaultUISchema ( jsonSchema ) ;
40
42
var newPath = removeLastPathElement ( path ) ;
41
43
writeFile ( newPath + '\\ui-schema.json' , JSON . stringify ( jsonUISchema , null , 2 ) , ( err ) => {
42
- if ( err ) throw err ;
44
+ if ( err ) callback ( err . message , 'err' ) ;
45
+ callback ( 'Successfully generated UI schema' ) ;
43
46
} ) ;
44
47
} ) ;
45
48
}
0 commit comments