Use import/export instead of references. Use webpack instead of tsc.

This commit is contained in:
József Farkas
2016-04-19 22:35:16 +02:00
parent 4a950283b3
commit 07cc4cef2f
44 changed files with 252 additions and 92 deletions

View File

@@ -1,4 +1,7 @@
abstract class ClassArray<T> extends Serializable<T> {
import {Serializable} from './Serializable';
import {UhkBuffer} from './UhkBuffer';
export abstract class ClassArray<T> extends Serializable<T> {
elements: Serializable<T>[] = [];

View File

@@ -1,4 +1,8 @@
abstract class Serializable<T> {
/// <references path="Function.d.ts">
import {UhkBuffer} from './UhkBuffer';
export abstract class Serializable<T> {
private static depth = 0;
private static maxDisplayedJsonLength = 160;

View File

@@ -1,4 +1,4 @@
class UhkBuffer {
export class UhkBuffer {
private static eepromSize = 32 * 1024;
private static maxCompactLength = 0xFFFF;

View File

@@ -1,4 +1,7 @@
class DelayMacroAction extends MacroAction {
import {UhkBuffer} from '../UhkBuffer';
import {MacroAction, macroActionType, MacroActionId} from './MacroAction';
export class DelayMacroAction extends MacroAction {
// @assertUInt16
delay: number;

View File

@@ -1,3 +1,6 @@
import {UhkBuffer} from '../UhkBuffer';
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
enum LongPressAction {
leftCtrl,
leftShift,
@@ -12,7 +15,7 @@ enum LongPressAction {
mouse
}
class DualRoleKeystrokeAction extends KeyAction {
export class DualRoleKeystrokeAction extends KeyAction {
// @assertUInt8
scancode: number;

View File

@@ -1,4 +1,7 @@
class HoldKeyMacroAction extends MacroAction {
import {UhkBuffer} from '../UhkBuffer';
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
export class HoldKeyMacroAction extends MacroAction {
// @assertUInt8
scancode: number;

View File

@@ -1,4 +1,7 @@
class HoldModifiersMacroAction extends MacroAction {
import {UhkBuffer} from '../UhkBuffer';
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
export class HoldModifiersMacroAction extends MacroAction {
// @assertUInt8
modifierMask: number;

View File

@@ -1,4 +1,7 @@
class HoldMouseButtonsMacroAction extends MacroAction {
import {UhkBuffer} from '../UhkBuffer';
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
export class HoldMouseButtonsMacroAction extends MacroAction {
// @assertUInt8
mouseButtonsMask: number;

View File

@@ -1,4 +1,9 @@
enum KeyActionId {
/// <reference path="../Function.d.ts" />
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
export enum KeyActionId {
NoneAction = 0,
KeystrokeAction = 1,
KeystrokeModifiersAction = 2,
@@ -10,7 +15,7 @@ enum KeyActionId {
PlayMacroAction = 8
}
let keyActionType = {
export let keyActionType = {
NoneAction : 'none',
KeystrokeAction : 'keystroke',
KeystrokeModifiersAction : 'keystrokeModifiers',
@@ -22,7 +27,7 @@ let keyActionType = {
PlayMacroAction : 'playMacro'
};
abstract class KeyAction extends Serializable<KeyAction> {
export abstract class KeyAction extends Serializable<KeyAction> {
assertKeyActionType(jsObject: any) {
let keyActionClassname = this.constructor.name;
let keyActionTypeString = keyActionType[keyActionClassname];

View File

@@ -1,4 +1,18 @@
class KeyActions extends ClassArray<KeyAction> {
import {ClassArray} from '../ClassArray';
import {UhkBuffer} from '../UhkBuffer';
import {Serializable} from '../Serializable';
import {DualRoleKeystrokeAction} from './DualRoleKeystrokeAction';
import {NoneAction} from './NoneAction';
import {KeystrokeAction} from './KeystrokeAction';
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {KeystrokeModifiersAction} from './KeystrokeModifiersAction';
import {KeystrokeWithModifiersAction} from './KeystrokeWithModifiersAction';
import {SwitchLayerAction} from './SwitchLayerAction';
import {SwitchKeymapAction} from './SwitchKeymapAction';
import {MouseAction} from './MouseAction';
import {PlayMacroAction} from './PlayMacroAction';
export class KeyActions extends ClassArray<KeyAction> {
jsObjectToClass(jsObject: any): Serializable<KeyAction> {
switch (jsObject.keyActionType) {

View File

@@ -1,4 +1,8 @@
class KeyMap extends Serializable<KeyMap> {
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {Layers} from './Layers';
export class KeyMap extends Serializable<KeyMap> {
// @assertUInt8
id: number;

View File

@@ -1,4 +1,9 @@
class KeyMaps extends ClassArray<KeyMap> {
import {ClassArray} from '../ClassArray';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {KeyMap} from './KeyMap';
export class KeyMaps extends ClassArray<KeyMap> {
jsObjectToClass(jsObject: any): Serializable<KeyMap> {
return new KeyMap().fromJsObject(jsObject);

View File

@@ -1,4 +1,7 @@
class KeystrokeAction extends KeyAction {
import {UhkBuffer} from '../UhkBuffer';
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
export class KeystrokeAction extends KeyAction {
// @assertUInt8
scancode: number;

View File

@@ -1,4 +1,7 @@
enum KeyModifiers {
import {UhkBuffer} from '../UhkBuffer';
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
export enum KeyModifiers {
leftCtrl = 1 << 0,
leftShift = 1 << 1,
leftAlt = 1 << 2,
@@ -9,7 +12,7 @@ enum KeyModifiers {
rightGui = 1 << 7
}
class KeystrokeModifiersAction extends KeyAction {
export class KeystrokeModifiersAction extends KeyAction {
// @assertUInt8
modifierMask: number;

View File

@@ -1,4 +1,8 @@
class KeystrokeWithModifiersAction extends KeyAction {
import {UhkBuffer} from '../UhkBuffer';
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {KeyModifiers} from './KeystrokeModifiersAction';
export class KeystrokeWithModifiersAction extends KeyAction {
// @assertUInt8
modifierMask: number;

View File

@@ -1,4 +1,8 @@
class Layer extends Serializable<Layer> {
import {Serializable} from '../Serializable';
import {Modules} from './Modules';
import {UhkBuffer} from '../UhkBuffer';
export class Layer extends Serializable<Layer> {
modules: Serializable<Modules>;

View File

@@ -1,4 +1,9 @@
class Layers extends ClassArray<Layer> {
import {ClassArray} from '../ClassArray';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {Layer} from './Layer';
export class Layers extends ClassArray<Layer> {
jsObjectToClass(jsObject: any): Serializable<Layer> {
return new Layer().fromJsObject(jsObject);

View File

@@ -1,4 +1,8 @@
class Macro extends Serializable<Macro> {
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {MacroActions} from './MacroActions';
export class Macro extends Serializable<Macro> {
// @assertUInt8
id: number;

View File

@@ -1,4 +1,7 @@
enum MacroActionId {
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
export enum MacroActionId {
PressKeyMacroAction = 0,
HoldKeyMacroAction = 1,
ReleaseKeyMacroAction = 2,
@@ -14,7 +17,7 @@ enum MacroActionId {
TextMacroAction = 12
}
let macroActionType = {
export let macroActionType = {
PressKeyMacroAction : 'pressKey',
HoldKeyMacroAction : 'holdKey',
ReleaseKeyMacroAction : 'releaseKey',
@@ -30,7 +33,7 @@ let macroActionType = {
TextMacroAction : 'text'
};
abstract class MacroAction extends Serializable<MacroAction> {
export abstract class MacroAction extends Serializable<MacroAction> {
assertMacroActionType(jsObject: any) {
let macroActionClassname = this.constructor.name;
let macroActionTypeString = macroActionType[macroActionClassname];

View File

@@ -1,4 +1,22 @@
class MacroActions extends ClassArray<MacroAction> {
import {ClassArray} from '../ClassArray';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
import {DelayMacroAction} from './DelayMacroAction';
import {MacroAction, macroActionType, MacroActionId} from './MacroAction';
import {HoldKeyMacroAction} from './HoldKeyMacroAction';
import {HoldModifiersMacroAction} from './HoldModifiersMacroAction';
import {HoldMouseButtonsMacroAction} from './HoldMouseButtonsMacroAction';
import {MoveMouseMacroAction} from './MoveMouseMacroAction';
import {PressKeyMacroAction} from './PressKeyMacroAction';
import {PressModifiersMacroAction} from './PressModifiersMacroAction';
import {PressMouseButtonsMacroAction} from './PressMouseButtonsMacroAction';
import {ReleaseKeyMacroAction} from './ReleaseKeyMacroAction';
import {ReleaseModifiersMacroAction} from './ReleaseModifiersMacroAction';
import {ReleaseMouseButtonsMacroAction} from './ReleaseMouseButtonsMacroAction';
import {ScrollMouseMacroAction} from './ScrollMouseMacroAction';
import {TextMacroAction} from './TextMacroAction';
export class MacroActions extends ClassArray<MacroAction> {
jsObjectToClass(jsObject: any): Serializable<MacroAction> {
switch (jsObject.macroActionType) {

View File

@@ -1,4 +1,9 @@
class Macros extends ClassArray<Macro> {
import {ClassArray} from '../ClassArray';
import {Serializable} from '../Serializable';
import {Macro} from './Macro';
import {UhkBuffer} from '../UhkBuffer';
export class Macros extends ClassArray<Macro> {
jsObjectToClass(jsObject: any): Serializable<Macro> {
return new Macro().fromJsObject(jsObject);

View File

@@ -1,10 +1,14 @@
import {Serializable} from '../Serializable';
import {KeyActions} from './KeyActions';
import {UhkBuffer} from '../UhkBuffer';
enum PointerRole {
none,
move,
scroll
}
class Module extends Serializable<Module> {
export class Module extends Serializable<Module> {
// @assertUInt8
id: number;

View File

@@ -1,4 +1,7 @@
class ModuleConfiguration extends Serializable<ModuleConfiguration> {
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
export class ModuleConfiguration extends Serializable<ModuleConfiguration> {
/*
* module id enumeration is a separate story

View File

@@ -1,4 +1,9 @@
class ModuleConfigurations extends ClassArray<ModuleConfiguration> {
import {ClassArray} from '../ClassArray';
import {Serializable} from '../Serializable';
import {ModuleConfiguration} from './ModuleConfiguration';
import {UhkBuffer} from '../UhkBuffer';
export class ModuleConfigurations extends ClassArray<ModuleConfiguration> {
jsObjectToClass(jsObject: any): Serializable<ModuleConfiguration> {
return new ModuleConfiguration().fromJsObject(jsObject);

View File

@@ -1,4 +1,9 @@
class Modules extends ClassArray<Module> {
import {ClassArray} from '../ClassArray';
import {Module} from './Module';
import {Serializable} from '../Serializable';
import {UhkBuffer} from '../UhkBuffer';
export class Modules extends ClassArray<Module> {
jsObjectToClass(jsObject: any): Serializable<Module> {
return new Module().fromJsObject(jsObject);

View File

@@ -1,3 +1,6 @@
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {UhkBuffer} from '../UhkBuffer';
enum MouseActionParam {
leftClick,
middleClick,
@@ -14,7 +17,7 @@ enum MouseActionParam {
decelerate
}
class MouseAction extends KeyAction {
export class MouseAction extends KeyAction {
// @assertUInt8
mouseAction: MouseActionParam;

View File

@@ -1,4 +1,7 @@
class MoveMouseMacroAction extends MacroAction {
import {MacroAction, macroActionType, MacroActionId} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class MoveMouseMacroAction extends MacroAction {
// @assertInt16
x: number;

View File

@@ -1,4 +1,7 @@
class NoneAction extends KeyAction {
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {UhkBuffer} from '../UhkBuffer';
export class NoneAction extends KeyAction {
_fromJsObject(jsObject: any): NoneAction {
this.assertKeyActionType(jsObject);

View File

@@ -1,4 +1,7 @@
class PlayMacroAction extends KeyAction {
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {UhkBuffer} from '../UhkBuffer';
export class PlayMacroAction extends KeyAction {
// @assertUInt8
macroId: number;

View File

@@ -1,4 +1,7 @@
class PressKeyMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class PressKeyMacroAction extends MacroAction {
// @assertUInt8
scancode: number;

View File

@@ -1,4 +1,7 @@
class PressModifiersMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class PressModifiersMacroAction extends MacroAction {
// @assertUInt8
modifierMask: number;

View File

@@ -1,4 +1,7 @@
class PressMouseButtonsMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class PressMouseButtonsMacroAction extends MacroAction {
// @assertUInt8
mouseButtonsMask: number;

View File

@@ -1,4 +1,7 @@
class ReleaseKeyMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class ReleaseKeyMacroAction extends MacroAction {
// @assertUInt8
scancode: number;

View File

@@ -1,4 +1,7 @@
class ReleaseModifiersMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class ReleaseModifiersMacroAction extends MacroAction {
// @assertUInt8
modifierMask: number;

View File

@@ -1,4 +1,7 @@
class ReleaseMouseButtonsMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class ReleaseMouseButtonsMacroAction extends MacroAction {
// @assertUInt8
mouseButtonsMask: number;

View File

@@ -1,4 +1,7 @@
class ScrollMouseMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class ScrollMouseMacroAction extends MacroAction {
// @assertInt16
x: number;

View File

@@ -1,4 +1,7 @@
class SwitchKeymapAction extends KeyAction {
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {UhkBuffer} from '../UhkBuffer';
export class SwitchKeymapAction extends KeyAction {
// @assertUInt8
keymapId: number;

View File

@@ -1,10 +1,13 @@
import {keyActionType, KeyActionId, KeyAction} from './KeyAction';
import {UhkBuffer} from '../UhkBuffer';
enum LayerName {
mod,
fn,
mouse
}
class SwitchLayerAction extends KeyAction {
export class SwitchLayerAction extends KeyAction {
isLayerToggleable: boolean;

View File

@@ -1,4 +1,7 @@
class TextMacroAction extends MacroAction {
import {MacroAction, MacroActionId, macroActionType} from './MacroAction';
import {UhkBuffer} from '../UhkBuffer';
export class TextMacroAction extends MacroAction {
text: string;

View File

@@ -1,4 +1,10 @@
class UhkConfiguration extends Serializable<UhkConfiguration> {
import {Serializable} from '../Serializable';
import {ModuleConfigurations} from './ModuleConfigurations';
import {KeyMaps} from './KeyMaps';
import {Macros} from './Macros';
import {UhkBuffer} from '../UhkBuffer';
export class UhkConfiguration extends Serializable<UhkConfiguration> {
signature: string;

View File

@@ -1,37 +0,0 @@
/// <reference path="KeyAction.ts" />
/// <reference path="KeyActions.ts" />
/// <reference path="KeystrokeAction.ts" />
/// <reference path="KeystrokeWithModifiersAction.ts" />
/// <reference path="KeystrokeModifiersAction.ts" />
/// <reference path="DualRoleKeystrokeAction.ts" />
/// <reference path="MouseAction.ts" />
/// <reference path="PlayMacroAction.ts" />
/// <reference path="SwitchLayerAction.ts" />
/// <reference path="SwitchKeymapAction.ts" />
/// <reference path="NoneAction.ts" />
/// <reference path="Module.ts" />
/// <reference path="Modules.ts" />
/// <reference path="Layer.ts" />
/// <reference path="Layers.ts" />
/// <reference path="KeyMap.ts" />
/// <reference path="KeyMaps.ts" />
/// <reference path="Macro.ts" />
/// <reference path="Macros.ts" />
/// <reference path="MacroAction.ts" />
/// <reference path="MacroActions.ts" />
/// <reference path="PressKeyMacroAction.ts" />
/// <reference path="HoldKeyMacroAction.ts" />
/// <reference path="ReleaseKeyMacroAction.ts" />
/// <reference path="PressModifiersMacroAction.ts" />
/// <reference path="HoldModifiersMacroAction.ts" />
/// <reference path="ReleaseModifiersMacroAction.ts" />
/// <reference path="PressMouseButtonsMacroAction.ts" />
/// <reference path="HoldMouseButtonsMacroAction.ts" />
/// <reference path="ReleaseMouseButtonsMacroAction.ts" />
/// <reference path="MoveMouseMacroAction.ts" />
/// <reference path="ScrollMouseMacroAction.ts" />
/// <reference path="DelayMacroAction.ts" />
/// <reference path="TextMacroAction.ts" />
/// <reference path="ModuleConfiguration.ts" />
/// <reference path="ModuleConfigurations.ts" />
/// <reference path="UhkConfiguration.ts" />

View File

@@ -1,9 +1,8 @@
/// <reference path="Function.d.ts" />
/// <reference path="assert.ts" />
/// <reference path="Serializable.ts" />
/// <reference path="ClassArray.ts" />
/// <reference path="UhkBuffer.ts" />
/// <reference path="config-items/config-items.ts" />
/// <reference path="../typings/main/ambient/node/index.d.ts" />
import {Serializable} from './Serializable';
import {UhkBuffer} from './UhkBuffer';
import {UhkConfiguration} from './config-items/UhkConfiguration';
let assert = require('assert');
let fs = require('fs');

View File

@@ -1,11 +1,13 @@
{
"compilerOptions": {
"out": "test-serializer.js",
"target": "es5",
"module": "commonjs",
"experimentalDecorators": true
},
"files": [
"../typings/main.d.ts",
"test-serializer.ts"
"exclude": [
"../src",
"../node_modules",
"../typings/main",
"../typings/main.d.ts"
]
}

View File

@@ -0,0 +1,32 @@
// var webpack = require("webpack");
module.exports = {
entry: {
main: './test-serializer.ts'
},
target: 'node',
output: {
filename: "test-serializer.js"
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'],
alias: {
},
modulesDirectories: [
'../node_modules'
]
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader', exclude: /node_modules/ }
]
},
plugins: [
// new webpack.optimize.UglifyJsPlugin({ minimize: true })
],
node: {
fs: "empty"
}
}