fix for windows

This commit is contained in:
Sean Yesmunt 2018-07-19 09:42:57 -04:00
parent 935f656add
commit d999dfa528
2 changed files with 19 additions and 15 deletions

4
.gitignore vendored
View file

@ -1,8 +1,8 @@
/node_modules /node_modules
/dist /dist
/static/daemon/lbrynet-daemon /static/daemon/lbrynet-daemon*
/static/locales /static/locales
yarn-error.log yarn-error.log
package-lock.json package-lock.json
.idea/ .idea/
/build/daemon.ver /build/daemon.ver

View file

@ -11,22 +11,25 @@ const downloadDaemon = targetPlatform =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate; const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion; const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir; const daemonDir = path.join(__dirname,'..',packageJSON.lbrySettings.lbrynetDaemonDir);
const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName; let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
const daemonFilePath = `${__dirname}/../${daemonDir}/${daemonFileName}`;
let currentPlatform = os.platform(); let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macos'; if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') currentPlatform = 'windows'; if (currentPlatform === 'win32') {
currentPlatform = 'windows';
daemonFileName = daemonFileName + '.exe';
}
const daemonVersionPath = __dirname + '/daemon.ver'; const daemonFilePath = path.join(daemonDir, daemonFileName);
const daemonVersionPath = path.join(__dirname, 'daemon.ver');
const daemonPlatform = targetPlatform || currentPlatform; const daemonPlatform = targetPlatform || currentPlatform;
const tmpZipPath = __dirname + '/../dist/daemon.zip'; const tmpZipPath = path.join(__dirname, '../','dist','daemon.zip');
const daemonURL = daemonURLTemplate const daemonURL = daemonURLTemplate
.replace(/DAEMONVER/g, daemonVersion) .replace(/DAEMONVER/g, daemonVersion)
.replace(/OSNAME/g, daemonPlatform); .replace(/OSNAME/g, daemonPlatform);
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version // If a daemon and daemon.ver exists, check to see if it matches the current daemon version
const hasDaemonDownloaded = fs.existsSync(daemonFilePath); const hasDaemonDownloaded = fs.existsSync(daemonFilePath);
const hasDaemonVersion = fs.existsSync(daemonVersionPath); const hasDaemonVersion = fs.existsSync(daemonVersionPath);
@ -34,8 +37,8 @@ const downloadDaemon = targetPlatform =>
if (hasDaemonVersion) { if (hasDaemonVersion) {
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8"); downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8");
} }
if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) { if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) {
console.log('\x1b[34minfo\x1b[0m Daemon already downloaded'); console.log('\x1b[34minfo\x1b[0m Daemon already downloaded');
resolve('Done'); resolve('Done');
return; return;
@ -60,17 +63,18 @@ const downloadDaemon = targetPlatform =>
}); });
}) })
) )
.then(() => del(`${daemonDir}/${daemonFileName}*`)) .then(() => del(`${daemonFilePath}*`))
.then(() => decompress(tmpZipPath, daemonDir, { .then(() => decompress(tmpZipPath, daemonDir, {
filter: file => filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName, path.basename(file.path) === daemonFileName,
})) }))
.then(() => del(`${tmpZipPath }*`))
.then(() => { .then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!'); console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
if (hasDaemonVersion) { if (hasDaemonVersion) {
del(daemonVersionPath); del(daemonVersionPath);
} }
fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8") fs.writeFileSync(daemonVersionPath, daemonVersion, "utf8")
resolve('Done'); resolve('Done');
}) })