@esslassi/electron-printer 0.0.3 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +222 -53
- package/binding.gyp +51 -33
- package/lib/electronPrinter.d.ts +33 -0
- package/lib/electronPrinter.js +38 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +17 -1
- package/package.json +47 -33
- package/src/linux_printer.cpp +171 -0
- package/src/linux_printer.h +21 -0
- package/src/mac_printer.cpp +166 -0
- package/src/mac_printer.h +22 -0
- package/src/main.cpp +22 -0
- package/src/print.cpp +272 -0
- package/src/printer_factory.cpp +20 -0
- package/src/printer_factory.h +13 -0
- package/src/printer_interface.h +29 -0
- package/src/windows_printer.cpp +210 -0
- package/src/windows_printer.h +35 -0
- package/.gitattributes +0 -2
- package/Gruntfile.js +0 -80
- package/LICENSE +0 -21
- package/binding.js +0 -244
- package/index.js +0 -1
- package/lib/binding.js +0 -244
- package/printer.js +0 -1
- package/src/hello_world.cc +0 -8
- package/src/macros.hh +0 -53
- package/src/node_printer.cc +0 -31
- package/src/node_printer.hpp +0 -77
- package/src/node_printer_win.cc +0 -586
- package/test/getDefaultPrinterName.test.js +0 -18
- package/test/getPrinters.test.js +0 -26
- package/test/incompleteFunctions.js +0 -56
- package/test/printDirect.test.js +0 -34
- package/test/sayMyName.test.js +0 -21
- package/tools/buildElectronLinux.sh +0 -10
- package/tools/buildElectronWindows.ps1 +0 -20
- package/tools/buildWindows.ps1 +0 -23
- package/tools/generateReleaseBuildsLinux.sh +0 -59
- package/tools/generateReleaseBuildsWindows.ps1 +0 -63
- package/tools/getSourceFiles.py +0 -12
- package/tools/remove_directory.py +0 -27
- package/tsconfig.json +0 -22
- package/types/index.d.ts +0 -56
package/test/printDirect.test.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const assert = require('assert/strict');
|
|
2
|
-
const { test, beforeEach } = require('node:test');
|
|
3
|
-
|
|
4
|
-
let addon;
|
|
5
|
-
let template;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
addon = require('../lib');
|
|
8
|
-
template = "N\nS4\nD15\nq400\nR\nB20,10,0,1,2,30,173,B,\"barcode\"\nP0\n";
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('Ensure printDirect function exists', (t) => {
|
|
12
|
-
assert.ok(addon.printDirect, 'printDirect function should exist');
|
|
13
|
-
assert.strictEqual(typeof addon.printDirect, 'function', 'printDirect should be a function');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('Ensure printDirect throws error when no arguments are passed', (t) => {
|
|
17
|
-
assert.throws(() => {
|
|
18
|
-
addon.printDirect();
|
|
19
|
-
}, /Error/, 'printDirect should throw an error when no arguments are passed');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('Ensure printDirect works properly', (t) => {
|
|
23
|
-
let barcode_text = "123";
|
|
24
|
-
let printer_name = addon.getDefaultPrinterName();
|
|
25
|
-
addon.printDirect({
|
|
26
|
-
data:template.replace(/barcode/, barcode_text)
|
|
27
|
-
, printer:printer_name
|
|
28
|
-
, type: "RAW"
|
|
29
|
-
, success:function(){
|
|
30
|
-
console.log("printed: "+barcode_text);
|
|
31
|
-
}
|
|
32
|
-
, error:function(err){console.log(err);}
|
|
33
|
-
});
|
|
34
|
-
});
|
package/test/sayMyName.test.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const assert = require('assert/strict');
|
|
2
|
-
const { test, beforeEach } = require('node:test');
|
|
3
|
-
|
|
4
|
-
let addon;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
addon = require('../lib');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('Ensure addon is loaded correctly', (t) => {
|
|
11
|
-
assert.ok(addon, 'Addon should be loaded');
|
|
12
|
-
assert.strictEqual(typeof addon, 'object', 'Addon should be an object');
|
|
13
|
-
// Add checks for specific functions if needed
|
|
14
|
-
assert.strictEqual(typeof addon.sayMyName, 'function', 'Addon should have sayMyName');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Additional test cases
|
|
18
|
-
test('Test sayMyName behavior', (t) => {
|
|
19
|
-
const result = addon.sayMyName();
|
|
20
|
-
assert.strictEqual(result, 'Hello, From C++ !', 'sayMyName should return "Hello, From C++ !"');
|
|
21
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
VERSION=$1
|
|
3
|
-
|
|
4
|
-
# # Build Electron Linux 64bit
|
|
5
|
-
node-pre-gyp configure --target=$VERSION --arch=x64 --dist-url=https://electronjs.org/headers --module_name=node_printer --module_path=../lib/
|
|
6
|
-
node-pre-gyp build package --runtime=electron --target=$VERSION --target_arch=x64 --build-from-source
|
|
7
|
-
|
|
8
|
-
# #Build Electron Linux 32bit
|
|
9
|
-
node-pre-gyp configure --target=$VERSION --arch=ia32 --dist-url=https://electronjs.org/headers --module_name=node_printer --module_path=../lib/
|
|
10
|
-
node-pre-gyp build package --runtime=electron --target=$VERSION --target_arch=ia32 --build-from-source
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Usage: buildElectronWindows.ps1 <version>
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
if ($args.Length -ne 1) {
|
|
6
|
-
echo "Must Supply only 1 argument - Version"
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$version = $args[0]
|
|
11
|
-
|
|
12
|
-
echo "Building Electron Version -> $version"
|
|
13
|
-
|
|
14
|
-
# Build Electron Windows 64bit
|
|
15
|
-
../node_modules\.bin\node-pre-gyp.cmd configure --target=$version --arch=x64 --dist-url=https://electronjs.org/headers --module_name=node_printer
|
|
16
|
-
../node_modules\.bin\node-pre-gyp.cmd build package --runtime=electron --target=$version --target_arch=x64 --build-from-source
|
|
17
|
-
|
|
18
|
-
# Build Electron Windows 32bit
|
|
19
|
-
../node_modules\.bin\node-pre-gyp.cmd configure --target=$version --arch=ia32 --dist-url=https://electronjs.org/headers --module_name=node_printer
|
|
20
|
-
../node_modules\.bin\node-pre-gyp.cmd build package --runtime=electron --target=$version --target_arch=ia32 --build-from-source
|
package/tools/buildWindows.ps1
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Build Win32 64bit
|
|
2
|
-
# node_modules\.bin\node-pre-gyp.cmd configure --target=$env:nodejs_version
|
|
3
|
-
# node_modules\.bin\node-pre-gyp.cmd build package --target=$env:nodejs_version --target_arch=x64
|
|
4
|
-
|
|
5
|
-
# Build Win32 32bit
|
|
6
|
-
# node_modules\.bin\node-pre-gyp.cmd configure --target=$env:nodejs_version
|
|
7
|
-
# node_modules\.bin\node-pre-gyp.cmd build package --target=$env:nodejs_version --target_arch=ia32
|
|
8
|
-
|
|
9
|
-
if ($env:build_electron -ne "true") {
|
|
10
|
-
echo "Skipping Electron Build as flag not set"
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
# Build Electron Versions
|
|
15
|
-
./tools/buildElectronWindows.ps1 1.2.8
|
|
16
|
-
./tools/buildElectronWindows.ps1 1.3.8
|
|
17
|
-
./tools/buildElectronWindows.ps1 1.4.6
|
|
18
|
-
./tools/buildElectronWindows.ps1 1.7.12
|
|
19
|
-
./tools/buildElectronWindows.ps1 2.0.18
|
|
20
|
-
./tools/buildElectronWindows.ps1 3.1.13
|
|
21
|
-
./tools/buildElectronWindows.ps1 4.2.10
|
|
22
|
-
./tools/buildElectronWindows.ps1 5.0.10
|
|
23
|
-
./tools/buildElectronWindows.ps1 6.0.7
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
RELEASE_VERSION=$1
|
|
4
|
-
PACKAGE_VERSION=$(node -pe "require('./package.json').version")
|
|
5
|
-
SOURCE_PATH="${BASH_SOURCE%/*}/.."
|
|
6
|
-
|
|
7
|
-
declare -a node_versions=(
|
|
8
|
-
"0.10.48"
|
|
9
|
-
"0.12.18"
|
|
10
|
-
"4.9.1"
|
|
11
|
-
"5.9.1"
|
|
12
|
-
"6.17.1"
|
|
13
|
-
"8.16.1"
|
|
14
|
-
"10.16.0"
|
|
15
|
-
"11.15.0"
|
|
16
|
-
"12.10.0"
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
declare -a electron_versions=(
|
|
20
|
-
"1.2.8"
|
|
21
|
-
"1.3.8"
|
|
22
|
-
"1.4.6"
|
|
23
|
-
"1.7.12"
|
|
24
|
-
"2.0.18"
|
|
25
|
-
"3.1.13"
|
|
26
|
-
"4.2.10"
|
|
27
|
-
"5.0.10"
|
|
28
|
-
"6.0.7"
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
# remove old build directory
|
|
32
|
-
rm -rf "$SOURCHE_PATH/build" > /dev/null
|
|
33
|
-
|
|
34
|
-
# create release path
|
|
35
|
-
mkdir -p "$SOURCE_PATH/releases/$RELEASE_VERSION" > /dev/null
|
|
36
|
-
|
|
37
|
-
for version in "${node_versions[@]}"
|
|
38
|
-
do
|
|
39
|
-
echo "Building for node version: $version..."
|
|
40
|
-
node-pre-gyp configure --target=$version --module_name=node_printer --silent
|
|
41
|
-
node-pre-gyp build package --target=$version --target_arch=x64 --build-from-source --silent
|
|
42
|
-
node-pre-gyp configure --target=$version --module_name=node_printer --silent
|
|
43
|
-
node-pre-gyp build package --target=$version --target_arch=ia32 --build-from-source --silent
|
|
44
|
-
rsync -a -v "$SOURCE_PATH/build/stage/$PACKAGE_VERSION/" "$SOURCE_PATH/releases/$RELEASE_VERSION/" --remove-source-files > /dev/null
|
|
45
|
-
echo "Done"
|
|
46
|
-
done
|
|
47
|
-
|
|
48
|
-
for version in "${electron_versions[@]}"
|
|
49
|
-
do
|
|
50
|
-
echo "Building for electron version: $version..."
|
|
51
|
-
node-pre-gyp configure --target=$version --dist-url=https://electronjs.org/headers --module_name=node_printer --silent
|
|
52
|
-
node-pre-gyp build package --target=$version --target_arch=x64 --runtime=electron --build-from-source --silent
|
|
53
|
-
node-pre-gyp configure --target=$version --dist-url=https://electronjs.org/headers --module_name=node_printer --silent
|
|
54
|
-
node-pre-gyp build package --target=$version --target_arch=ia32 --runtime=electron --build-from-source --silent
|
|
55
|
-
rsync -a -v "$SOURCE_PATH/build/stage/$PACKAGE_VERSION/" "$SOURCE_PATH/releases/$RELEASE_VERSION/" --remove-source-files > /dev/null
|
|
56
|
-
echo "Done"
|
|
57
|
-
done
|
|
58
|
-
|
|
59
|
-
echo "Finished succesfully!"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
param (
|
|
2
|
-
[Parameter(Mandatory=$true)][string]$release
|
|
3
|
-
)
|
|
4
|
-
|
|
5
|
-
$SOURCE_PATH = split-path -parent $MyInvocation.MyCommand.Definition
|
|
6
|
-
$RELEASE_VERSION = $release
|
|
7
|
-
$PACKAGE_VERSION = node -pe "require('./package.json').version"
|
|
8
|
-
|
|
9
|
-
echo $SOURCE_PATH
|
|
10
|
-
|
|
11
|
-
$node_versions = @(
|
|
12
|
-
"0.10.48",
|
|
13
|
-
"0.12.18",
|
|
14
|
-
"4.9.1",
|
|
15
|
-
"5.9.1",
|
|
16
|
-
"6.17.1",
|
|
17
|
-
"8.16.1",
|
|
18
|
-
"10.16.0",
|
|
19
|
-
"11.15.0",
|
|
20
|
-
"12.10.0"
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
$electron_versions = @(
|
|
24
|
-
"1.2.8",
|
|
25
|
-
"1.3.8",
|
|
26
|
-
"1.4.6",
|
|
27
|
-
"1.7.12",
|
|
28
|
-
"2.0.18",
|
|
29
|
-
"3.1.13",
|
|
30
|
-
"4.2.10",
|
|
31
|
-
"5.0.10",
|
|
32
|
-
"6.0.7",
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
# remove old build directory
|
|
36
|
-
Remove-Item -Recurse -Force $SOURCE_PATH'\..\build' -ErrorAction Ignore | Out-Null
|
|
37
|
-
|
|
38
|
-
# create release path
|
|
39
|
-
New-Item $SOURCE_PATH'\..\releases\'$RELEASE_VERSION -ItemType Directory -ea 0 | Out-Null
|
|
40
|
-
|
|
41
|
-
foreach ($version in $node_versions) {
|
|
42
|
-
Write-Output "Building for node version: $version..."
|
|
43
|
-
node-pre-gyp configure --target=$version --module_name=node_printer --silent | Out-Null
|
|
44
|
-
node-pre-gyp build package --target=$version --target_arch=x64 --build-from-source --silent | Out-Null
|
|
45
|
-
node-pre-gyp configure --target=$version --module_name=node_printer --silent | Out-Null
|
|
46
|
-
node-pre-gyp build package --target=$version --target_arch=ia32 --build-from-source --silent | Out-Null
|
|
47
|
-
Copy-item -Force -Recurse $SOURCE_PATH'\..\build\stage\'$PACKAGE_VERSION\* -Destination $SOURCE_PATH'\..\releases\'$RELEASE_VERSION -ErrorAction Ignore | Out-Null
|
|
48
|
-
Remove-Item -Recurse -Force $SOURCE_PATH'\..\build\stage' | Out-Null
|
|
49
|
-
Write-Output "Done"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
foreach ($version in $electron_versions) {
|
|
53
|
-
Write-Output "Building for electron version: $version..."
|
|
54
|
-
node-pre-gyp configure --target=$version --dist-url=https://electronjs.org/headers --module_name=node_printer --silent | Out-Null
|
|
55
|
-
node-pre-gyp build package --target=$version --target_arch=x64 --runtime=electron --build-from-source --silent | Out-Null
|
|
56
|
-
node-pre-gyp configure --target=$version --dist-url=https://electronjs.org/headers --module_name=node_printer --silent | Out-Null
|
|
57
|
-
node-pre-gyp build package --target=$version --target_arch=ia32 --runtime=electron --build-from-source --silent | Out-Null
|
|
58
|
-
Copy-item -Force -Recurse $SOURCE_PATH'\..\build\stage\'$PACKAGE_VERSION\* -Destination $SOURCE_PATH'\..\releases\'$RELEASE_VERSION -ErrorAction Ignore | Out-Null
|
|
59
|
-
Remove-Item -Recurse -Force $SOURCE_PATH'\..\build\stage' | Out-Null
|
|
60
|
-
Write-Output "Done"
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Write-Output "Finished succesfully!"
|
package/tools/getSourceFiles.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# simple python command to list files like ls -1
|
|
2
|
-
import os, sys
|
|
3
|
-
|
|
4
|
-
if len(sys.argv) < 3:
|
|
5
|
-
sys.stderr.write('use: '+sys.argv[0]+' <path> <ext>. e.g.:'+sys.argv[0]+' src cc\n')
|
|
6
|
-
sys.exit(1)
|
|
7
|
-
folder = sys.argv[1]
|
|
8
|
-
file_ext = '.'+sys.argv[2]
|
|
9
|
-
|
|
10
|
-
for file in os.listdir(folder):
|
|
11
|
-
if (file.endswith(file_ext)):
|
|
12
|
-
print(folder+'/'+file)
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import shutil
|
|
2
|
-
import sys
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
def remove_directory(directory):
|
|
6
|
-
try:
|
|
7
|
-
shutil.rmtree(directory)
|
|
8
|
-
except OSError as e:
|
|
9
|
-
print(f"Error: {directory} : {e.strerror}")
|
|
10
|
-
sys.exit(1)
|
|
11
|
-
|
|
12
|
-
if __name__ == "__main__":
|
|
13
|
-
# Check if the directory argument is provided
|
|
14
|
-
if len(sys.argv) < 2:
|
|
15
|
-
print("Usage: python remove_directory.py <directory>")
|
|
16
|
-
sys.exit(1)
|
|
17
|
-
|
|
18
|
-
# Get the directory to remove from command line argument
|
|
19
|
-
directory = sys.argv[1]
|
|
20
|
-
|
|
21
|
-
# Check if the directory exists
|
|
22
|
-
if not os.path.exists(directory):
|
|
23
|
-
print(f"Error: Directory '{directory}' does not exist.")
|
|
24
|
-
sys.exit(1)
|
|
25
|
-
|
|
26
|
-
# Call the function to remove the directory
|
|
27
|
-
remove_directory(directory)
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"lib": [
|
|
5
|
-
"es6"
|
|
6
|
-
],
|
|
7
|
-
"noImplicitAny": true,
|
|
8
|
-
"noImplicitThis": true,
|
|
9
|
-
"strictFunctionTypes": true,
|
|
10
|
-
"strictNullChecks": true,
|
|
11
|
-
"baseUrl": "../",
|
|
12
|
-
"typeRoots": [
|
|
13
|
-
"../"
|
|
14
|
-
],
|
|
15
|
-
"types": [],
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
"forceConsistentCasingInFileNames": true
|
|
18
|
-
},
|
|
19
|
-
"files": [
|
|
20
|
-
"types/index.d.ts",
|
|
21
|
-
]
|
|
22
|
-
}
|
package/types/index.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export function getPrinters(): PrinterDetails[];
|
|
2
|
-
export function getPrinter(printerName: string): PrinterDetails;
|
|
3
|
-
export function getPrinterDriverOptions(printerName: string): PrinterDriverOptions;
|
|
4
|
-
export function getSelectedPaperSize(printerName: string): string;
|
|
5
|
-
export function getDefaultPrinterName(): string | undefined;
|
|
6
|
-
export function printDirect(options: PrintDirectOptions): void;
|
|
7
|
-
export function printFile(options: PrintFileOptions): void;
|
|
8
|
-
export function getSupportedPrintFormats(): string[];
|
|
9
|
-
export function getJob(printerName: string, jobId: number): JobDetails;
|
|
10
|
-
export function setJob(printerName: string, jobId: number, command: 'CANCEL' | string): void;
|
|
11
|
-
export function getSupportedJobCommands(): string[];
|
|
12
|
-
|
|
13
|
-
export interface PrintDirectOptions {
|
|
14
|
-
data: string | Buffer;
|
|
15
|
-
printer?: string | undefined;
|
|
16
|
-
type?: 'RAW' | 'TEXT' | 'PDF' | 'JPEG' | 'POSTSCRIPT' | 'COMMAND' | 'AUTO' | undefined;
|
|
17
|
-
options?: { [key: string]: string } | undefined;
|
|
18
|
-
success?: PrintOnSuccessFunction | undefined;
|
|
19
|
-
error?: PrintOnErrorFunction | undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface PrintFileOptions {
|
|
23
|
-
filename: string;
|
|
24
|
-
printer?: string | undefined;
|
|
25
|
-
success?: PrintOnSuccessFunction | undefined;
|
|
26
|
-
error?: PrintOnErrorFunction | undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type PrintOnSuccessFunction = (jobId: string) => any;
|
|
30
|
-
export type PrintOnErrorFunction = (err: Error) => any;
|
|
31
|
-
|
|
32
|
-
export interface PrinterDetails {
|
|
33
|
-
name: string;
|
|
34
|
-
isDefault: boolean;
|
|
35
|
-
options: { [key: string]: string; };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface PrinterDriverOptions {
|
|
39
|
-
[key: string]: { [key: string]: boolean; };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface JobDetails {
|
|
43
|
-
id: number;
|
|
44
|
-
name: string;
|
|
45
|
-
printerName: string;
|
|
46
|
-
user: string;
|
|
47
|
-
format: string;
|
|
48
|
-
priority: number;
|
|
49
|
-
size: number;
|
|
50
|
-
status: JobStatus[];
|
|
51
|
-
completedTime: Date;
|
|
52
|
-
creationTime: Date;
|
|
53
|
-
processingTime: Date;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type JobStatus = 'PAUSED' | 'PRINTING' | 'PRINTED' | 'CANCELLED' | 'PENDING' | 'ABORTED';
|