最后活跃于 10 months ago

這段 PowerShell 腳本建立一個專案目錄,初始化基本的前端專案結構,包括 index.html、src 資料夾及子目錄,並透過 npm 安裝必要的依賴 (lit、vite、serve),最後列出目錄結構供檢查。

timmy 修订了这个 Gist 10 months ago. 转到此修订

没有任何变更

timmy 修订了这个 Gist 11 months ago. 转到此修订

没有任何变更

timmy 修订了这个 Gist 11 months ago. 转到此修订

1 file changed, 47 insertions

setup_project.ps1(文件已创建)

@@ -0,0 +1,47 @@
1 + # 檢查是否提供了目錄名稱參數
2 + if ($args.Length -eq 0) {
3 + Write-Host "Usage: .\setup_project.ps1 <directory_name>"
4 + exit 1
5 + }
6 +
7 + # 將參數設定為 PROJECT_DIR 變數
8 + $PROJECT_DIR = $args[0]
9 +
10 + # 嘗試建立目錄
11 + if (-not (Test-Path $PROJECT_DIR)) {
12 + New-Item -ItemType Directory -Path $PROJECT_DIR | Out-Null
13 + } else {
14 + Write-Host "Failed: Unable to create directory '$PROJECT_DIR'. Exiting..."
15 + exit 1
16 + }
17 +
18 + # 切換到該目錄
19 + Set-Location -Path $PROJECT_DIR
20 +
21 + # 建立空的 index.html
22 + New-Item -ItemType File -Name "index.html" | Out-Null
23 +
24 + # 建立 src 目錄及其子目錄
25 + New-Item -ItemType Directory -Name "src" | Out-Null
26 + New-Item -ItemType Directory -Path "src\components" | Out-Null
27 +
28 + # 建立 my-element.js 和 main.js 檔案
29 + New-Item -ItemType File -Path "src\components\my-element.js" | Out-Null
30 + New-Item -ItemType File -Path "src\main.js" | Out-Null
31 +
32 + # 初始化 npm 專案
33 + npm init -y
34 +
35 + # 安裝 lit 為依賴
36 + npm install lit --save
37 +
38 + # 安裝 vite 和 serve 作為開發依賴
39 + npm install vite --save-dev
40 + npm install serve --save-dev
41 +
42 + # 列出目錄結構(不包括 node_modules)
43 + Write-Host "Directory structure:"
44 + Get-ChildItem -Recurse -Directory | Where-Object { $_.Name -ne "node_modules" } | ForEach-Object { Write-Host $_.FullName }
45 +
46 + # 暫停,讓使用者查看輸出
47 + Pause
上一页 下一页