Чтобы обойти эту проблему, нужно было разбить исходный одиночный скрипт на 2 скрипта, которые можно запустить в командной строке. Это разделение необходимо было продолжить после завершения npm run build
и, если необходимо запустить и завершить composer vendor-expose
. Это потому, что мой скрипт автоматически завершается, когда они заканчивают. Ниже приведены два сценария с аргументами:
updateReactInSS_1 "C: \ wamp64 \ www \ silverstripeProject" "C: \ wamp64 \ www \ silverstripeProject \ app \ ReactApp"
Rem =======updateReactInSS_1=============
Rem updateReactInSS_1 is part 1 of 2 that updates a React Application nested inside a SilverStripe project.
Rem It deletes an existing React application build directory and rebuilds it with npm.
Rem Dependencies are node package manager (npm) and Composer installed globally by editing the
Rem environment variable path on your machine so they can be run from the command line (cmd).
Rem You also need a virtual host configured to point at your-SilverStripe-project folder.
Rem Argument 1 = full path to the nested SilverStripe project folder
Rem Argument 2 = full path to the nested React application
Rem updateReactInSS_1 file is located at Argument 2.
Rem updateReactInSS_2 file is located at Argument 2. It renames the "hash" js and css build files to "bundle"
Rem then copies and moves existing media build media files to the public directory of the SilverStripe project.
Rem Note: If "composer vendor-expose" runs then updateReactInSS_2 needs to be run again to complete the script.
Rem =======START===========
@echo off
Rem Checking argument 1 entered correctly.
if "%~1"=="" (
echo You forgot to specify the full path to the SilverStripe project folder:
echo argument 1 = ?
goto exit
) else (
echo argument 1 = %1 (path to the SilverStripe project folder)
)
Rem Checking argument 2 entered correctly.
if "%~2"=="" (
echo You forgot to specify the full path to the nested React application:
echo argument 2 = ?
goto exit
) else (
echo argument 2 = %2 (path to the nested React application)
)
Rem Going to React application path (NOTE could also add condition to check npm install if 1st time run)
cd %2
Rem Deletes the React application build directory if it exists and then use node package manager to build the React application.
if exist build\ del build /s /e
npm run build
:exit
updateReactInSS_2 "C: \ wamp64 \ www \ silverstripeProject" "C: \ wamp64 \ www \ silverstripeProject \ app \ ReactApp"
Rem updateReactInSS_2 is part 2 of 2.
Rem Argument 1 = full path to the nested SilverStripe project folder
Rem Argument 2 = full path to the nested React application
Rem updateReactInSS_2 file is located at Argument 2 (where updateReactInSS_1 is forced to end by npm run build).
Rem It renames the "hash" js and css build files to "bundle" and copies and moves
Rem existing build media files to the public directory of the SilverStripe project.
Rem Note: If updateReactInSS_2 is forced to end by composer vendor-expose command at Argument 1,
Rem you need to cd to Argument 2 to run updateReactInSS_2 again to complete the script.
Rem If symlinks have already been created by Composer, the command composer vendor-expose is
Rem skipped so updateReactInSS_2 only needs to be run once from the command line.
Rem =======START=======
@echo off
Rem Checking argument 1 entered correctly.
if "%~1"=="" (
echo You forgot to specify the full path to the SilverStripe project folder:
echo argument 1 = ?
goto finished
) else (
echo argument 1 = %1 (path to the SilverStripe project folder)
)
Rem Checking argument 2 entered correctly.
if "%~2"=="" (
echo You forgot to specify the full path to the nested React application:
echo argument 2 = ?
goto finished
) else (
echo argument 2 = %2 (path to the nested React application)
)
Rem Rename main.hashcode.js to main.bundle.js so consistent with requirements in related SS page controller.
cd %2\build\static\js
rename main.*.js "main.bundle.js"
Rem Rename main.hashcode.css to main.bundle.css so consistent with requirements in related SS page controller.
cd %2\build\static\css
rename main.*.css "main.bundle.css"
Rem checking if composer vendor-expose needs to run to create symlinking.
cd %1\public\resources
if not exist app\moe-card-app\build\ (
echo Please cd to %2 and run updateReactInSS_2 again to complete script commands.
cd %1
composer vendor-expose
)
Rem Go to public folder of SilverStripe project if no static\media directory exists, make it.
cd %1\public
if not exist static\media\ (
MD 1%\public\static\media
)
Rem Copying media build files if media directory exists in React build files to the public folder in SilverStripe. project.
if exist %2\build\static\media\ (
xcopy %2\build\static\media %1\public\static\media /s /e
) else (
echo No media directory to copy in react build\static\
goto exit
)
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 (
cd %2
goto finished
)
:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
:finished
echo updateReactInSS_2 COMPLETED
:exit
Прокомментируйте, пожалуйста, лучшие дизайнерские решения. Можно ли сделать их одним скриптом или управлять третьим скриптом, поэтому в командной строке нужно вводить только одну команду? Я учусь и обязан делать вещи, противоречащие лучшим практикам и соглашениям здесь !!!!! Большое спасибо за ваше время и за то, что поделились своими знаниями о StackOverflow: -).