Skip to content

Commit

Permalink
Changes for 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
haavardlian committed Feb 6, 2017
1 parent a283b05 commit 57a5362
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 74 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.2",
"version": "1.0.3",
"name": "escpos-print",
"bugs": {
"url": "https://github.com/haavardlian/escpos/issues"
Expand Down Expand Up @@ -32,6 +32,7 @@
},
"contributors": [],
"devDependencies": {
"@types/fs-extra": "0.0.37",
"@types/iconv-lite": "^0.0.1",
"@types/node": "^6.0.45",
"@types/serialport": "^4.0.6",
Expand All @@ -43,7 +44,8 @@
"get-pixels": "^3.3.0",
"iconv-lite": "^0.4.15",
"mutable-buffer": "^2.0.3",
"serialport": "^4.0.3"
"serialport": "^4.0.3",
"moment": "^2.17.1"
},
"scripts": {
"compile": "tsc",
Expand Down
128 changes: 59 additions & 69 deletions scripts/createPackageDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,75 @@ const path = require('path');
const fse = require('fs-extra');

const files = [
'README.md',
'LICENSE',
'README.md',
'LICENSE',
];

Promise.all(
files.map((file) => copyFile(file))
)
.then(() => createPackageFile());
Promise.all(files.map(file => copyFile(file))).then(() => createPackageFile());

function copyFile(file) {
const buildPath = resolveBuildPath(file);
return new Promise((resolve) => {
fse.copy(
file,
buildPath,
(err) => {
if (err) throw err;
resolve();
}
);
})
.then(() => console.log(`Copied ${file} to ${buildPath}`));
const buildPath = resolveBuildPath(file);
return new Promise(resolve => {
fse.copy(file, buildPath, (err) => {
if (err) throw err;
resolve();
});
})
.then(() => console.log(`Copied ${file} to ${buildPath}`));
}

function resolveBuildPath(file) {
return path.resolve(__dirname, '../dist/', path.basename(file));
return path.resolve(__dirname, '../dist/', path.basename(file));
}

function createPackageFile() {
return new Promise((resolve) => {
fse.readFile(path.resolve(__dirname, '../package.json'), 'utf8', (err, data) => {
if (err) {
throw err;
}

resolve(data);
});
})
.then((data) => JSON.parse(data))
.then((packageData) => {
const {
author,
name,
version,
description,
keywords,
repository,
license,
bugs,
homepage,
peerDependencies,
typings,
dependencies,
} = packageData;
return new Promise((resolve) => {
fse.readFile(path.resolve(__dirname, '../package.json'), 'utf8', (err, data) => {
if (err) throw err;
resolve(data);
});
})
.then((data) => JSON.parse(data))
.then((packageData) => {
const {
author,
name,
version,
description,
keywords,
repository,
license,
bugs,
homepage,
peerDependencies,
typings,
dependencies,
} = packageData;

const minimalPackage = {
name,
author,
version,
description,
main: './index.js',
typings: './index.d.ts',
keywords,
repository,
license,
bugs,
homepage,
peerDependencies,
dependencies,
};
const minimalPackage = {
name,
author,
version,
description,
main: './index.js',
typings: './',
keywords,
repository,
license,
bugs,
homepage,
peerDependencies,
dependencies,
};

return new Promise((resolve) => {
const buildPath = path.resolve(__dirname, '../dist/package.json');
const data = JSON.stringify(minimalPackage, null, 2);
fse.writeFile(buildPath, data, (err) => {
if (err) throw (err);
console.log(`Created package.json in ${buildPath}`);
resolve();
});
return new Promise((resolve) => {
const buildPath = path.resolve(__dirname, '../dist/package.json');
const data = JSON.stringify(minimalPackage, null, 2);
fse.writeFile(buildPath, data, (err) => {
if (err) throw (err);
console.log(`Created package.json in ${buildPath}`);
resolve();
});
});
});
});
}
}
12 changes: 10 additions & 2 deletions src/adapters/Console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Adapter from "../Adapter";

export default class Console extends Adapter {
private numbersPerLine: number;

constructor(numbersPerLine: number = 16) {
super();
this.numbersPerLine = numbersPerLine;
}

public open(): Promise<undefined> {
return new Promise((resolve) => {
resolve();
Expand All @@ -9,8 +16,9 @@ export default class Console extends Adapter {

public write(data: Buffer): Promise<undefined> {
return new Promise((resolve) => {
// tslint:disable-next-line
console.log(data.toString("hex").replace(/(.{2})/g, "$1 ").replace(/(.{48})/g, "$1\n"));
const regex = new RegExp(`/(.{${this.numbersPerLine * 3}})`, "g");
// tslint:disable-next-line no-console
console.log(data.toString("hex").replace(/(.{2})/g, "$1 ").replace(regex, "$1\n"));
resolve();
});
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"typeRoots": ["node_modules/@types"],
"types": ["node", "serialport", "iconv-lite"],
"types": ["node", "serialport", "iconv-lite", "fs-extra"],
"files": [
"src/Adapter.ts",
"src/Adapters.ts",
"src/adapters/Console.ts",
"src/adapters/Network.ts",
"src/adapters/Serial.ts",
"src/adapters/PNG.ts",
"src/Printer.ts",
"src/Commands.ts",
"src/Image.ts",
Expand Down

0 comments on commit 57a5362

Please sign in to comment.