Skip to content

Commit

Permalink
Change the way environment variables are set
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Feb 2, 2025
1 parent ae17804 commit 0858543
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/offline
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import * as Config from "./config"
import pathParam, profileFileAppend from "./utils"
import pathParam, setEnvSystem from "./utils"

fn installDependencies (tempDirectory: str) {
fs_mkdirSync(tempDirectory)
Expand All @@ -27,7 +27,7 @@ fn installDependencies (tempDirectory: str) {
installPath := Config.getDependenciesPath()

fs_copyDirectorySync(platformDependenciesPath, installPath)
profileFileAppend("export THE_DEPS_DIR=" + pathParam(installPath) + " # Added by `the offline`")
setEnvSystem("THE_DEPS_DIR", installPath)
}

fn installCompiler (tempDirectory: str) {
Expand Down
58 changes: 32 additions & 26 deletions src/utils
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@ export fn excludePaths (paths: str[], exclude: str[]) str[] {
return result
}

export fn profileFileAppend (text: str) {
mut filePath := process_home + path_SEP + ".zprofile"

if !fs_existsSync(filePath) {
filePath = process_home + path_SEP + ".bash_profile"
}

if !fs_existsSync(filePath) {
filePath = process_home + path_SEP + ".profile"
}

mut content := fs_existsSync(filePath) ? fs_readFileSync(filePath).str() : ""

if content[content.len - 1] != '\n' {
content += os_EOL
}

content += text

if text[text.len - 1] != '\n' {
content += os_EOL
}

fs_writeFileSync(filePath, content.toBuffer())
}

export fn mapStr (arr: str[], cb: (str, int) -> str) str[] {
l := arr.len
mut result := arr
Expand All @@ -82,6 +56,38 @@ export fn removeDirectorySync (path: str) {
}
}

export fn setEnvSystem (name: str, value: str) {
if os_NAME == "Windows" {
process_runSync(
"powershell '[System.Environment]::SetEnvironmentVariable(" +
"\"" + name + "\", \"" + value + "\", " +
"[System.EnvironmentVariableTarget]::User" +
")'"
)

return
}

mut filePath := process_home + path_SEP + ".zprofile"

if !fs_existsSync(filePath) {
filePath = process_home + path_SEP + ".bash_profile"
}

if !fs_existsSync(filePath) {
filePath = process_home + path_SEP + ".profile"
}

mut content := fs_existsSync(filePath) ? fs_readFileSync(filePath).str() : ""

if !content.empty && content[content.len - 1] != '\n' {
content += os_EOL
}

content += "export " + name + "=\"" + value + "\" # Added by The CLI\n"
fs_writeFileSync(filePath, content.toBuffer())
}

export fn scandirDeepSync (path: str) str[] {
files := fs_scandirSync(path)
filesLen := files.len
Expand Down

0 comments on commit 0858543

Please sign in to comment.