@@ -20,7 +20,8 @@ interpreter.addFunction('showAsserts', () => {
20
20
console . table ( context . asserts ) ;
21
21
} ) ;
22
22
interpreter . addFunction ( 'params' , ( name : string ) => {
23
- return context . params [ name ] ;
23
+ const value = context . params [ name ] ;
24
+ return value === undefined ? null : value ;
24
25
} ) ;
25
26
26
27
run ( ) ;
@@ -48,9 +49,12 @@ async function run() {
48
49
interpreter . registerPackagesLoader ( packageLoader as PackageLoader ) ;
49
50
const scripts = fs . readFileSync ( options . file , 'utf8' ) ;
50
51
context . asserts . length = 0 ;
51
- const res = await interpreter . evaluate ( scripts ) ;
52
- console . log ( 'Execution result:\n' , res ) ;
53
- console . log ( 'Finish' ) ;
52
+ console . log ( "JSPython (c) FalconSoft Ltd" )
53
+ console . log ( `${ options . file } ` )
54
+ const res = await interpreter . evaluate ( scripts , undefined , undefined , options . file ) ;
55
+ if ( res !== null ) {
56
+ console . log ( res ) ;
57
+ }
54
58
}
55
59
}
56
60
@@ -90,15 +94,20 @@ function getOptionsFromArguments(rawArgs: string[]) {
90
94
91
95
/**@type {PackageLoader } */
92
96
function packageLoader ( packageName : string ) : any {
93
- if ( [ 'fs' , 'path' , 'readline' , 'timers' , 'child_process' , 'util' , 'zlib' , 'stream' , 'net' , 'https' , 'http' , 'events' , 'os' , 'buffer' ]
94
- . includes ( packageName ) ) {
95
- return require ( packageName )
96
- }
97
-
98
97
try {
98
+ if ( [ 'fs' , 'path' , 'readline' , 'timers' , 'child_process' , 'util' , 'zlib' , 'stream' , 'net' , 'https' , 'http' , 'events' , 'os' , 'buffer' ]
99
+ . includes ( packageName ) ) {
100
+ return require ( packageName )
101
+ }
102
+
103
+ if ( packageName . toLowerCase ( ) . endsWith ( '.js' ) || packageName . toLowerCase ( ) . endsWith ( '.json' ) ) {
104
+ return require ( `${ process . cwd ( ) . split ( '\\' ) . join ( '/' ) } /${ packageName } ` )
105
+ }
106
+
99
107
return require ( `${ process . cwd ( ) . split ( '\\' ) . join ( '/' ) } /node_modules/${ packageName } ` ) ;
100
108
}
101
109
catch ( err ) {
102
110
console . log ( 'Import Error: ' , err ) ;
111
+ throw err ;
103
112
}
104
113
}
0 commit comments