mirror of
https://github.com/morten-olsen/mini-loader.git
synced 2026-02-08 01:36:26 +01:00
qa: add e2e tests
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import envPaths from 'env-paths';
|
||||
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
||||
import { mkdir } from 'fs/promises';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
import { join, dirname } from 'path';
|
||||
import { ContainerInstance, Service } from 'typedi';
|
||||
import { Paths } from '../paths/paths.js';
|
||||
|
||||
type ConfigValues = {
|
||||
context?: string;
|
||||
};
|
||||
|
||||
const paths = envPaths('mini-loader');
|
||||
|
||||
@Service()
|
||||
class Config {
|
||||
#paths: Paths;
|
||||
#location: string;
|
||||
#config?: ConfigValues;
|
||||
|
||||
constructor() {
|
||||
this.#location = join(paths.config, 'config.json');
|
||||
constructor(contianer: ContainerInstance) {
|
||||
this.#paths = contianer.get(Paths);
|
||||
this.#location = join(this.#paths.config, 'config.json');
|
||||
if (existsSync(this.#location)) {
|
||||
this.#config = JSON.parse(readFileSync(this.#location, 'utf-8'));
|
||||
}
|
||||
@@ -24,8 +26,12 @@ class Config {
|
||||
return this.#config?.context || 'default';
|
||||
}
|
||||
|
||||
public get location() {
|
||||
return this.#paths.config;
|
||||
}
|
||||
|
||||
public get cacheLocation() {
|
||||
return join(paths.cache, this.context);
|
||||
return join(this.#paths.cache, this.context);
|
||||
}
|
||||
|
||||
public setContext = (context: string) => {
|
||||
@@ -42,7 +48,7 @@ class Config {
|
||||
}
|
||||
const json = JSON.stringify(this.#config);
|
||||
mkdir(dirname(this.#location), { recursive: true });
|
||||
writeFileSync(this.#location, json);
|
||||
writeFile(this.#location, json);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user