You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-20 07:26:18 +00:00
Move to Renderer V2
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": [ "@nitrots/eslint-config" ]
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
# Only exists if Bazel was run
|
||||
/bazel-out
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# profiling files
|
||||
chrome-profiler-events*.json
|
||||
speed-measure-plugin*.json
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history/*
|
||||
|
||||
# misc
|
||||
/.sass-cache
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
testem.log
|
||||
/typings
|
||||
.git
|
||||
|
||||
# System Files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
*.zip
|
||||
*.as
|
||||
*.bin
|
||||
@@ -0,0 +1 @@
|
||||
export * from './src';
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@nitrots/configuration",
|
||||
"description": "Nitro configuration module",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"license": "GPL-3.0",
|
||||
"scripts": {
|
||||
"compile": "tsc --project ./tsconfig.json --noEmit false",
|
||||
"eslint": "eslint ./src --fix"
|
||||
},
|
||||
"main": "./index",
|
||||
"dependencies": {
|
||||
"@nitrots/api": "1.0.0",
|
||||
"@nitrots/eslint-config": "1.0.0",
|
||||
"@nitrots/utils": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.4.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import { NitroLogger, NitroVersion } from '@nitrots/utils';
|
||||
import { IConfigurationManager } from './IConfigurationManager';
|
||||
|
||||
export class ConfigurationManager implements IConfigurationManager
|
||||
{
|
||||
private _definitions: Map<string, unknown> = new Map();
|
||||
private _config: any = {};
|
||||
private _missingKeys: string[] = [];
|
||||
|
||||
constructor()
|
||||
{
|
||||
NitroVersion.sayHello();
|
||||
}
|
||||
|
||||
public async init(): Promise<void>
|
||||
{
|
||||
await this.reloadConfiguration();
|
||||
}
|
||||
|
||||
public async reloadConfiguration(): Promise<void>
|
||||
{
|
||||
try
|
||||
{
|
||||
this.resetConfiguration();
|
||||
this.parseConfiguration(this.getDefaultConfig(), true);
|
||||
|
||||
const configurationUrls = this.getValue<string[]>('config.urls').slice();
|
||||
|
||||
if(!configurationUrls || !configurationUrls.length) throw new Error('Invalid configuration urls');
|
||||
|
||||
for(const url of configurationUrls)
|
||||
{
|
||||
if(!url || !url.length) return;
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if(response.status !== 200) throw new Error('Invalid configuration file');
|
||||
|
||||
this.parseConfiguration(await response.json());
|
||||
}
|
||||
}
|
||||
|
||||
catch (err)
|
||||
{
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
|
||||
public resetConfiguration(): void
|
||||
{
|
||||
this._definitions.clear();
|
||||
this._config = {};
|
||||
this._missingKeys = [];
|
||||
}
|
||||
|
||||
public parseConfiguration(data: { [index: string]: any }, overrides: boolean = false): boolean
|
||||
{
|
||||
if(!data) return false;
|
||||
|
||||
try
|
||||
{
|
||||
const regex = new RegExp(/\${(.*?)}/g);
|
||||
|
||||
for(const key in data)
|
||||
{
|
||||
let value = data[key];
|
||||
|
||||
if(typeof value === 'string') value = this.interpolate((value as string), regex);
|
||||
|
||||
if(this._definitions.has(key))
|
||||
{
|
||||
if(overrides) this.setValue(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setValue(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (e)
|
||||
{
|
||||
NitroLogger.error(e.stack);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public interpolate(value: string, regex: RegExp = null): string
|
||||
{
|
||||
if(!regex) regex = new RegExp(/\${(.*?)}/g);
|
||||
|
||||
const pieces = value.match(regex);
|
||||
|
||||
if(pieces && pieces.length)
|
||||
{
|
||||
for(const piece of pieces)
|
||||
{
|
||||
const existing = (this._definitions.get(this.removeInterpolateKey(piece)) as string);
|
||||
|
||||
if(existing) (value = value.replace(piece, existing));
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private removeInterpolateKey(value: string): string
|
||||
{
|
||||
return value.replace('${', '').replace('}', '');
|
||||
}
|
||||
|
||||
public getValue<T>(key: string, value: T = null): T
|
||||
{
|
||||
let existing = this._definitions.get(key);
|
||||
|
||||
if(existing === undefined)
|
||||
{
|
||||
if(this._missingKeys.indexOf(key) >= 0) return value;
|
||||
|
||||
this._missingKeys.push(key);
|
||||
|
||||
NitroLogger.warn(`Missing configuration key: ${key}`);
|
||||
|
||||
existing = value;
|
||||
}
|
||||
|
||||
return (existing as T);
|
||||
}
|
||||
|
||||
public setValue<T>(key: string, value: T): void
|
||||
{
|
||||
const parts = key.split('.');
|
||||
|
||||
let last = this._config;
|
||||
|
||||
for(let i = 0; i < parts.length; i++)
|
||||
{
|
||||
const part = parts[i].toString();
|
||||
|
||||
if(i !== (parts.length - 1))
|
||||
{
|
||||
if(!last[part]) last[part] = {};
|
||||
|
||||
last = last[part];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
last[part] = value;
|
||||
}
|
||||
|
||||
this._definitions.set(key, value);
|
||||
}
|
||||
|
||||
public getDefaultConfig(): { [index: string]: any }
|
||||
{
|
||||
return window.NitroConfig;
|
||||
}
|
||||
|
||||
public get definitions(): Map<string, unknown>
|
||||
{
|
||||
return this._definitions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ConfigurationManager } from './ConfigurationManager';
|
||||
import { IConfigurationManager } from './IConfigurationManager';
|
||||
|
||||
const configuration = new ConfigurationManager();
|
||||
|
||||
export const GetConfiguration = (): IConfigurationManager => configuration;
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface IConfigurationManager
|
||||
{
|
||||
init(): Promise<void>;
|
||||
reloadConfiguration(): Promise<void>;
|
||||
resetConfiguration(): void;
|
||||
parseConfiguration(data: { [index: string]: any }, overrides?: boolean): boolean;
|
||||
interpolate(value: string, regex?: RegExp): string;
|
||||
getValue<T>(key: string, value?: T): T;
|
||||
setValue<T>(key: string, value: T): void;
|
||||
getDefaultConfig(): { [index: string]: any };
|
||||
readonly definitions: Map<string, unknown>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './ConfigurationManager';
|
||||
export * from './GetConfiguration';
|
||||
export * from './IConfigurationManager';
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./src",
|
||||
"outDir": "./dist",
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "Node",
|
||||
"esModuleInterop": true,
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"resolveJsonModule": true,
|
||||
"downlevelIteration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"strict": false,
|
||||
"strictNullChecks": false,
|
||||
"target": "ES6",
|
||||
"lib": [
|
||||
"DOM",
|
||||
"DOM.Iterable",
|
||||
"ESNext"
|
||||
],
|
||||
"module": "ES6"
|
||||
},
|
||||
"include": [
|
||||
"src" ]
|
||||
}
|
||||
Reference in New Issue
Block a user