forked from Domiii/dbux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
101 lines (81 loc) · 2.42 KB
/
run.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# NOTE: This script is used for developing the slicing feature, to quickly run some tests
set -e # cancel on error
# set -x # verbose echo mode
# fname="__samplesInput__/async/promisify5-no-root"
# fname="__samplesInput__/defineProperty3-setter"
fname="__samplesInput__/generator-functions1"
# fname="__samplesInput__/async/await2"
thisDirRelative=$(dirname "$0")
rootDir=$(node -e "console.log(require('path').resolve('$thisDirRelative'))") # get absolute path using node
nodeArgsAlways="--stack-trace-limit=100"
nodeArgs=""
dbuxArgsI="--esnext"
# dbuxArgs="--pw=.*"
# dbuxArgs=""
# dbuxArgsI=""
dbuxCmd="$1"
if [[ $dbuxCmd = "" ]]
then
dbuxCmd="r"
fi
isInstrument=$([[ $dbuxCmd == "i" ]] && echo 1 || echo 0)
if [[ "$2" = "d" || "$3" = "d" ]]
then
nodeArgs="${nodeArgs} --inspect-brk"
fi
if [[ "$2" = "sm" || "$3" = "sm" ]]
then
# NOTE: --enable-source-maps can mess things up when executing the raw output
nodeArgs="${nodeArgs} --enable-source-maps"
fi
if [[ "$2" = "td" || "$3" = "td" ]]
then
dbuxArgsI='--runtime={"tracesDisabled":1}'
fi
if [[ $dbuxCmd = "i" ]]
then
nodeArgsI="$nodeArgsAlways $nodeArgs"
nodeArgsR="$nodeArgsAlways"
else
nodeArgsI="$nodeArgsAlways"
nodeArgsR="$nodeArgsAlways $nodeArgs"
fi
# echo "i $nodeArgsI r $nodeArgsR ($nodeArgs, $2)"
inPath="$rootDir/samples/$fname.js"
# if [[ $dbuxCmd = "i" ]]
# then
# else
# outPath=""
# fi
# x=$(( $isInstrument ))
# echo "$dbuxCmd i:$isInstrument x:$x"
if [[ "$dbuxCmd" == "b" ]]
then
# babel
# babelTarget="es5"
babelTarget="node"
outPath="$rootDir/samples/$fname.$babelTarget.js"
node $nodeArgs --enable-source-maps "$rootDir/node_modules/@babel/cli/bin/babel.js" --config-file="$rootDir/config/babel-presets-$babelTarget.js" $inPath --out-file="$outPath"
echo "Babeled ($babelTarget): $outPath"
else
outPath="$rootDir/samples/$fname.dbux.js"
if [[ "$dbuxCmd" != "rr" ]] && [[ "$dbuxCmd" != "rrr" ]]
then
# instrument
node $nodeArgsI --enable-source-maps "$rootDir/node_modules/@dbux/cli/bin/dbux.js" i $dbuxArgs $dbuxArgsI $inPath $outPath
fi
if [[ "$dbuxCmd" = "rrr" ]]
then
node $nodeArgsR --enable-source-maps "$rootDir/node_modules/@dbux/cli/bin/dbux.js" r $dbuxArgs $dbuxArgsI $inPath
# run with @babel/register
elif [[ "$dbuxCmd" = "r" ]] || [[ "$dbuxCmd" = "rr" ]]
then
# run
node $nodeArgsR -r "@dbux/runtime" $outPath
fi
fi
# if (( $isInstrument ))
# then
# code $outPath
# fi