Skip to content

Commit 011fd03

Browse files
authored
Fix missing Printer methods, update examples to match 0.7 (#147)
* Fix missing Printer methods, update examples to match 0.7 * bump * Update examples to use sample image * Update code coverage to ignore scripts and examples
1 parent 03ff8ec commit 011fd03

File tree

15 files changed

+122
-189
lines changed

15 files changed

+122
-189
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "printers-js"
33
authors = ["Evan Simkowitz <[email protected]>"]
4-
version = "0.7.0"
4+
version = "0.7.1"
55
edition = "2021"
66
publish = false
77

examples/bun/main.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
*/
66

77
import {
8-
cleanupOldJobs,
98
getAllPrinterNames,
109
getAllPrinters,
1110
getPrinterByName,
12-
getPrinterJob,
1311
isSimulationMode,
1412
runtimeInfo,
1513
shutdown,
1614
type PrinterJob,
1715
} from "@printers/printers";
16+
import { CUPSOptions } from "../../src";
1817

1918
async function main() {
2019
console.log("🥟 Bun Printers Example");
@@ -47,8 +46,17 @@ async function main() {
4746

4847
for (const printer of printers) {
4948
console.log(` Name: ${printer.name}`);
49+
console.log(` System Name: ${printer.systemName || "Unknown"}`);
50+
console.log(` Driver: ${printer.driverName || "Unknown"}`);
51+
console.log(` Description: ${printer.description || "None"}`);
52+
console.log(` Location: ${printer.location || "Not specified"}`);
5053
console.log(` Default: ${printer.isDefault ? "Yes" : "No"}`);
54+
console.log(` Shared: ${printer.isShared ? "Yes" : "No"}`);
5155
console.log(` State: ${printer.state || "Unknown"}`);
56+
if (printer.stateReasons && printer.stateReasons.length > 0) {
57+
console.log(` State Reasons: ${printer.stateReasons.join(", ")}`);
58+
}
59+
console.log(` Exists: ${printer.exists() ? "Yes" : "No"}`);
5260
console.log(" ---");
5361
}
5462

@@ -61,17 +69,23 @@ async function main() {
6169
// Submit multiple print jobs with different options
6270
console.log("📄 Submitting print jobs...");
6371

64-
const jobId1 = await printer.printFile("document.pdf", {
65-
"job-name": "PDF Document",
66-
copies: "2",
67-
"paper-size": "A4",
72+
const jobId1 = await printer.printFile("../sample-image.png", {
73+
jobName: "Sample Image",
74+
simple: {
75+
copies: 2,
76+
paperSize: "Letter",
77+
quality: "high",
78+
},
6879
});
6980

7081
const jobId2 = await printer.printBytes(
7182
new Uint8Array([72, 101, 108, 108, 111]), // "Hello"
7283
{
73-
"job-name": "Raw Text Job",
74-
copies: "1",
84+
jobName: "Raw Text Job",
85+
cups: {
86+
copies: 1,
87+
"media-size": "Letter",
88+
},
7589
}
7690
);
7791

@@ -125,8 +139,12 @@ async function main() {
125139

126140
// Feature 7: Job Cleanup
127141
console.log("\n🧹 Cleanup:");
128-
const cleaned = cleanupOldJobs(3600); // 1 hour
129-
console.log(` Cleaned up ${cleaned} old print job(s)`);
142+
if (printers.length > 0) {
143+
const cleaned = printers[0].cleanupOldJobs(3600); // 1 hour
144+
console.log(
145+
` Cleaned up ${cleaned} old print job(s) for ${printers[0].name}`
146+
);
147+
}
130148

131149
// Feature 8: Printer Comparison
132150
if (printers.length >= 2) {

examples/bun/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "bun --watch main.ts"
1010
},
1111
"dependencies": {
12-
"@printers/printers": "^0.6.0"
12+
"@printers/printers": "^0.7"
1313
},
1414
"engines": {
1515
"bun": ">= 1.0"

examples/deno/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dev": "deno run --allow-env --allow-read --allow-net --allow-ffi --watch main.ts"
55
},
66
"imports": {
7-
"@printers/printers": "npm:@printers/printers@^0.6"
7+
"@printers/printers": "npm:@printers/printers@^0.7"
88
},
99
"nodeModulesDir": "auto",
1010
"compilerOptions": {

examples/deno/main.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
*/
66

77
import {
8-
cleanupOldJobs,
98
getAllPrinterNames,
109
getAllPrinters,
1110
getPrinterByName,
12-
getPrinterJob,
1311
isSimulationMode,
1412
runtimeInfo,
1513
type PrinterJob,
@@ -46,8 +44,17 @@ async function main() {
4644

4745
for (const printer of printers) {
4846
console.log(` Name: ${printer.name}`);
47+
console.log(` System Name: ${printer.systemName || "Unknown"}`);
48+
console.log(` Driver: ${printer.driverName || "Unknown"}`);
49+
console.log(` Description: ${printer.description || "None"}`);
50+
console.log(` Location: ${printer.location || "Not specified"}`);
4951
console.log(` Default: ${printer.isDefault ? "Yes" : "No"}`);
52+
console.log(` Shared: ${printer.isShared ? "Yes" : "No"}`);
5053
console.log(` State: ${printer.state || "Unknown"}`);
54+
if (printer.stateReasons && printer.stateReasons.length > 0) {
55+
console.log(` State Reasons: ${printer.stateReasons.join(", ")}`);
56+
}
57+
console.log(` Exists: ${printer.exists() ? "Yes" : "No"}`);
5158
console.log(" ---");
5259
}
5360

@@ -60,17 +67,23 @@ async function main() {
6067
// Submit multiple print jobs with different options
6168
console.log("📄 Submitting print jobs...");
6269

63-
const jobId1 = await printer.printFile("document.pdf", {
64-
"job-name": "PDF Document",
65-
copies: "2",
66-
"paper-size": "A4",
70+
const jobId1 = await printer.printFile("../sample-image.png", {
71+
jobName: "Sample Image",
72+
simple: {
73+
copies: 2,
74+
paperSize: "Letter",
75+
quality: "high",
76+
},
6777
});
6878

6979
const jobId2 = await printer.printBytes(
7080
new Uint8Array([72, 101, 108, 108, 111]), // "Hello"
7181
{
72-
"job-name": "Raw Text Job",
73-
copies: "1",
82+
jobName: "Raw Text Job",
83+
cups: {
84+
copies: 1,
85+
"media-size": "Letter",
86+
},
7487
}
7588
);
7689

@@ -126,22 +139,32 @@ async function main() {
126139

127140
// Feature 7: Job Cleanup
128141
console.log("\n🧹 Cleanup:");
129-
const cleaned = cleanupOldJobs(3600); // 1 hour
130-
console.log(` Cleaned up ${cleaned} old print job(s)`);
142+
if (printers.length > 0) {
143+
const cleaned = printers[0].cleanupOldJobs(3600); // 1 hour
144+
console.log(
145+
` Cleaned up ${cleaned} old print job(s) for ${printers[0].name}`
146+
);
147+
}
131148

132-
// Feature 8: Printer Comparison
133-
if (printers.length >= 2) {
134-
console.log("\n🔄 Printer Comparison:");
149+
// Feature 8: Printer Comparison & Methods
150+
if (printers.length >= 1) {
151+
console.log("\n🔄 Printer Interface Demo:");
135152
const printer1 = printers[0];
136-
const printer2 = printers[1];
137153
const samePrinter = getPrinterByName(printer1.name);
138154

155+
console.log(` getName(): ${printer1.getName()}`);
156+
console.log(` toString(): ${printer1.toString()}`);
157+
console.log(` exists(): ${printer1.exists()}`);
139158
console.log(
140-
` ${printer1.name} equals ${printer2.name}: ${printer1.equals(printer2)}`
141-
);
142-
console.log(
143-
` ${printer1.name} equals itself: ${samePrinter?.equals(printer1) ?? false}`
159+
` equals(samePrinter): ${samePrinter?.equals(printer1) ?? false}`
144160
);
161+
162+
if (printers.length >= 2) {
163+
const printer2 = printers[1];
164+
console.log(
165+
` ${printer1.name} equals ${printer2.name}: ${printer1.equals(printer2)}`
166+
);
167+
}
145168
}
146169
} catch (error) {
147170
console.error(

examples/node/main.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
*/
66

77
import {
8-
cleanupOldJobs,
98
getAllPrinterNames,
109
getAllPrinters,
1110
getPrinterByName,
12-
getPrinterJob,
1311
isSimulationMode,
1412
runtimeInfo,
1513
} from "@printers/printers";
@@ -45,8 +43,17 @@ async function main() {
4543

4644
for (const printer of printers) {
4745
console.log(` Name: ${printer.name}`);
46+
console.log(` System Name: ${printer.systemName || "Unknown"}`);
47+
console.log(` Driver: ${printer.driverName || "Unknown"}`);
48+
console.log(` Description: ${printer.description || "None"}`);
49+
console.log(` Location: ${printer.location || "Not specified"}`);
4850
console.log(` Default: ${printer.isDefault ? "Yes" : "No"}`);
51+
console.log(` Shared: ${printer.isShared ? "Yes" : "No"}`);
4952
console.log(` State: ${printer.state || "Unknown"}`);
53+
if (printer.stateReasons && printer.stateReasons.length > 0) {
54+
console.log(` State Reasons: ${printer.stateReasons.join(", ")}`);
55+
}
56+
console.log(` Exists: ${printer.exists() ? "Yes" : "No"}`);
5057
console.log(" ---");
5158
}
5259

@@ -59,15 +66,21 @@ async function main() {
5966
// Submit multiple print jobs with different options
6067
console.log("📄 Submitting print jobs...");
6168

62-
const jobId1 = await printer.printFile("document.pdf", {
63-
"job-name": "PDF Document",
64-
copies: "2",
65-
"paper-size": "A4",
69+
const jobId1 = await printer.printFile("../sample-image.png", {
70+
jobName: "Sample Image",
71+
simple: {
72+
copies: 2,
73+
paperSize: "Letter",
74+
quality: "high",
75+
},
6676
});
6777

6878
const jobId2 = await printer.printBytes(Buffer.from("Hello", "utf-8"), {
69-
"job-name": "Raw Text Job",
70-
copies: "1",
79+
jobName: "Raw Text Job",
80+
cups: {
81+
copies: 1,
82+
"media-size": "Letter",
83+
},
7184
});
7285

7386
console.log(` Job 1 ID: ${jobId1}`);
@@ -120,8 +133,12 @@ async function main() {
120133

121134
// Feature 7: Job Cleanup
122135
console.log("\n🧹 Cleanup:");
123-
const cleaned = cleanupOldJobs(3600); // 1 hour
124-
console.log(` Cleaned up ${cleaned} old print job(s)`);
136+
if (printers.length > 0) {
137+
const cleaned = printers[0].cleanupOldJobs(3600); // 1 hour
138+
console.log(
139+
` Cleaned up ${cleaned} old print job(s) for ${printers[0].name}`
140+
);
141+
}
125142

126143
// Feature 8: Printer Comparison
127144
if (printers.length >= 2) {

examples/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "node --watch main.js"
1010
},
1111
"dependencies": {
12-
"@printers/printers": "^0.6"
12+
"@printers/printers": "^0.7"
1313
},
1414
"engines": {
1515
"node": ">= 20"

examples/sample-image.png

3.24 MB
Loading

0 commit comments

Comments
 (0)