Skip to content

Commit

Permalink
Merge branch 'dominik-korsa-typescript' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
song940 committed Aug 3, 2022
2 parents 89b17d5 + f295f56 commit 6f57a5e
Show file tree
Hide file tree
Showing 46 changed files with 1,936 additions and 1,797 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,8 +1,9 @@

.idea

*.log
.idea/
yarn.lock
package-lock.json

node_modules/
dist/
7 changes: 4 additions & 3 deletions examples/status.js
@@ -1,6 +1,6 @@
const escpos = require('../packages/printer');
escpos.SerialPort = require('../packages/serialport');
const statuses = require('../packages/printer/statuses');
escpos.SerialPort = require('../packages/serialport/src');
const statuses = require('../packages/printer/src/statuses');

const device = new escpos.SerialPort('COM3');
const printer = new escpos.Printer(device);
Expand All @@ -12,7 +12,8 @@ device.open(function (error) {
}

printer
.getStatus(statuses.PrinterStatus.getClassName(), status => {
// TODO: Update
.getStatus('PrinterStatus', status => {
console.log(status.toJSON());
})
.close();
Expand Down
2 changes: 1 addition & 1 deletion examples/statuses.js
@@ -1,5 +1,5 @@
const escpos = require('../packages/printer');
escpos.SerialPort = require('../packages/serialport');
escpos.SerialPort = require('../packages/serialport/src');

const device = new escpos.SerialPort('COM3');
const printer = new escpos.Printer(device);
Expand Down
22 changes: 0 additions & 22 deletions packages/adapter/index.js

This file was deleted.

11 changes: 9 additions & 2 deletions packages/adapter/package.json
Expand Up @@ -2,14 +2,21 @@
"name": "escpos-adapter",
"version": "3.0.0-alpha.4",
"description": "escpos adapter base class",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"escpos"
],
"author": "Lsong <song940@gmail.com> (https://lsong.org)",
"license": "MIT",
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb"
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb",
"devDependencies": {
"@tsconfig/node10": "^1.0.8",
"@types/node": "^10.0.0",
"typescript": "^4.5.2"
}
}
11 changes: 11 additions & 0 deletions packages/adapter/src/index.ts
@@ -0,0 +1,11 @@
'use strict';
const EventEmitter = require('events');

export class NotImplementedException extends Error {}

export abstract class Adapter<CloseArgs extends unknown[]> extends EventEmitter {
abstract open(callback?: (error: Error | null) => void): this;
abstract write(data: Buffer | string, callback?: (error: Error | null) => void): this;
abstract close(callback?: (error: Error | null) => void, ...closeArgs: CloseArgs): this;
abstract read(callback?: (data: Buffer) => void): void;
}
10 changes: 10 additions & 0 deletions packages/adapter/tsconfig.json
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/node10/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"declaration": true,
"declarationMap": true
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions packages/adapter/tsconfig.ref.json
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
},
}
54 changes: 0 additions & 54 deletions packages/console/index.js

This file was deleted.

11 changes: 9 additions & 2 deletions packages/console/package.json
Expand Up @@ -2,8 +2,10 @@
"name": "escpos-console",
"version": "3.0.0-alpha.2",
"description": "console adapter for escpos",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
Expand All @@ -12,5 +14,10 @@
],
"author": "Lsong <song940@gmail.com> (https://lsong.org)",
"license": "MIT",
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb"
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb",
"devDependencies": {
"@tsconfig/node10": "^1.0.8",
"@types/node": "^10.0.0",
"typescript": "^4.5.2"
}
}
66 changes: 66 additions & 0 deletions packages/console/src/index.ts
@@ -0,0 +1,66 @@
'use strict';
import {Adapter, NotImplementedException} from "escpos-adapter";

/**
* [stdout description]
* @param {[type]} data [description]
* @return {[type]} [description]
*/
function stdout(data: string | Buffer) {
const bit = 8;
for (let i=0; i < data.length; i += bit){
let arr = [];
for (let j = 0; j < bit && i + j < data.length; j++) arr.push(data[i + j]);
arr = arr
.map((b) => b.toString(16).toUpperCase())
.map((b) => {
if (b.length == 1) b = '0' + b;
return b;
})
console.log(arr.join(' '));
}
console.log();
}

/**
* [Console description]
*/
export default class Console extends Adapter<[]> {
public handler: (data: (string | Buffer)) => void;

constructor(handler: (data: string | Buffer) => void = stdout) {
super();
this.handler = handler;
}

/**
* [open description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
open(callback?: (error: Error | null) => void) {
if (callback) callback(null);
return this;
};

/**
* [write description]
* @param {[type]} data [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
write(data: string | Buffer, callback?: (error: Error | null) => void) {
this.handler(data);
if (callback) callback(null);
return this;
};

close(callback?: (error: Error | null) => void) {
if (callback) callback(null);
return this;
}

read() {
return NotImplementedException;
}
}
10 changes: 10 additions & 0 deletions packages/console/tsconfig.json
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/node10/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"declaration": true,
"declarationMap": true
},
"include": ["src"]
}
6 changes: 6 additions & 0 deletions packages/console/tsconfig.ref.json
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
},
}
71 changes: 0 additions & 71 deletions packages/network/index.js

This file was deleted.

11 changes: 9 additions & 2 deletions packages/network/package.json
Expand Up @@ -2,8 +2,10 @@
"name": "escpos-network",
"version": "3.0.0-alpha.5",
"description": "network adapter for escpos",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
Expand All @@ -12,5 +14,10 @@
],
"author": "Lsong <song940@gmail.com> (https://lsong.org)",
"license": "MIT",
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb"
"gitHead": "a3a65c61c0b990298258331f54546a93d6875ddb",
"devDependencies": {
"@tsconfig/node10": "^1.0.8",
"@types/node": "^10.0.0",
"typescript": "^4.5.2"
}
}

0 comments on commit 6f57a5e

Please sign in to comment.