Skip to content

Commit 1b104a6

Browse files
committed
init
0 parents  commit 1b104a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+13305
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
yarn-error.log
34+
testem.log
35+
/typings
36+
37+
# System Files
38+
.DS_Store
39+
Thumbs.db

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# PrintLib
2+
3+
A library for connecting Angular apps with thermal printers.
4+
5+
## Drivers
6+
7+
1. WEBUSB API (No drivers needed. Only works with Chrome and Opera with USB connection)
8+
2. WebPRNT (http)
9+
10+
## Print Language Drivers
11+
12+
1. ESC/POS
13+
2. StarPRNT
14+
3. Star WebPRNT
15+
16+
17+
## Installation
18+
19+
`npm install _yet_to_be_determined_`
20+
21+
Import the module into your app:
22+
23+
import { BrowserModule } from '@angular/platform-browser';
24+
import { NgModule } from '@angular/core';
25+
import { EscPosPrintModule } from 'ng-thermal-print'; //add this line
26+
import { AppComponent } from './app.component';
27+
28+
@NgModule({
29+
declarations: [
30+
AppComponent
31+
],
32+
imports: [
33+
BrowserModule,
34+
EscPosPrintModule //add this line
35+
],
36+
providers: [],
37+
bootstrap: [AppComponent]
38+
})
39+
export class AppModule { }
40+
41+
## Examples
42+
43+
### WebUSB API
44+
45+
46+
import { EscPosPrintService } from 'ng-thermal-print/ng-thermal-print.service';
47+
import { UsbDriver } from 'ng-thermal-print/drivers';
48+
import { Component } from '@angular/core';
49+
50+
@Component({
51+
selector: 'app-root',
52+
templateUrl: './app.component.html',
53+
styleUrls: ['./app.component.css']
54+
})
55+
export class AppComponent {
56+
status: boolean = false;
57+
usbPrintDriver = new UsbDriver(1046, 20497);
58+
59+
constructor(private printService: EscPosPrintService) {
60+
this.printService.isConnected.subscribe(result => {
61+
this.status = result;
62+
if (result) {
63+
console.log('connected printer from app');
64+
} else {
65+
console.log('not connected');
66+
}
67+
});
68+
}
69+
70+
requestUsb() {
71+
// this must be called from an event to work
72+
let usbPrintDriver = new UsbDriver();
73+
usbPrintDriver.requestUsb().then(result => {
74+
this.printService.setDriver(usbPrintDriver);
75+
});
76+
}
77+
78+
writeToUsb() {
79+
this.printService.init()
80+
.setBold(true)
81+
.writeLine('Hello World!')
82+
.setBold(false)
83+
.feed(4)
84+
.cut('full')
85+
.flush();
86+
}
87+
}

