Update cli install for nsis install path

This commit is contained in:
Labhansh Agrawal 2021-01-20 18:09:26 +05:30 committed by Benjamin Staneck
parent f81158cad9
commit 244a4c3134

View file

@ -40,10 +40,10 @@ const addBinToUserPath = () => {
try { try {
const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!; const envKey = Registry.openKey(Registry.HKCU, 'Environment', Registry.Access.ALL_ACCESS)!;
// C:\Users\<user>\AppData\Local\hyper\app-<version>\resources\bin // C:\Users\<user>\AppData\Local\Programs\hyper\resources\bin
const binPath = path.dirname(cliScriptPath); const binPath = path.dirname(cliScriptPath);
// C:\Users\<user>\AppData\Local\hyper // C:\Users\<user>\AppData\Local\hyper
const basePath = path.resolve(binPath, '../../..'); const oldPath = path.resolve(process.env.LOCALAPPDATA!, 'hyper');
const items = Registry.enumValueNames(envKey); const items = Registry.enumValueNames(envKey);
const pathItem = items.find((item) => item.toUpperCase() === 'PATH'); const pathItem = items.find((item) => item.toUpperCase() === 'PATH');
@ -58,19 +58,21 @@ const addBinToUserPath = () => {
return; return;
} }
const value = Registry.queryValue(envKey, pathItem) as string; const value = Registry.queryValue(envKey, pathItem) as string;
const pathParts = value.split(';'); let pathParts = value.split(';');
const existingPath = pathParts.includes(binPath); const existingPath = pathParts.includes(binPath);
if (existingPath) { const existingOldPath = pathParts.some((pathPart) => pathPart.startsWith(oldPath));
if (existingPath && !existingOldPath) {
console.log('Hyper CLI already in PATH'); console.log('Hyper CLI already in PATH');
Registry.closeKey(envKey);
resolve(); resolve();
return; return;
} }
// Because version is in path we need to remove old path if present and add current path // Because nsis install path is different from squirrel we need to remove old path if present
newPathValue = pathParts // and add current path if absent
.filter((pathPart) => !pathPart.startsWith(basePath)) if (existingOldPath) pathParts = pathParts.filter((pathPart) => !pathPart.startsWith(oldPath));
.concat([binPath]) if (!pathParts.includes(binPath)) pathParts.push(binPath);
.join(';'); newPathValue = pathParts.join(';');
} }
console.log('Adding HyperCLI path (registry)'); console.log('Adding HyperCLI path (registry)');
Registry.setValueRaw(envKey, pathItemName, type, Registry.formatString(newPathValue)); Registry.setValueRaw(envKey, pathItemName, type, Registry.formatString(newPathValue));