6
6
7
7
import 'reflect-metadata' ;
8
8
import * as crypto from 'node:crypto' ;
9
- import * as fs from 'node:fs' ;
10
- import * as path from 'node:path' ;
11
- import * as url from 'node:url' ;
12
9
import { program } from 'commander' ;
13
10
import serverModule from './inversify-module.js' ;
14
11
import { Container } from 'inversify' ;
15
12
import { initializeProtocol } from 'open-collaboration-protocol' ;
16
13
import { CollaborationServer } from './collaboration-server.js' ;
17
14
import { ConfigurationFile } from './utils/configuration.js' ;
15
+ import pck from '../package.json' with { type : 'json' } ;
18
16
19
17
initializeProtocol ( {
20
18
cryptoModule : crypto . webcrypto
21
19
} ) ;
22
20
23
- // This is a replacement for `__dirname`
24
- function getDirname ( ) : string {
25
- return url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
26
- }
27
-
28
- function getVersion ( ) : string {
29
- const ownPackagePath = path . resolve ( getDirname ( ) , '..' , 'package.json' ) ;
30
- const packString = fs . readFileSync ( ownPackagePath , { encoding : 'utf-8' } ) ;
31
- const pack = JSON . parse ( packString ) ;
32
- return pack . version ;
33
- }
34
-
35
21
function startServer ( options : { port : number , hostname : string , config : string } ) {
36
22
const container = new Container ( ) ;
37
23
container . bind ( ConfigurationFile ) . toConstantValue ( options . config ) ;
@@ -45,7 +31,7 @@ process.on('unhandledRejection', (reason, promise) => {
45
31
} ) ;
46
32
47
33
program
48
- . version ( getVersion ( ) )
34
+ . version ( pck . version )
49
35
. option ( '-p, --port <number>' , 'Port to listen on' , parseInt , 8100 )
50
36
. option ( '-h, --hostname <string>' , 'Hostname to bind to' , 'localhost' )
51
37
. option ( '-c, --config <string>' , 'Path to the configuration file' )
0 commit comments