angular.json

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"print-lib": {
7+
"root": "",
8+
"sourceRoot": "src",
9+
"projectType": "application",
10+
"prefix": "app",
11+
"schematics": {},
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:browser",
15+
"options": {
16+
"outputPath": "dist/print-lib",
17+
"index": "src/index.html",
18+
"main": "src/main.ts",
19+
"polyfills": "src/polyfills.ts",
20+
"tsConfig": "src/tsconfig.app.json",
21+
"assets": [
22+
"src/favicon.ico",
23+
"src/assets"
24+
],
25+
"styles": [
26+
"src/styles.css"
27+
],
28+
"scripts": [
29+
"js/StarWebPrintTrader.js",
30+
"js/StarWebPrintBuilder.js"
31+
]
32+
},
33+
"configurations": {
34+
"production": {
35+
"fileReplacements": [{
36+
"replace": "src/environments/environment.ts",
37+
"with": "src/environments/environment.prod.ts"
38+
}],
39+
"optimization": true,
40+
"outputHashing": "all",
41+
"sourceMap": false,
42+
"extractCss": true,
43+
"namedChunks": false,
44+
"aot": true,
45+
"extractLicenses": true,
46+
"vendorChunk": false,
47+
"buildOptimizer": true
48+
}
49+
}
50+
},
51+
"serve": {
52+
"builder": "@angular-devkit/build-angular:dev-server",
53+
"options": {
54+
"browserTarget": "print-lib:build"
55+
},
56+
"configurations": {
57+
"production": {
58+
"browserTarget": "print-lib:build:production"
59+
}
60+
}
61+
},
62+
"extract-i18n": {
63+
"builder": "@angular-devkit/build-angular:extract-i18n",
64+
"options": {
65+
"browserTarget": "print-lib:build"
66+
}
67+
},
68+
"test": {
69+
"builder": "@angular-devkit/build-angular:karma",
70+
"options": {
71+
"main": "src/test.ts",
72+
"polyfills": "src/polyfills.ts",
73+
"tsConfig": "src/tsconfig.spec.json",
74+
"karmaConfig": "src/karma.conf.js",
75+
"styles": [
76+
"src/styles.css"
77+
],
78+
"scripts": [],
79+
"assets": [
80+
"src/favicon.ico",
81+
"src/assets"
82+
]
83+
}
84+
},
85+
"lint": {
86+
"builder": "@angular-devkit/build-angular:tslint",
87+
"options": {
88+
"tsConfig": [
89+
"src/tsconfig.app.json",
90+
"src/tsconfig.spec.json"
91+
],
92+
"exclude": [
93+
"**/node_modules/**"
94+
]
95+
}
96+
}
97+
}
98+
},
99+
"print-lib-e2e": {
100+
"root": "e2e/",
101+
"projectType": "application",
102+
"architect": {
103+
"e2e": {
104+
"builder": "@angular-devkit/build-angular:protractor",
105+
"options": {
106+
"protractorConfig": "e2e/protractor.conf.js",
107+
"devServerTarget": "print-lib:serve"
108+
},
109+
"configurations": {
110+
"production": {
111+
"devServerTarget": "print-lib:serve:production"
112+
}
113+
}
114+
},
115+
"lint": {
116+
"builder": "@angular-devkit/build-angular:tslint",
117+
"options": {
118+
"tsConfig": "e2e/tsconfig.e2e.json",
119+
"exclude": [
120+
"**/node_modules/**"
121+
]
122+
}
123+
}
124+
}
125+
},
126+
"ng-thermal-print": {
127+
"root": "projects/ng-thermal-print",
128+
"sourceRoot": "projects/ng-thermal-print/src",
129+
"projectType": "library",
130+
"prefix": "",
131+
"architect": {
132+
"build": {
133+
"builder": "@angular-devkit/build-ng-packagr:build",
134+
"options": {
135+
"tsConfig": "projects/ng-thermal-print/tsconfig.lib.json",
136+
"project": "projects/ng-thermal-print/ng-package.json"
137+
},
138+
"configurations": {
139+
"production": {
140+
"project": "projects/ng-thermal-print/ng-package.prod.json"
141+
}
142+
}
143+
},
144+
"test": {
145+
"builder": "@angular-devkit/build-angular:karma",
146+
"options": {
147+
"main": "projects/ng-thermal-print/src/test.ts",
148+
"tsConfig": "projects/ng-thermal-print/tsconfig.spec.json",
149+
"karmaConfig": "projects/ng-thermal-print/karma.conf.js"
150+
}
151+
},
152+
"lint": {
153+
"builder": "@angular-devkit/build-angular:tslint",
154+
"options": {
155+
"tsConfig": [
156+
"projects/ng-thermal-print/tsconfig.lib.json",
157+
"projects/ng-thermal-print/tsconfig.spec.json"
158+
],
159+
"exclude": [
160+
"**/node_modules/**"
161+
]
162+
}
163+
}
164+
}
165+
}
166+
},
167+
"defaultProject": "print-lib"
168+
}

e2e/protractor.conf.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Protractor configuration file, see link for more information
2+
// https://github.com/angular/protractor/blob/master/lib/config.ts
3+
4+
const { SpecReporter } = require('jasmine-spec-reporter');
5+
6+
exports.config = {
7+
allScriptsTimeout: 11000,
8+
specs: [
9+
'./src/**/*.e2e-spec.ts'
10+
],
11+
capabilities: {
12+
'browserName': 'chrome'
13+
},
14+
directConnect: true,
15+
baseUrl: 'http://localhost:4200/',
16+
framework: 'jasmine',
17+
jasmineNodeOpts: {
18+
showColors: true,
19+
defaultTimeoutInterval: 30000,
20+
print: function() {}
21+
},
22+
onPrepare() {
23+
require('ts-node').register({
24+
project: require('path').join(__dirname, './tsconfig.e2e.json')
25+
});
26+
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27+
}
28+
};

e2e/src/app.e2e-spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AppPage } from './app.po';
2+
3+
describe('workspace-project App', () => {
4+
let page: AppPage;
5+
6+
beforeEach(() => {
7+
page = new AppPage();
8+
});
9+
10+
it('should display welcome message', () => {
11+
page.navigateTo();
12+
expect(page.getParagraphText()).toEqual('Welcome to print-lib!');
13+
});
14+
});

e2e/src/app.po.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { browser, by, element } from 'protractor';
2+
3+
export class AppPage {
4+
navigateTo() {
5+
return browser.get('/');
6+
}
7+
8+
getParagraphText() {
9+
return element(by.css('app-root h1')).getText();
10+
}
11+
}

e2e/tsconfig.e2e.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../out-tsc/app",
5+
"module": "commonjs",
6+
"target": "es5",
7+
"types": [
8+
"jasmine",
9+
"jasminewd2",
10+
"node"
11+
]
12+
}
13+
}

0 commit comments

Comments
 (0)