Skip to content

Instantly share code, notes, and snippets.

@yosukesan
Last active March 12, 2023 02:35
Show Gist options
  • Save yosukesan/851dfbe2dbb05ade1fd285f6019f5665 to your computer and use it in GitHub Desktop.
Save yosukesan/851dfbe2dbb05ade1fd285f6019f5665 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# make typescript env in docker and run main.ts
#
if [ $# != 1 ]; then
echo "usage: docker_tsc \${file}.ts"
exit 1
fi
TMP_DOCKERFILE_PATH=./Dockerfile
function generate_dockerfile (){
echo -e "FROM node:19-alpine\n\
RUN npm install -g typescript" > ${TMP_DOCKERFILE_PATH}
}
generate_dockerfile
IMAGE=yosukesan:ts_19alpine
TS_FILE_PATH=$1
docker build -t ${IMAGE} .
docker run --rm --network bridge --volume $(pwd):/tmp ${IMAGE} tsc /tmp/${TS_FILE_PATH} && node ${TS_FILE_PATH%.ts}.js
rm -f ${TMP_DOCKERFILE_PATH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment