Skip to content

Commit

Permalink
chore: setup & refactor to ts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dohooo committed Oct 22, 2022
0 parents commit 2ba4b18
Show file tree
Hide file tree
Showing 98 changed files with 9,328 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@dohooo"
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [dohooo]
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Lint
run: nr lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Typecheck
run: nr typecheck

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [14.x, 16.x]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Build
run: nr build

- name: Test
run: nr test
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 16.x

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.cache
.DS_Store
.idea
*.log
*.tgz
coverage
dist
lib-cov
logs
node_modules
temp
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_*
node_modules
*.sublime*
psd
thumb
*.log
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-workspace-root-check=true
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dohooo.gold-right"]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cSpell.words": [
"dohooo",
"escpos"
],
"prettier.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"goldRight.templateDirectoryPath": "./.vscode/templates"
}
22 changes: 22 additions & 0 deletions .vscode/templates/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"paths": [
{
"directory": "[directory]",
"templates": [
"[template-name]"
]
}
],
"templatesConfig": [
{
"templateName": "[template-name]",
"inputsVariables": [
{
"key": "[key]",
"title": "[prompt-title]",
"required": "[is-required]"
}
]
}
]
}
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please refer to https://github.com/dohooo/contribute
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 lsong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
## ESCPOS PROJECT

ESC/POS Printer driver for Node.js

[![npm version](https://badge.fury.io/js/escpos.svg)](https://www.npmjs.com/package/escpos )
[![Build Status](https://travis-ci.org/song940/node-escpos.svg?branch=master)](https://travis-ci.org/song940/node-escpos)

[![NPM](https://nodei.co/npm/escpos.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/escpos )

Packages Available:

+ [escpos Printer](packages/printer/README.md)
+ [escpos Screen Display](packages/screen/README.md)
+ [escpos USB Adapter](packages/usb/README.md)
+ [escpos Network Adapter](packages/network/README.md)
+ [escpos Bluetooth Adapter](packages/bluetooth/README.md)
+ [escpos SerialPort Adapter](packages/serialport/README.md)

## Example

````javascript
const escpos = require('escpos');
// install escpos-usb adapter module manually
escpos.USB = require('escpos-usb');
// Select the adapter based on your printer type
const device = new escpos.USB();
// const device = new escpos.Network('localhost');
// const device = new escpos.Serial('/dev/usb/lp0');

const options = { encoding: "GB18030" /* default */ }
// encoding is optional

const printer = new escpos.Printer(device, options);

device.open(function(error){
printer
.font('a')
.align('ct')
.style('bu')
.size(1, 1)
.text('The quick brown fox jumps over the lazy dog')
.text('敏捷的棕色狐狸跳过懒狗')
.barcode('1234567', 'EAN8')
.table(["One", "Two", "Three"])
.tableCustom(
[
{ text:"Left", align:"LEFT", width:0.33, style: 'B' },
{ text:"Center", align:"CENTER", width:0.33},
{ text:"Right", align:"RIGHT", width:0.33 }
],
{ encoding: 'cp857', size: [1, 1] } // Optional
)
.qrimage('https://github.com/song940/node-escpos', function(err){
this.cut();
this.close();
});
});
````
- See `./examples` for more examples.

----

## Screencast

![img_1031](https://user-images.githubusercontent.com/8033320/29250339-d66ce470-807b-11e7-89ce-9962da88ca18.JPG)

----

## Contributing
- Fork this repo
- Clone your repo
- Install dependencies
- Checkout a feature branch
- Feel free to add your features
- Make sure your features are fully tested
- Open a pull request, and enjoy <3

----

## Contributors

Thanks to our [contributors][contributors-href] 🎉👏

+ [Tao Yuan](https://github.com/taoyuan)
+ [Jose Vera](https://github.com/jor3l)
+ [Sébastien Vidal](https://github.com/Psychopoulet)
+ [Yu Yongwoo](https://github.com/uyu423)
+ [Attawit Kittikrairit](https://github.com/atton16)
+ [Michael Kuenzli](https://github.com/pfirpfel)

[![](https://opencollective.com/node-escpos/contributors.svg?width=890&button=false)][contributors-href]

----

### MIT license
Copyright (c) 2015 ~ now Lsong <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the &quot;Software&quot;), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

---

[contributors-href]: https://github.com/song940/node-escpos/graphs/contributors

19 changes: 19 additions & 0 deletions examples/barcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
const escpos = require('../');

const device = new escpos.USB();

const printer = new escpos.Printer(device);

device.open(function() {
printer
.font('a')
.align('ct')
.size(1, 1)
.text('EAN13 barcode example')
.barcode('123456789012', 'EAN13') // code length 12
.barcode('109876543210') // default type 'EAN13'
.barcode('7654321', 'EAN8') // The EAN parity bit is automatically added.
.cut()
.close();
});
8 changes: 8 additions & 0 deletions examples/bt_find_printer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { Bluetooth } = require('..');

(async () => {

const printers = await Bluetooth.findPrinters();
console.log(printers);

})();
23 changes: 23 additions & 0 deletions examples/bt_promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { Bluetooth, Printer } = require('..');

(async () => {

try {
const availablePrinters = await Bluetooth.findPrinters();
// Uncomment if you want to use a specific printer instead of the first bt device that responds:
// const preferredPrinterName = 'MHT-P5801';
// const btPrinter = availablePrinters.filter(p => p && p.name === preferredPrinterName)[0];
const btPrinter = availablePrinters[0];
console.log('Connect to ' + btPrinter.name);
const device = await Bluetooth.getDevice(btPrinter.address, btPrinter.channel);
const printer = await Printer.create(device);

await printer.text('hello');
await printer.cut();
await printer.close();

console.log('print job done');
} catch(error) {
console.log('error', error);
}
})();
21 changes: 21 additions & 0 deletions examples/codepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const escpos = require('../');
const path = require('path');

const device = new escpos.Serial('COM9', { baudRate: 9600, autoOpen: false });
// const device = new escpos.RawBT();
// const device = new escpos.Network('localhost');
// const device = new escpos.Serial('/dev/usb/lp0');
const printer = new escpos.Printer(device);

device.open(function(err){
printer
.encode('cp866')
.setCharacterCodeTable(17)
.text('Тест на кирилица.')
.size(1, 1)
.feed()
.feed()
.cut()
.close();
});
Loading

0 comments on commit 2ba4b18

Please sign in to comment.