diff --git a/ts/util.ts b/ts/util.ts new file mode 100644 index 00000000..99a04ab5 --- /dev/null +++ b/ts/util.ts @@ -0,0 +1,35 @@ +type ErrType = { new(msg?: string): T } +type Nullable = T | null | undefined + +export class RuntimeError extends Error { + public name = 'RuntimeError'; + constructor(public message: string = '') { + super(message); + } + toString(): string { + if (this.message) { + return this.name + ': ' + this.message; + } + else { + return this.name; + } + } +} + +export class NotNullExpected extends RuntimeError { + public name = 'NotNullExpected'; +} + +export function unwrap(result: Nullable): T { + if (result === null || result === undefined) { + throw new NotNullExpected(); + } + return result; +} + +export function unwrap_err(result: Nullable, errType: ErrType, errMsg?: string): T { + if (result === null || result === undefined) { + throw new errType(errMsg); + } + return result; +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 6970ba53..8528c54d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,31 +1,64 @@ const path = require('path'); -module.exports = { - resolve: { - extensions: [".ts", ".tsx"] - }, - entry: { - inheritPoint: './hwe/ts/inheritPoint.ts', - }, - output: { - filename: '[name].js', - path: path.resolve(__dirname, 'hwe/js'), - }, - mode: 'production', - devtool: 'source-map', - module: { - rules: [{ - test: /\.(ts|tsx)$/, - exclude: /(node_modules)/, - use: { - loader: 'babel-loader', - options: { - presets: [ - '@babel/preset-env', - '@babel/preset-typescript' - ] +module.exports = [ + { + name: 'ingame', + resolve: { + extensions: [".ts", ".tsx"] + }, + entry: { + inheritPoint: './hwe/ts/inheritPoint.ts', + }, + output: { + filename: '[name].js', + path: path.resolve(__dirname, 'hwe/js'), + }, + mode: 'production', + devtool: 'source-map', + module: { + rules: [{ + test: /\.(ts|tsx)$/, + exclude: /(node_modules)/, + use: { + loader: 'babel-loader', + options: { + presets: [ + '@babel/preset-env', + '@babel/preset-typescript' + ] + } } - } - }] + }] + }, }, -} \ No newline at end of file + { + name: 'gateway', + resolve: { + extensions: [".ts", ".tsx"] + }, + entry: { + //test: './ts/test.ts', + }, + output: { + filename: '[name].js', + path: path.resolve(__dirname, 'js'), + }, + mode: 'none', + devtool: 'source-map', + module: { + rules: [{ + test: /\.(ts|tsx)$/, + exclude: /(node_modules)/, + use: { + loader: 'babel-loader', + options: { + presets: [ + '@babel/preset-env', + '@babel/preset-typescript' + ] + } + } + }] + }, + }, +]