diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpm.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvm.kt similarity index 53% rename from src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpm.kt rename to src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvm.kt index 7d63655..344f8c2 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpm.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvm.kt @@ -2,38 +2,38 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.ProvResult -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.userHome import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalledCheckCommand -import java.io.File fun Prov.installNpmByNvm(): ProvResult = task { if (!isPackageInstalledCheckCommand("npm")) { //Node-Version-Manager from https://github.com/nvm-sh/nvm - val versNvm = "0.40.1" - cmd("sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$versNvm/install.sh | bash") + val version = "0.40.1" + cmd("sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$version/install.sh | bash") cmd("chmod 755 .nvm/nvm.sh") - addTextToFile("\n##### NVM #####\n", File("~/.bashrc")) - addTextToFile("""export NVM_DIR="${"\$HOME/.nvm"}" """ + "\n", File("~/.bashrc")) - addTextToFile("""[ -s "${"\$NVM_DIR/nvm.sh"}" ] && \. "${"\$NVM_DIR/nvm.sh"}" """ + "\n", File("~/.bashrc")) - addTextToFile("""[ -s "${"\$NVM_DIR/bash_completion"}" ] && \. "${"\$NVM_DIR/bash_completion"}" """ + "\n", File("~/.bashrc")) + configureBashForUser() + createFile("~/.bashrc.d/npmbynvm.sh", """export NVM_DIR="${userHome()}.nvm" """ + "\n" + + """[ -s "${"\$NVM_DIR/nvm.sh"}" ] && \. "${"\$NVM_DIR/nvm.sh"}" """ + "\n") cmd(". .nvm/nvm.sh && nvm install --lts") - //to be discussed, sourcing in docker test container, separtely? + val nvmRes = cmd(". .nvm/nvm.sh && nvm --version").toString() - if (versNvm == nvmRes) { - println("NVM version $versNvm") - addResultToEval(ProvResult(true, out = "SUCCESS: NVM version $versNvm installed !!")) + if (version == nvmRes) { + println("NVM version $version") + addResultToEval(ProvResult(true, out = "SUCCESS: NVM version $version installed !!")) } else { - println("FAIL: NVM version $versNvm is not installed !!") - addResultToEval(ProvResult(true, out = "FAIL: NVM version $versNvm is not installed !!")) + println("FAIL: NVM version $version is not installed !!") + addResultToEval(ProvResult(true, out = "FAIL: NVM version $version is not installed !!")) } cmd(". .nvm/nvm.sh && node -v") cmd(". .nvm/nvm.sh && npm --version") - } else { - ProvResult(true, out = "npm already installed") + + } else { + addResultToEval(ProvResult(true, out = "npm already installed")) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/ClojureScriptKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/ClojureScriptKtTest.kt index 1eb057c..4fa402f 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/ClojureScriptKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/ClojureScriptKtTest.kt @@ -1,6 +1,5 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure -import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode import org.domaindrivenarchitecture.provs.test.defaultTestContainer import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.junit.jupiter.api.Assertions.assertTrue @@ -12,14 +11,18 @@ internal class ClojureScriptKtTest { // given val prov = defaultTestContainer() + //Todo: + // To be discussed, should init container, but not available for prov.installShadowCljs() !! + // Howto work in addition prov.a() + prov.b()? prov.installNpmByNvm() // when - val res = prov.installShadowCljs() - val res2 = prov.installShadowCljs() // check if it can be run twice successfully + // check if it can be run twice successfully + val res01 = prov.installShadowCljs() + val res02 = prov.installShadowCljs() // then - assertTrue(res.success) - assertTrue(res2.success) + assertTrue(res01.success) + assertTrue(res02.success) } } \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpmKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvmKtTest.kt similarity index 85% rename from src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpmKtTest.kt rename to src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvmKtTest.kt index 49ababd..5e016cd 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NVMnpmKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NpmByNvmKtTest.kt @@ -3,20 +3,18 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall import org.domaindrivenarchitecture.provs.test.defaultTestContainer +import org.domaindrivenarchitecture.provs.test.tags.ContainerTest import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test +internal class NpmByNvmKtTest { -internal class NVMnpmKtTest { - - @Test + @ContainerTest fun installNVMnpm() { // given val container = defaultTestContainer(ContainerStartMode.CREATE_NEW_KILL_EXISTING) container.aptInstall("curl") // when val res01 = container.installNpmByNvm() - //test repeatability val res02 = container.installNpmByNvm() // then assertTrue(res01.success)