Skip to content

Commit 1d73001

Browse files
committed
fix run.bash to support monorepos
1 parent d0be842 commit 1d73001

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

src/bin/run.bash

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ yellow=$(tput setaf 3)
99
green=$(tput setaf 2)
1010
reset=$(tput sgr0)
1111
bold=$(tput bold)
12-
pythagora_dir="pythagora"
12+
pythagora_dir="$1"
1313

1414
function exit_handler {
1515
while [ ! -f "./.pythagora/finishingup" ]
@@ -25,26 +25,6 @@ function exit_handler {
2525
exit 0
2626
}
2727

28-
commands=(basename realpath dirname)
29-
found_all=true
30-
31-
for cmd in "${commands[@]}"; do
32-
if ! command -v "$cmd" >/dev/null 2>&1 ; then
33-
echo "$cmd command not found"
34-
found_all=false
35-
fi
36-
done
37-
38-
if [ "$found_all" = true ] ;
39-
then
40-
pythagora_dir=$(basename "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")
41-
fi
42-
43-
if [ "$pythagora_dir" == "pythagora-dev" ]
44-
then
45-
pythagora_dir="@pythagora.io/pythagora-dev"
46-
fi
47-
4828
for (( i=0; i<${#args[@]}; i++ ))
4929
do
5030
if [[ "${args[$i]}" =~ ^--init[-_]command$ ]]
@@ -71,37 +51,37 @@ do
7151
exit 0
7252
elif [[ "${args[$i]}" == "--review" ]]
7353
then
74-
PYTHAGORA_CONFIG="$@" node "./node_modules/${pythagora_dir}/src/scripts/review.js"
54+
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/review.js"
7555
exit 0
7656
elif [[ "${args[$i]}" == "--tests-eligible-for-export" ]]
7757
then
7858
echo "${yellow}${bold}Tests eligible for export:${reset}"
79-
PYTHAGORA_CONFIG="$@" node "./node_modules/${pythagora_dir}/src/scripts/testsEligibleForExport.js"
59+
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/testsEligibleForExport.js"
8060
exit 0
8161
elif [[ "${args[$i]}" == "--unit-tests" ]]
8262
then
8363
echo "${green}${bold}Generating unit tests...${reset}"
84-
PYTHAGORA_CONFIG="$@" node "./node_modules/${pythagora_dir}/src/scripts/unit.js"
64+
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/unit.js"
8565
exit 0
8666
elif [[ "${args[$i]}" == "--export-setup" ]]
8767
then
88-
PYTHAGORA_CONFIG="$@" node "./node_modules/${pythagora_dir}/src/scripts/enterData.js"
68+
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/enterData.js"
8969
exit 0
9070
elif [[ "${args[$i]}" =~ ^--rename[-_]tests$ ]]
9171
then
92-
node "./node_modules/${pythagora_dir}/src/scripts/renameTests.js"
72+
node "${pythagora_dir}/src/scripts/renameTests.js"
9373
exit 0
9474
elif [[ "${args[$i]}" =~ ^--delete[-_]all[-_]failed$ ]]
9575
then
96-
node "./node_modules/${pythagora_dir}/src/scripts/deleteAllFailed.js"
76+
node "${pythagora_dir}/src/scripts/deleteAllFailed.js"
9777
exit 0
9878
elif [[ "${args[$i]}" == "--delete" ]]
9979
then
100-
PYTHAGORA_CONFIG="$@" node "./node_modules/${pythagora_dir}/src/scripts/deleteTest.js"
80+
PYTHAGORA_CONFIG="$@" node "${pythagora_dir}/src/scripts/deleteTest.js"
10181
exit 0
10282
elif [[ "${args[$i]}" == "--export" ]]
10383
then
104-
PYTHAGORA_CONFIG="$@" node -e "require('./node_modules/${pythagora_dir}/src/commands/export.js').runExport()"
84+
PYTHAGORA_CONFIG="$@" node -e "require('${pythagora_dir}/src/commands/export.js').runExport()"
10585
exit 0
10686
elif [[ "${args[$i]}" == "--mode" ]]
10787
then
@@ -118,7 +98,7 @@ fi
11898
if [[ " ${args[@]} " =~ " --no-code-coverage " ]] || ([[ ! " ${args[@]} " =~ " --mode test " ]] && [[ ! " ${args[@]} " =~ " --mode=test " ]])
11999
then
120100
args=( "${args[@]//--no-code-coverage/}" )
121-
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ./node_modules/${pythagora_dir}/src/RunPythagora.js" $init_command &
101+
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ${pythagora_dir}/src/RunPythagora.js" $init_command &
122102
else
123103
nyc_args=( "--reporter=text-summary" )
124104

@@ -129,11 +109,11 @@ else
129109
nyc_args+=( "--report-dir=./pythagora_tests/code_coverage_report" )
130110
fi
131111

132-
if [ -f "./node_modules/$pythagora_dir/node_modules/nyc/bin/nyc.js" ]
112+
if [ -f "$pythagora_dir/node_modules/nyc/bin/nyc.js" ]
133113
then
134-
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ./node_modules/${pythagora_dir}/src/RunPythagora.js" ./node_modules/"$pythagora_dir"/node_modules/nyc/bin/nyc.js "${nyc_args[@]}" $init_command &
114+
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ${pythagora_dir}/src/RunPythagora.js" "$pythagora_dir"/node_modules/nyc/bin/nyc.js "${nyc_args[@]}" $init_command &
135115
else
136-
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ./node_modules/${pythagora_dir}/src/RunPythagora.js" ./node_modules/nyc/bin/nyc.js "${nyc_args[@]}" $init_command &
116+
PYTHAGORA_CONFIG="$@" NODE_OPTIONS="${inspect} --require ${pythagora_dir}/src/RunPythagora.js" ./node_modules/nyc/bin/nyc.js "${nyc_args[@]}" $init_command &
137117
fi
138118

139119
fi

src/bin/run.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ exec(bashCommand, (error, stdout, stderr) => {
3838
const bashPaths = stdout.split('\r\n').filter(line => line.trim() !== '').map(line => line.trim());
3939
const bashPath = bashPaths.find((p) => fs.existsSync(p));
4040
const bashScript = winOS ? process.argv[1].replace('run.js', 'run.bash') : path.join(__dirname, 'run.bash');
41+
const scriptDir = path.dirname(bashScript); // Get the directory of the bash script
42+
const pythagoraDir = path.dirname(path.dirname(scriptDir)); // Get the pythagora directory
4143
const args = process.argv.slice(2);
4244

4345
// Run the bash script and forward all arguments
44-
const child = spawn(bashPath, [bashScript, ...args], { stdio: 'inherit' });
46+
const child = spawn(bashPath, [bashScript, pythagoraDir, ...args], { stdio: 'inherit' });
4547

4648
child.on('error', (error) => {
4749
console.error(`Error running the bash script: ${error.message}`);

0 commit comments

Comments
 (0)