@weitc/dfy-awesome-sidebar 0.0.0-stage → 1.0.1
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/CHANGELOG.md +4540 -0
- package/FEASIBILITY.md +250 -0
- package/INSTALL.md +93 -0
- package/LICENSE +43 -0
- package/README.md +170 -2
- package/assets/backgrounds/sidebar-default.jpg +0 -0
- package/assets/eggs/325/avatar.png +0 -0
- package/assets/eggs/325/baka-65-105-40s.webm +0 -0
- package/assets/eggs/325/stage.jpg +0 -0
- package/assets/eggs/347/avatar.png +0 -0
- package/assets/eggs/347/stage.jpg +0 -0
- package/assets/eggs/347/track-10-50-40s.webm +0 -0
- package/assets/themes/glass/actions-frame.css +90 -0
- package/assets/themes/glass/brand-frame.css +64 -0
- package/assets/themes/glass/footer-frame.css +111 -0
- package/assets/themes/glass/header-frame.css +285 -0
- package/assets/themes/glass/options-frame.css +129 -0
- package/assets/themes/glass/sidebar-outer.css +66 -0
- package/assets/themes/glass/topbar-frame.css +91 -0
- package/assets/themes/metal/actions-frame.css +90 -0
- package/assets/themes/metal/brand-frame.css +64 -0
- package/assets/themes/metal/footer-frame.css +111 -0
- package/assets/themes/metal/header-frame.css +300 -0
- package/assets/themes/metal/options-frame.css +129 -0
- package/assets/themes/metal/sidebar-outer.css +66 -0
- package/assets/themes/metal/topbar-frame.css +91 -0
- package/assets/themes/minimal/actions-frame.css +90 -0
- package/assets/themes/minimal/brand-frame.css +64 -0
- package/assets/themes/minimal/footer-frame.css +115 -0
- package/assets/themes/minimal/header-frame.css +271 -0
- package/assets/themes/minimal/options-frame.css +129 -0
- package/assets/themes/minimal/sidebar-outer.css +66 -0
- package/assets/themes/minimal/topbar-frame.css +91 -0
- package/assets/themes/neon/actions-frame.css +90 -0
- package/assets/themes/neon/brand-frame.css +64 -0
- package/assets/themes/neon/footer-frame.css +111 -0
- package/assets/themes/neon/header-frame.css +286 -0
- package/assets/themes/neon/options-frame.css +129 -0
- package/assets/themes/neon/sidebar-outer.css +66 -0
- package/assets/themes/neon/topbar-frame.css +91 -0
- package/assets/themes/ocean/actions-frame.css +90 -0
- package/assets/themes/ocean/brand-frame.css +64 -0
- package/assets/themes/ocean/footer-frame.css +111 -0
- package/assets/themes/ocean/header-frame.css +287 -0
- package/assets/themes/ocean/options-frame.css +129 -0
- package/assets/themes/ocean/sidebar-outer.css +66 -0
- package/assets/themes/ocean/topbar-frame.css +91 -0
- package/assets/themes/oldday/actions-frame.css +90 -0
- package/assets/themes/oldday/brand-frame.css +43 -0
- package/assets/themes/oldday/footer-frame.css +116 -0
- package/assets/themes/oldday/header-frame.css +142 -0
- package/assets/themes/oldday/options-frame.css +129 -0
- package/assets/themes/oldday/sidebar-outer.css +69 -0
- package/assets/themes/oldday/topbar-frame.css +91 -0
- package/assets/themes/pop/actions-frame.css +3 -0
- package/assets/themes/pop/brand-frame.css +3 -0
- package/assets/themes/pop/footer-frame.css +3 -0
- package/assets/themes/pop/header-frame.css +289 -0
- package/assets/themes/pop/options-frame.css +3 -0
- package/assets/themes/pop/pop-dust.css +37 -0
- package/assets/themes/pop/sidebar-outer.css +3 -0
- package/assets/themes/pop/topbar-frame.css +3 -0
- package/assets/themes/vaporwave/actions-frame.css +3 -0
- package/assets/themes/vaporwave/brand-frame.css +3 -0
- package/assets/themes/vaporwave/footer-frame.css +3 -0
- package/assets/themes/vaporwave/header-frame.css +436 -0
- package/assets/themes/vaporwave/options-frame.css +3 -0
- package/assets/themes/vaporwave/sidebar-outer.css +3 -0
- package/assets/themes/vaporwave/topbar-frame.css +3 -0
- package/assets/themes/vaporwave/vapor-dust.css +40 -0
- package/client.js +8116 -0
- package/cordis.patch.yml +6 -0
- package/docs/ACCEPTANCE-/345/244/264/345/203/217/351/242/204/350/247/210-20261201.md +42 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/pin-compare.png +0 -0
- package/docs/pin-modes.png +0 -0
- package/docs/preview.svg +84 -0
- package/docs/shot-fix7.png +0 -0
- package/docs/shot-frame-ocean.png +0 -0
- package/docs/shot-metal.png +0 -0
- package/docs/shot-stars.png +0 -0
- package/docs/shot-zones.png +0 -0
- package/icon.svg +5 -0
- package/index.js +2015 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +58 -3
- package/pin.ps1 +172 -0
- package/rollback.ps1 +196 -0
- package/tools/__pycache__/pack-release.cpython-312.pyc +0 -0
- package/tools/_slice.txt +9 -0
- package/tools/boot.cjs +16 -0
- package/tools/build-frame-css.cjs +33 -0
- package/tools/check-docs.ps1 +41 -0
- package/tools/check-names.ps1 +35 -0
- package/tools/extract.cjs +28 -0
- package/tools/find-in-asar.cjs +43 -0
- package/tools/list-dir.cjs +21 -0
- package/tools/list-pkgs.cjs +10 -0
- package/tools/probe-delay.cjs +109 -0
- package/tools/probe-star-icon.cjs +164 -0
- package/tools/proof-glow-persist.cjs +102 -0
- package/tools/proof-migration.cjs +88 -0
- package/tools/proof-opacity.cjs +153 -0
- package/tools/proof-race.cjs +103 -0
- package/tools/run-asar.ps1 +53 -0
- package/tools/run.cmd +8 -0
- package/tools/scan.cjs +24 -0
- package/tools/smoke.cjs +179 -0
- package/tools/source-health.cjs +165 -0
- package/tools/splice.cjs +20 -0
- package/tools/test-account.cjs +74 -0
- package/tools/test-client.cjs +265 -0
- package/tools/test-dom.cjs +258 -0
- package/tools/test-host.cjs +500 -0
- package/tools/test-menu.cjs +591 -0
- package/tools/test-recharge.cjs +111 -0
- package/tools/test-v20.cjs +1793 -0
- package/workspace-pin.cmd +8 -0
package/locale/en.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Fancy Bar",
|
|
4
|
+
"description": "Turns the sidebar into a lid-and-box layout: a metal-brushed frame per workspace, a recessed session box that joins it seamlessly, and tighter session-title indentation — plus pin/star ordering and a settings panel. Formerly workspace-pin, named on 2026-11-23.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weitc/dfy-awesome-sidebar",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"displayName": "很炫的栏",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "很炫的栏(原 workspace-pin):金属质感的工作区分组框 + 置顶/星标排序 + 三页设置面板(置顶/星标、侧边栏外观、工作区头像)。",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./index.js",
|
|
10
|
+
"./client": "./client.js",
|
|
11
|
+
"./locale/*.json": "./locale/*.json",
|
|
12
|
+
"./icon": "./icon.svg"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"client.js",
|
|
17
|
+
"cordis.patch.yml",
|
|
18
|
+
"locale/*.json",
|
|
19
|
+
"docs",
|
|
20
|
+
"assets",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"README.md",
|
|
23
|
+
"INSTALL.md",
|
|
24
|
+
"FEASIBILITY.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"pin.ps1",
|
|
28
|
+
"workspace-pin.cmd",
|
|
29
|
+
"rollback.ps1",
|
|
30
|
+
"tools",
|
|
31
|
+
"!assets/themes/_preview",
|
|
32
|
+
"!backup",
|
|
33
|
+
"!queue"
|
|
34
|
+
],
|
|
35
|
+
"dsh": {
|
|
36
|
+
"bundle": {
|
|
37
|
+
"patch": "./cordis.patch.yml"
|
|
38
|
+
},
|
|
39
|
+
"client": {
|
|
40
|
+
"platform": "web",
|
|
41
|
+
"immediately": true,
|
|
42
|
+
"inject": [
|
|
43
|
+
"@deepseek-ai/dsh-client-ui-context-menu"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"author": "狐皮鱼鱼们(CommanderT 指挥)",
|
|
52
|
+
"contributors": [
|
|
53
|
+
"狐草鱼鱼仙(总调度)",
|
|
54
|
+
"6 号 · 通潮(会话总线与打包)",
|
|
55
|
+
"7 号 · 定海(侧栏置顶插件原型)",
|
|
56
|
+
"8 号 · 补鳞(开发与修缺)",
|
|
57
|
+
"9 号 · 描边(美术与主题)",
|
|
58
|
+
"11 号 · 理纹(功能开发)",
|
|
59
|
+
"13 号 · 体检(独立验收)"
|
|
60
|
+
]
|
|
6
61
|
}
|
package/pin.ps1
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[Parameter(Position = 0)][string]$Action = 'list',
|
|
3
|
+
[Parameter(Position = 1)][string]$Target,
|
|
4
|
+
[Parameter(Position = 2)][string]$Value,
|
|
5
|
+
[string]$BaseUrl = ''
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
if (-not $BaseUrl) { if ($env:DSH_WEB_URL) { $BaseUrl = $env:DSH_WEB_URL } else { throw '未设置 DSH_WEB_URL;请设为 http://127.0.0.1:<端口>' } }
|
|
10
|
+
|
|
11
|
+
# pin.ps1 — 置顶/星标的命令行入口(插件之外的退化通道,或批量/脚本化操作)。
|
|
12
|
+
# 它不直接改 workspace.json:所有重排都走插件注册的 /workspace-pin/* 路由,
|
|
13
|
+
# 由 Host 用官方 insertBefore 完成,因此和界面上点按钮是同一套逻辑。
|
|
14
|
+
#
|
|
15
|
+
# pin.ps1 list 看当前顺序、置顶与星标
|
|
16
|
+
# pin.ps1 pin <名称|路径片段|id> 置顶(会顶替原来的置顶)
|
|
17
|
+
# pin.ps1 unpin [名称] 取消置顶(不写名字就清除当前置顶)
|
|
18
|
+
# pin.ps1 star <名称|路径片段|id> 星标
|
|
19
|
+
# pin.ps1 unstar <名称|路径片段|id> 取消星标
|
|
20
|
+
# pin.ps1 order <id1,id2,...> 按显式顺序重排(排障)
|
|
21
|
+
#
|
|
22
|
+
# 参数:-BaseUrl http://127.0.0.1:<端口>(或设 DSH_WEB_URL)
|
|
23
|
+
|
|
24
|
+
$ErrorActionPreference = 'Stop'
|
|
25
|
+
# 关键:本脚本常被父进程以管道捕获 stdout 调用;PowerShell 5.1 在重定向宿主里
|
|
26
|
+
# 渲染进度条会静默终止脚本(下面也不用 Invoke-WebRequest,双保险)。
|
|
27
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
28
|
+
$base = $BaseUrl.TrimEnd('/')
|
|
29
|
+
$dshHome = if ($env:DSH_HOME) { $env:DSH_HOME } else { Join-Path $env:USERPROFILE '.dsh' }
|
|
30
|
+
$workspaceFile = Join-Path $dshHome 'storages\workspace.json'
|
|
31
|
+
|
|
32
|
+
function Read-Text([string]$path) {
|
|
33
|
+
return [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::UTF8)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function Get-Workspaces {
|
|
37
|
+
if (-not (Test-Path $workspaceFile)) { throw "找不到 workspace.json:$workspaceFile" }
|
|
38
|
+
$json = Read-Text $workspaceFile | ConvertFrom-Json
|
|
39
|
+
$table = $json.tables.workspaces
|
|
40
|
+
$list = @()
|
|
41
|
+
foreach ($id in $json.global.workspaceIds) {
|
|
42
|
+
$row = $table.$id
|
|
43
|
+
$list += [pscustomobject]@{
|
|
44
|
+
id = $id
|
|
45
|
+
title = if ($row) { $row.title } else { '' }
|
|
46
|
+
path = if ($row) { $row.path } else { '' }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return $list
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Resolve-Workspace([string]$needle) {
|
|
53
|
+
if ([string]::IsNullOrWhiteSpace($needle)) { throw '请给出工作区名称、路径片段或 id' }
|
|
54
|
+
$all = @(Get-Workspaces)
|
|
55
|
+
$hit = @($all | Where-Object { $_.id -eq $needle })
|
|
56
|
+
if ($hit.Count -eq 0) { $hit = @($all | Where-Object { $_.title -eq $needle }) }
|
|
57
|
+
if ($hit.Count -eq 0) { $hit = @($all | Where-Object { $_.title -like "*$needle*" }) }
|
|
58
|
+
if ($hit.Count -eq 0) { $hit = @($all | Where-Object { $_.path -like "*$needle*" }) }
|
|
59
|
+
if ($hit.Count -eq 0) { throw "没找到匹配「$needle」的工作区" }
|
|
60
|
+
if ($hit.Count -gt 1) {
|
|
61
|
+
$names = ($hit | ForEach-Object { "" + $_.title + " [" + $_.id.Substring(0, 8) + "]" }) -join ', '
|
|
62
|
+
throw "「$needle」匹配到多个工作区:$names;请写得更精确或直接用 id"
|
|
63
|
+
}
|
|
64
|
+
return $hit[0]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function Invoke-Api([string]$path, [string]$method, $payload) {
|
|
68
|
+
$request = [System.Net.WebRequest]::Create("$base/workspace-pin/$path")
|
|
69
|
+
$request.Method = $method
|
|
70
|
+
$request.Timeout = 15000
|
|
71
|
+
$request.ReadWriteTimeout = 15000
|
|
72
|
+
if ($null -ne $payload) {
|
|
73
|
+
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($payload | ConvertTo-Json -Compress))
|
|
74
|
+
$request.ContentType = 'application/json; charset=utf-8'
|
|
75
|
+
$request.ContentLength = $bytes.Length
|
|
76
|
+
$stream = $request.GetRequestStream()
|
|
77
|
+
try { $stream.Write($bytes, 0, $bytes.Length) } finally { $stream.Close() }
|
|
78
|
+
}
|
|
79
|
+
$response = $request.GetResponse()
|
|
80
|
+
$reader = New-Object System.IO.StreamReader($response.GetResponseStream(), [System.Text.Encoding]::UTF8)
|
|
81
|
+
try { return $reader.ReadToEnd() } finally { $reader.Close(); $response.Close() }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function State {
|
|
85
|
+
return Invoke-Api 'state' 'GET' $null | ConvertFrom-Json
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
switch ($Action.ToLowerInvariant()) {
|
|
90
|
+
'list' {
|
|
91
|
+
$state = State
|
|
92
|
+
$pinned = $state.pinnedWorkspaceId
|
|
93
|
+
$starred = @($state.starredWorkspaces)
|
|
94
|
+
$map = @{}
|
|
95
|
+
foreach ($w in Get-Workspaces) { $map[$w.id] = $w }
|
|
96
|
+
$i = 0
|
|
97
|
+
foreach ($id in $state.workspaceIds) {
|
|
98
|
+
$i++
|
|
99
|
+
$w = $map[$id]
|
|
100
|
+
$mark = if ($id -eq $pinned) { '[置顶]' } elseif ($starred -contains $id) { '[星标]' } else { ' ' }
|
|
101
|
+
$title = if ($w) { $w.title } else { '(已删除)' }
|
|
102
|
+
$path = if ($w) { $w.path } else { '' }
|
|
103
|
+
Write-Host ('{0,2}. {1} {2} {3}' -f $i, $mark, $title, $path)
|
|
104
|
+
}
|
|
105
|
+
if ($pinned) {
|
|
106
|
+
$pw = $map[$pinned]
|
|
107
|
+
Write-Host ("置顶:$($pw.title)") -ForegroundColor Green
|
|
108
|
+
} else {
|
|
109
|
+
Write-Host '当前没有置顶的工作区'
|
|
110
|
+
}
|
|
111
|
+
Write-Host ("星标 $($starred.Count) 个" + $(if ($starred.Count -gt 0) { '(按星标先后)' } else { '' }))
|
|
112
|
+
if (@($state.starredSessions).Count -gt 0) {
|
|
113
|
+
Write-Host ("星标会话 $((@($state.starredSessions)).Count) 个(不改变会话顺序)")
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
'setting' {
|
|
117
|
+
if ([string]::IsNullOrWhiteSpace($Target)) {
|
|
118
|
+
$state = State
|
|
119
|
+
$state.settings.PSObject.Properties | ForEach-Object { Write-Host ("{0} = {1}" -f $_.Name, $_.Value) }
|
|
120
|
+
} else {
|
|
121
|
+
if ([string]::IsNullOrWhiteSpace($Value)) { throw 'setting 需要 <key> <value>,例如 setting workspaceStarColor "#4D6BFE"' }
|
|
122
|
+
$result = Invoke-Api 'setting' 'POST' @{ key = $Target; value = $Value } | ConvertFrom-Json
|
|
123
|
+
Write-Host ("设置已更新:" + $Target + " = " + $Value) -ForegroundColor Green
|
|
124
|
+
$result.settings.PSObject.Properties | ForEach-Object { Write-Host (" {0} = {1}" -f $_.Name, $_.Value) }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
'pin' {
|
|
128
|
+
$w = Resolve-Workspace $Target
|
|
129
|
+
$null = Invoke-Api 'pin' 'POST' @{ workspaceId = $w.id }
|
|
130
|
+
Write-Host "已置顶:$($w.title)" -ForegroundColor Green
|
|
131
|
+
}
|
|
132
|
+
'unpin' {
|
|
133
|
+
if ([string]::IsNullOrWhiteSpace($Target)) {
|
|
134
|
+
$null = Invoke-Api 'pin' 'POST' @{ workspaceId = $null }
|
|
135
|
+
Write-Host '已取消置顶' -ForegroundColor Green
|
|
136
|
+
} else {
|
|
137
|
+
$w = Resolve-Workspace $Target
|
|
138
|
+
$state = State
|
|
139
|
+
if ($state.pinnedWorkspaceId -ne $w.id) {
|
|
140
|
+
Write-Host "「$($w.title)」当前不是置顶项,无需取消" -ForegroundColor Yellow
|
|
141
|
+
} else {
|
|
142
|
+
$null = Invoke-Api 'pin' 'POST' @{ workspaceId = $null }
|
|
143
|
+
Write-Host "已取消置顶:$($w.title)" -ForegroundColor Green
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
'star' {
|
|
148
|
+
$w = Resolve-Workspace $Target
|
|
149
|
+
$null = Invoke-Api 'star' 'POST' @{ kind = 'workspace'; id = $w.id; starred = $true }
|
|
150
|
+
Write-Host "已星标:$($w.title)" -ForegroundColor Green
|
|
151
|
+
}
|
|
152
|
+
'unstar' {
|
|
153
|
+
$w = Resolve-Workspace $Target
|
|
154
|
+
$null = Invoke-Api 'star' 'POST' @{ kind = 'workspace'; id = $w.id; starred = $false }
|
|
155
|
+
Write-Host "已取消星标:$($w.title)" -ForegroundColor Green
|
|
156
|
+
}
|
|
157
|
+
'order' {
|
|
158
|
+
if ([string]::IsNullOrWhiteSpace($Target)) { throw 'order 需要一个逗号分隔的 id 列表' }
|
|
159
|
+
$ids = @($Target.Split(',') | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' })
|
|
160
|
+
$result = Invoke-Api 'order' 'POST' @{ workspaceIds = $ids } | ConvertFrom-Json
|
|
161
|
+
Write-Host ('新顺序:' + ($result.workspaceIds -join ',')) -ForegroundColor Green
|
|
162
|
+
}
|
|
163
|
+
default { throw "未知动作「$Action」;可用:list / pin / unpin / star / unstar / order / setting" }
|
|
164
|
+
}
|
|
165
|
+
exit 0
|
|
166
|
+
} catch {
|
|
167
|
+
Write-Error $_
|
|
168
|
+
Write-Host ''
|
|
169
|
+
Write-Host '提示:本脚本依赖 @local/workspace-pin 的 Host 半插件在运行(它注册了 /workspace-pin/* 路由)。' -ForegroundColor Yellow
|
|
170
|
+
Write-Host ' 若插件已卸载或 DSH 未启动,请改用界面右键菜单,或先重新安装插件。' -ForegroundColor Yellow
|
|
171
|
+
exit 1
|
|
172
|
+
}
|
package/rollback.ps1
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$BackupFile,
|
|
3
|
+
[string]$BaseUrl = '',
|
|
4
|
+
[switch]$SkipProfileEdit
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (-not $BaseUrl) { if ($env:DSH_WEB_URL) { $BaseUrl = $env:DSH_WEB_URL } else { throw '未设置 DSH_WEB_URL;请设为 http://127.0.0.1:<端口>' } }
|
|
9
|
+
|
|
10
|
+
# rollback.ps1 — 一键回退 @local/workspace-pin(v2 规格,含置顶/星标状态)
|
|
11
|
+
#
|
|
12
|
+
# 顺序很重要:必须先清掉插件的置顶/星标状态(它会强制把顺序摆回 置顶>星标>普通),
|
|
13
|
+
# 再去调 /order 还原顺序,否则"回弹"会立刻把我们还原的顺序改回去。
|
|
14
|
+
#
|
|
15
|
+
# 1. 删掉置顶/星标状态文件(先留档)——此后插件的顺序约束变回恒等;
|
|
16
|
+
# 2. 经插件路由把 Host 内存里的顺序重排回备份顺序;
|
|
17
|
+
# 3. 用备份覆盖 workspace.json(逐字节校验);
|
|
18
|
+
# 4. 从 profile 的 package.json 去掉依赖与 bundle 选择;
|
|
19
|
+
# 5. 删掉 profile\node_modules\@local\workspace-pin 的 junction;
|
|
20
|
+
# 6. 检查 cordis.patch.yml 有无残留 override。
|
|
21
|
+
#
|
|
22
|
+
# 运行后插件行会被 DSH 卸载(实测路由立刻 404);如需彻底清锁文件,在 DSH 关闭后跑
|
|
23
|
+
# `dsh plugin --profile desktop install`。
|
|
24
|
+
#
|
|
25
|
+
# rollback.ps1 用最新备份
|
|
26
|
+
# rollback.ps1 -BackupFile <path> 指定备份
|
|
27
|
+
# rollback.ps1 -SkipProfileEdit 只还原数据、不改 profile
|
|
28
|
+
|
|
29
|
+
$ErrorActionPreference = 'Stop'
|
|
30
|
+
$ProgressPreference = 'SilentlyContinue'
|
|
31
|
+
|
|
32
|
+
$root = $PSScriptRoot
|
|
33
|
+
$backupDir = Join-Path $root 'backup'
|
|
34
|
+
$dshHome = if ($env:DSH_HOME) { $env:DSH_HOME } else { Join-Path $env:USERPROFILE '.dsh' }
|
|
35
|
+
$profileDir = if ($env:DSH_PROFILE_DIR) { $env:DSH_PROFILE_DIR } else { Join-Path $dshHome 'profiles\desktop' }
|
|
36
|
+
$workspaceFile = Join-Path $dshHome 'storages\workspace.json'
|
|
37
|
+
$stateFile = Join-Path $dshHome 'workspace-pin.json'
|
|
38
|
+
$profileFile = Join-Path $profileDir 'package.json'
|
|
39
|
+
$linkDir = Join-Path $profileDir 'node_modules\@local\workspace-pin'
|
|
40
|
+
$base = $BaseUrl.TrimEnd('/')
|
|
41
|
+
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
42
|
+
|
|
43
|
+
function Step([string]$text) { Write-Host ''; Write-Host "==> $text" -ForegroundColor Cyan }
|
|
44
|
+
function Ok([string]$text) { Write-Host " OK $text" -ForegroundColor Green }
|
|
45
|
+
function Warn([string]$text) { Write-Host " ! $text" -ForegroundColor Yellow }
|
|
46
|
+
|
|
47
|
+
function Read-Text([string]$path) {
|
|
48
|
+
return [System.IO.File]::ReadAllText($path, [System.Text.Encoding]::UTF8)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function Write-Text([string]$path, [string]$text) {
|
|
52
|
+
# UTF-8 无 BOM:带 BOM 会让 DSH 读 package.json 直接失败。
|
|
53
|
+
[System.IO.File]::WriteAllText($path, $text, (New-Object System.Text.UTF8Encoding($false)))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function Invoke-Api([string]$path, [string]$method, $payload) {
|
|
57
|
+
$request = [System.Net.WebRequest]::Create("$base/workspace-pin/$path")
|
|
58
|
+
$request.Method = $method
|
|
59
|
+
$request.Timeout = 8000
|
|
60
|
+
$request.ReadWriteTimeout = 8000
|
|
61
|
+
if ($null -ne $payload) {
|
|
62
|
+
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($payload | ConvertTo-Json -Compress))
|
|
63
|
+
$request.ContentType = 'application/json; charset=utf-8'
|
|
64
|
+
$request.ContentLength = $bytes.Length
|
|
65
|
+
$stream = $request.GetRequestStream()
|
|
66
|
+
try { $stream.Write($bytes, 0, $bytes.Length) } finally { $stream.Close() }
|
|
67
|
+
}
|
|
68
|
+
$response = $request.GetResponse()
|
|
69
|
+
$reader = New-Object System.IO.StreamReader($response.GetResponseStream(), [System.Text.Encoding]::UTF8)
|
|
70
|
+
try { return $reader.ReadToEnd() } finally { $reader.Close(); $response.Close() }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
Write-Host '工作区置顶插件 · 一键回退' -ForegroundColor White
|
|
74
|
+
Write-Host "插件目录:$root"
|
|
75
|
+
Write-Host "DSH home:$dshHome"
|
|
76
|
+
Write-Host "profile :$profileDir"
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------- 0. 选备份
|
|
79
|
+
Step '0. 选择 workspace.json 备份'
|
|
80
|
+
if (-not (Test-Path $backupDir)) { throw "找不到备份目录:$backupDir" }
|
|
81
|
+
if ([string]::IsNullOrWhiteSpace($BackupFile)) {
|
|
82
|
+
# 只认真正的备份:排除脚本自己生成的 before-rollback 留档(否则会“还原”成上一次回退前)
|
|
83
|
+
$candidate = Get-ChildItem $backupDir -Filter 'workspace.json.*.bak' |
|
|
84
|
+
Where-Object { $_.Name -notlike 'workspace.json.before-rollback-*' } |
|
|
85
|
+
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
|
86
|
+
if (-not $candidate) { throw "备份目录里没有 workspace.json.*.bak" }
|
|
87
|
+
$BackupFile = $candidate.FullName
|
|
88
|
+
}
|
|
89
|
+
if (-not (Test-Path $BackupFile)) { throw "备份文件不存在:$BackupFile" }
|
|
90
|
+
$backupJson = Read-Text $BackupFile | ConvertFrom-Json
|
|
91
|
+
$backupOrder = @($backupJson.global.workspaceIds)
|
|
92
|
+
if ($backupOrder.Count -eq 0) { throw "备份里没有 workspaceIds:$BackupFile" }
|
|
93
|
+
Ok "使用备份:$BackupFile($($backupOrder.Count) 个工作区)"
|
|
94
|
+
|
|
95
|
+
# ---------------------------------------------------------------- 1. 清状态
|
|
96
|
+
Step '1. 清掉置顶/星标状态(否则插件会把顺序弹回去)'
|
|
97
|
+
if (Test-Path $stateFile) {
|
|
98
|
+
$stateBackup = Join-Path $backupDir ("workspace-pin.json.$stamp.bak")
|
|
99
|
+
Copy-Item -LiteralPath $stateFile -Destination $stateBackup -Force
|
|
100
|
+
Remove-Item -LiteralPath $stateFile -Force
|
|
101
|
+
Ok "已删除置顶/星标状态(留档:$stateBackup)"
|
|
102
|
+
} else {
|
|
103
|
+
Ok '状态文件不存在,跳过'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# ---------------------------------------------------------------- 2. 还原顺序
|
|
107
|
+
Step '2. 还原工作区顺序'
|
|
108
|
+
$restoredLive = $false
|
|
109
|
+
try {
|
|
110
|
+
$null = Invoke-Api 'order' 'POST' @{ workspaceIds = $backupOrder }
|
|
111
|
+
$state = (Invoke-Api 'state' 'GET' $null) | ConvertFrom-Json
|
|
112
|
+
if ((@($state.workspaceIds) -join ',') -eq ($backupOrder -join ',')) {
|
|
113
|
+
$restoredLive = $true
|
|
114
|
+
Ok 'Host 内存里的顺序已重排为备份顺序(走官方 insertBefore)'
|
|
115
|
+
} else {
|
|
116
|
+
Warn "Host 返回的顺序与备份不一致:$((@($state.workspaceIds)) -join ',')"
|
|
117
|
+
}
|
|
118
|
+
} catch {
|
|
119
|
+
Warn "无法经插件路由重排($($_.Exception.Message))。"
|
|
120
|
+
Warn '插件可能已被禁用/卸载。覆盖文件后,请在重启 DSH 前不要再增删工作区。'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Step '3. 用备份覆盖 workspace.json'
|
|
124
|
+
if (-not $restoredLive) {
|
|
125
|
+
Warn '顺序未能在线还原:本次文件覆盖只在 DSH 下次启动时才生效;'
|
|
126
|
+
Warn '若 DSH 仍在运行并再次写工作区,会覆盖这次还原。'
|
|
127
|
+
}
|
|
128
|
+
$before = Join-Path $backupDir ("workspace.json.before-rollback-$stamp.bak")
|
|
129
|
+
Copy-Item -LiteralPath $workspaceFile -Destination $before -Force
|
|
130
|
+
Copy-Item -LiteralPath $BackupFile -Destination $workspaceFile -Force
|
|
131
|
+
try {
|
|
132
|
+
$check = Read-Text $workspaceFile | ConvertFrom-Json
|
|
133
|
+
if ((@($check.global.workspaceIds) -join ',') -ne ($backupOrder -join ',')) {
|
|
134
|
+
throw '覆盖后的顺序与备份不一致'
|
|
135
|
+
}
|
|
136
|
+
Ok "workspace.json 已还原(原文件留档:$before)"
|
|
137
|
+
} catch {
|
|
138
|
+
Copy-Item -LiteralPath $before -Destination $workspaceFile -Force
|
|
139
|
+
throw "还原后的 workspace.json 校验失败,已回滚到覆盖前状态:$($_.Exception.Message)"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# ---------------------------------------------------------------- 4. profile
|
|
143
|
+
if ($SkipProfileEdit) {
|
|
144
|
+
Step '4. 跳过 profile 修改(-SkipProfileEdit)'
|
|
145
|
+
} else {
|
|
146
|
+
Step '4. 从 profile 移除 bundle'
|
|
147
|
+
$profileBackup = Join-Path $backupDir ("profile-package.json.$stamp.bak")
|
|
148
|
+
Copy-Item -LiteralPath $profileFile -Destination $profileBackup -Force
|
|
149
|
+
$text = Read-Text $profileFile
|
|
150
|
+
$original = $text
|
|
151
|
+
# 依赖行(含前导逗号,避免留下尾逗号)
|
|
152
|
+
$text = [regex]::Replace($text, ',\s*\r?\n\s*"@local/workspace-pin"\s*:\s*"[^"]*"', '')
|
|
153
|
+
# bundle 选择项(同样吃掉前导逗号)
|
|
154
|
+
$text = [regex]::Replace($text, ',\s*\r?\n\s*"@local/workspace-pin"', '')
|
|
155
|
+
if ($text -eq $original) {
|
|
156
|
+
Warn 'package.json 里没有 @local/workspace-pin 条目(可能已移除)'
|
|
157
|
+
} else {
|
|
158
|
+
Write-Text $profileFile $text
|
|
159
|
+
$parsed = Read-Text $profileFile | ConvertFrom-Json
|
|
160
|
+
$stillDependency = $parsed.dependencies.PSObject.Properties.Name -contains '@local/workspace-pin'
|
|
161
|
+
$stillBundle = @($parsed.dsh.profile.bundles) -contains '@local/workspace-pin'
|
|
162
|
+
if ($stillDependency -or $stillBundle) {
|
|
163
|
+
Copy-Item -LiteralPath $profileBackup -Destination $profileFile -Force
|
|
164
|
+
throw 'package.json 仍包含 @local/workspace-pin,已回滚该文件'
|
|
165
|
+
}
|
|
166
|
+
Ok "package.json 已清理(留档:$profileBackup)"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
Step '5. 移除 node_modules 链接'
|
|
170
|
+
if (Test-Path $linkDir) {
|
|
171
|
+
$item = Get-Item -LiteralPath $linkDir -Force
|
|
172
|
+
if ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
|
|
173
|
+
# rmdir 对目录联接/符号链接只删除链接本身,不会删掉插件目录里的真实文件。
|
|
174
|
+
$null = cmd /c "rmdir `"$linkDir`"" 2>&1
|
|
175
|
+
if (Test-Path $linkDir) { Warn "删除链接失败,请手动删除:$linkDir" } else { Ok '链接已移除' }
|
|
176
|
+
} else {
|
|
177
|
+
Warn "$linkDir 不是链接(可能是实体目录),已跳过,请自行确认"
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
Ok '链接不存在,跳过'
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Step '6. 检查 patch 里是否还有残留 override'
|
|
184
|
+
$patchFile = Join-Path $profileDir 'cordis.patch.yml'
|
|
185
|
+
if ((Test-Path $patchFile) -and ((Read-Text $patchFile) -match 'workspace-pin')) {
|
|
186
|
+
Warn "cordis.patch.yml 里仍出现 workspace-pin,请手动删除对应 override:$patchFile"
|
|
187
|
+
} else {
|
|
188
|
+
Ok 'cordis.patch.yml 干净'
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
Write-Host ''
|
|
193
|
+
Write-Host '回退完成。' -ForegroundColor Green
|
|
194
|
+
Write-Host '插件行会被 DSH 当场卸载(路由消失);置顶/星标状态已清除,顺序已还原。' -ForegroundColor Yellow
|
|
195
|
+
Write-Host '若还想彻底清理锁文件,可在 DSH 关闭后运行:dsh plugin --profile desktop install' -ForegroundColor Yellow
|
|
196
|
+
exit 0
|
|
Binary file
|
package/tools/_slice.txt
ADDED
package/tools/boot.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// boot.cjs — 用 DSH 自带 Electron(ELECTRON_RUN_AS_NODE=1)跑一个脚本的最小引导。
|
|
2
|
+
// 用法:pwsh: & $env:DSH_NODE_EXECUTABLE -e "require('./tools/boot.cjs')" -- ./tools/xxx.cjs arg1 arg2
|
|
3
|
+
// 说明:把所有引号都留在 JS 文件里,避免 PowerShell 传参时吃掉引号。
|
|
4
|
+
module.exports = function () {
|
|
5
|
+
const target = process.argv[1];
|
|
6
|
+
if (!target) {
|
|
7
|
+
console.error('boot.cjs: 缺少目标脚本路径');
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const resolved = path.resolve(process.cwd(), target);
|
|
12
|
+
Promise.resolve(require(resolved)(process.argv.slice(2))).then(
|
|
13
|
+
(code) => process.exit(typeof code === 'number' ? code : 0),
|
|
14
|
+
(error) => { console.error(error && error.stack || error); process.exit(1); },
|
|
15
|
+
);
|
|
16
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// build-frame-css.cjs — 把 assets/themes/<theme>/*.css 按接入顺序内联成 FRAME_CSS 常量块。
|
|
2
|
+
// usage: run-asar.ps1 build-frame-css.cjs <pluginDir> <outFile>
|
|
3
|
+
// 顺序固定(ASSETS.md §三):header → outer → brand → actions → options → footer → topbar
|
|
4
|
+
module.exports = function (args) {
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const pluginDir = args[0];
|
|
8
|
+
const outFile = args[1];
|
|
9
|
+
const themes = ['metal', 'glass', 'neon', 'minimal', 'ocean', 'oldday'];
|
|
10
|
+
// T-05:topbar 放最后(后者覆盖前者),由 9 号描边交付的六套一起拼
|
|
11
|
+
const files = ['header-frame.css', 'sidebar-outer.css', 'brand-frame.css', 'actions-frame.css', 'options-frame.css', 'footer-frame.css', 'topbar-frame.css'];
|
|
12
|
+
const parts = [];
|
|
13
|
+
parts.push(' /* ===== 美术素材(9 号 · 描边):五套主题 × 六区,按固定顺序拼接 =====');
|
|
14
|
+
parts.push(' * 顺序:header → outer → brand → actions → options → footer(ASSETS.md §三,后者覆盖前者)。');
|
|
15
|
+
parts.push(' * 只注入当前主题那一份;来源 assets/themes/<theme>/*.css,用 tools/build-frame-css.cjs 生成,勿手改。 */');
|
|
16
|
+
parts.push(' const FRAME_CSS = {');
|
|
17
|
+
for (const theme of themes) {
|
|
18
|
+
const chunks = [];
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const full = path.join(pluginDir, 'assets', 'themes', theme, file);
|
|
21
|
+
const text = fs.readFileSync(full, 'utf8');
|
|
22
|
+
if (text.indexOf('`') !== -1) throw new Error(theme + '/' + file + ': CSS 含反引号');
|
|
23
|
+
chunks.push('/* ===== ' + file + ' ===== */\n' + text);
|
|
24
|
+
}
|
|
25
|
+
parts.push(' ' + theme + ': ' + JSON.stringify(chunks.join('\n')) + ',');
|
|
26
|
+
}
|
|
27
|
+
parts.push(' };');
|
|
28
|
+
parts.push('');
|
|
29
|
+
const body = parts.join('\n');
|
|
30
|
+
fs.writeFileSync(outFile, body, 'utf8');
|
|
31
|
+
console.log('themes: ' + themes.join(', ') + ' | files/theme: ' + files.length + ' | bytes: ' + body.length);
|
|
32
|
+
return 0;
|
|
33
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$Dir = '.'
|
|
3
|
+
)
|
|
4
|
+
$ErrorActionPreference = 'Stop'
|
|
5
|
+
$root = (Resolve-Path -LiteralPath $Dir).Path
|
|
6
|
+
|
|
7
|
+
# Build the pattern from pieces so this checker does not contain the forbidden literal.
|
|
8
|
+
$mods = @('Ctrl', 'Control', 'Cmd', 'Command', 'Shift', 'Alt', 'Option', 'Meta', 'Super', 'Win')
|
|
9
|
+
$modAlt = ($mods | ForEach-Object { [regex]::Escape($_) }) -join '|'
|
|
10
|
+
$sep = '`?\s*\+\s*`?'
|
|
11
|
+
$pattern = '(?i)(?:' + $modAlt + ')(?:' + $sep + '(?:' + $modAlt + '))*' + $sep + '`?R`?(?![A-Za-z0-9_])'
|
|
12
|
+
|
|
13
|
+
$exts = @('.md', '.js', '.mjs', '.cjs', '.yml', '.yaml', '.txt', '.ps1', '.cmd')
|
|
14
|
+
$skipDirs = @('backup', 'queue', 'node_modules', '_preview')
|
|
15
|
+
$hits = @()
|
|
16
|
+
|
|
17
|
+
Get-ChildItem -LiteralPath $root -Recurse -File | ForEach-Object {
|
|
18
|
+
$file = $_
|
|
19
|
+
if ($exts -notcontains $file.Extension.ToLowerInvariant()) { return }
|
|
20
|
+
$segments = $file.FullName.Substring($root.Length).TrimStart('\') -split '\\'
|
|
21
|
+
if ($segments | Where-Object { $skipDirs -contains $_ }) { return }
|
|
22
|
+
$lineNo = 0
|
|
23
|
+
Get-Content -LiteralPath $file.FullName -Encoding UTF8 | ForEach-Object {
|
|
24
|
+
$lineNo += 1
|
|
25
|
+
if ($_ -match $pattern) {
|
|
26
|
+
$rel = $file.FullName.Substring($root.Length).TrimStart('\')
|
|
27
|
+
$text = $_.Trim()
|
|
28
|
+
if ($text.Length -gt 180) { $text = $text.Substring(0, 180) + '...' }
|
|
29
|
+
$hits += "${rel}:${lineNo}: $text"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if ($hits.Count -eq 0) {
|
|
35
|
+
Write-Output 'PASS: no forbidden refresh-shortcut wording found'
|
|
36
|
+
exit 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Write-Output "FAIL: $($hits.Count) forbidden refresh-shortcut occurrence(s)"
|
|
40
|
+
$hits | ForEach-Object { Write-Output " $_" }
|
|
41
|
+
exit 1
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
param(
|
|
2
|
+
[string]$Dir = '.'
|
|
3
|
+
)
|
|
4
|
+
$ErrorActionPreference = 'Stop'
|
|
5
|
+
$root = (Resolve-Path -LiteralPath $Dir).Path
|
|
6
|
+
$pkgPath = Join-Path $root 'package.json'
|
|
7
|
+
$patchPath = Join-Path $root 'cordis.patch.yml'
|
|
8
|
+
$clientPath = Join-Path $root 'client.js'
|
|
9
|
+
foreach ($f in @($pkgPath, $patchPath, $clientPath)) {
|
|
10
|
+
if (-not (Test-Path -LiteralPath $f)) { throw "missing file: $f" }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
$pkg = Get-Content -LiteralPath $pkgPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
14
|
+
$packageName = [string]$pkg.name
|
|
15
|
+
|
|
16
|
+
$patch = Get-Content -LiteralPath $patchPath -Raw -Encoding UTF8
|
|
17
|
+
$pm = [regex]::Match($patch, "(?m)^\s*name:\s*['""]?([^'""\s]+)")
|
|
18
|
+
$patchName = if ($pm.Success) { $pm.Groups[1].Value } else { '' }
|
|
19
|
+
|
|
20
|
+
$client = Get-Content -LiteralPath $clientPath -Raw -Encoding UTF8
|
|
21
|
+
$lm = [regex]::Match($client, "__ModuleLoader__\s*\.\s*load\s*\(\s*\{[\s\S]{0,800}?\bid\s*:\s*['""]([^'""]+)")
|
|
22
|
+
$loaderName = if ($lm.Success) { $lm.Groups[1].Value } else { '' }
|
|
23
|
+
|
|
24
|
+
Write-Output "package: $packageName"
|
|
25
|
+
Write-Output "patch: $patchName"
|
|
26
|
+
Write-Output "loader: $loaderName"
|
|
27
|
+
|
|
28
|
+
if ($packageName -and ($packageName -eq $patchName) -and ($packageName -eq $loaderName)) {
|
|
29
|
+
Write-Output 'OK: all three names match'
|
|
30
|
+
exit 0
|
|
31
|
+
}
|
|
32
|
+
Write-Output 'FAIL: package.json / cordis.patch.yml / client.js loader id differ'
|
|
33
|
+
if (-not $patchName) { Write-Output ' missing: cordis.patch.yml name' }
|
|
34
|
+
if (-not $loaderName) { Write-Output ' missing: client.js __ModuleLoader__ id' }
|
|
35
|
+
exit 1
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// extract.cjs — 把 asar 内的一个目录/文件复制到本地目录,便于用普通编辑器/read 工具查看。
|
|
2
|
+
// 用法:run-asar.ps1 extract.cjs <asarPath> <destDir>
|
|
3
|
+
// 说明:node 的 fs 在 ELECTRON_RUN_AS_NODE=1 下可直接读 asar 路径(Electron 会接管 asar 访问)。
|
|
4
|
+
module.exports = function (args) {
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const src = args[0];
|
|
8
|
+
const dest = args[1];
|
|
9
|
+
let files = 0;
|
|
10
|
+
let bytes = 0;
|
|
11
|
+
const copy = (from, to) => {
|
|
12
|
+
let st;
|
|
13
|
+
try { st = fs.statSync(from); } catch (error) { console.log('SKIP ' + from + ' ' + error.message); return; }
|
|
14
|
+
if (st.isDirectory()) {
|
|
15
|
+
fs.mkdirSync(to, { recursive: true });
|
|
16
|
+
for (const name of fs.readdirSync(from)) copy(path.join(from, name), path.join(to, name));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
20
|
+
const buf = fs.readFileSync(from);
|
|
21
|
+
fs.writeFileSync(to, buf);
|
|
22
|
+
files += 1;
|
|
23
|
+
bytes += buf.length;
|
|
24
|
+
};
|
|
25
|
+
copy(src, dest);
|
|
26
|
+
console.log('COPIED files=' + files + ' bytes=' + bytes + ' -> ' + dest);
|
|
27
|
+
return 0;
|
|
28
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// find-in-asar.js — 在 asar 内按正则搜索文本,输出 path:line
|
|
2
|
+
// 用法:find-in-asar.js <root> <regex> <extFilterCsv> <maxMatches> <maxFileBytes>
|
|
3
|
+
module.exports = function (args) {
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const root = args[0];
|
|
7
|
+
const re = new RegExp(args[1]);
|
|
8
|
+
const exts = (args[2] || '.yml,.yaml,.json,.ts,.js,.md').split(',');
|
|
9
|
+
const max = Number(args[3] || 40);
|
|
10
|
+
const maxBytes = Number(args[4] || 512 * 1024);
|
|
11
|
+
let shown = 0;
|
|
12
|
+
const skipDirs = new Set(['node_modules', '.git', 'dist', 'tests', '__tests__']);
|
|
13
|
+
function walk(dir) {
|
|
14
|
+
if (shown >= max) return;
|
|
15
|
+
let items;
|
|
16
|
+
try { items = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
17
|
+
for (const it of items) {
|
|
18
|
+
if (shown >= max) return;
|
|
19
|
+
const p = path.join(dir, it.name);
|
|
20
|
+
if (it.isDirectory()) {
|
|
21
|
+
if (skipDirs.has(it.name)) continue;
|
|
22
|
+
walk(p);
|
|
23
|
+
} else {
|
|
24
|
+
if (!exts.some(e => it.name.endsWith(e))) continue;
|
|
25
|
+
let st;
|
|
26
|
+
try { st = fs.statSync(p); } catch { continue; }
|
|
27
|
+
if (st.size > maxBytes) continue;
|
|
28
|
+
let text;
|
|
29
|
+
try { text = fs.readFileSync(p, 'utf8'); } catch { continue; }
|
|
30
|
+
const lines = text.split('\n');
|
|
31
|
+
for (let i = 0; i < lines.length && shown < max; i++) {
|
|
32
|
+
if (re.test(lines[i])) {
|
|
33
|
+
console.log(p.replace(root, '') + ':' + (i + 1) + ': ' + lines[i].trim().slice(0, 200));
|
|
34
|
+
shown++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
walk(root);
|
|
41
|
+
if (shown === 0) console.log('(no match)');
|
|
42
|
+
return 0;
|
|
43
|
+
};
|