-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move runtime config into dedicated component, Closes #67
* Move runtime config into dedicated component, Closes #67 * Migrate FileResourceStore to RuntimeConfig
- Loading branch information
1 parent
4f8ebff
commit 5126356
Showing
14 changed files
with
194 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* This class holds all configuration options that can be defined by the user via the command line. | ||
* | ||
* Concretely, this contains data that is only relevant *after* dependency injection. | ||
*/ | ||
export class RuntimeConfig implements RuntimeConfigData { | ||
private pport!: number; | ||
private pbase!: string; | ||
private prootFilepath!: string; | ||
|
||
public constructor(data: RuntimeConfigData = {}) { | ||
this.reset(data); | ||
} | ||
|
||
public reset(data: RuntimeConfigData): void { | ||
this.pport = data.port ?? 3000; | ||
this.pbase = data.base ?? `http://localhost:${this.port}/`; | ||
this.prootFilepath = data.rootFilepath ?? process.cwd(); | ||
} | ||
|
||
public get base(): string { | ||
return this.pbase; | ||
} | ||
|
||
public get port(): number { | ||
return this.pport; | ||
} | ||
|
||
public get rootFilepath(): string { | ||
return this.prootFilepath; | ||
} | ||
} | ||
|
||
export interface RuntimeConfigData { | ||
port?: number; | ||
base?: string; | ||
rootFilepath?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig'; | ||
|
||
describe('RuntimeConfig', (): void => { | ||
it('handles undefined args.', async(): Promise<void> => { | ||
const config = new RuntimeConfig(); | ||
expect(config.port).toEqual(3000); | ||
expect(config.base).toEqual('http://localhost:3000/'); | ||
}); | ||
|
||
it('handles empty args.', async(): Promise<void> => { | ||
const config = new RuntimeConfig({}); | ||
expect(config.port).toEqual(3000); | ||
expect(config.base).toEqual('http://localhost:3000/'); | ||
}); | ||
|
||
it('handles args with port.', async(): Promise<void> => { | ||
const config = new RuntimeConfig({ port: 1234 }); | ||
expect(config.port).toEqual(1234); | ||
expect(config.base).toEqual('http://localhost:1234/'); | ||
}); | ||
|
||
it('handles args with base.', async(): Promise<void> => { | ||
const config = new RuntimeConfig({ base: 'http://example.org/' }); | ||
expect(config.port).toEqual(3000); | ||
expect(config.base).toEqual('http://example.org/'); | ||
}); | ||
|
||
it('handles args with port and base.', async(): Promise<void> => { | ||
const config = new RuntimeConfig({ port: 1234, base: 'http://example.org/' }); | ||
expect(config.port).toEqual(1234); | ||
expect(config.base).toEqual('http://example.org/'); | ||
}); | ||
|
||
it('handles resetting data.', async(): Promise<void> => { | ||
const config = new RuntimeConfig({}); | ||
expect(config.port).toEqual(3000); | ||
expect(config.base).toEqual('http://localhost:3000/'); | ||
|
||
config.reset({ port: 1234, base: 'http://example.org/' }); | ||
expect(config.port).toEqual(1234); | ||
expect(config.base).toEqual('http://example.org/'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.