1
- #!/usr/bin/env ts-node
1
+ #!/usr/bin/env tsx
2
2
3
- import fs from 'fs' ;
4
- import path from 'path' ;
3
+ import fs from 'node:fs' ;
4
+ import path from 'node:path' ;
5
+ import url from 'node:url' ;
5
6
import si from 'systeminformation' ;
6
- import loggerText from './logger_text' ;
7
- import loggerStructured from './logger_structured' ;
8
- import loggerHierarchy from './logger_hierarchy' ;
9
- import loggerFiltered from './logger_filtered' ;
10
- import loggerHandlers from './logger_handlers' ;
7
+ import { benchesPath } from './utils/utils.js' ;
8
+ import loggerText from './logger_text.js' ;
9
+ import loggerStructured from './logger_structured.js' ;
10
+ import loggerHierarchy from './logger_hierarchy.js' ;
11
+ import loggerFiltered from './logger_filtered.js' ;
12
+ import loggerHandlers from './logger_handlers.js' ;
11
13
12
14
async function main ( ) : Promise < void > {
13
- await fs . promises . mkdir ( path . join ( __dirname , 'results' ) , { recursive : true } ) ;
15
+ await fs . promises . mkdir ( path . join ( benchesPath , 'results' ) , {
16
+ recursive : true ,
17
+ } ) ;
14
18
await loggerText ( ) ;
15
19
await loggerStructured ( ) ;
16
20
await loggerHierarchy ( ) ;
17
21
await loggerFiltered ( ) ;
18
22
await loggerHandlers ( ) ;
19
23
const resultFilenames = await fs . promises . readdir (
20
- path . join ( __dirname , 'results' ) ,
24
+ path . join ( benchesPath , 'results' ) ,
21
25
) ;
22
26
const metricsFile = await fs . promises . open (
23
- path . join ( __dirname , 'results' , 'metrics.txt' ) ,
27
+ path . join ( benchesPath , 'results' , 'metrics.txt' ) ,
24
28
'w' ,
25
29
) ;
26
30
let concatenating = false ;
27
31
for ( const resultFilename of resultFilenames ) {
28
32
if ( / .+ _ m e t r i c s \. t x t $ / . test ( resultFilename ) ) {
29
33
const metricsData = await fs . promises . readFile (
30
- path . join ( __dirname , 'results' , resultFilename ) ,
34
+ path . join ( benchesPath , 'results' , resultFilename ) ,
31
35
) ;
32
36
if ( concatenating ) {
33
37
await metricsFile . write ( '\n' ) ;
@@ -43,9 +47,16 @@ async function main(): Promise<void> {
43
47
system : 'model, manufacturer' ,
44
48
} ) ;
45
49
await fs . promises . writeFile (
46
- path . join ( __dirname , 'results' , 'system.json' ) ,
50
+ path . join ( benchesPath , 'results' , 'system.json' ) ,
47
51
JSON . stringify ( systemData , null , 2 ) ,
48
52
) ;
49
53
}
50
54
51
- void main ( ) ;
55
+ if ( import . meta. url . startsWith ( 'file:' ) ) {
56
+ const modulePath = url . fileURLToPath ( import . meta. url ) ;
57
+ if ( process . argv [ 1 ] === modulePath ) {
58
+ void main ( ) ;
59
+ }
60
+ }
61
+
62
+ export default main ;
0 commit comments