pdca0-dev-hub/cmd/pdc-xdce-setup.bat

655 lines
24 KiB
Batchfile

@echo off
setlocal enableDelayedExpansion
set "current_dir=%~dp0"
set "is_test=false"
if "%~1" == "test" (
set "is_test=true"
set "current_dir=%~dp0target\"
if not exist "!current_dir!" (
mkdir "!current_dir!"
)
set "USERPROFILE=!current_dir!\user"
if not exist "!USERPROFILE!" (
mkdir "!USERPROFILE!"
)
)
set "default_modules="
set "config_file=!current_dir!pdc-xdce-setup.conf"
set "module_name_key=installed_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%> "!current_dir!pdc-xdce-setup.conf"
echo I moduli da installare sono: %modules%
:: Controllo della versione di Node.js
for /f "tokens=*" %%v in ('node -v 2^>nul') do set "node_version=%%v"
if not defined node_version (
echo Node.js non e' installato.
exit /b 1
)
if not "%node_version%"=="v10.24.1" (
echo Versione di Node.js non compatibile. Richiesta: v10.24.1, trovata: %node_version%
exit /b 1
)
:: Check if git is installed
where git >nul 2>nul
if %errorlevel% neq 0 (
echo Git could not be found. Please install Git.
endlocal
pause
exit /b
)
if not exist "!current_dir!package.json" (
(
echo {
echo "name": "package-json-master",
echo "version": "0.1.0",
echo "scripts": ^{
echo "ng": "ng"
echo ^},
echo "repository": ^{
echo "type": "git",
echo "url": "example.com"
echo ^},
echo "author": ^{
echo "name": "ARCH",
echo "email": "arch@isp.com"
echo ^},
echo "keywords": ^[
echo "angular"
echo ^],
echo "license": "MIT",
echo "bugs": ^{
echo "url": "example.com/issues"
echo ^},
echo "engines": ^{
echo "node": ">=6.0.0"
echo ^},
echo "dependencies": ^{
echo "@angular-devkit/architect": "0.11.0",
echo "@angular-devkit/build-angular": "0.11.0",
echo "@angular-devkit/build-optimizer": "0.11.0",
echo "@angular-devkit/core": "7.1.0",
echo "@angular-devkit/schematics": "7.1.0",
echo "@angular-devkit/schematics-cli": "0.11.0",
echo "@angular/cli": "7.1.0",
echo "@isp/xdce-build-utils": "1",
echo "@isp/xdce-schematics": "1",
echo "@schematics/angular": "7.1.0",
echo "@schematics/update": "0.11.0",
echo "node-sass": "^4.9.3",
echo "node-sass-tilde-importer": "1.0.1"
echo ^}
echo ^}
) > "!current_dir!package.json"
)
:: Create .angular.json file
if not exist "!current_dir!.angular.json" (
(
echo ^{
echo "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
echo "version": 1,
echo "newProjectRoot": "projects",
echo "projects": ^{
echo "showcase-webapp": ^{
echo "root": "",
echo "sourceRoot": "src",
echo "projectType": "application",
echo "architect": ^{
echo "build": ^{
echo "builder": "@angular-devkit/build-angular:browser",
echo "options": ^{
echo "outputPath": "target/app",
echo "index": "src/index.html",
echo "main": "src/main.ts",
echo "tsConfig": "src/tsconfig.app.json",
echo "polyfills": "src/polyfills.ts",
echo "extractCss":true,
echo "assets": ^[
echo "src/assets",
echo "src/nginx-cfg",
echo "src/nginx-default-cfg",
echo "src/favicon.ico",
echo "src/login",
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-tutorial/e2e",
echo "output": "/e2e/xdce-module-tutorial"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-tutorial/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-docs/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-arch-pluggable-impl/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core-base/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-tutorial/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-ui/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-arch-pluggable-impl/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core-base/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-widgetdemo/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-common-docs/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-ui/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-widget/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-widget/assets",
echo "output": "/assets"
echo ^}
echo ^],
echo "styles": ^[
echo ^{
echo "input": "node_modules/@isp/xdce-arch-core/bootstrap/bootstrap.min.css",
echo "bundleName": "bootstrap.css"
echo ^},
echo ^{
echo "input": "node_modules/@isp/xdce-arch-core-base/style/xdce-arch-core-base.css",
echo "bundleName": "xdce-arch-core-base.css"
echo ^},
echo ^{
echo "input": "node_modules/@isp/xdce-arch-core/style/xdce-arch-core.css",
echo "bundleName": "xdce-arch-core.css"
echo ^},
echo ^{
echo "input": "node_modules/@isp/showcase-ui/style/showcase-ui.css",
echo "bundleName": "showcase-ui.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.green.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.green.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.blue.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.blue.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.ipo.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.ipo.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.green.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.green.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.blue.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.blue.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.ipo.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.ipo.css"
echo ^},
echo "src/styles.scss"
echo ^],
echo "scripts": ^[
echo ^{
echo "input": "node_modules/prismjs/prism.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-typescript.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-sass.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-javascript.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-json.js"
echo ^}
echo ^]
echo ^},
echo "configurations": ^{
echo "production": ^{
echo "optimization": true,
echo "outputHashing": "all",
echo "sourceMap": false,
echo "extractCss": true,
echo "namedChunks": false,
echo "aot": true,
echo "extractLicenses": true,
echo "vendorChunk": false,
echo "buildOptimizer": true,
echo "fileReplacements": ^[
echo ^{
echo "replace": "src/environments/environment.ts",
echo "with": "src/environments/environment.prod.ts"
echo ^}
echo ^]
echo ^}
echo ^}
echo ^},
echo "serve": ^{
echo "builder": "@angular-devkit/build-angular:dev-server",
echo "options": ^{
echo "browserTarget": "showcase-webapp:build",
echo "proxyConfig": "proxy.conf.json"
echo ^},
echo "configurations": ^{
echo "production": ^{
echo "extractCss": true,
echo "browserTarget": "showcase-webapp:build:production"
echo ^}
echo ^}
echo ^},
echo "extract-i18n": ^{
echo "builder": "@angular-devkit/build-angular:extract-i18n",
echo "options": ^{
echo "browserTarget": "showcase-webapp:build"
echo ^}
echo ^},
echo "test": ^{
echo "builder": "@angular-devkit/build-angular:karma",
echo "options": ^{
echo "main": "src/test.ts",
echo "karmaConfig": "./karma.conf.js",
echo "polyfills": "src/polyfills.ts",
echo "tsConfig": "src/tsconfig.spec.json",
echo "scripts": ^[
echo ^{
echo "input": "node_modules/prismjs/prism.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-typescript.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-sass.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-javascript.js"
echo ^},
echo ^{
echo "input": "node_modules/prismjs/components/prism-json.js"
echo ^}
echo ^],
echo "styles": ^[
echo ^{
echo "input": "node_modules/@isp/xdce-arch-core/bootstrap/bootstrap.min.css",
echo "bundleName": "bootstrap.css"
echo ^},
echo ^{
echo "input": "node_modules/@isp/xdce-arch-core/style/xdce-arch-core.css",
echo "bundleName": "xdce-arch-core.css"
echo ^},
echo ^{
echo "input": "node_modules/@isp/showcase-ui/style/showcase-ui.css",
echo "bundleName": "showcase-ui.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.green.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.green.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.blue.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.blue.css"
echo ^},
echo ^{
echo "input": "src/theme-colors.ipo.scss",
echo "lazy": true,
echo "bundleName": "theme-colors.ipo.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.green.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.green.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.blue.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.blue.css"
echo ^},
echo ^{
echo "input": "src/widget-colors.ipo.scss",
echo "lazy": true,
echo "bundleName": "widget-colors.ipo.css"
echo ^},
echo "src/styles.scss"
echo ^],
echo "assets": ^[
echo "src/assets",
echo "src/favicon.ico",
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-tutorial/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-docs/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-bear-docs/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-arch-pluggable-impl/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-tutorial/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-ui/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/showcase-arch-pluggable-impl/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-arch-core/docs",
echo "output": "/docs"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-widgetdemo/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-module-common-docs/assets",
echo "output": "/assets"
echo ^},
echo ^{
echo "glob": "**/*",
echo "input": "node_modules/@isp/xdce-widget/assets",
echo "output": "/assets"
echo ^}
echo ^]
echo ^}
echo ^},
echo "lint": ^{
echo "builder": "@angular-devkit/build-angular:tslint",
echo "options": ^{
echo "tsConfig": ^[
echo "src/tsconfig.app.json",
echo "src/tsconfig.spec.json"
echo ^],
echo "exclude": ^[
echo "**/node_modules/**"
echo ^]
echo ^}
echo ^}
echo ^}
echo ^},
echo "showcase-webapp-e2e": ^{
echo "root": "",
echo "sourceRoot": "",
echo "projectType": "application",
echo "architect": ^{
echo "e2e": ^{
echo "builder": "@angular-devkit/build-angular:protractor",
echo "options": ^{
echo "protractorConfig": "./protractor.conf.js",
echo "devServerTarget": "showcase-webapp:serve"
echo ^}
echo ^},
echo "lint": ^{
echo "builder": "@angular-devkit/build-angular:tslint",
echo "options": ^{
echo "tsConfig": ^[
echo "e2e/tsconfig.e2e.json"
echo ^],
echo "exclude": ^[
echo "**/node_modules/**"
echo ^]
echo ^}
echo ^}
echo ^}
echo ^}
echo ^},
echo "defaultProject": "showcase-webapp",
echo "schematics": ^{
echo "@schematics/angular:component": ^{
echo "prefix": "app",
echo "styleext": "scss"
echo ^},
echo "@schematics/angular:directive": ^{
echo "prefix": "app"
echo ^}
echo ^}
echo ^}
) > "!current_dir!.angular.json"
)
call :set_npmrc
@REM call :npm_install
call :set_sass_binary_file
for %%a in (!modules!) do (
echo %%a
set "module=%%a"
call :check_repo_exists !module!
if %errorlevel% neq 0 (
echo Repository does not exist or is not accessible.
endlocal
pause
exit /b
)
call :install_module !module!
)
echo Setup complete.
endlocal
exit /b
:: #region Functions
:: Funzione per settare il corretto .npmrc
:set_npmrc
set "npmrc_path=!USERPROFILE!\.npmrc"
if exist "!npmrc_path!" (
echo Il file .npmrc esiste.
:: Controlla se contiene la stringa "arti0-artifactory.sede.corp.sanpaoloimi.com"
findstr /C:"arti0-artifactory.sede.corp.sanpaoloimi.com" "!npmrc_path!" >nul
if errorlevel 1 (
echo La stringa "arti0-artifactory.sede.corp.sanpaoloimi.com" non e' presente.
:: Rinomina il file esistente
ren "!npmrc_path!" ".npmrc_old"
echo Creazione di un nuovo file .npmrc con informazioni predefinite.
(
echo registry=https://arti0-artifactory.sede.corp.sanpaoloimi.com/artifactory/api/npm/npm-repos
echo strict-ssl=false
echo insecure=true
echo rejectUnauthorized=false
echo always-auth=true
echo email=cm.dipartimentale@intesasanpaolo.com
echo //arti0-artifactory.sede.corp.sanpaoloimi.com/artifactory/api/npm/:_auth="bnBtLXNuYXBzaG90LWRlcGxveWVyOkFQOTQ0SGd4YlR2ZFZkY1RmenVySkpFZ1c0ag=="
) > "!npmrc_path!"
) else (
echo La stringa "arti0-artifactory.sede.corp.sanpaoloimi.com" e' presente.
)
) else (
echo Il file .npmrc non esiste. Creazione del file con informazioni predefinite.
(
echo registry=https://arti0-artifactory.sede.corp.sanpaoloimi.com/artifactory/api/npm/npm-repos
echo strict-ssl=false
echo insecure=true
echo rejectUnauthorized=false
echo always-auth=true
echo email=cm.dipartimentale@intesasanpaolo.com
echo //arti0-artifactory.sede.corp.sanpaoloimi.com/artifactory/api/npm/:_auth="bnBtLXNuYXBzaG90LWRlcGxveWVyOkFQOTQ0SGd4YlR2ZFZkY1RmenVySkpFZ1c0ag=="
) > "!npmrc_path!"
)
exit /b
:: Funzione che setta il sass_binary_file
:set_sass_binary_file
set "npmrc_path=!USERPROFILE!\.npmrc"
:: Controlla se contiene la stringa "sass_binary_path"
findstr /C:"sass_binary_path" "!npmrc_path!" >nul
if errorlevel 1 (
echo La stringa "sass_binary_path" non e' presente. Aggiungo il path al "binding.node".
echo sass_binary_path=!current_dir!node_modules\node-sass\vendor\win32-x64-64\binding.node >> "!npmrc_path!"
for /d %%d in ("!current_dir!*") do (
if exist "%%d\node_modules\node-sass" (
echo Trovata cartella node-sass in "%%d". Cancello...
rmdir /s /q "%%d\node_modules\node-sass"
rmdir /s /q "%%d\node_modules\node-sass-tilde-importer"
echo Eseguo npm install in "%%d"...
pushd "%%d"
npm install
popd
)
)
) else (
echo La stringa "sass_binary_path" e' presente.
)
exit /b
:: Install dependencies if either node_modules or package-lock.json does not exist
:npm_install
set "folder_name="
if "%~1" neq "" (
set "folder_name=%~1\"
)
if "!is_test!" == "false" (
if not exist "!current_dir!!folder_name!node_modules" (
cd "!current_dir!!folder_name!"
npm install
cd "!current_dir!"
)
if not exist "!current_dir!!folder_name!package-lock.json" (
cd "!current_dir!!folder_name!"
npm install
cd "!current_dir!"
)
)
exit /b
:: Check if the repository exists
:check_repo_exists
set "module_name=%~1"
git ls-remote "https://bitbucket.intesasanpaolo.com/scm/pdca0/!module_name!.git" >nul 2>nul
exit /b
:: Clone the repository if it does not exist
:clone_repo
set "module_name=%~1"
echo !current_dir!!module_name!
if not exist "!current_dir!!module_name!" (
cd "!current_dir!"
git clone "https://bitbucket.intesasanpaolo.com/scm/pdca0/!module_name!.git" "!module_name!"
cd "!current_dir!!module_name!"
git checkout env/svil
git pull
cd "!current_dir!"
)
exit /b
:: Install the module
:install_module
set "module_name=%~1"
call :clone_repo !module_name!
@REM call :npm_install !module_name!
exit /b
:: #endregion