node-thermal-printer-js 1.2.1 ā 1.2.2
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/package.json +1 -6
- package/scripts/install-deps.js +0 -177
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-thermal-printer-js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "ESC/POS printer helper for PSF588 Bluetooth and COM printing.",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,18 +11,13 @@
|
|
|
11
11
|
"ble_print.py",
|
|
12
12
|
"ble_scan.py",
|
|
13
13
|
"ble_server.py",
|
|
14
|
-
"scripts/install-deps.js",
|
|
15
14
|
"README.md"
|
|
16
15
|
],
|
|
17
16
|
"scripts": {
|
|
18
|
-
"postinstall": "node scripts/install-deps.js",
|
|
19
17
|
"test": "node test-api.js",
|
|
20
18
|
"dev": "node --watch app.js",
|
|
21
19
|
"pack:dry": "npm pack --dry-run"
|
|
22
20
|
},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=16.0.0"
|
|
25
|
-
},
|
|
26
21
|
"keywords": [
|
|
27
22
|
"printer",
|
|
28
23
|
"escpos",
|
package/scripts/install-deps.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Postinstall script to verify and auto-install Python dependencies
|
|
4
|
-
* Runs: npm install --> postinstall hook
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { spawnSync } from "node:child_process";
|
|
8
|
-
import { existsSync } from "node:fs";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
|
|
12
|
-
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
|
|
14
|
-
const findPythonCmd = () => {
|
|
15
|
-
const localVenvCandidates =
|
|
16
|
-
process.platform === "win32"
|
|
17
|
-
? [
|
|
18
|
-
{
|
|
19
|
-
cmd: path.join(scriptDir, ".venv", "Scripts", "python.exe"),
|
|
20
|
-
args: [],
|
|
21
|
-
},
|
|
22
|
-
{ cmd: path.join(scriptDir, ".venv", "Scripts", "python"), args: [] },
|
|
23
|
-
]
|
|
24
|
-
: [
|
|
25
|
-
{ cmd: path.join(scriptDir, ".venv", "bin", "python"), args: [] },
|
|
26
|
-
{ cmd: path.join(scriptDir, ".venv", "bin", "python3"), args: [] },
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const systemCandidates =
|
|
30
|
-
process.platform === "win32"
|
|
31
|
-
? [
|
|
32
|
-
{ cmd: "py", args: ["-3.11"] },
|
|
33
|
-
{ cmd: "py", args: ["-3"] },
|
|
34
|
-
{ cmd: "py", args: [] },
|
|
35
|
-
{ cmd: "python3", args: [] },
|
|
36
|
-
{ cmd: "python", args: [] },
|
|
37
|
-
]
|
|
38
|
-
: [
|
|
39
|
-
{ cmd: "python3", args: [] },
|
|
40
|
-
{ cmd: "python", args: [] },
|
|
41
|
-
{ cmd: "py", args: [] },
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
const candidates = [
|
|
45
|
-
...localVenvCandidates.filter((candidate) => existsSync(candidate.cmd)),
|
|
46
|
-
...systemCandidates,
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
for (const candidate of candidates) {
|
|
50
|
-
try {
|
|
51
|
-
const result = spawnSync(
|
|
52
|
-
candidate.cmd,
|
|
53
|
-
[...candidate.args, "--version"],
|
|
54
|
-
{
|
|
55
|
-
encoding: "utf8",
|
|
56
|
-
stdio: "pipe",
|
|
57
|
-
timeout: 2000,
|
|
58
|
-
shell: false,
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Skip if command failed or timed out
|
|
63
|
-
if (result.status !== 0 || result.error) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const version = `${result.stdout || ""}${result.stderr || ""}`.trim();
|
|
68
|
-
// Check if Python 3.9+
|
|
69
|
-
const match = version.match(/Python (\d+)\.(\d+)/);
|
|
70
|
-
if (match) {
|
|
71
|
-
const major = parseInt(match[1], 10);
|
|
72
|
-
const minor = parseInt(match[2], 10);
|
|
73
|
-
if (major > 3 || (major === 3 && minor >= 9)) {
|
|
74
|
-
console.log(
|
|
75
|
-
`ā Found ${candidate.cmd} ${candidate.args.join(" ")} (${version})`,
|
|
76
|
-
);
|
|
77
|
-
return candidate;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
} catch {
|
|
81
|
-
// Continue to next candidate
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return null;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const installBleak = (pythonCmd) => {
|
|
89
|
-
console.log(`\nš¦ Installing bleak Python package...`);
|
|
90
|
-
try {
|
|
91
|
-
const result = spawnSync(
|
|
92
|
-
pythonCmd.cmd,
|
|
93
|
-
[...pythonCmd.args, "-m", "pip", "install", "bleak"],
|
|
94
|
-
{
|
|
95
|
-
encoding: "utf8",
|
|
96
|
-
stdio: "inherit",
|
|
97
|
-
timeout: 120000,
|
|
98
|
-
shell: false,
|
|
99
|
-
},
|
|
100
|
-
);
|
|
101
|
-
if (result.status !== 0) {
|
|
102
|
-
throw new Error(`pip exited with code ${result.status ?? "unknown"}`);
|
|
103
|
-
}
|
|
104
|
-
console.log("ā bleak installed successfully");
|
|
105
|
-
return true;
|
|
106
|
-
} catch (err) {
|
|
107
|
-
console.warn("ā Could not auto-install bleak");
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const main = async () => {
|
|
113
|
-
console.log("\nš§ node-thermal-printer postinstall setup\n");
|
|
114
|
-
|
|
115
|
-
// Step 1: Find Python
|
|
116
|
-
console.log("1ļøā£ Checking Python installation...");
|
|
117
|
-
const pythonCmd = findPythonCmd();
|
|
118
|
-
|
|
119
|
-
if (!pythonCmd) {
|
|
120
|
-
console.error("\nā ERROR: Python 3.9+ not found!");
|
|
121
|
-
console.error(
|
|
122
|
-
"\nPlease install Python from https://www.python.org/downloads/",
|
|
123
|
-
);
|
|
124
|
-
console.error("After installing Python, run: npm install again\n");
|
|
125
|
-
process.exit(1);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
console.log(` Using: ${pythonCmd}\n`);
|
|
129
|
-
|
|
130
|
-
// Step 2: Install bleak
|
|
131
|
-
console.log("2ļøā£ Checking bleak dependency...");
|
|
132
|
-
try {
|
|
133
|
-
const importCheck = spawnSync(
|
|
134
|
-
pythonCmd.cmd,
|
|
135
|
-
[...pythonCmd.args, "-c", "import bleak"],
|
|
136
|
-
{
|
|
137
|
-
stdio: "pipe",
|
|
138
|
-
timeout: 2000,
|
|
139
|
-
shell: false,
|
|
140
|
-
},
|
|
141
|
-
);
|
|
142
|
-
if (importCheck.status !== 0) {
|
|
143
|
-
throw new Error("bleak import check failed");
|
|
144
|
-
}
|
|
145
|
-
console.log("ā bleak already installed\n");
|
|
146
|
-
} catch {
|
|
147
|
-
const installed = installBleak(pythonCmd);
|
|
148
|
-
if (!installed) {
|
|
149
|
-
console.error("\nā Manual installation required:");
|
|
150
|
-
console.error(
|
|
151
|
-
` ${pythonCmd.cmd} ${pythonCmd.args.join(" ")} -m pip install bleak\n`,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Step 3: Platform-specific notes
|
|
157
|
-
console.log("3ļøā£ Platform-specific requirements:");
|
|
158
|
-
const platform = process.platform;
|
|
159
|
-
if (platform === "linux") {
|
|
160
|
-
console.log(" š Linux detected - BLE requires group permissions:");
|
|
161
|
-
console.log(" sudo usermod -a -G dialout,plugdev $USER");
|
|
162
|
-
console.log(" (Log out and back in for changes to take effect)\n");
|
|
163
|
-
} else if (platform === "darwin") {
|
|
164
|
-
console.log(" š macOS detected - Ensure Bluetooth is enabled\n");
|
|
165
|
-
} else if (platform === "win32") {
|
|
166
|
-
console.log(
|
|
167
|
-
" š Windows detected - Ensure Bluetooth drivers are installed\n",
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
console.log("ā
Setup complete! You can now use node-thermal-printer-js\n");
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
main().catch((err) => {
|
|
175
|
-
console.error("Error during setup:", err.message);
|
|
176
|
-
process.exit(1);
|
|
177
|
-
});
|