-
Notifications
You must be signed in to change notification settings - Fork 0
/
initNodeTypeScript.sh
127 lines (90 loc) · 2.67 KB
/
initNodeTypeScript.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /usr/bin/env bash
cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
NC="\033[0m"
printf "${!1}${2} ${NC}\n"
}
echo "Node Initializer Starting Successfully";
echo -e "\e[33m ===========================STEP 1================================"
read -p "Where You want to initialize this project ? [Leave it blank to start here] : " directoryinit
if ["$directoryinit" -eq ""]
then
echo "I am going to initialize the project here!"
else
if [ -d "$directoryinit" ]
then
echo -e "\e[31m Directory alrady exists!"
read -p "do you want to rewrite it (the original will be deleted!)? [y/N] " rewriteIt
if [[ "$rewriteIt" == "y" ]] || [[ "$rewriteIt" == "Y" ]]
then
rm -rf $directoryinit
mkdir -p $directoryinit
else
echo -e "\e[31m I am exiting from the session!"
exit 1
fi
else
echo -e "\e[32m I am going to init project in ${directoryinit}"
mkdir -p $directoryinit
fi
fi
cd $directoryinit
echo -e "\e[33m ===========================STEP 2================================"
read -p "project name(without spaces and upper cases) : " projectname
read -p "Auther : " authername
cat << EOF > package.json
{
"name": "${projectname}",
"version": "0.0.1",
"description": "",
"main": "src/app.ts",
"scripts": {
"start": "node -r ts-node/register src/app.ts"
},
"keywords": [ ],
"author": "${authername}",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"moment": "^2.29.1",
"ts-node": "^10.0.0",
"typescript": "4.1.3"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^14.14.7"
}
}
EOF
mkdir src
cat << EOF > src/app.ts
import express from "express";
const app = express();
app.get( "/", ( req, res ) => {
res.send( "Hello world!" );
} );
// start Express server
app.listen( 8080, () => {
console.log( `server started at http://localhost:8080` );
} );
EOF
if command -v nvm > /dev/null
then
read -p "nvm not exists do you want to install it? [Y/n]" projectname
if [[ "$projectname" == "n" ]] || [[ "$projectname" == "N" ]]
then
exit 1
else
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
fi
fi
nvm install --lts
nvm use --lts
npm i
echo -e "\e[32m now your project is ready!"
echo -e "\e[32m type 'npm run start' to run your project on 8080 port"
exit;