(dispatcher: TaskEventDispatcher)
| 115 | * @returns |
| 116 | */ |
| 117 | export async function installCondaTask(dispatcher: TaskEventDispatcher): Promise<boolean> { |
| 118 | let success = false; |
| 119 | let lastError = null; |
| 120 | for (let i = 0; i < 3; i++) { |
| 121 | try { |
| 122 | if (await checkIfInstalled("conda")) { |
| 123 | dispatcher({ |
| 124 | message: `Already Find Conda` |
| 125 | }); |
| 126 | return true; |
| 127 | } |
| 128 | dispatcher({ |
| 129 | message: `Start install conda` |
| 130 | }); |
| 131 | let installerUrl, installerPath, installCommand: any[] = []; |
| 132 | if (systemType.toUpperCase().includes("WINDOWS")) { |
| 133 | await fsExtra.ensureDir('C:\\tools'); |
| 134 | installerUrl = 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe'; |
| 135 | installerPath = path.resolve(appTmpDir, './Miniconda3-latest-Windows-x86_64.exe'); |
| 136 | installCommand = [installerPath, ['/InstallationType=JustMe', '/RegisterPython=0', '/S', '/D=C:\\tools\\Miniconda3']]; |
| 137 | } else if (systemType.toUpperCase().includes("DARWIN")) { |
| 138 | const architecture = await getMacArchitecture(); |
| 139 | installerUrl = architecture === 'arm64' |
| 140 | ? 'https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh' |
| 141 | : 'https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh'; |
| 142 | installerPath = path.resolve(appTmpDir, architecture === 'arm64' |
| 143 | ? 'Miniconda3-latest-MacOSX-arm64.sh' |
| 144 | : 'Miniconda3-latest-MacOSX-x86_64.sh' |
| 145 | ); |
| 146 | |
| 147 | installCommand = ['bash', [installerPath, '-b']]; |
| 148 | } else if (systemType.toUpperCase().includes("LINUX")) { |
| 149 | installerUrl = 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh'; |
| 150 | installerPath = path.resolve(appTmpDir, './Miniconda3-latest-Linux-x86_64.sh'); |
| 151 | installCommand = ['bash', [installerPath, '-b', '-u']]; |
| 152 | } |
| 153 | await downloadUrl(dispatcher,installerUrl!, installerPath!) |
| 154 | try { |
| 155 | await runCommand(`${installCommand[0]} ${installCommand[1].join(" ")}`, dispatcher); |
| 156 | dispatcher({ |
| 157 | message: `Install conda end` |
| 158 | }); |
| 159 | success = true; |
| 160 | break; |
| 161 | } catch (err: any) { |
| 162 | console.error('Error running command:', err); |
| 163 | dispatcher({ |
| 164 | message: `Error running command:` + err.message |
| 165 | }); |
| 166 | lastError = err; |
| 167 | } |
| 168 | } catch (e: any) { |
| 169 | lastError = e; |
| 170 | } |
| 171 | } |
| 172 | if (!success) { |
| 173 | throw new Error(`Install conda error: ${lastError.message}, You can directly install conda from https://docs.anaconda.com/free/miniconda/miniconda-install/. After that, restart Comflowy.`) |
| 174 | } |
no test coverage detected