-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwindows-devinstall.js
72 lines (66 loc) · 2.04 KB
/
windows-devinstall.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import fs from 'fs';
import path from 'path';
import util from 'util';
// Todo: Remove after engines supporting Node 11 (and use fs.promises instead)
const readdir = util.promisify(fs.readdir);
const readFile = util.promisify(fs.readFile);
const writeFile = util.promisify(fs.writeFile);
const isWin = process.platform.startsWith('win');
// Todo: Remove after engines supporting Node 7.6.0
/**
*
* @param {string} fromPath
* @param {string} toPath
* @throws {Error}
* @returns {void}
*/
async function copy (fromPath, toPath) {
let fileContents;
try {
fileContents = await readFile(fromPath);
} catch (err) {
if (err.code === 'ENOENT') {
throw new Error('Could not find ' + fromPath);
}
throw err;
}
try {
return writeFile(toPath, fileContents);
} catch (err) {
if (err.code === 'EEXIST') {
throw new Error(
'File already exists at target path: ' + toPath
);
}
throw err;
}
}
if (isWin) {
const pathToGTKBin = 'C:\\GTK\\bin\\';
const pathToIEShims =
String.raw`C:\Program Files (x86)\Internet Explorer\IEShims.dll`;
const targetDir = path.join(
import.meta.resolve('canvas'), '../../build/Release'
);
await copy(pathToIEShims, targetDir + String.raw`\IEShims.dll`);
let files;
try {
files = await readdir(pathToGTKBin);
} catch (err) {
if (err.code === 'ENOENT') {
throw new Error('Could not find ' + pathToGTKBin);
}
throw new Error('Could not list the directory contents.');
}
files.filter((f) => f.endsWith('.dll')).forEach(async (file) => {
const targetPath = targetDir + '\\' + file;
await copy(pathToGTKBin + file, targetPath);
console.log('Copied missing file to: ' + targetPath);
});
console.log('Successfully installed Canvas files for Windows build.');
} else {
console.log(
'Windows not detected, so skipping Windows-specific (Canvas) ' +
'installation steps'
);
}