@wanggangqi/workspace-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +410 -0
- package/bin/cli.js +177 -0
- package/config.json +41 -0
- package/lib/workspace.js +1591 -0
- package/nginx-config/3620_zhongtai.conf +73 -0
- package/nginx-config/reload-nginx.ps1 +106 -0
- package/nginx-config/start-nginx.ps1 +163 -0
- package/nginx-config/status-nginx.ps1 +96 -0
- package/nginx-config/stop-nginx.ps1 +127 -0
- package/package.json +41 -0
- package/prompts/prompt.md +264 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
# [提示] 请根据当前工作空间调整以下路径:
|
|
3
|
+
server {
|
|
4
|
+
listen <serveport>; # 监听端口
|
|
5
|
+
server_name localhost; # 监听地址
|
|
6
|
+
client_max_body_size 100m;
|
|
7
|
+
|
|
8
|
+
location = / {
|
|
9
|
+
return 301 /erdc-app/erdc-portal-web/index.html;
|
|
10
|
+
}
|
|
11
|
+
location = /index.html {
|
|
12
|
+
return 301 /erdc-app/erdc-portal-web/index.html;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# 平台
|
|
16
|
+
set $workspaceDir <workspaceDir>;
|
|
17
|
+
set $platDir 'erdcloud-plat-frontend';
|
|
18
|
+
set $platPluginDir 'erdcloud-plat-plugins-frontend';
|
|
19
|
+
set $platRoot "${workspaceDir}/${platDir}";
|
|
20
|
+
set $platPlugin "${workspaceDir}/${platPluginDir}";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
location ~ ^/erdc-app/(erdc-portal-web|erdc-bizadmin-web|erdc-sysadmin-web|erdc-platform-web)/ {
|
|
24
|
+
root $platRoot;
|
|
25
|
+
}
|
|
26
|
+
location ~ ^/erdc-app/(erdc-product-example-web|erdc-license-web|erdc-reports-web)/ {
|
|
27
|
+
root $platPlugin;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
location ~ ^/(erdc-layout|erdc-theme)/ {
|
|
31
|
+
root $platRoot;
|
|
32
|
+
}
|
|
33
|
+
location ~ ^/erdc-libs/(avatars|common-page|doc-sdk|erdc-app|erdc-auth|erdc-components|erdc-fonts|erdc-kit|erdc-permission-components|erdc-plat-icon|erdc-process-components|erdc-product-components|erdc-type-components|framework|erdc-guideline|erdc-img|dashboard-skin|erdc-assets|erdc-plat-nav-icon|erdc-polyfill|ai) {
|
|
34
|
+
root $platRoot;
|
|
35
|
+
}
|
|
36
|
+
location ~ ^/erdc-libs/(erdc-sso-login|erdc-token-login|erdc-skywalking-client)/ {
|
|
37
|
+
root $platPlugin;
|
|
38
|
+
}
|
|
39
|
+
location ~ ^/erdc-resource/(advanced-search|erdc-druid|erdc-login|leave-resource-package|erdc-login-ldap|erdc-druid|erdc-ai|erdc-plat-demo) {
|
|
40
|
+
root $platRoot;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
location ~ ^/erdc-thirdparty/platform/(.+\.\w+$) {
|
|
44
|
+
root $platRoot;
|
|
45
|
+
try_files $uri $uri/ /erdc-thirdparty/platform/node_modules/$1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
location ~ ^/erdc-thirdparty/platform-core {
|
|
49
|
+
root $platRoot;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# java服务
|
|
57
|
+
location / {
|
|
58
|
+
#开发
|
|
59
|
+
proxy_pass <proxyTarget>;
|
|
60
|
+
proxy_redirect off;
|
|
61
|
+
#开发
|
|
62
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
63
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
64
|
+
client_max_body_size 1000m;
|
|
65
|
+
proxy_buffer_size 128k;
|
|
66
|
+
proxy_buffers 16 128k;
|
|
67
|
+
proxy_busy_buffers_size 512k;
|
|
68
|
+
proxy_temp_file_write_size 512k;
|
|
69
|
+
proxy_set_header appId erdp;
|
|
70
|
+
add_header appId erdp;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
#Requires -Version 7.0
|
|
3
|
+
|
|
4
|
+
# 设置输入输出编码为 UTF-8
|
|
5
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
6
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
7
|
+
[System.Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
8
|
+
|
|
9
|
+
# 防止窗口一闪而过
|
|
10
|
+
trap {
|
|
11
|
+
Write-Host "[错误] 发生异常:$_" -ForegroundColor Red
|
|
12
|
+
exit 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$Host.UI.RawUI.WindowTitle = "Nginx 重载配置脚本"
|
|
16
|
+
|
|
17
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
18
|
+
Write-Host " Nginx 重载配置脚本" -ForegroundColor Cyan
|
|
19
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
20
|
+
Write-Host ""
|
|
21
|
+
|
|
22
|
+
# 获取脚本所在目录
|
|
23
|
+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
24
|
+
$PidFile = Join-Path $ScriptDir "nginx.pid"
|
|
25
|
+
|
|
26
|
+
# 自动推断 nginx 路径(如果环境变量未设置)
|
|
27
|
+
if (-not $env:NGINX_EXE) {
|
|
28
|
+
# 检查是否运行的是模板脚本(在 nginx-config 目录下)
|
|
29
|
+
if ($ScriptDir -like "*nginx-config") {
|
|
30
|
+
Write-Host "[错误] 这是模板脚本,不能直接运行!" -ForegroundColor Red
|
|
31
|
+
Write-Host "[提示] 请先在工作空间运行: wsc nginx init" -ForegroundColor Yellow
|
|
32
|
+
Write-Host "[提示] 然后运行生成的脚本: .workspace\nginx\reload-nginx.ps1" -ForegroundColor Gray
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$NginxDir = Join-Path $ScriptDir "nginx-*"
|
|
37
|
+
$NginxExe = Get-ChildItem -Path $NginxDir -Filter "nginx.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
38
|
+
if ($NginxExe) {
|
|
39
|
+
$env:NGINX_EXE = $NginxExe.FullName
|
|
40
|
+
$env:NGINX_DIR = $NginxExe.DirectoryName
|
|
41
|
+
$env:NGINX_CONF = Join-Path $NginxExe.DirectoryName "conf\nginx.conf"
|
|
42
|
+
$env:WORKSPACE_DIR = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
|
43
|
+
Write-Host "[信息] 自动推断 nginx 路径: $($env:NGINX_EXE)" -ForegroundColor Gray
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# 检查环境变量
|
|
48
|
+
if (-not $env:NGINX_EXE) {
|
|
49
|
+
Write-Host "[错误] 未设置 NGINX_EXE 环境变量,且无法自动推断" -ForegroundColor Red
|
|
50
|
+
Write-Host "[提示] 请通过 'wsc nginx reload' 命令运行" -ForegroundColor Yellow
|
|
51
|
+
exit 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (-not $env:NGINX_CONF) {
|
|
55
|
+
Write-Host "[错误] 未设置 NGINX_CONF 环境变量,且无法自动推断" -ForegroundColor Red
|
|
56
|
+
exit 1
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# 推断 NGINX_DIR(nginx 安装目录)
|
|
60
|
+
if (-not $env:NGINX_DIR) {
|
|
61
|
+
$env:NGINX_DIR = Split-Path -Parent $env:NGINX_EXE
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Write-Host "[信息] 工作空间: $env:WORKSPACE_DIR" -ForegroundColor Gray
|
|
65
|
+
Write-Host ""
|
|
66
|
+
|
|
67
|
+
# 检查当前工作空间的 nginx 是否在运行
|
|
68
|
+
$IsRunning = $false
|
|
69
|
+
if (Test-Path $PidFile) {
|
|
70
|
+
$Pids = Get-Content $PidFile -ErrorAction SilentlyContinue
|
|
71
|
+
foreach ($NginxPid in $Pids) {
|
|
72
|
+
$Process = Get-Process -Id $NginxPid -ErrorAction SilentlyContinue
|
|
73
|
+
if ($Process -and $Process.ProcessName -eq "nginx") {
|
|
74
|
+
$IsRunning = $true
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (-not $IsRunning) {
|
|
81
|
+
Write-Host "[错误] 当前工作空间的 nginx 未运行" -ForegroundColor Red
|
|
82
|
+
Write-Host "[提示] 请先运行 'wsc nginx start' 启动 nginx" -ForegroundColor Yellow
|
|
83
|
+
exit 1
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Write-Host "[信息] 正在重新加载 nginx 配置..." -ForegroundColor Green
|
|
87
|
+
|
|
88
|
+
# 先测试配置(使用 -p 指定前缀目录)
|
|
89
|
+
Write-Host "[信息] 正在测试配置..." -ForegroundColor Gray
|
|
90
|
+
& $env:NGINX_EXE -p $env:NGINX_DIR -t -c $env:NGINX_CONF
|
|
91
|
+
|
|
92
|
+
if ($LASTEXITCODE -ne 0) {
|
|
93
|
+
Write-Host "[错误] 配置测试失败" -ForegroundColor Red
|
|
94
|
+
exit 1
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# 重载配置(使用 -p 指定前缀目录)
|
|
98
|
+
& $env:NGINX_EXE -p $env:NGINX_DIR -c $env:NGINX_CONF -s reload
|
|
99
|
+
|
|
100
|
+
if ($LASTEXITCODE -eq 0) {
|
|
101
|
+
Write-Host "[成功] nginx 配置已重新加载" -ForegroundColor Green
|
|
102
|
+
} else {
|
|
103
|
+
Write-Host "[错误] 重新加载失败,请检查 nginx 是否正在运行" -ForegroundColor Red
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Write-Host ""
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
#Requires -Version 7.0
|
|
3
|
+
|
|
4
|
+
# 设置输入输出编码为 UTF-8
|
|
5
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
6
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
7
|
+
[System.Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
8
|
+
|
|
9
|
+
# 防止窗口一闪而过
|
|
10
|
+
trap {
|
|
11
|
+
Write-Host "[错误] 发生异常:$_" -ForegroundColor Red
|
|
12
|
+
exit 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$Host.UI.RawUI.WindowTitle = "Nginx 启动脚本"
|
|
16
|
+
|
|
17
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
18
|
+
Write-Host " Nginx 启动脚本" -ForegroundColor Cyan
|
|
19
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
20
|
+
Write-Host ""
|
|
21
|
+
|
|
22
|
+
# 获取脚本所在目录
|
|
23
|
+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
24
|
+
$PidFile = Join-Path $ScriptDir "nginx.pid"
|
|
25
|
+
|
|
26
|
+
# 自动推断 nginx 路径(如果环境变量未设置)
|
|
27
|
+
if (-not $env:NGINX_EXE) {
|
|
28
|
+
# 检查是否运行的是模板脚本(在 nginx-config 目录下)
|
|
29
|
+
if ($ScriptDir -like "*nginx-config") {
|
|
30
|
+
Write-Host "[错误] 这是模板脚本,不能直接运行!" -ForegroundColor Red
|
|
31
|
+
Write-Host "[提示] 请先在工作空间运行: wsc nginx init" -ForegroundColor Yellow
|
|
32
|
+
Write-Host "[提示] 然后运行生成的脚本: .workspace\nginx\start-nginx.ps1" -ForegroundColor Gray
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# 脚本在 .workspace/nginx/ 目录下,nginx 在 .workspace/nginx/nginx-*/nginx.exe
|
|
37
|
+
$NginxDir = Join-Path $ScriptDir "nginx-*"
|
|
38
|
+
$NginxExe = Get-ChildItem -Path $NginxDir -Filter "nginx.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
39
|
+
if ($NginxExe) {
|
|
40
|
+
$env:NGINX_EXE = $NginxExe.FullName
|
|
41
|
+
$env:NGINX_DIR = $NginxExe.DirectoryName
|
|
42
|
+
$env:NGINX_CONF = Join-Path $NginxExe.DirectoryName "conf\nginx.conf"
|
|
43
|
+
$env:WORKSPACE_DIR = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
|
44
|
+
Write-Host "[信息] 自动推断 nginx 路径: $($env:NGINX_EXE)" -ForegroundColor Gray
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# 检查环境变量
|
|
49
|
+
if (-not $env:NGINX_EXE) {
|
|
50
|
+
Write-Host "[错误] 未设置 NGINX_EXE 环境变量,且无法自动推断" -ForegroundColor Red
|
|
51
|
+
Write-Host "[提示] 请通过 'wsc nginx start' 命令运行" -ForegroundColor Yellow
|
|
52
|
+
exit 1
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (-not $env:NGINX_CONF) {
|
|
56
|
+
Write-Host "[错误] 未设置 NGINX_CONF 环境变量,且无法自动推断" -ForegroundColor Red
|
|
57
|
+
exit 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# 推断 NGINX_DIR(nginx 安装目录)
|
|
61
|
+
if (-not $env:NGINX_DIR) {
|
|
62
|
+
$env:NGINX_DIR = Split-Path -Parent $env:NGINX_EXE
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# 检查是否已有该工作空间的 nginx 在运行
|
|
66
|
+
if (Test-Path $PidFile) {
|
|
67
|
+
$ExistingPid = Get-Content $PidFile -ErrorAction SilentlyContinue
|
|
68
|
+
if ($ExistingPid) {
|
|
69
|
+
$Process = Get-Process -Id $ExistingPid -ErrorAction SilentlyContinue
|
|
70
|
+
if ($Process -and $Process.ProcessName -eq "nginx") {
|
|
71
|
+
Write-Host "[警告] 当前工作空间的 nginx 已在运行 (PID: $ExistingPid)" -ForegroundColor Yellow
|
|
72
|
+
Write-Host "[提示] 如需重启,请先运行 'wsc nginx stop' 停止" -ForegroundColor Gray
|
|
73
|
+
exit 0
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
# PID 文件存在但进程不存在,删除过期 PID 文件
|
|
77
|
+
Remove-Item $PidFile -Force -ErrorAction SilentlyContinue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# 同时检查 nginx 自己的 pid 文件
|
|
81
|
+
$NginxPidFile = Join-Path $env:NGINX_DIR "logs\nginx.pid"
|
|
82
|
+
if (Test-Path $NginxPidFile) {
|
|
83
|
+
$NginxPid = Get-Content $NginxPidFile -ErrorAction SilentlyContinue
|
|
84
|
+
if ($NginxPid) {
|
|
85
|
+
$Process = Get-Process -Id $NginxPid -ErrorAction SilentlyContinue
|
|
86
|
+
if ($Process -and $Process.ProcessName -eq "nginx") {
|
|
87
|
+
Write-Host "[警告] nginx 已在运行 (PID: $NginxPid)" -ForegroundColor Yellow
|
|
88
|
+
# 同步 PID 文件
|
|
89
|
+
$NginxPid | Out-File $PidFile -Encoding UTF8
|
|
90
|
+
exit 0
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
# 清理过期的 nginx pid 文件
|
|
94
|
+
Remove-Item $NginxPidFile -Force -ErrorAction SilentlyContinue
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# 显示工作空间信息
|
|
98
|
+
Write-Host "工作空间信息:" -ForegroundColor Green
|
|
99
|
+
Write-Host " 目录: $env:WORKSPACE_DIR" -ForegroundColor Gray
|
|
100
|
+
Write-Host " 主配置: $env:NGINX_CONF" -ForegroundColor Gray
|
|
101
|
+
Write-Host ""
|
|
102
|
+
|
|
103
|
+
# 列出可用的项目配置(仅显示信息)
|
|
104
|
+
$ConfDir = Join-Path $env:NGINX_DIR "conf\conf.d"
|
|
105
|
+
if (Test-Path $ConfDir) {
|
|
106
|
+
$ConfFiles = Get-ChildItem -Path $ConfDir -Filter "*.conf" -ErrorAction SilentlyContinue
|
|
107
|
+
if ($ConfFiles) {
|
|
108
|
+
Write-Host "[信息] 将加载以下项目配置:" -ForegroundColor Green
|
|
109
|
+
foreach ($File in $ConfFiles) {
|
|
110
|
+
Write-Host " • $($File.Name)" -ForegroundColor Gray
|
|
111
|
+
}
|
|
112
|
+
Write-Host ""
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# 测试主配置(使用 -p 指定前缀目录)
|
|
117
|
+
Write-Host "[信息] 正在测试 nginx 配置..." -ForegroundColor Green
|
|
118
|
+
& $env:NGINX_EXE -p $env:NGINX_DIR -c $env:NGINX_CONF -t
|
|
119
|
+
|
|
120
|
+
if ($LASTEXITCODE -ne 0) {
|
|
121
|
+
Write-Host "[错误] 配置测试失败,请检查配置文件" -ForegroundColor Red
|
|
122
|
+
exit 1
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Write-Host ""
|
|
126
|
+
Write-Host "[信息] 正在启动 nginx..." -ForegroundColor Green
|
|
127
|
+
|
|
128
|
+
# 启动 nginx(使用 -NoNewWindow 让其在后台运行,不阻塞脚本)
|
|
129
|
+
$Process = Start-Process -FilePath $env:NGINX_EXE -ArgumentList "-p `"$env:NGINX_DIR`" -c `"$env:NGINX_CONF`"" -NoNewWindow -PassThru
|
|
130
|
+
|
|
131
|
+
# 等待 nginx 启动并创建 pid 文件
|
|
132
|
+
Start-Sleep -Seconds 2
|
|
133
|
+
|
|
134
|
+
# 检查进程是否还在运行
|
|
135
|
+
$CheckProcess = Get-Process -Id $Process.Id -ErrorAction SilentlyContinue
|
|
136
|
+
if (-not $CheckProcess) {
|
|
137
|
+
Write-Host "[错误] nginx 启动失败,请检查端口是否被占用" -ForegroundColor Red
|
|
138
|
+
exit 1
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
# 保存 PID 到文件
|
|
142
|
+
$Process.Id | Out-File $PidFile -Encoding UTF8
|
|
143
|
+
|
|
144
|
+
# 获取所有属于当前工作空间的 nginx 进程
|
|
145
|
+
$AllNginxProcesses = Get-Process -Name "nginx" -ErrorAction SilentlyContinue | Where-Object {
|
|
146
|
+
try {
|
|
147
|
+
$processPath = $_.Path
|
|
148
|
+
$processPath -and ($processPath -like "*$env:NGINX_DIR*")
|
|
149
|
+
} catch { $false }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
Write-Host "[成功] nginx 已启动" -ForegroundColor Green
|
|
153
|
+
Write-Host "[成功] 主进程 PID: $($Process.Id)" -ForegroundColor Green
|
|
154
|
+
if ($AllNginxProcesses) {
|
|
155
|
+
Write-Host "[成功] 共 $($AllNginxProcesses.Count) 个进程" -ForegroundColor Green
|
|
156
|
+
}
|
|
157
|
+
Write-Host ""
|
|
158
|
+
Write-Host "[信息] 常用命令:" -ForegroundColor Gray
|
|
159
|
+
Write-Host " - 查看状态:wsc nginx status" -ForegroundColor Gray
|
|
160
|
+
Write-Host " - 停止 nginx:wsc nginx stop" -ForegroundColor Gray
|
|
161
|
+
Write-Host " - 重新加载配置:wsc nginx reload" -ForegroundColor Gray
|
|
162
|
+
|
|
163
|
+
Write-Host ""
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
#Requires -Version 7.0
|
|
3
|
+
|
|
4
|
+
# 设置输入输出编码为 UTF-8
|
|
5
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
6
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
7
|
+
[System.Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
8
|
+
|
|
9
|
+
# 防止窗口一闪而过
|
|
10
|
+
trap {
|
|
11
|
+
Write-Host "[错误] 发生异常:$_" -ForegroundColor Red
|
|
12
|
+
exit 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$Host.UI.RawUI.WindowTitle = "Nginx 状态检查脚本"
|
|
16
|
+
|
|
17
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
18
|
+
Write-Host " Nginx 状态检查脚本" -ForegroundColor Cyan
|
|
19
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
20
|
+
Write-Host ""
|
|
21
|
+
|
|
22
|
+
# 获取脚本所在目录
|
|
23
|
+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
24
|
+
$PidFile = Join-Path $ScriptDir "nginx.pid"
|
|
25
|
+
|
|
26
|
+
# 自动推断工作空间路径(如果环境变量未设置)
|
|
27
|
+
if (-not $env:WORKSPACE_DIR) {
|
|
28
|
+
# 检查是否运行的是模板脚本(在 nginx-config 目录下)
|
|
29
|
+
if ($ScriptDir -like "*nginx-config") {
|
|
30
|
+
Write-Host "[错误] 这是模板脚本,不能直接运行!" -ForegroundColor Red
|
|
31
|
+
Write-Host "[提示] 请先在工作空间运行: wsc nginx init" -ForegroundColor Yellow
|
|
32
|
+
Write-Host "[提示] 然后运行生成的脚本: .workspace\nginx\status-nginx.ps1" -ForegroundColor Gray
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$env:WORKSPACE_DIR = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
|
37
|
+
$NginxDir = Join-Path $ScriptDir "nginx-*"
|
|
38
|
+
$NginxExe = Get-ChildItem -Path $NginxDir -Filter "nginx.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
39
|
+
if ($NginxExe) {
|
|
40
|
+
$env:NGINX_EXE = $NginxExe.FullName
|
|
41
|
+
$env:NGINX_DIR = $NginxExe.DirectoryName
|
|
42
|
+
$env:NGINX_CONF = Join-Path $NginxExe.DirectoryName "conf\nginx.conf"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# 显示工作空间信息
|
|
47
|
+
Write-Host "工作空间信息:" -ForegroundColor Green
|
|
48
|
+
if ($env:WORKSPACE_DIR) {
|
|
49
|
+
Write-Host " 目录: $env:WORKSPACE_DIR" -ForegroundColor Gray
|
|
50
|
+
}
|
|
51
|
+
if ($env:NGINX_EXE) {
|
|
52
|
+
Write-Host " 程序: $env:NGINX_EXE" -ForegroundColor Gray
|
|
53
|
+
}
|
|
54
|
+
Write-Host ""
|
|
55
|
+
|
|
56
|
+
Write-Host "[信息] 正在检查当前工作空间的 nginx 进程..." -ForegroundColor Green
|
|
57
|
+
Write-Host ""
|
|
58
|
+
|
|
59
|
+
# 只检查当前工作空间(PID 文件中记录)的 nginx 进程
|
|
60
|
+
$FoundProcesses = @()
|
|
61
|
+
if (Test-Path $PidFile) {
|
|
62
|
+
$Pids = Get-Content $PidFile -ErrorAction SilentlyContinue
|
|
63
|
+
foreach ($NginxPid in $Pids) {
|
|
64
|
+
$Process = Get-Process -Id $NginxPid -ErrorAction SilentlyContinue
|
|
65
|
+
if ($Process -and $Process.ProcessName -eq "nginx") {
|
|
66
|
+
$FoundProcesses += $Process
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if ($FoundProcesses.Count -gt 0) {
|
|
72
|
+
Write-Host "[状态] nginx 正在运行 (${FoundProcesses.Count} 个进程)" -ForegroundColor Green
|
|
73
|
+
Write-Host ""
|
|
74
|
+
$FoundProcesses | Format-Table -Property Id, ProcessName, @{N="Memory(MB)";E={[math]::Round($_.WorkingSet64/1MB,2)}}, StartTime -AutoSize
|
|
75
|
+
Write-Host ""
|
|
76
|
+
Write-Host "[信息] 常用命令:" -ForegroundColor Gray
|
|
77
|
+
Write-Host " - 停止 nginx:wsc nginx stop" -ForegroundColor Gray
|
|
78
|
+
Write-Host " - 重新加载配置:wsc nginx reload" -ForegroundColor Gray
|
|
79
|
+
|
|
80
|
+
if ($env:NGINX_CONF) {
|
|
81
|
+
Write-Host " - 配置文件:$env:NGINX_CONF" -ForegroundColor Gray
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
Write-Host "[状态] 当前工作空间的 nginx 未运行" -ForegroundColor Yellow
|
|
85
|
+
Write-Host ""
|
|
86
|
+
Write-Host "[提示] 启动命令:wsc nginx start" -ForegroundColor Gray
|
|
87
|
+
|
|
88
|
+
# 检查 PID 文件是否存在但进程不存在
|
|
89
|
+
if (Test-Path $PidFile) {
|
|
90
|
+
Write-Host ""
|
|
91
|
+
Write-Host "[警告] PID 文件存在但进程不存在,可能已异常退出" -ForegroundColor Yellow
|
|
92
|
+
Write-Host "[提示] 如需清理,请删除 PID 文件: $PidFile" -ForegroundColor Gray
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Write-Host ""
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
#Requires -Version 7.0
|
|
3
|
+
|
|
4
|
+
# 设置输入输出编码为 UTF-8
|
|
5
|
+
$OutputEncoding = [System.Text.Encoding]::UTF8
|
|
6
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
7
|
+
[System.Console]::InputEncoding = [System.Text.Encoding]::UTF8
|
|
8
|
+
|
|
9
|
+
# 防止窗口一闪而过
|
|
10
|
+
trap {
|
|
11
|
+
Write-Host "[错误] 发生异常:$_" -ForegroundColor Red
|
|
12
|
+
exit 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
$Host.UI.RawUI.WindowTitle = "Nginx 停止脚本"
|
|
16
|
+
|
|
17
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
18
|
+
Write-Host " Nginx 停止脚本" -ForegroundColor Cyan
|
|
19
|
+
Write-Host "==========================================" -ForegroundColor Cyan
|
|
20
|
+
Write-Host ""
|
|
21
|
+
|
|
22
|
+
# 获取脚本所在目录
|
|
23
|
+
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
24
|
+
$PidFile = Join-Path $ScriptDir "nginx.pid"
|
|
25
|
+
|
|
26
|
+
# 自动推断 nginx 路径(如果环境变量未设置)
|
|
27
|
+
if (-not $env:NGINX_EXE) {
|
|
28
|
+
# 检查是否运行的是模板脚本(在 nginx-config 目录下)
|
|
29
|
+
if ($ScriptDir -like "*nginx-config") {
|
|
30
|
+
Write-Host "[错误] 这是模板脚本,不能直接运行!" -ForegroundColor Red
|
|
31
|
+
Write-Host "[提示] 请先在工作空间运行: wsc nginx init" -ForegroundColor Yellow
|
|
32
|
+
Write-Host "[提示] 然后运行生成的脚本: .workspace\nginx\stop-nginx.ps1" -ForegroundColor Gray
|
|
33
|
+
exit 1
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$NginxDir = Join-Path $ScriptDir "nginx-*"
|
|
37
|
+
$NginxExe = Get-ChildItem -Path $NginxDir -Filter "nginx.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
38
|
+
if ($NginxExe) {
|
|
39
|
+
$env:NGINX_EXE = $NginxExe.FullName
|
|
40
|
+
$env:NGINX_DIR = $NginxExe.DirectoryName
|
|
41
|
+
$env:NGINX_CONF = Join-Path $NginxExe.DirectoryName "conf\nginx.conf"
|
|
42
|
+
$env:WORKSPACE_DIR = Split-Path -Parent (Split-Path -Parent $ScriptDir)
|
|
43
|
+
Write-Host "[信息] 自动推断 nginx 路径: $($env:NGINX_EXE)" -ForegroundColor Gray
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# 检查环境变量
|
|
48
|
+
if (-not $env:NGINX_EXE) {
|
|
49
|
+
Write-Host "[错误] 未设置 NGINX_EXE 环境变量,且无法自动推断" -ForegroundColor Red
|
|
50
|
+
Write-Host "[提示] 请通过 'wsc nginx stop' 命令运行" -ForegroundColor Yellow
|
|
51
|
+
exit 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (-not $env:NGINX_CONF) {
|
|
55
|
+
Write-Host "[错误] 未设置 NGINX_CONF 环境变量,且无法自动推断" -ForegroundColor Red
|
|
56
|
+
exit 1
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# 推断 NGINX_DIR(nginx 安装目录)
|
|
60
|
+
if (-not $env:NGINX_DIR) {
|
|
61
|
+
$env:NGINX_DIR = Split-Path -Parent $env:NGINX_EXE
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Write-Host "[信息] 正在停止当前工作空间的 nginx..." -ForegroundColor Green
|
|
65
|
+
Write-Host "[信息] 工作空间: $env:WORKSPACE_DIR" -ForegroundColor Gray
|
|
66
|
+
Write-Host ""
|
|
67
|
+
|
|
68
|
+
$StoppedCount = 0
|
|
69
|
+
|
|
70
|
+
# 方法1: 使用 nginx -s stop 命令(最可靠的方式)
|
|
71
|
+
Write-Host "[信息] 尝试使用 nginx -s stop 命令停止..." -ForegroundColor Gray
|
|
72
|
+
& $env:NGINX_EXE -p $env:NGINX_DIR -c $env:NGINX_CONF -s stop 2>$null
|
|
73
|
+
$StopExitCode = $LASTEXITCODE
|
|
74
|
+
|
|
75
|
+
# 等待 nginx 进程退出
|
|
76
|
+
Start-Sleep -Seconds 2
|
|
77
|
+
|
|
78
|
+
# 删除 PID 文件(如果存在)
|
|
79
|
+
if (Test-Path $PidFile) {
|
|
80
|
+
Remove-Item $PidFile -Force -ErrorAction SilentlyContinue
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# 检查剩余的 nginx 进程
|
|
84
|
+
$NginxProcesses = Get-Process -Name "nginx" -ErrorAction SilentlyContinue | Where-Object {
|
|
85
|
+
try {
|
|
86
|
+
$processPath = $_.Path
|
|
87
|
+
$processPath -and ($processPath -like "*$env:NGINX_DIR*")
|
|
88
|
+
} catch {
|
|
89
|
+
$false
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# 如果还有进程,强制停止
|
|
94
|
+
if ($NginxProcesses) {
|
|
95
|
+
Write-Host "[信息] 发现 $($NginxProcesses.Count) 个 nginx 进程,正在停止..." -ForegroundColor Gray
|
|
96
|
+
foreach ($proc in $NginxProcesses) {
|
|
97
|
+
try {
|
|
98
|
+
Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue
|
|
99
|
+
$StoppedCount++
|
|
100
|
+
} catch {
|
|
101
|
+
Write-Host "[错误] 无法停止进程 (PID: $($proc.Id)): $_" -ForegroundColor Red
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
Write-Host "[信息] nginx 已通过命令正常停止" -ForegroundColor Gray
|
|
106
|
+
$StoppedCount = 0
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# 最终检查
|
|
110
|
+
Start-Sleep -Milliseconds 500
|
|
111
|
+
$RemainingNginx = Get-Process -Name "nginx" -ErrorAction SilentlyContinue | Where-Object {
|
|
112
|
+
try {
|
|
113
|
+
$processPath = $_.Path
|
|
114
|
+
$processPath -and ($processPath -like "*$env:NGINX_DIR*")
|
|
115
|
+
} catch { $false }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
Write-Host ""
|
|
119
|
+
if ($RemainingNginx) {
|
|
120
|
+
Write-Host "[警告] 仍有 $($RemainingNginx.Count) 个 nginx 进程在运行" -ForegroundColor Yellow
|
|
121
|
+
} elseif ($StoppedCount -gt 0) {
|
|
122
|
+
Write-Host "[成功] nginx 已停止 (强制停止 $StoppedCount 个进程)" -ForegroundColor Green
|
|
123
|
+
} else {
|
|
124
|
+
Write-Host "[成功] nginx 已停止" -ForegroundColor Green
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Write-Host ""
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wanggangqi/workspace-cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "工作空间管理 CLI 工具,用于初始化、扫描和管理工作空间下的项目",
|
|
5
|
+
"main": "lib/workspace.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"lib/",
|
|
12
|
+
"prompts/",
|
|
13
|
+
"nginx-config/",
|
|
14
|
+
"config.json"
|
|
15
|
+
],
|
|
16
|
+
"bin": {
|
|
17
|
+
"workspace-cli": "./bin/cli.js",
|
|
18
|
+
"wsc": "./bin/cli.js"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"start": "node bin/cli.js",
|
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"workspace",
|
|
26
|
+
"cli",
|
|
27
|
+
"project-management",
|
|
28
|
+
"git",
|
|
29
|
+
"repository"
|
|
30
|
+
],
|
|
31
|
+
"author": "",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"commander": "^11.0.0",
|
|
35
|
+
"chalk": "^4.1.2",
|
|
36
|
+
"inquirer": "^8.2.6"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=14.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|