Skip to content

Commit 485c680

Browse files
committed
Typescript added
1 parent ebe79e0 commit 485c680

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

scripts/files.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ SCRIPTS_IN = \
6666
nasm-x86-version.in\
6767
node.in\
6868
node-version.in\
69+
tsnode.in\
70+
tsnode-version.in\
6971
qb.in\
7072
qb-version.in\
7173
perl.in\

scripts/lang_ids.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ dotnet-vb=74
6161
rars=75
6262
swift=76
6363
custom=77
64+
tsnode=78

scripts/tsnode-version.in

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
# Copyright (c) 2023 Alexander Chernov <[email protected]>
3+
4+
LANG_CONFIG_DIR="@lang_config_dir@"
5+
6+
common_config() {
7+
echo 'long_name="Typescript"'
8+
echo 'src_sfx=".ts"'
9+
echo 'arch="linux-shared"'
10+
echo 'insecure=1'
11+
}
12+
13+
failure() {
14+
rm -f conftest*
15+
echo 'version='
16+
echo 'arg="'"${arg}"'"'
17+
common_config
18+
echo 'NODEPATH=/bin/false'
19+
[ "${verbose}" = 1 ] && echo "no" >&2
20+
exit 1
21+
}
22+
23+
unset LANG
24+
unset LC_ALL
25+
unset LC_MESSAGES
26+
unset LANGUAGE
27+
28+
if [ x"$1" = x-v ]
29+
then
30+
verbose=1
31+
shift
32+
fi
33+
34+
# recheck the language
35+
if [ x"$1" = x-r ]
36+
then
37+
arg="$2"
38+
[ x"$2" != x ] && node="$2"
39+
[ "${node}" = "" ] && node="ts-node"
40+
41+
[ "${verbose}" = 1 ] && echo -n "checking whether TypeScript is available..." >&2
42+
"${node}" --version >/dev/null 2>&1 || failure
43+
version=`"${node}" --version 2>&1 | sed 's/v//g'` || failure
44+
[ "${version}" != "" ] || failure
45+
NODEPATH=`which "${node}"` || failure
46+
[ "${NODEPATH}" != "" ] || failure
47+
echo "#! ${NODEPATH}" > conftest.rb
48+
echo "console.log('yes');" >> conftest.rb
49+
chmod +x ./conftest.rb || failure
50+
./conftest.rb >/dev/null 2>&1 || failure
51+
52+
rm -f ./conftest*
53+
echo 'version="'"${version}"'"'
54+
echo 'arg="'"${arg}"'"'
55+
common_config
56+
echo 'NODEPATH="'"${NODEPATH}"'"'
57+
[ "${verbose}" = 1 ] && echo "yes, ${NODEPATH}, ${version}" >&2
58+
exit 0
59+
fi
60+
61+
if [ x"$1" = x-l ]
62+
then
63+
echo "NodeJS interpreter [https://nodejs.org]"
64+
exit 0
65+
fi
66+
67+
[ "${EJUDGE_LANG_CONFIG}" = "" ] && EJUDGE_LANG_CONFIG="${LANG_CONFIG_DIR}/tsnode.cfg"
68+
69+
if [ -f "${EJUDGE_LANG_CONFIG}" ]
70+
then
71+
. "${EJUDGE_LANG_CONFIG}"
72+
else
73+
NODEPATH=`which ts-node`
74+
fi
75+
76+
if [ x"${NODEPATH}" = x -o x"${NODEPATH}" = x/bin/false ]
77+
then
78+
echo "This language is not supported." >&2
79+
exit 1
80+
fi
81+
82+
if [ x"$1" = x-p ]
83+
then
84+
echo "${NODEPATH}"
85+
exit 0
86+
fi
87+
88+
"${NODEPATH}" --version 2>/dev/null >/dev/null || exit 1
89+
90+
[ x"$1" = x-f ] && echo -n "NodeJS "
91+
92+
"${NODEPATH}" --version 2>&1 | sed 's/v//g'

scripts/tsnode.in

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
# Copyright (c) 2023 Alexander Chernov <[email protected]>
3+
4+
# This is a `compilation' script for the JavaScript (NodeJS) language.
5+
# The idea is to append "#!${NODEPATH}" string
6+
# to the beginning of the file.
7+
# Usage: tsnode <input> <output>
8+
9+
# using EJUDGE_FLAGS we may pass additional flags
10+
11+
LANG_CONFIG_DIR="@lang_config_dir@"
12+
[ "${EJUDGE_LANG_CONFIG}" = "" ] && EJUDGE_LANG_CONFIG="${LANG_CONFIG_DIR}/tsnode.cfg"
13+
14+
if [ -f "${EJUDGE_LANG_CONFIG}" ]
15+
then
16+
. "${EJUDGE_LANG_CONFIG}"
17+
else
18+
version="unknown"
19+
NODEPATH="/usr/bin/ts-node"
20+
fi
21+
22+
if [ x"${version}" = x ]
23+
then
24+
echo "This language is not supported." >&2
25+
exit 1
26+
fi
27+
28+
echo "#! ${NODEPATH} ${EJUDGE_FLAGS}" > $2
29+
echo >> $2
30+
cat $1 >> $2
31+
chmod +x $2
32+
exit 0

0 commit comments

Comments
 (0)