@esslassi/electron-printer 0.0.1

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.
@@ -0,0 +1,26 @@
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 getPrinters function exists', (t) => {
11
+ assert.ok(addon.getPrinters, 'getPrinters function should exist');
12
+ assert.strictEqual(typeof addon.getPrinters, 'function', 'getPrinters should be a function');
13
+ });
14
+
15
+ test('Ensure getPrinters returns an array', (t) => {
16
+ const printers = addon.getPrinters();
17
+ assert.ok(Array.isArray(printers), 'getPrinters should return an array');
18
+ });
19
+
20
+ test('Ensure getPrinters handles no printers scenario', (t) => {
21
+ const printers = addon.getPrinters();
22
+ assert.ok(Array.isArray(printers), 'getPrinters should return an array');
23
+ if (printers.length > 0) {
24
+ assert.strictEqual(typeof printers[0], 'object', 'Each printer should be an object');
25
+ }
26
+ });
@@ -0,0 +1,56 @@
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 Non-functional apis do not lead any issues', (t) => {
11
+ assert.ok(addon, 'Non-functional apis');
12
+ // Add checks for specific functions if needed
13
+ assert.strictEqual(typeof addon.getPrinter, 'function', 'Addon should have getPrinter');
14
+ });
15
+
16
+ // Additional test cases
17
+ test('Test getPrinter behavior', (t) => {
18
+ const result = addon.getPrinter();
19
+ assert.strictEqual(result, 'getPrinter is not implemented yet, request for a PR if required', 'getPrinter is not implemented yet, request for a PR if required"');
20
+ });
21
+
22
+ test('Test printFile behavior', (t) => {
23
+ const filename = process.argv[2] || __filename; // use this file as an input
24
+ if( process.platform != 'win32') {
25
+ addon.printFile({filename:filename,
26
+ printer: process.env[3], // printer name, if missing then will print to default printer
27
+ success:function(jobID){
28
+ console.log("addon.printFile: Job ID: "+jobID);
29
+ },
30
+ error:function(err){
31
+ console.log(err);
32
+ }
33
+ });
34
+ } else {
35
+ // not yet implemented, use printDirect and text
36
+ var fs = require('fs');
37
+ addon.printDirect({data:fs.readFileSync(filename),
38
+ printer: addon.getDefaultPrinterName(), // printer name, if missing then will print to default printer
39
+ type: "RAW",
40
+ success:function(jobID){
41
+ assert.equal(jobID>0, true, 'addon.printFile');
42
+ },
43
+ error:function(err){
44
+ console.log(err);
45
+ assert.strictEqual(!err, true, 'addon.printFile'); // failed test case
46
+ }
47
+ });
48
+ }
49
+ });
50
+
51
+ // getSupportedPrintFormats
52
+ test('Test getSupportedPrintFormats behavior', (t) => {
53
+ assert.throws(() => {
54
+ addon.getSupportedPrintFormats();
55
+ }, /Error/, 'getSupportedPrintFormats should throw an error when no arguments are passed');
56
+ });
@@ -0,0 +1,34 @@
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
+ });
@@ -0,0 +1,21 @@
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
+ });
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,59 @@
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!"
@@ -0,0 +1,63 @@
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!"
@@ -0,0 +1,12 @@
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)
@@ -0,0 +1,27 @@
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 ADDED
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,56 @@
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';