pdca0-dev-hub/cmd/pdca0-fe.bat

164 lines
5.5 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set "current_dir=%~dp0..\..\pdca0\"
set "is_test=false"
if "%~1" == "test" (
set "is_test=true"
set "current_dir=%~dp0..\..\target\"
if not exist "!current_dir!" (
mkdir "!current_dir!"
)
)
set "default_modules="
set "config_file=%~dp0pdc-xdce-setup.conf"
set "module_name_key=watched_modules"
if exist %config_file% (
for /f "tokens=1,2 delims==" %%A in ('findstr /R "^%module_name_key%=.*" %config_file%') do (
set "default_modules=%%B"
)
)
:: Prompt for the module to watch
set /p modules="Enter the module or modules (separated with coma) to watch [!default_modules!]: "
if "!modules!"=="" set "modules=!default_modules!"
:: Scrivi il valore nel file pdc-xdce-setup.conf
echo %module_name_key%=%modules%> "%~dp0pdc-xdce-setup.conf"
echo Watched module/s: %modules%
:: Sostituisce le virgole con spazi
set "modules=!modules:,= !"
echo !modules!
:: Itera sulla stringa modificata
for %%a in (!modules!) do (
echo %%a
set "module=%%a"
set "module_dir=!current_dir!!module!"
cd /d !module_dir!
echo Eseguo controlli su !cd!
:: Controlla se local-gulpfile.js esiste
if not exist "!cd!\local-gulpfile.js" (
(
echo var gulp = require('gulp'^);
echo var path = require('path'^);
echo var fileSystem = require('fs'^);
echo.
echo function emptyFolder(directoryPath^) ^{
echo if (fileSystem.existsSync(directoryPath^)^) ^{
echo fileSystem.readdirSync(directoryPath^).forEach(function (file^) ^{
echo var curPath = path.join(directoryPath, file^);
echo if (fileSystem.lstatSync(curPath^).isDirectory(^)^) ^{
echo emptyFolder(curPath^);
echo fileSystem.rmdirSync(curPath^);
echo ^} else ^{
echo fileSystem.unlinkSync(curPath^);
echo ^}
echo ^}^);
echo ^}
echo ^}
echo.
echo gulp.task('custom:after-all', function (^)^{
echo var mainTask = process.argv.slice(2^)^[0^];
echo if (mainTask === 'build:watch_local'^) ^{
echo var dest = path.join(process.cwd(^), '..', 'pdca0-deploy-arch', 'node_modules', '@isp', '!module!'^);
echo if (!fileSystem.existsSync(dest^)^)^{
echo emptyFolder(dest^);
echo ^}
echo return gulp.src(^`${configuration.distFolder}/**^`^)
echo .pipe(gulp.dest(dest^)^);
echo ^}
echo ^}^);
) > "!cd!\local-gulpfile.js"
) else (
findstr /C:"require('gulp')" "!cd!\local-gulpfile.js" >nul || (
echo.
echo var gulp = require('gulp'^);
echo.
) >> "!cd!\local-gulpfile.js"
findstr /C:"require('path')" "!cd!\local-gulpfile.js" >nul || (
echo.
echo var path = require('path'^);
echo.
) >> "!cd!\local-gulpfile.js"
findstr /C:"require('path')" "!cd!\local-gulpfile.js" >nul || (
echo.
echo var path = require('path'^);
echo.
) >> "!cd!\local-gulpfile.js"
findstr /C:"custom:after-all" "!cd!\local-gulpfile.js" >nul || (
echo.
echo var fileSystem = require('fs'^);
echo.
echo function emptyFolder(directoryPath^) ^{
echo if (fileSystem.existsSync(directoryPath^)^) ^{
echo fileSystem.readdirSync(directoryPath^).forEach(function (file^) ^{
echo var curPath = path.join(directoryPath, file^);
echo if (fileSystem.lstatSync(curPath^).isDirectory(^)^) ^{
echo emptyFolder(curPath^);
echo fileSystem.rmdirSync(curPath^);
echo ^} else ^{
echo fileSystem.unlinkSync(curPath^);
echo ^}
echo ^}^);
echo ^}
echo ^}
echo.
echo gulp.task('custom:after-all', function (^)^{
echo var mainTask = process.argv.slice(2^)^[0^];
echo if (mainTask === 'build:watch_local'^) ^{
echo var dest = path.join(process.cwd(^), '..', 'pdca0-deploy-arch', 'node_modules', '@isp', '!module!'^);
echo if (!fileSystem.existsSync(dest^)^)^{
echo emptyFolder(dest^);
echo ^}
echo return gulp.src(^`${configuration.distFolder}/**^`^)
echo .pipe(gulp.dest(dest^)^);
echo ^}
echo ^}^);
) >> "!cd!\local-gulpfile.js"
)
:: Controllo esistenza node_modules e package-lock.json
if not exist "!cd!\node_modules" (
echo node_modules non esiste, eseguo npm install...
npm install
) else if not exist "!cd!\package-lock.json" (
echo package-lock.json non esiste, eseguo npm install...
npm install
)
echo Avvio e !module!
:: Esegue npm run build:watch_local
start cmd /k "npm run build:watch_local"
)
netstat -ano | findstr :4200 >nul
if errorlevel 1 (
set "deploy_name=pdca0-deploy-arch"
echo Attendi 15 secondi prima di avviare !deploy_name!...
:: Attendi 15 secondi
timeout /t 15 /nobreak
set "deploy_dir=!current_dir!!deploy_name!"
cd /d !deploy_dir!
echo Avvio !deploy_name!
start cmd /k "npm start"
)
endlocal
exit