Skip to content

Instantly share code, notes, and snippets.

@marcorodas
Last active August 26, 2018 07:24
Show Gist options
  • Select an option

  • Save marcorodas/10a4e77e1860fbd1011e0275a1986ddb to your computer and use it in GitHub Desktop.

Select an option

Save marcorodas/10a4e77e1860fbd1011e0275a1986ddb to your computer and use it in GitHub Desktop.
@echo off
IF EXIST %temp%\command.bat (
DEL %temp%\command.bat
)
SET "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_92"
powershell.exe -Command ^
$title = 'Projects Menu';^
$options = @(^
[PSCustomObject]@{dir = 'Projects_Exe\LoginApp'; title = 'Login App';},^
[PSCustomObject]@{dir = 'Projects_Exe\Expedientes'; title = 'Expedientes';},^
[PSCustomObject]@{dir = 'Projects_Exe\Documentos'; title = 'Documentos';},^
[PSCustomObject]@{dir = 'Projects_Exe\PDFUtilPack'; title = 'PDF Utilities';^
exeCreator = 'mvn clean package';^
exe = 'target\PDFUtilPack-1.0-SNAPSHOT.jar'},^
[PSCustomObject]@{dir = 'Projects_Exe\FilesCollection\JavaFxClient'; title = 'Files Collection - Run';^
exe = 'mvn jfx:run'},^
[PSCustomObject]@{dir = 'Projects_Exe\FilesCollection\JavaFxClient'; title = 'Files Collection - Clean Run';^
exe = 'mvn clean jfx:run'},^
[PSCustomObject]@{dir = 'C:\AS_Support\Seguros.Web'; title = 'Seguros.Web';},^
[PSCustomObject]@{title = 'CristoParaLasNaciones';^
dir = '%USERPROFILE%\AndroidStudioProjects\CristoParaLasNaciones';},^
[PSCustomObject]@{dir = 'Java_Demos\controlsfx-samples'; title = 'Demo: Controlsfx';^
exeCreator = 'mvn clean package';^
exe = 'target\controlsfx-samples.exe'};^
[PSCustomObject]@{dir = 'Java_Demos\javaIconDemo'; title = 'Demo: Java Icons Fontawesomefx';^
exeCreator = 'mvn clean package';^
exe = 'target\javaIconDemo.exe'}^
);^
function showSelection($len, $showBack){^
Write-Host "`n-----------------------`n";^
if($showBack){^
Write-Host "B : Back";^
}^
Write-Host "Q : Quit`n";^
do{^
$sel = Read-Host "Please make a selection";^
if($sel -eq 'q' -or $sel -eq 'Q'){^
Clear-Host;^
exit;^
}^
if($showBack){^
if($sel -eq 'b' -or $sel -eq 'B'){^
return 0;^
}^
}^
if(($sel -as [int]) -ne $null){^
$sel = [int]$sel;^
}else{^
$sel = 0;^
}^
}until($sel -gt 0 -and $sel -le $len);^
return $sel;^
}^
function showMenu($folder, $header){^
$json = Get-Content -Path $folder\package.json ^| ConvertFrom-Json;^
$properties = [array]$json.scripts.PSobject.Properties.Name;^
Clear-Host;^
Write-Host "======= $header =======`n";^
for ($i=0; $i -lt $properties.Length; $i++){^
Write-Host ($i+1) ':' $properties[$i];^
};^
$result = showSelection -len $properties.Length -showBack true;^
if($result -eq 0){^
showMain;^
}else {^
$command = -join('cd ',$folder,' ^&^& ','npm run ', $properties[$result-1]);^
writeCommand -command $command;^
}^
}^
function writeCommand($command){^
Clear-Host;^
$command ^| Set-Content -Path $Env:Temp\command.bat;^
}^
function writeCommandExe($dir, $exe, $exeCreator){^
$command = -join('cd ', $dir);^
if($exeCreator -ne $null){^
$command = -join($command, ' ^&^& IF NOT EXIST ', $exe, ' ',$exeCreator);^
}^
$command = -join($command, [Environment]::NewLine, $exe, ' ^&^& exit');^
writeCommand -command $command^
}^
function showMain(){^
Clear-Host;^
Write-Host "======= $title =======`n";^
for ($i=0; $i -lt $options.Length; $i++){^
Write-Host ($i+1) ':' $options[$i].title;^
};^
$result = showSelection -len $options.Length;^
$selObj = $options[$result-1];^
if($selObj.PSobject.Properties.Name -contains 'exe'){^
if($selObj.PSobject.Properties.Name -contains 'exeCreator'){^
writeCommandExe -dir $selObj.dir -exe $selObj.exe -exeCreator $selObj.exeCreator;^
}else {^
$command = -join('cd ', $selObj.dir, ' ^&^& ', $selObj.exe, ' ^&^& exit');^
writeCommand -command $command^
}^
}else {^
showMenu -folder $selObj.dir -header $selObj.title;^
}^
}^
showMain
IF EXIST %temp%\command.bat (
%temp%\command.bat
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment