-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anton Nefjodov
committed
Dec 18, 2022
1 parent
202ba58
commit cbac3a3
Showing
14 changed files
with
149 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
CONFIG=../../../../../dev.json | ||
CONFIG=dev.json |
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
import {build} from "esbuild"; | ||
import {transformSync} from "esbuild"; | ||
import NodeModulesPolyfills from '@esbuild-plugins/node-modules-polyfill'; | ||
import GlobalsPolyfills from '@esbuild-plugins/node-globals-polyfill'; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
|
||
class Build | ||
{ | ||
private readonly distName = "../dist_client"; | ||
private readonly distPath = path.resolve(__dirname, this.distName); | ||
|
||
public constructor() | ||
{ | ||
fs.rmSync(this.distPath, {recursive: true, force: true}); | ||
fs.mkdirSync(this.distPath); | ||
|
||
this.copy("./test.html", "/test.html"); | ||
this.copy("../dev.json", "/dev.json"); | ||
|
||
transformSync("isBrowser", {define: {isBrowser: "true"}}); | ||
build({ | ||
plugins: [NodeModulesPolyfills(), GlobalsPolyfills({process: true, buffer: true})], | ||
entryPoints: [ | ||
'./test/index.ts', | ||
], | ||
outfile: "./dist_client" + "/test.js", | ||
bundle: true, | ||
loader: {".ts": "ts"}, | ||
define: { | ||
"global": 'window' | ||
} | ||
} | ||
).then(() => console.log("⚡ Done")).catch(() => process.exit(1)); | ||
} | ||
|
||
private copy(from: string, to: string): void | ||
{ | ||
fs.copyFileSync( | ||
path.resolve(__dirname, from), | ||
path.resolve(__dirname, this.distName + to) | ||
); | ||
} | ||
} | ||
|
||
new Build(); |
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,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"noImplicitAny": true, | ||
"module": "commonjs", | ||
"sourceMap": true, | ||
"target": "ES2015", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"esModuleInterop": true, | ||
"noImplicitOverride": true, | ||
"moduleResolution": "Node", | ||
"outDir": "./dist", | ||
"strict": true | ||
} | ||
} |
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,48 @@ | ||
import {MessageDispatcher} from "../mvc/message/IMessageDispatcher"; | ||
import fs from "fs"; | ||
import * as dotenv from "dotenv"; | ||
import {isNode} from "browser-or-node"; | ||
|
||
dotenv.config(); | ||
|
||
export abstract class AbstractApp<TAppConfig = unknown> extends MessageDispatcher | ||
{ | ||
protected _appConfigJson!: TAppConfig; | ||
|
||
public get appConfigJson(): TAppConfig | ||
{ | ||
return this._appConfigJson; | ||
} | ||
|
||
public loadConfig(configLoaded?: (success: boolean) => void): void | ||
{ | ||
const configPath = process.env.CONFIG || "./dev" + ".json"; | ||
|
||
try | ||
{ | ||
this.warn("Loading app config:", configPath); | ||
|
||
if (isNode) | ||
{ | ||
this._appConfigJson = JSON.parse(fs.readFileSync(configPath, "utf-8")); | ||
|
||
if (configLoaded) configLoaded(true); | ||
} | ||
else | ||
{ | ||
fetch(configPath).then(() => | ||
{ | ||
if (configLoaded) configLoaded(true); | ||
}).catch(() => | ||
{ | ||
if (configLoaded) configLoaded(false); | ||
}); | ||
} | ||
} catch (e) | ||
{ | ||
this.warn("Failed to load app config:", configPath); | ||
|
||
if (configLoaded) configLoaded(false); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
import "reflect-metadata"; | ||
import {Suite} from "mocha"; | ||
import {expect} from "chai"; | ||
import {Factory, Logger, LogLevel} from "../src"; | ||
import {AbstractApp} from "../src/com/domwires/core/app/AbstractApp"; | ||
|
||
describe('AppTest', function (this: Suite) | ||
{ | ||
class MockApp extends AbstractApp<{ name: string; age: number }> | ||
{ | ||
} | ||
|
||
it('testAppConfig', async () => | ||
{ | ||
const f = new Factory(new Logger(LogLevel.VERBOSE)); | ||
const app = f.getInstance<MockApp>(MockApp); | ||
|
||
app.loadConfig(success => | ||
{ | ||
expect(success).true; | ||
expect(app.appConfigJson.name).equals("Anton"); | ||
expect(app.appConfigJson.age).equals(36); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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