Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-05 17:18:48 -05:00
parent fc48c9c0db
commit 539238efb7
10 changed files with 163 additions and 160 deletions

View File

@@ -8,6 +8,20 @@ const spawn = require('child_process').spawn;
const Constants = require('./constants');
const RandomString = require('randomstring');
const _getDataDirectory = () => {
return _resolvePath(Constants.DATA_LOCATIONS[os.platform()]);
};
const _resolvePath = str => {
if (os.platform() === 'win32') {
return str.replace(/%([^%]+)%/g, (_, n) => {
return process.env[n];
});
} else {
return str.replace('~', os.homedir());
}
};
const tryParse = (j, def) => {
try {
return JSON.parse(j);
@@ -16,7 +30,7 @@ const tryParse = (j, def) => {
}
};
module.exports.checkDaemonVersion = (directory, version, storageType) => {
module.exports.checkDaemonVersion = (version, storageType) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
@@ -24,7 +38,7 @@ module.exports.checkDaemonVersion = (directory, version, storageType) => {
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-cv');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
@@ -67,7 +81,7 @@ module.exports.createSignatureFiles = (signature, publicKey) => {
};
};
module.exports.detectRepertoryMounts = (directory, version) => {
module.exports.detectRepertoryMounts = version => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
@@ -75,7 +89,7 @@ module.exports.detectRepertoryMounts = (directory, version) => {
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-status');
@@ -240,7 +254,7 @@ module.exports.executeScript = script => {
});
};
module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => {
module.exports.executeMount = (version, storageType, location, noConsoleSupported, exitCallback) => {
return new Promise((resolve) => {
const processOptions = {
detached: false,
@@ -248,7 +262,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
stdio: 'ignore',
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
@@ -285,7 +299,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
});
};
module.exports.getConfig = (directory, version, storageType) => {
module.exports.getConfig = (version, storageType) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
@@ -293,7 +307,7 @@ module.exports.getConfig = (directory, version, storageType) => {
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-dc');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
@@ -331,7 +345,7 @@ module.exports.getConfig = (directory, version, storageType) => {
});
};
module.exports.getConfigTemplate = (directory, version, storageType) => {
module.exports.getConfigTemplate = (version, storageType) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
@@ -339,7 +353,7 @@ module.exports.getConfigTemplate = (directory, version, storageType) => {
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-gt');
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
@@ -364,6 +378,8 @@ module.exports.getConfigTemplate = (directory, version, storageType) => {
});
};
module.exports.getDataDirectory = _getDataDirectory;
module.exports.getMissingDependencies = dependencies => {
return new Promise((resolve, reject) => {
if (!dependencies) {
@@ -482,17 +498,9 @@ module.exports.removeDirectoryRecursively = (p) => {
}
};
module.exports.resolvePath = str => {
if (os.platform() === 'win32') {
return str.replace(/%([^%]+)%/g, (_, n) => {
return process.env[n];
});
} else {
return str.replace('~', os.homedir());
}
};
module.exports.resolvePath = _resolvePath;
module.exports.setConfigValue = (name, value, directory, storageType, version) => {
module.exports.setConfigValue = (name, value, storageType, version) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: true,
@@ -500,7 +508,7 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = [];
args.push('-set');
args.push(name);
@@ -523,7 +531,7 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
});
};
module.exports.stopMountProcess = (directory, version, storageType) => {
module.exports.stopMountProcess = (version, storageType) => {
return new Promise((resolve, reject) => {
const processOptions = {
detached: os.platform() === 'darwin',
@@ -531,7 +539,7 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = ['-unmount'];
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
@@ -555,14 +563,14 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
});
};
module.exports.stopMountProcessSync = (directory, version, storageType) => {
module.exports.stopMountProcessSync = (version, storageType) => {
const processOptions = {
detached: true,
shell: os.platform() !== 'darwin',
windowsHide: true,
};
const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const command = path.join(_getDataDirectory(), version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
const args = ['-unmount'];
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);