@@ -9,7 +9,7 @@ yellow=$(tput setaf 3)
9
9
green=$( tput setaf 2)
10
10
reset=$( tput sgr0)
11
11
bold=$( tput bold)
12
- pythagora_dir=" pythagora "
12
+ pythagora_dir=" $1 "
13
13
14
14
function exit_handler {
15
15
while [ ! -f " ./.pythagora/finishingup" ]
@@ -25,26 +25,6 @@ function exit_handler {
25
25
exit 0
26
26
}
27
27
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
-
48
28
for (( i= 0 ; i< ${# args[@]} ; i++ ))
49
29
do
50
30
if [[ " ${args[$i]} " =~ ^--init[-_]command$ ]]
53
33
elif [[ " ${args[$i]} " == " --config" ]]
54
34
then
55
35
# TODO refactor and make it flexible
56
- CONFIG_DIR=" ./.pythagora"
57
- CONFIG_FILE=" $CONFIG_DIR /config.json"
58
- TMP_FILE=" $CONFIG_DIR /tmp.json"
36
+ CONFIG_FILE=" ./.pythagora/config.json"
37
+ rm " $CONFIG_FILE "
59
38
60
- # Create the config file if it doesn't exist
61
39
if [ ! -f " $CONFIG_FILE " ]; then
62
- mkdir -p $CONFIG_DIR
63
- echo " {} " > $CONFIG_FILE
40
+ mkdir -p ./.pythagora
41
+ touch " ./ $CONFIG_FILE "
64
42
fi
65
43
66
44
API_NAME=" ${args[$i+1]// --/ } "
67
45
API_NAME=" ${API_NAME// -/ _} "
68
46
API_KEY=" ${args[$i+2]} "
69
-
70
- if [ " $API_NAME " == " pythagora_api_key" ]; then
71
- jq ' del(.openai_api_key)' $CONFIG_FILE > $TMP_FILE && mv $TMP_FILE $CONFIG_FILE
72
- elif [ " $API_NAME " == " openai_api_key" ]; then
73
- jq ' del(.pythagora_api_key)' $CONFIG_FILE > $TMP_FILE && mv $TMP_FILE $CONFIG_FILE
74
- fi
75
-
76
- # Use jq to add the new key-value pair to the JSON object
77
- jq --arg key " $API_NAME " --arg value " $API_KEY " ' . + {($key): $value}' $CONFIG_FILE > $TMP_FILE && mv $TMP_FILE $CONFIG_FILE
47
+ echo " {" >> $CONFIG_FILE
48
+ echo " \" $API_NAME \" : \" $API_KEY \" " >> $CONFIG_FILE
49
+ echo " }" >> $CONFIG_FILE
78
50
echo " ${green}${bold} API key added to config!${reset} "
79
51
exit 0
80
52
elif [[ " ${args[$i]} " == " --review" ]]
81
53
then
82
- PYTHAGORA_CONFIG=" $@ " node " ./node_modules/ ${pythagora_dir} /src/scripts/review.js"
54
+ PYTHAGORA_CONFIG=" $@ " node " ${pythagora_dir} /src/scripts/review.js"
83
55
exit 0
84
56
elif [[ " ${args[$i]} " == " --tests-eligible-for-export" ]]
85
57
then
86
58
echo " ${yellow}${bold} Tests eligible for export:${reset} "
87
- PYTHAGORA_CONFIG=" $@ " node " ./node_modules/ ${pythagora_dir} /src/scripts/testsEligibleForExport.js"
59
+ PYTHAGORA_CONFIG=" $@ " node " ${pythagora_dir} /src/scripts/testsEligibleForExport.js"
88
60
exit 0
89
61
elif [[ " ${args[$i]} " == " --unit-tests" ]]
90
62
then
91
63
echo " ${green}${bold} Generating unit tests...${reset} "
92
- PYTHAGORA_CONFIG=" $@ " node " ./node_modules/ ${pythagora_dir} /src/scripts/unit.js"
64
+ PYTHAGORA_CONFIG=" $@ " node " ${pythagora_dir} /src/scripts/unit.js"
93
65
exit 0
94
66
95
67
elif [[ " ${args[$i]} " == " --expand-unit-tests" ]]
100
72
101
73
elif [[ " ${args[$i]} " == " --export-setup" ]]
102
74
then
103
- PYTHAGORA_CONFIG=" $@ " node " ./node_modules/ ${pythagora_dir} /src/scripts/enterData.js"
75
+ PYTHAGORA_CONFIG=" $@ " node " ${pythagora_dir} /src/scripts/enterData.js"
104
76
exit 0
105
77
elif [[ " ${args[$i]} " =~ ^--rename[-_]tests$ ]]
106
78
then
107
- node " ./node_modules/ ${pythagora_dir} /src/scripts/renameTests.js"
79
+ node " ${pythagora_dir} /src/scripts/renameTests.js"
108
80
exit 0
109
81
elif [[ " ${args[$i]} " =~ ^--delete[-_]all[-_]failed$ ]]
110
82
then
111
- node " ./node_modules/ ${pythagora_dir} /src/scripts/deleteAllFailed.js"
83
+ node " ${pythagora_dir} /src/scripts/deleteAllFailed.js"
112
84
exit 0
113
85
elif [[ " ${args[$i]} " == " --delete" ]]
114
86
then
115
- PYTHAGORA_CONFIG=" $@ " node " ./node_modules/ ${pythagora_dir} /src/scripts/deleteTest.js"
87
+ PYTHAGORA_CONFIG=" $@ " node " ${pythagora_dir} /src/scripts/deleteTest.js"
116
88
exit 0
117
89
elif [[ " ${args[$i]} " == " --export" ]]
118
90
then
119
- PYTHAGORA_CONFIG=" $@ " node -e " require('./node_modules/ ${pythagora_dir} /src/commands/export.js').runExport()"
91
+ PYTHAGORA_CONFIG=" $@ " node -e " require('${pythagora_dir} /src/commands/export.js').runExport()"
120
92
exit 0
121
93
elif [[ " ${args[$i]} " == " --mode" ]]
122
94
then
133
105
if [[ " ${args[@]} " =~ " --no-code-coverage " ]] || ([[ ! " ${args[@]} " =~ " --mode test " ]] && [[ ! " ${args[@]} " =~ " --mode=test " ]])
134
106
then
135
107
args=( " ${args[@]// --no-code-coverage/ } " )
136
- PYTHAGORA_CONFIG=" $@ " NODE_OPTIONS=" ${inspect} --require ./node_modules/ ${pythagora_dir} /src/RunPythagora.js" $init_command &
108
+ PYTHAGORA_CONFIG=" $@ " NODE_OPTIONS=" ${inspect} --require ${pythagora_dir} /src/RunPythagora.js" $init_command &
137
109
else
138
110
nyc_args=( " --reporter=text-summary" )
139
111
@@ -144,11 +116,11 @@ else
144
116
nyc_args+=( " --report-dir=./pythagora_tests/code_coverage_report" )
145
117
fi
146
118
147
- if [ -f " ./node_modules/ $pythagora_dir /node_modules/nyc/bin/nyc.js" ]
119
+ if [ -f " $pythagora_dir /node_modules/nyc/bin/nyc.js" ]
148
120
then
149
- 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 &
121
+ PYTHAGORA_CONFIG=" $@ " NODE_OPTIONS=" ${inspect} --require ${pythagora_dir} /src/RunPythagora.js" " $pythagora_dir " /node_modules/nyc/bin/nyc.js " ${nyc_args[@]} " $init_command &
150
122
else
151
- PYTHAGORA_CONFIG=" $@ " NODE_OPTIONS=" ${inspect} --require ./node_modules/ ${pythagora_dir} /src/RunPythagora.js" ./node_modules/nyc/bin/nyc.js " ${nyc_args[@]} " $init_command &
123
+ PYTHAGORA_CONFIG=" $@ " NODE_OPTIONS=" ${inspect} --require ${pythagora_dir} /src/RunPythagora.js" ./node_modules/nyc/bin/nyc.js " ${nyc_args[@]} " $init_command &
152
124
fi
153
125
154
126
fi
0 commit comments