generated from devvianto605/create-dtx-ts-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-script.sh
executable file
·39 lines (30 loc) · 1 KB
/
run-script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Check if a project name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <project-name>"
exit 1
fi
# Set the project directory from the argument
PROJECT_DIR="$1"
# Create project directory and navigate into it
mkdir -p $PROJECT_DIR
cd $PROJECT_DIR
# Initialize a new Node.js project
npm init -y
# Install TypeScript, ts-node, and @types/node as dev dependencies
npm install typescript ts-node @types/node --save-dev
# Create a tsconfig.json file
npx tsc --init
# Add scripts to package.json
npx json -I -f package.json -e 'this.scripts={
"start": "ts-node ./index.ts",
"build": "tsc --outDir dist",
"serve": "node dist/index.js"
}'
# Compile TypeScript to JavaScript
npx tsc --outDir dist
# Output completion message
echo "TypeScript project setup complete in directory $PROJECT_DIR. You can run your project using:"
echo " npm start # To run with ts-node"
echo " npm run build # To compile TypeScript to JavaScript"
echo " npm run serve # To run the compiled JavaScript with Node.js"