Skip to content

Instantly share code, notes, and snippets.

@robertolos
Created June 29, 2023 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertolos/9c079e1f8ea580268be078487dbbf18c to your computer and use it in GitHub Desktop.
Save robertolos/9c079e1f8ea580268be078487dbbf18c to your computer and use it in GitHub Desktop.
Initialise a new node project with typescript
# 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