The goal is to have a script repository to automate the creation of TypeScript projects of different types.
Every contribution is welcome! Feel free to help as you prefer.
#!/bin/bash | |
# CREATE INITIAL FILES | |
cat > package.json <<EOF | |
{ | |
"name": "@typescript/scaffold", | |
"version": "1.0.0", | |
"author": "Anderson Bosa", | |
"license": "CC0-1.0", | |
"keywords": ["typescript"], | |
"private": true, | |
"scripts": { | |
"devv":"nodemon ./src/index.ts", | |
"dev":"tsx --watch --inspect ./src/index.ts", | |
"start":"tsx ./src/index.ts", | |
"build": "tsc", | |
"build:watch": "tsc --watch", | |
"test": "tsx --inspect-brk ./node_modules/.bin/jest --watch --detectOpenHandles --runInBand ", | |
"test:adapters": "npm run test -- ./src/adapters", | |
"test:domain": "npm run test -- ./src/domain", | |
"test:coverage": "npm run test -- --coverage .", | |
"test:ci": "jest" | |
}, | |
"engines": { | |
"node": ">=20.x" | |
}, | |
"devDependencies": {}, | |
"dependencies": {} | |
} | |
EOF | |
cat > nodemon.json <<EOF | |
{ | |
"ext": "ts", | |
"watch": ["src"], | |
"verbose": true, | |
"ignore": [ | |
"./**/*.json", | |
"./**/src/logs/**", | |
"./**/fixtures/**", | |
"./**/tests/**", | |
"./**/*.spec.ts" | |
], | |
"env": {} | |
} | |
EOF | |
cat > tsconfig.json <<EOF | |
{ | |
/* Visit https://aka.ms/tsconfig to read more about this file */ | |
"extends": "@tsconfig/node20/tsconfig.json", | |
"exclude": [ | |
"**/*.spec.*" | |
], | |
"compilerOptions": { | |
"typeRoots": [ | |
"./node_modules/@types", | |
"./@types" | |
], | |
"sourceMap": true, | |
"outDir": "./dist", | |
"strict": true | |
} | |
} | |
EOF | |
cat > .nvmrc <<EOF | |
v20.12.1 | |
EOF | |
cat > Makefile <<EOF | |
IMAGE_NAME = boilerplate-ts | |
IMAGE_TAG = unstable | |
build: | |
docker build -t \$(IMAGE_NAME):\$(IMAGE_TAG) . | |
run: | |
docker run --rm \$(IMAGE_NAME):\$(IMAGE_TAG) | |
.PHONY: build run | |
EOF | |
# CREATE SOURCE-CODE FILES | |
mkdir -p ./@types ./src | |
cat > ./src/index.ts <<EOF | |
console.log('Hello, World!'); | |
EOF | |
mkdir -p ./src/{adapters,domain,ports} | |
touch ./src/{adapters,domain,ports}/.gitkeep | |
# INSTALL DEPENDENCIES | |
npm install --save-dev typescript@latest tsx@latest ts-node@latest @tsconfig/node20 @types/node | |
npm install --save-dev nodemon | |
cat > ./Dockerfile <<EOF | |
# https://hub.docker.com/_/node/tags | |
FROM node:20.12.1-slim | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build | |
CMD ["npm", "start"] | |
EOF | |
# https://jestjs.io/docs/getting-started#using-typescript | |
npm install --save-dev jest ts-jest @types/jest @jest/globals | |
npm install --save-dev supertest @types/supertest | |
npm init jest@latest |