-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtnode.sh
More file actions
executable file
·147 lines (104 loc) · 3.23 KB
/
tnode.sh
File metadata and controls
executable file
·147 lines (104 loc) · 3.23 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Colors
blue="\033[0;34m"
yellow="\033[0;33m"
bold_yellow="\033[33;1m"
bold_blue="\033[34;1m"
bold_red="\033[31;1m"
green="\033[0;32m"
bold_green="\033[32;1m"
white="\033[0;37m"
# Symbols
check_mark="\xE2\x9C\x85"
info="\xE2\x84\xB9\xEF\xB8\x8F"
# Check if NodeJS is installed
command -v node >/dev/null 2>&1 || { echo >&2 "Error: Node.js is not installed."; exit 1; }
# Prompt user to enter a name for the NodeJS project
printf "$bold_blue Enter a name for your NodeJS project: $bold_yellow"
read name
# Check if a folder with the same name already exists
while [[ -z $name ]]; do
printf "$bold_red You must enter a name for your project\n $bold_yellow "
read name
done
# Check if a folder with the same name already exists
while [[ -d "$name" ]]; do
printf "$bold_red Error: A folder with the name '$name' already exists.\n $bold_yellow "
read name
done
# Create the project folder
mkdir $name
# Inform about project creation
printf "$green Creating $bold_yellow$name$white...\n"
# Change directory to the project folder
cd $name
# Initialize npm project with default settings
npm init -y > /dev/null 2>&1
# Install TypeScript as a development dependency
npm i -D typescript > /dev/null 2>&1
# Install ts-node as a development dependency
npm i -D ts-node > /dev/null 2>&1
# Create tsconfig.json file
npx tsconfig.json
# Install ESLint and TypeScript ESLint plugins as development dependencies
npm i -D eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser > /dev/null 2>&1
# Create .eslintrc.json file with ESLint configuration
echo '{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"no-console": 0,
"@typescript-eslint/no-inferrable-types": 0
},
"ignorePatterns": ["node_modules", "dist"]
}' > .eslintrc.json
# Create .eslintignore file to ignore specified directories
echo 'node_modules
dist' > .eslintignore
# Append scripts to package.json file
sed -i '' '/"scripts": {/a\
"build": "npx tsc ./src/index.ts",\
"start": "ts-node ./src/index.ts",\
"js": "node ./src/index.js",\
' package.json
# Create .gitignore file for the project
echo "# Dependency directories
node_modules/
# Build output
dist/
build/
# Environment variables
.env
# Logs
logs/
*.log
# IDE specific files
.vscode/
.idea/" > .gitignore
mkdir src
echo "// Define a simple TypeScript class
class Greeting {
private message: string;
constructor(message: string) {
this.message = message;
}
greet() {
console.log(this.message);
}
}
// Create an instance of the class and call the greet() method
const greeting = new Greeting('Hello, World!');
greeting.greet();" > src/index.ts
printf "\n$check_mark$bold_green Project $bold_yellow$name$bold_green created successfully!\n"
printf "\n$info $blue The following scripts will save your life\n\n"
printf "$bold_yellow npm run start $white> Execute your typescript (index.ts) directly\n"
printf "$bold_yellow npm run build $white> Convert your Typescript into JavaScript\n"
printf "$bold_yellow npm run js $white> Execute your JavaScript\n\n"
# Exit the script with success status
exit 0