create_project_structure.sh
· 1.1 KiB · Bash
原始文件
#!/bin/bash
# Check if the user provided a directory name as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <directory_name>"
exit 1
fi
# Set the user-provided parameter to the PROJECT_DIR variable
PROJECT_DIR="$1"
# Try to create a directory named PROJECT_DIR
if ! mkdir "$PROJECT_DIR"; then
echo "Failed: Unable to create directory $PROJECT_DIR. Exiting..."
exit 1
fi
# Change to the newly created directory
cd "$PROJECT_DIR"
# Create an empty index.html file
touch index.html
# Create a directory named src
mkdir src
# Create a subdirectory named components inside the src directory
mkdir src/components
# Create a file named my-element.js in the components directory
touch src/components/my-element.js
# Create a file named main.js
touch src/main.js
# Initialize a new npm project
npm init -y
# Install lit as a dependency
npm install lit --save
# Install vite as a development dependency
npm install vite --save-dev
# Install serve as a development dependency
npm install serve --save-dev
# List the directory structure excluding node_modules
tree -I "node_modules"
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Check if the user provided a directory name as an argument |
| 4 | if [ -z "$1" ]; then |
| 5 | echo "Usage: $0 <directory_name>" |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | # Set the user-provided parameter to the PROJECT_DIR variable |
| 10 | PROJECT_DIR="$1" |
| 11 | |
| 12 | # Try to create a directory named PROJECT_DIR |
| 13 | if ! mkdir "$PROJECT_DIR"; then |
| 14 | echo "Failed: Unable to create directory $PROJECT_DIR. Exiting..." |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | # Change to the newly created directory |
| 19 | cd "$PROJECT_DIR" |
| 20 | |
| 21 | # Create an empty index.html file |
| 22 | touch index.html |
| 23 | |
| 24 | # Create a directory named src |
| 25 | mkdir src |
| 26 | |
| 27 | # Create a subdirectory named components inside the src directory |
| 28 | mkdir src/components |
| 29 | |
| 30 | # Create a file named my-element.js in the components directory |
| 31 | touch src/components/my-element.js |
| 32 | |
| 33 | # Create a file named main.js |
| 34 | touch src/main.js |
| 35 | |
| 36 | # Initialize a new npm project |
| 37 | npm init -y |
| 38 | |
| 39 | # Install lit as a dependency |
| 40 | npm install lit --save |
| 41 | |
| 42 | # Install vite as a development dependency |
| 43 | npm install vite --save-dev |
| 44 | |
| 45 | # Install serve as a development dependency |
| 46 | npm install serve --save-dev |
| 47 | |
| 48 | # List the directory structure excluding node_modules |
| 49 | tree -I "node_modules" |
| 50 |