forked from epaderevyanko/electron-printer
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprinter.js
More file actions
40 lines (32 loc) · 1.15 KB
/
Copy pathprinter.js
File metadata and controls
40 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var fs = require('fs');
var path = require('path');
var binary = require('@mapbox/node-pre-gyp');
function findBinding() {
// Try the default node-pre-gyp resolution first.
try {
var resolved = binary.find(path.resolve(path.join(__dirname, './package.json')));
if (resolved && fs.existsSync(resolved)) {
return resolved;
}
} catch (_) {
// Ignore and fall back to manual resolution below.
}
var platform = process.platform;
var arch = process.arch;
var electronVer = process.versions.electron || '';
var releaseDir = path.join(__dirname, 'build', 'Release');
var candidates = [];
if (electronVer) {
candidates.push(path.join(releaseDir, 'electron-v' + electronVer + '-' + platform + '-' + arch, 'node_printer.node'));
}
candidates.push(path.join(releaseDir, 'electron-v-' + platform + '-' + arch, 'node_printer.node'));
var found = candidates.find(function (p) {
return fs.existsSync(p);
});
if (!found) {
throw new Error('node_printer.node not found in: ' + candidates.join(', '));
}
return found;
}
var bindingPath = findBinding();
var printer = exports = module.exports = require(bindingPath);