Typescript with webpack
This commit is contained in:
parent
ce8419f773
commit
7717c1d975
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# VSC
|
||||
.vscode
|
||||
|
||||
# Pipeline
|
||||
dist/js
|
||||
build
|
12
dist/home_overlay.html
vendored
Normal file
12
dist/home_overlay.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Home Overlay</title>
|
||||
<script src="js/bundle.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
11
package.json
Normal file
11
package.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "undefined-tv",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"build": "webpack"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Sunpy",
|
||||
"license": "GPL 3.0"
|
||||
}
|
8
src/index.ts
Normal file
8
src/index.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { InputHandler } from "./inputManager";
|
||||
|
||||
const inputHandler: InputHandler = InputHandler.getInstance();
|
||||
|
||||
function test(e: KeyboardEvent) {
|
||||
console.log(e);
|
||||
}
|
||||
inputHandler.addHandler(test);
|
47
src/inputManager.ts
Normal file
47
src/inputManager.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
export class InputHandler {
|
||||
private static instance: InputHandler;
|
||||
private handlers: { (e: KeyboardEvent): void; } [] = [];
|
||||
private bound_onkeydown: { (e: KeyboardEvent): void; } = this.onkeydown.bind(this);
|
||||
|
||||
private constructor() {
|
||||
this.enable();
|
||||
}
|
||||
|
||||
public enable = () => addEventListener("keydown", this.bound_onkeydown);
|
||||
public disable = () => removeEventListener("keydown", this.bound_onkeydown);
|
||||
|
||||
private onkeydown(e: KeyboardEvent) {
|
||||
this.handlers.forEach(f => f(e));
|
||||
}
|
||||
|
||||
public addHandler(handler: { (e: KeyboardEvent): void; }) {
|
||||
if (this.handlers.indexOf(handler) !== -1)
|
||||
return;
|
||||
|
||||
this.handlers.push(handler);
|
||||
}
|
||||
|
||||
public removeHandler(handler: { (e: KeyboardEvent): void; }) {
|
||||
this.handlers = this.handlers.filter(f => f !== handler);
|
||||
}
|
||||
|
||||
public static getInstance(): InputHandler {
|
||||
if (!InputHandler.instance)
|
||||
InputHandler.instance = new InputHandler();
|
||||
return InputHandler.instance;
|
||||
}
|
||||
}
|
||||
|
||||
const KEYS_TV = {
|
||||
PLAY: 80,
|
||||
PAUSE: 81,
|
||||
STOP: 83,
|
||||
|
||||
RED: 116,
|
||||
GREEN: 117,
|
||||
YELLOW: 118,
|
||||
BLUE: 119,
|
||||
|
||||
FAST_FWD: 70,
|
||||
REWIND: 82,
|
||||
};
|
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ES6",
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"jsx": "preserve",
|
||||
"strictFunctionTypes": true,
|
||||
"sourceMap": true,
|
||||
"removeComments": true,
|
||||
"outDir": "./build/",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es6"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/node_modules/*"
|
||||
]
|
||||
}
|
24
webpack.config.js
Normal file
24
webpack.config.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const path = require('path');
|
||||
module.exports = {
|
||||
watch: true,
|
||||
devtool: 'inline-source-map',
|
||||
entry: path.join(__dirname, 'build', 'index'),
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: 'ts-loader',
|
||||
exclude: '/node_modules/'
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.tsx', '.ts', '.js'],
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, 'dist', 'js'),
|
||||
publicPath: '/dist/',
|
||||
filename: "bundle.js",
|
||||
chunkFilename: '[name].js'
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user