@luckykiet/node-printer 1.0.0

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,14 @@
1
+ exports.testLoadLibrary = function(test) {
2
+ test.doesNotThrow(function(){
3
+ printer = require("../");
4
+ });
5
+ test.done();
6
+ }
7
+
8
+ exports.testGetprinters = function(test) {
9
+ printer = require("../");
10
+ test.equal(typeof(printer.getPrinters()), 'object');
11
+ test.done();
12
+ }
13
+
14
+ // TODO: add more tests
@@ -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)
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,57 @@
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
+ options?: { [key: string]: string } | undefined;
26
+ success?: PrintOnSuccessFunction | undefined;
27
+ error?: PrintOnErrorFunction | undefined;
28
+ }
29
+
30
+ export type PrintOnSuccessFunction = (jobId: string) => any;
31
+ export type PrintOnErrorFunction = (err: Error) => any;
32
+
33
+ export interface PrinterDetails {
34
+ name: string;
35
+ isDefault: boolean;
36
+ options: { [key: string]: string; };
37
+ }
38
+
39
+ export interface PrinterDriverOptions {
40
+ [key: string]: { [key: string]: boolean; };
41
+ }
42
+
43
+ export interface JobDetails {
44
+ id: number;
45
+ name: string;
46
+ printerName: string;
47
+ user: string;
48
+ format: string;
49
+ priority: number;
50
+ size: number;
51
+ status: JobStatus[];
52
+ completedTime: Date;
53
+ creationTime: Date;
54
+ processingTime: Date;
55
+ }
56
+
57
+ export type JobStatus = 'PAUSED' | 'PRINTING' | 'PRINTED' | 'CANCELLED' | 'PENDING' | 'ABORTED';