Created
June 29, 2023 22:08
-
-
Save robertolos/9c079e1f8ea580268be078487dbbf18c to your computer and use it in GitHub Desktop.
Initialise a new node project with typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialise a new node project with typescript | |
# usage: | |
# > ./initTypescriptProject.sh my-app-name | |
PROJECT_NAME=$1 | |
mkdir $PROJECT_NAME | |
cd $PROJECT_NAME | |
npm init -y | |
yarn add --dev typescript ts-node nodemon rimraf @types/node jest | |
# init typescript | |
npx tsc --init --rootDir src --outDir build \ | |
--esModuleInterop --resolveJsonModule --lib es6 \ | |
--module commonjs --allowJs true --noImplicitAny true | |
# source directory | |
mkdir src | |
touch src/index.ts | |
echo "console.log('Hello world!')" > src/index.ts | |
# watch mode | |
touch nodemon.json | |
cat <<EOT >> nodemon.json | |
{ | |
"watch": ["src"], | |
"ext": ".ts,.js", | |
"ignore": [], | |
"exec": "npx ts-node ./src/index.ts" | |
} | |
EOT | |
# update package.json scripts | |
echo "$(jq '.scripts.test="jest" | .scripts."start:dev"="npx nodemon" | .scripts.build="rimraf ./build && tsc" | .scripts.start="npm run build && node build/index.js"' package.json)" > package.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment