mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01: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:
parent
aee3c489ed
commit
208e593df7
|
@ -12,23 +12,32 @@ import (
|
||||||
|
|
||||||
var bundles = []bundle{
|
var bundles = []bundle{
|
||||||
{
|
{
|
||||||
name: "dotnet",
|
names: []string{"dotnet"},
|
||||||
installDir: "./dotnet_bin",
|
installDir: "./dotnet_bin",
|
||||||
installArguments: []string{"-NoPath", "-InstallDir", "$installDir", "-Channel", "Current", "-Version", "3.0.100-preview6-012264"},
|
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 {
|
func install(b bundle) error {
|
||||||
switch b.name {
|
for _, name := range b.names {
|
||||||
case "dotnet":
|
switch name {
|
||||||
return installDotnet(b)
|
case "dotnet":
|
||||||
default:
|
return installDotnet(b)
|
||||||
return nil
|
case "node", "nodejs", "npm":
|
||||||
|
return installNode(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type bundle struct {
|
type bundle struct {
|
||||||
name string
|
names []string
|
||||||
installDir string
|
installDir string
|
||||||
|
|
||||||
installArguments []string
|
installArguments []string
|
||||||
|
@ -40,8 +49,11 @@ func (b bundle) parseArguments() []string {
|
||||||
// let's not use reflection here.
|
// let's not use reflection here.
|
||||||
switch arg[1:] {
|
switch arg[1:] {
|
||||||
case "name":
|
case "name":
|
||||||
b.installArguments[i] = b.name
|
b.installArguments[i] = b.names[0]
|
||||||
case "installDir":
|
case "installDir":
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
b.installDir = filepath.FromSlash(b.installDir)
|
||||||
|
}
|
||||||
b.installArguments[i] = b.installDir
|
b.installArguments[i] = b.installDir
|
||||||
default:
|
default:
|
||||||
panic(arg + " not a bundle struct field")
|
panic(arg + " not a bundle struct field")
|
||||||
|
@ -100,39 +112,40 @@ func attachCmd(cmd *exec.Cmd) {
|
||||||
|
|
||||||
func getPlatform(name string) (p *platform) {
|
func getPlatform(name string) (p *platform) {
|
||||||
for _, b := range bundles {
|
for _, b := range bundles {
|
||||||
if b.name != name {
|
for _, bName := range b.names {
|
||||||
continue
|
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
|
pathEnv += b.installDir
|
||||||
// in order the exec.LookPath to check for programs there too.
|
os.Setenv("PATH", pathEnv)
|
||||||
pathEnv := os.Getenv("PATH")
|
executable, err := exec.LookPath(name)
|
||||||
if len(pathEnv) > 1 {
|
if err != nil {
|
||||||
if pathEnv[len(pathEnv)-1] != ';' {
|
golog.Debugf("%s executable couldn't be found from PATH. Trying to install it...", name)
|
||||||
pathEnv += ";"
|
|
||||||
|
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)
|
golog.Fatalf("%s not found", name)
|
||||||
|
@ -145,4 +158,12 @@ func main() {
|
||||||
dotnet := getPlatform("dotnet")
|
dotnet := getPlatform("dotnet")
|
||||||
dotnetVersion := dotnet.exec("--version")
|
dotnetVersion := dotnet.exec("--version")
|
||||||
golog.Infof("Dotnet version: %s", dotnetVersion)
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,3 +22,7 @@ func installDotnet(b bundle) error {
|
||||||
// Right click on the ./scripts/dotnet-install.ps1 and check the "unblock" property, save and exit the dialog.
|
// Right click on the ./scripts/dotnet-install.ps1 and check the "unblock" property, save and exit the dialog.
|
||||||
return powershell("./scripts/dotnet-install.ps1", b.parseArguments()...)
|
return powershell("./scripts/dotnet-install.ps1", b.parseArguments()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func installNode(b bundle) error {
|
||||||
|
return powershell("./scripts/node-install.ps1", b.parseArguments()...)
|
||||||
|
}
|
||||||
|
|
38
_benchmarks/benchmarker/scripts/node-install.ps1
Normal file
38
_benchmarks/benchmarker/scripts/node-install.ps1
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
$INSTALL_DIR=$args[0]
|
||||||
|
$VERSION=$args[1]
|
||||||
|
# param([String]$VERSION="12.4.0",[String]$INSTALL_DIR="../nodejs_bin")
|
||||||
|
|
||||||
|
If(!(test-path $INSTALL_DIR))
|
||||||
|
{
|
||||||
|
New-Item -ItemType Directory -Force -Path $INSTALL_DIR
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = "https://nodejs.org/dist/v$VERSION/node-v$VERSION-x64.msi"
|
||||||
|
|
||||||
|
# i.e https://nodejs.org/dist/v10.16.0/node-v10.16.0-x64.msi
|
||||||
|
write-host "`n----------------------------"
|
||||||
|
write-host " downloading node "
|
||||||
|
write-host "----------------------------`n"
|
||||||
|
write-host "url : $url"
|
||||||
|
|
||||||
|
$filename = "node.msi"
|
||||||
|
$node_msi = "$INSTALL_DIR\$filename"
|
||||||
|
$start_time = Get-Date
|
||||||
|
$wc = New-Object System.Net.WebClient
|
||||||
|
$wc.DownloadFile($url, $node_msi)
|
||||||
|
write-Output "Download of $filename finished at: $((Get-Date).Subtract($start_time).Seconds) second(s)"
|
||||||
|
|
||||||
|
write-host "`n----------------------------"
|
||||||
|
write-host " installing node "
|
||||||
|
write-host "----------------------------`n"
|
||||||
|
|
||||||
|
$node_msi = $node_msi.substring(2)
|
||||||
|
|
||||||
|
$INSTALL_DIR=[System.IO.Path]::GetFullPath($INSTALL_DIR)
|
||||||
|
write-host "installation directory: $INSTALL_DIR"
|
||||||
|
|
||||||
|
$params = '/i', "$node_msi",
|
||||||
|
'INSTALLDIR="$INSTALL_DIR"',
|
||||||
|
'/qn',
|
||||||
|
'/norestart'
|
||||||
|
$p = Start-Process 'msiexec.exe' -ArgumentList $params -Wait -PassThru
|
7
_benchmarks/benchmarker/scripts/node-install.sh
Normal file
7
_benchmarks/benchmarker/scripts/node-install.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
INSTALL_DIR=$1
|
||||||
|
VERSION=$2
|
||||||
|
cd $INSTALL_DIR
|
||||||
|
curl http://nodejs.org/dist/node-$VERSION.tar.gz | tar xz --strip-components=1
|
||||||
|
./configure --prefix=$INSTALL_DIR
|
||||||
|
make install
|
||||||
|
curl https://www.npmjs.org/install.sh | sh
|
Loading…
Reference in New Issue
Block a user