1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-24 05:17:03 +00:00

finally make the silent and local installation for nodejs get working on windows - there is no resource online that works correctly LAWL!

Former-commit-id: f6727efd6bbc059c96a0f242b29e10bbac3b65b8
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-06-23 17:32:37 +03:00
parent aee3c489ed
commit 208e593df7
4 changed files with 108 additions and 38 deletions

View File

@@ -12,23 +12,32 @@ import (
var bundles = []bundle{
{
name: "dotnet",
names: []string{"dotnet"},
installDir: "./dotnet_bin",
installArguments: []string{"-NoPath", "-InstallDir", "$installDir", "-Channel", "Current", "-Version", "3.0.100-preview6-012264"},
},
{
names: []string{"node", "npm"},
installDir: "./node_bin",
installArguments: []string{"$installDir", "12.4.0"},
},
}
func install(b bundle) error {
switch b.name {
case "dotnet":
return installDotnet(b)
default:
return nil
for _, name := range b.names {
switch name {
case "dotnet":
return installDotnet(b)
case "node", "nodejs", "npm":
return installNode(b)
}
}
return nil
}
type bundle struct {
name string
names []string
installDir string
installArguments []string
@@ -40,8 +49,11 @@ func (b bundle) parseArguments() []string {
// let's not use reflection here.
switch arg[1:] {
case "name":
b.installArguments[i] = b.name
b.installArguments[i] = b.names[0]
case "installDir":
if runtime.GOOS == "windows" {
b.installDir = filepath.FromSlash(b.installDir)
}
b.installArguments[i] = b.installDir
default:
panic(arg + " not a bundle struct field")
@@ -100,39 +112,40 @@ func attachCmd(cmd *exec.Cmd) {
func getPlatform(name string) (p *platform) {
for _, b := range bundles {
if b.name != name {
continue
}
for _, bName := range b.names {
if bName == name {
// temporarily set the path env to the installation directories
// in order the exec.LookPath to check for programs there too.
pathEnv := os.Getenv("PATH")
if len(pathEnv) > 1 {
if pathEnv[len(pathEnv)-1] != ';' {
pathEnv += ";"
}
}
// temporarily set the path env to the installation directories
// in order the exec.LookPath to check for programs there too.
pathEnv := os.Getenv("PATH")
if len(pathEnv) > 1 {
if pathEnv[len(pathEnv)-1] != ';' {
pathEnv += ";"
pathEnv += b.installDir
os.Setenv("PATH", pathEnv)
executable, err := exec.LookPath(name)
if err != nil {
golog.Debugf("%s executable couldn't be found from PATH. Trying to install it...", name)
err = install(b)
if err != nil {
golog.Fatalf("unable to auto-install %s, please do it yourself: %v", name, err)
}
executable = b.installDir + "/" + name
if runtime.GOOS == "windows" {
executable += ".exe"
}
}
return &platform{
executable: executable,
}
}
}
pathEnv += b.installDir
os.Setenv("PATH", pathEnv)
executable, err := exec.LookPath(name)
if err != nil {
golog.Debugf("%s executable couldn't be found from PATH. Trying to install it...", name)
err = install(b)
if err != nil {
golog.Fatalf("unable to auto-install %s, please do it yourself: %v", name, err)
}
executable = filepath.Join(b.installDir, name)
if runtime.GOOS == "windows" {
executable += ".exe"
}
}
return &platform{
executable: executable,
}
}
golog.Fatalf("%s not found", name)
@@ -145,4 +158,12 @@ func main() {
dotnet := getPlatform("dotnet")
dotnetVersion := dotnet.exec("--version")
golog.Infof("Dotnet version: %s", dotnetVersion)
node := getPlatform("node")
nodeVersion := node.exec("--version")
golog.Infof("Nodejs version: %s", nodeVersion)
npm := getPlatform("npm")
npmVersion := npm.exec("--version")
golog.Infof("NPM version: %s", npmVersion)
}