forked from advanced-security/codeql-sap-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-files.cmd
More file actions
58 lines (49 loc) · 2.22 KB
/
index-files.cmd
File metadata and controls
58 lines (49 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@echo off
if "%~1"=="" (
echo Usage: %0 ^<response_file_path^>
exit /b 1
)
where node >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo node executable is required (in PATH) to run the 'index-files.js' script. Please install Node.js and try again.
exit /b 2
)
where npm >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo npm executable is required (in PATH) to install the dependencies for the 'index-files.js' script.
exit /b 3
)
set "_response_file_path=%~1"
set "_script_dir=%~dp0"
REM Set _cwd before changing the working directory to the script directory.
REM We assume this script is called from the source root directory of the
REM to be scanned project.
set "_cwd=%CD%"
echo Checking response file for CDS files to index
REM Terminate early if the _response_file_path doesn't exist or is empty,
REM which indicates that no CDS files were selected or found.
if not exist "%_response_file_path%" (
echo 'codeql database index-files --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.
exit /b 0
)
REM Change to the directory of this script to ensure that npm looks up the
REM package.json file in the correct directory and installs the dependencies
REM (i.e. node_modules) relative to this directory. This is technically a
REM violation of the assumption that extractor scripts will be run with the
REM current working directory set to the root of the project source, but we
REM also need node_modules to be installed here and not in the project source
REM root, so we make a compromise of:
REM 1. changing to this script's directory;
REM 2. installing node dependencies here;
REM 3. passing the original working directory as a parameter to the
REM index-files.js script;
REM 4. expecting the index-files.js script to immediately change back to
REM the original working (aka the project source root) directory.
cd /d "%_script_dir%" && ^
echo Installing node package dependencies && ^
npm install --quiet --no-audit --no-fund && ^
echo Building TypeScript code && ^
npm run build && ^
echo Running the 'index-files.js' script && ^
node "%_script_dir%out\index-files.js" "%_response_file_path%" "%_cwd%"
exit /b %ERRORLEVEL%