From a419b6df5a74ce3b00c9e20b54bdc43d9b9b8104 Mon Sep 17 00:00:00 2001 From: Syndesi Date: Sat, 2 Mar 2024 16:45:55 +0100 Subject: [PATCH] WIP. --- package.json | 6 ++-- src/EmberNexus.ts | 35 ++++++----------------- src/Factory/LoggerFactory.ts | 1 + test.html | 30 ++++++++++++++++++++ tsconfig.release.json | 13 ++++++--- webpack.release.config.cjs | 55 ++++++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 test.html create mode 100644 webpack.release.config.cjs diff --git a/package.json b/package.json index 2410150..4cdef9f 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,11 @@ "main": "dist/EmberNexus.js", "types": "dist/EmberNexus.d.ts", "scripts": { - "watch": "webpack --mode development --watch", - "build": "webpack --mode production", + "build": "rm -rf ./dist && webpack --config webpack.release.config.cjs", "cs": "eslint --ext .ts ./src ./test", "cs:fix": "eslint --ext .ts ./src ./test --fix", "test:unit": "jest ./test/Unit", "test:feature": "jest ./test/Feature", - "test:unit:old": "mocha --config .mocharc.unit.json", - "test:feature:old": "mocha --config .mocharc.feature.json", "prepare": "ts-patch install" }, "author": "Syndesi ", @@ -51,6 +48,7 @@ "prettier": "^3.0.3", "rimraf": "~5.0.5", "sinon": "^17.0.1", + "terser-webpack-plugin": "^5.3.10", "ts-jest": "^29.1.2", "ts-loader": "^9.5.1", "ts-mockito": "^2.6.1", diff --git a/src/EmberNexus.ts b/src/EmberNexus.ts index c62e000..a2a1f53 100644 --- a/src/EmberNexus.ts +++ b/src/EmberNexus.ts @@ -1,35 +1,16 @@ import 'reflect-metadata'; -import { Container, Service } from 'typedi'; -// import { parse as uuidParse } from 'uuid'; +import { Container } from 'typedi'; -import { GetElementEvent } from '~/BrowserEvent/Element/GetElementEvent'; -import { Logger } from '~/Service/Logger'; -// import GetElementEndpoint from "~/Endpoint/Element/GetElementEndpoint"; +import GetElementEndpoint from '~/Endpoint/Element/GetElementEndpoint'; import { WebSdkConfiguration } from '~/Service/WebSdkConfiguration'; -import { validateUuidFromString } from '~/Type/Definition/Uuid'; +import { Relation } from '~/Type/Definition/Relation'; +import { Uuid } from '~/Type/Definition/Uuid'; -@Service() -class TestService { - constructor(public logger: Logger) {} - - test(): void { - this.logger.debug('level is debug'); - this.logger.info('level is info'); - this.logger.warn('level is warn'); - this.logger.error('level is error'); - console.log(new GetElementEvent(validateUuidFromString('b63a3196-7373-4d44-b590-f94e31021bf3'))); +class EmberNexus { + test(uuid: Uuid): Promise { + return Container.get(GetElementEndpoint).getElement(uuid); } } -export { TestService, GetElementEvent }; - -const service = Container.get(TestService); -service.test(); - -const webSdkConfiguration = Container.get(WebSdkConfiguration); -webSdkConfiguration.setApiHost('http://localhost'); - -// const getElementEndpoint = Container.get(GetElementEndpoint); -// const res = await getElementEndpoint.getElement(uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b')); -// console.log(res); +export { EmberNexus, Container, WebSdkConfiguration }; diff --git a/src/Factory/LoggerFactory.ts b/src/Factory/LoggerFactory.ts index e422dcb..be6e3e0 100644 --- a/src/Factory/LoggerFactory.ts +++ b/src/Factory/LoggerFactory.ts @@ -9,6 +9,7 @@ class LoggerFactory { create(): Logger { const tsLogger: TsLogger = new TsLogger({ minLevel: LogLevel.Debug, + stylePrettyLogs: false, }); return new Logger(tsLogger); } diff --git a/test.html b/test.html new file mode 100644 index 0000000..d72ea90 --- /dev/null +++ b/test.html @@ -0,0 +1,30 @@ + + + + + + Test + + + + +

Test

+ + + + + diff --git a/tsconfig.release.json b/tsconfig.release.json index fa1db46..8d5bd12 100644 --- a/tsconfig.release.json +++ b/tsconfig.release.json @@ -1,12 +1,12 @@ { "compilerOptions": { "target": "ES2022", - "module": "Node16", + "module": "es2022", "lib": [ "ES2022", "dom" ], - "moduleResolution": "nodenext", + "moduleResolution": "bundler", "outDir": "dist", "baseUrl": ".", "allowSyntheticDefaultImports": true, @@ -20,8 +20,13 @@ "noUnusedParameters": true, "noImplicitAny": false, "noImplicitThis": false, - "strictNullChecks": false, - "declaration": true + "strictNullChecks": true, + "declaration": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "paths": { + "~/*": ["./src/*"] + } }, "include": ["src/**/*"] } diff --git a/webpack.release.config.cjs b/webpack.release.config.cjs new file mode 100644 index 0000000..8bbb424 --- /dev/null +++ b/webpack.release.config.cjs @@ -0,0 +1,55 @@ +const path = require('path'); +const TerserPlugin = require("terser-webpack-plugin"); + +module.exports = { + entry: './src/EmberNexus.ts', + mode: "production", + module: { + rules: [ + { + test: /\.ts?$/, + use: [ + { + loader: 'ts-loader', + options: { + configFile: 'tsconfig.release.json' + } + } + ], + exclude: /node_modules/ + }, + ], + }, + resolve: { + extensions: ['.ts', '.js'], + alias: { + '~': path.resolve(__dirname, 'src/'), + } + }, + output: { + filename: 'bundle.js', + path: path.resolve(__dirname, 'dist'), + clean: true, + library: 'EmberNexusWebSDK', + libraryTarget: 'umd', + umdNamedDefine: true + }, + performance: { + hints: false + }, + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + terserOptions: { + format: { + comments: false, + }, + keep_classnames: true, + keep_fnames: true, + }, + extractComments: false, + }), + ], + }, +};