Skip to content

Commit a501c00

Browse files
authored
add a utility command 'unidoc list-assets' (#370)
1 parent a0cf60b commit a501c00

15 files changed

+138
-49
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ let package:Package = .init(
136136

137137
.executableTarget(name: "unidoc-tools",
138138
dependencies: [
139-
.target(name: "System_ArgumentParser"),
140139
.target(name: "UnidocCLI"),
141140
.target(name: "UnidocClient"),
142141
.target(name: "UnidocServer"),
@@ -146,8 +145,6 @@ let package:Package = .init(
146145

147146
.executableTarget(name: "unidoc-linkerd",
148147
dependencies: [
149-
.target(name: "System_ArgumentParser"),
150-
.target(name: "System_"),
151148
.target(name: "UnidocCLI"),
152149
.target(name: "UnidocServer"),
153150
.target(name: "UnidocServerInsecure"),
@@ -478,6 +475,7 @@ let package:Package = .init(
478475

479476
.target(name: "UnidocAssets",
480477
dependencies: [
478+
.target(name: "SemanticVersions"),
481479
.target(name: "Unidoc"),
482480
]),
483481

@@ -490,6 +488,7 @@ let package:Package = .init(
490488

491489
.target(name: "UnidocCLI",
492490
dependencies: [
491+
.target(name: "System_ArgumentParser"),
493492
.target(name: "UnidocServer"),
494493
.product(name: "ArgumentParser", package: "swift-argument-parser"),
495494
]),

Scripts/Package

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
set -e
33

44
SWIFTPM_SCRATCH=$1
5-
shift
65

7-
if [ -z "$SWIFTPM_SCRATCH" ]; then
6+
if [ -z $SWIFTPM_SCRATCH ]; then
87
echo "Usage: $0 <scratch-path> [ unidoc | unidoc-linkerd ]"
98
exit 1
9+
else
10+
shift
1011
fi
1112

1213
while [[ $# -gt 0 ]]; do
@@ -15,21 +16,14 @@ while [[ $# -gt 0 ]]; do
1516
shift
1617
# Note: ordering is significant as each `-C` is relative to the last.
1718
tar -czf unidoc.tar.gz \
18-
-C . \
19-
Assets/css/Main.css \
20-
Assets/css/Main.css.map \
21-
Assets/js/Main.js \
22-
Assets/js/Main.js.map \
23-
Assets/woff2/*.woff2 \
24-
-C $SWIFTPM_SCRATCH/release \
25-
unidoc
19+
-C . $($SWIFTPM_SCRATCH/release/unidoc list-assets -p Assets/) \
20+
-C $SWIFTPM_SCRATCH/release unidoc
2621
;;
2722

2823
unidoc-linkerd )
2924
shift
3025
tar -czf unidoc-linkerd.tar.gz \
31-
-C $SWIFTPM_SCRATCH/release \
32-
unidoc-linkerd
26+
-C $SWIFTPM_SCRATCH/release unidoc-linkerd
3327
;;
3428

3529
* )

Sources/SymbolGraphBuilder/SSGC.Compile.swift renamed to Sources/SymbolGraphBuilder/SSGC.CompileCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import System_ArgumentParser
88
extension SSGC
99
{
1010
public
11-
struct Compile:Decodable
11+
struct CompileCommand:Decodable
1212
{
1313
@Option(
1414
name: [.customLong("workspace-name"), .customShort("w")],
@@ -170,7 +170,7 @@ extension SSGC
170170
}
171171
}
172172
}
173-
extension SSGC.Compile
173+
extension SSGC.CompileCommand
174174
{
175175
public
176176
func launch() throws

Sources/UnidocAssets/Unidoc.Asset.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import SemanticVersions
2+
13
extension Unidoc
24
{
35
@frozen public
@@ -55,6 +57,36 @@ extension Unidoc.Asset
5557
extension Unidoc.Asset
5658
{
5759
@inlinable public
60+
func path(prepending version:MajorVersion) -> String
61+
{
62+
self.versioned ? "/asset/\(version)/\(self)" : "/asset/\(self)"
63+
}
64+
65+
@inlinable public
66+
var libre:Bool
67+
{
68+
switch self
69+
{
70+
case .error404_jpg: false
71+
case .error4xx_jpg: false
72+
case .error500_jpg: false
73+
case .favicon_ico: true
74+
case .favicon_png: true
75+
case .github_jpg: false
76+
case .literata45_woff2: true
77+
case .literata47_woff2: true
78+
case .literata75_woff2: true
79+
case .literata77_woff2: true
80+
case .main_css: true
81+
case .main_css_map: true
82+
case .main_js: true
83+
case .main_js_map: true
84+
case .admin_css: false
85+
case .admin_css_map: false
86+
}
87+
}
88+
89+
@inlinable
5890
var versioned:Bool
5991
{
6092
switch self

Sources/UnidocCLI/Regex (ext).swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ArgumentParser
2+
3+
extension Regex<Substring>:@retroactive ExpressibleByArgument
4+
{
5+
@inlinable public
6+
init?(argument:String)
7+
{
8+
do
9+
{
10+
try self.init(argument)
11+
}
12+
catch
13+
{
14+
return nil
15+
}
16+
}
17+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import ArgumentParser
2+
import System_ArgumentParser
3+
import System_
4+
5+
extension Unidoc
6+
{
7+
public
8+
struct ListAssetsCommand:ParsableCommand
9+
{
10+
public
11+
static let configuration:CommandConfiguration = .init(commandName: "list-assets")
12+
13+
@Argument
14+
var pattern:Regex<Substring>?
15+
16+
@Option(name: [.customLong("assets-directory"), .customShort("p")])
17+
var assets:FilePath = "Assets"
18+
19+
@Flag(name: [.customLong("long"), .customShort("l")])
20+
var long:Bool = false
21+
22+
@Flag(name: [.customLong("include-nonfree"), .customShort("a")])
23+
var includeNonfree:Bool = false
24+
25+
public
26+
init() {}
27+
28+
public
29+
func run() throws
30+
{
31+
for asset:Unidoc.Asset in Unidoc.Asset.allCases
32+
{
33+
guard self.includeNonfree || asset.libre
34+
else
35+
{
36+
continue
37+
}
38+
39+
if let pattern:Regex<Substring> = self.pattern,
40+
case nil = try pattern.wholeMatch(in: "\(asset)")
41+
{
42+
continue
43+
}
44+
45+
let path:FilePath = self.assets.appending(asset.source)
46+
47+
print(self.long ? """
48+
\(path)\t\
49+
\(asset.path(prepending: Unidoc.RenderFormat.Assets.version))\t\
50+
\(asset.type)
51+
""" : """
52+
\(path)
53+
""")
54+
}
55+
}
56+
}
57+
}

Sources/UnidocRender/Formats/Unidoc.Asset (ext).swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/ssgc/SSGC.Compile (ext).swift renamed to Sources/ssgc/SSGC.CompileCommand (ext).swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import SymbolGraphBuilder
33

44
@main
5-
extension SSGC.Compile:ParsableCommand
5+
extension SSGC.CompileCommand:ParsableCommand
66
{
77
public
88
func run() throws

Sources/unidoc-tools/Main.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import SymbolGraphCompiler
55
struct Main:AsyncParsableCommand
66
{
77
static let configuration:CommandConfiguration = .init(subcommands: [
8-
SSGC.Compile.self,
9-
Init.self,
10-
Local.self,
11-
Preview.self
8+
SSGC.CompileCommand.self,
9+
Unidoc.InitCommand.self,
10+
Unidoc.LocalCommand.self,
11+
Unidoc.PreviewCommand.self,
12+
Unidoc.ListAssetsCommand.self,
1213
])
1314
}

0 commit comments

Comments
 (0)