|
1 | 1 | @echo off |
2 | 2 |
|
3 | | -if "%~1"=="" ( |
4 | | - echo Usage: %0 ^<response_file_path^> |
5 | | - exit /b 1 |
6 | | -) |
| 3 | +REM This script currently: |
| 4 | +REM - ignores any arguments passed to it; |
| 5 | +REM - assumes it is run from the root of the project source directory; |
7 | 6 |
|
8 | 7 | where node >nul 2>nul |
9 | 8 | if %ERRORLEVEL% neq 0 ( |
10 | 9 | echo node executable is required (in PATH) to run the 'cds-extractor.js' script. Please install Node.js and try again. |
11 | 10 | exit /b 2 |
12 | 11 | ) |
13 | 12 |
|
14 | | -where npm >nul 2>nul |
15 | | -if %ERRORLEVEL% neq 0 ( |
16 | | - echo npm executable is required (in PATH) to install the dependencies for the 'cds-extractor.js' script. |
17 | | - exit /b 3 |
18 | | -) |
19 | | - |
20 | | -set "_response_file_path=%~1" |
21 | | -set "_run_mode=index-files" |
22 | | -set "_script_dir=%~dp0" |
23 | | -REM Set _cwd before changing the working directory to the script directory. |
24 | | -REM We assume this script is called from the source root directory of the |
25 | | -REM to be scanned project. |
| 13 | +REM Set the _cwd variable to the present working directory as the directory |
| 14 | +REM from which this script was called, which we assume is the "source root" directory |
| 15 | +REM of the project that to be scanned / indexed. |
26 | 16 | set "_cwd=%CD%" |
| 17 | +set "_script_dir=%~dp0" |
| 18 | +set "_cds_extractor_js_path=%_script_dir%dist\cds-extractor.js" |
| 19 | +set "_cds_extractor_node_modules_dir=%_script_dir%node_modules" |
27 | 20 |
|
28 | | -echo Checking response file for CDS files to index |
| 21 | +if not exist "%_cds_extractor_js_path%" ( |
| 22 | + echo Error: The 'cds-extractor.js' script does not exist at the expected path: %_cds_extractor_js_path% |
| 23 | + echo Please ensure that the script has been built and is available in the 'dist' directory. |
| 24 | + exit /b 3 |
| 25 | +) |
29 | 26 |
|
30 | | -REM Terminate early if the _response_file_path doesn't exist or is empty, |
31 | | -REM which indicates that no CDS files were selected or found. |
32 | | -if not exist "%_response_file_path%" ( |
33 | | - echo 'codeql database cds-extractor --language cds' command terminated early as response file '%_response_file_path%' does not exist or is empty. This is because no CDS files were selected or found. |
34 | | - exit /b 0 |
| 27 | +if not exist "%_cds_extractor_node_modules_dir%" ( |
| 28 | + echo Error: The 'node_modules' directory does not exist at the expected path: %_cds_extractor_node_modules_dir% |
| 29 | + echo Please ensure that the dependencies have been installed by running 'npm install' in the 'extractors\cds\tools' directory. |
| 30 | + exit /b 4 |
35 | 31 | ) |
36 | 32 |
|
37 | | -REM Change to the directory of this script to ensure that npm looks up the |
| 33 | +REM Change to the directory of this batch script to ensure that npm looks up the |
38 | 34 | REM package.json file in the correct directory and installs the dependencies |
39 | 35 | REM (i.e. node_modules) relative to this directory. This is technically a |
40 | 36 | REM violation of the assumption that extractor scripts will be run with the |
41 | 37 | REM current working directory set to the root of the project source, but we |
42 | 38 | REM also need node_modules to be installed here and not in the project source |
43 | 39 | REM root, so we make a compromise of: |
44 | | -REM 1. changing to this script's directory; |
45 | | -REM 2. installing node dependencies here; |
46 | | -REM 3. passing the original working directory as a parameter to the |
| 40 | +REM 1. changing to this batch script's directory; |
| 41 | +REM 2. passing the original working directory as a parameter to the |
47 | 42 | REM cds-extractor.js script; |
48 | | -REM 4. expecting the cds-extractor.js script to immediately change back to |
49 | | -REM the original working (aka the project source root) directory. |
| 43 | +REM 3. expecting the cds-extractor.js script to immediately change back to |
| 44 | +REM original working (aka the project source root) directory. |
50 | 45 |
|
51 | 46 | cd /d "%_script_dir%" && ^ |
52 | | -echo Installing node package dependencies && ^ |
53 | | -npm install --quiet --no-audit --no-fund && ^ |
54 | | -echo Building TypeScript code && ^ |
55 | | -npm run build && ^ |
56 | 47 | echo Running the 'cds-extractor.js' script && ^ |
57 | | -node "%_script_dir%out\cds-extractor.js" "%_run_mode%" "%_cwd%" "%_response_file_path%" |
58 | | - |
59 | | -exit /b %ERRORLEVEL% |
| 48 | +node "%_cds_extractor_js_path%" "%_cwd%" |
0 commit comments