1
1
#!/usr/bin/env node
2
2
import { bootstrap } from 'global-agent' ;
3
3
4
- import { getParams } from './args' ;
5
- import commands from './commands' ;
4
+ import { getParams , ExportParams , ImportParams } from './args' ;
6
5
import log from './logger' ;
7
6
import tools from './tools' ;
7
+ import { Stage } from './tools/auth0'
8
8
9
- async function run ( params ) {
9
+ import importCMD from './commands/import'
10
+ import exportCMD from './commands/export'
11
+
12
+ async function run ( params : ImportParams | ExportParams ) : Promise < void > {
10
13
// Run command
11
- const cmd = commands [ params . _ [ 0 ] ] ;
14
+ const command = params . _ [ 0 ] ;
15
+
12
16
const proxy = params . proxy_url ;
13
17
14
18
if ( proxy ) {
@@ -23,9 +27,14 @@ async function run(params) {
23
27
bootstrap ( ) ;
24
28
}
25
29
26
- log . debug ( `Start command ${ params . _ [ 0 ] } ` ) ;
27
- await cmd ( params ) ;
28
- log . debug ( `Finished command ${ params . _ [ 0 ] } ` ) ;
30
+ log . debug ( `Start command ${ command } ` ) ;
31
+ if ( [ 'deploy' , 'import' ] . includes ( command ) && 'input_file' in params ) {
32
+ await importCMD ( params )
33
+ }
34
+ if ( [ 'dump' , 'export' ] . includes ( command ) && 'output_folder' in params ) {
35
+ await exportCMD ( params )
36
+ }
37
+ log . debug ( `Finished command ${ command } ` ) ;
29
38
}
30
39
31
40
// Only run if from command line
@@ -35,8 +44,6 @@ if (require.main === module) {
35
44
36
45
log . debug ( 'Starting Auth0 Deploy CLI Tool' ) ;
37
46
38
- // Set log level
39
- log . transports . console . level = params . level ;
40
47
if ( params . debug ) {
41
48
log . transports . console . level = 'debug' ;
42
49
// Set for tools
@@ -46,17 +53,23 @@ if (require.main === module) {
46
53
47
54
run ( params )
48
55
. then ( ( ) => process . exit ( 0 ) )
49
- . catch ( ( error ) => {
56
+ . catch ( ( error : {
57
+ type ?: string
58
+ stage ?: Stage
59
+ message ?: string
60
+ stack ?: string
61
+ } ) => {
62
+ const command = params . _ [ 0 ]
50
63
if ( error . type || error . stage ) {
51
- log . error ( `Problem running command ${ params . _ [ 0 ] } during stage ${ error . stage } when processing type ${ error . type } ` ) ;
64
+ log . error ( `Problem running command ${ command } during stage ${ error . stage } when processing type ${ error . type } ` ) ;
52
65
} else {
53
- log . error ( `Problem running command ${ params . _ [ 0 ] } ` ) ;
66
+ log . error ( `Problem running command ${ command } ` ) ;
54
67
}
55
68
56
69
const msg = error . message || error . toString ( ) ;
57
70
log . error ( msg ) ;
58
71
59
- if ( process . env . AUTH0_DEBUG === 'true' ) {
72
+ if ( process . env . AUTH0_DEBUG === 'true' && error . stack ) {
60
73
log . debug ( error . stack ) ;
61
74
}
62
75
@@ -69,9 +82,9 @@ if (require.main === module) {
69
82
70
83
// Export commands to be used programmatically
71
84
module . exports = {
72
- deploy : commands . import ,
73
- dump : commands . export ,
74
- import : commands . import ,
75
- export : commands . export ,
85
+ deploy : importCMD ,
86
+ dump : exportCMD ,
87
+ import : importCMD ,
88
+ export : exportCMD ,
76
89
tools : tools
77
90
} ;
0 commit comments