-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-config.js
41 lines (34 loc) · 1.29 KB
/
package-config.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
/* eslint-disable */
const fs = require("fs");
const TENSORFLOW_TFJSNODE_DLL_PATH =
"node_modules/@tensorflow/tfjs-node/deps/lib/tensorflow.dll";
const TARGET_PATH = "node_modules/@tensorflow/tfjs-node/lib/napi-v5/tensorflow.dll";
const PACKAGE_CONFIG_COMPLETE_MESSAGE = "Package config is complete.";
const PACKAGE_CONFIG_ERROR_MESSAGE = "[PACKAGE CONFIG ERROR]: Please reinstall the package.";
function checkFileIsExistByPath(path) {
try {
fs.statSync(path);
} catch (err) {
return false;
}
return true;
}
function runPackageConfig(oldPath, newPath, callback) {
const readStream = fs.createReadStream(oldPath);
const writeStream = fs.createWriteStream(newPath);
readStream.on('error', callback);
writeStream.on('error', callback);
readStream.on('close', () => fs.unlink(oldPath, callback));
readStream.pipe(writeStream);
}
(function bootstrap() {
const originalFileIsExist = checkFileIsExistByPath(TENSORFLOW_TFJSNODE_DLL_PATH);
const fileInTargetPath = checkFileIsExistByPath(TARGET_PATH);
if (originalFileIsExist === fileInTargetPath) throw new Error(PACKAGE_CONFIG_ERROR_MESSAGE);
if (originalFileIsExist) {
runPackageConfig(TENSORFLOW_TFJSNODE_DLL_PATH, TARGET_PATH, (err) => {
if (err) throw err;
});
}
console.log(PACKAGE_CONFIG_COMPLETE_MESSAGE);
})();