Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 6587f53

Browse files
committed
Use post-css cli and move node files to .node
1 parent cc55796 commit 6587f53

File tree

10 files changed

+3938
-9530
lines changed

10 files changed

+3938
-9530
lines changed

.node/package-lock.json

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

.node/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "swift-doc",
3+
"browserslist": ["> 1%", "not dead"],
4+
"scripts": {
5+
"build": "postcss ../Assets/css/all.css -o ../Resources/all.min.css --config ./postcss.config.js -u cssnano",
6+
"watch": "postcss -w ../Assets/**/*.css --dir ../Resources --config ./postcss.config.js "
7+
},
8+
"dependencies": {
9+
"cssnano": "^4.1.10",
10+
"postcss-cli": "^7.1.0",
11+
"postcss-preset-env": "^6.7.0"
12+
}
13+
}

postcss.config.js renamed to .node/postcss.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports = {
22
plugins: [
3-
require('autoprefixer'),
43
require('postcss-preset-env')({
54
stage: 0,
65
features: {
File renamed without changes.

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,17 @@ jobs:
246246
## Development
247247
### Web Assets
248248
249-
[Parcel](https://parceljs.org) is used to process Web assets such as CSS and JavaScript. To make changes, you need to have Node and a package manager such as `npm` installed. In the project root, run `npm install` to install the dependencies.
249+
To make changes to the CSS files, you need to have Node and a package manager such as `npm` installed. To get started:
250250

251-
During development, run the following command in a terminal:
251+
```terminal
252+
$ cd .node
253+
$ npm install
254+
```
255+
256+
To process the PostCSS files during development:
252257

253258
```terminal
259+
$ cd .node
254260
$ npm run watch
255261
```
256262

Resources/all.css

Lines changed: 1148 additions & 1 deletion
Large diffs are not rendered by default.

Resources/all.min.css

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 110 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,130 @@
11
import ArgumentParser
22
import Foundation
3+
import SwiftDoc
4+
import SwiftMarkup
35
import SwiftSemantics
46
import struct SwiftSemantics.Protocol
5-
import SwiftMarkup
6-
import SwiftDoc
77

88
extension SwiftDoc {
9-
struct Generate: ParsableCommand {
10-
enum Format: String, ExpressibleByArgument {
11-
case commonmark
12-
case html
13-
}
9+
struct Generate: ParsableCommand {
10+
enum Format: String, ExpressibleByArgument {
11+
case commonmark
12+
case html
13+
}
14+
15+
struct Options: ParsableArguments {
16+
@Argument(help: "One or more paths to Swift files")
17+
var inputs: [String]
18+
19+
@Option(name: [.long, .customShort("n")],
20+
help: "The name of the module")
21+
var moduleName: String
22+
23+
@Option(name: .shortAndLong,
24+
default: ".build/documentation",
25+
help: "The path for generated output")
26+
var output: String
27+
28+
@Option(name: .shortAndLong,
29+
default: .commonmark,
30+
help: "The output format")
31+
var format: Format
1432

15-
struct Options: ParsableArguments {
16-
@Argument(help: "One or more paths to Swift files")
17-
var inputs: [String]
33+
@Option(name: .customLong("base-url"),
34+
default: "/",
35+
help: "The base URL used for all relative URLs in generated documents.")
36+
var baseURL: String
37+
}
38+
39+
static var configuration = CommandConfiguration(abstract: "Generates Swift documentation")
40+
41+
@OptionGroup()
42+
var options: Options
43+
44+
func run() throws {
45+
let module = try Module(name: options.moduleName, paths: options.inputs)
46+
47+
let outputDirectoryURL = URL(fileURLWithPath: options.output)
48+
try fileManager.createDirectory(at: outputDirectoryURL, withIntermediateDirectories: true, attributes: fileAttributes)
1849

19-
@Option(name: [.long, .customShort("n")],
20-
help: "The name of the module")
21-
var moduleName: String
50+
do {
51+
let format = options.format
2252

23-
@Option(name: .shortAndLong,
24-
default: ".build/documentation",
25-
help: "The path for generated output")
26-
var output: String
53+
var pages: [String: Page] = [:]
2754

28-
@Option(name: .shortAndLong,
29-
default: .commonmark,
30-
help: "The output format")
31-
var format: Format
55+
var globals: [String: [Symbol]] = [:]
56+
for symbol in module.interface.topLevelSymbols.filter({ $0.isPublic }) {
57+
switch symbol.api {
58+
case is Class, is Enumeration, is Structure, is Protocol:
59+
pages[path(for: symbol)] = TypePage(module: module, symbol: symbol)
60+
case let `typealias` as Typealias:
61+
pages[path(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol)
62+
case let function as Function where !function.isOperator:
63+
globals[function.name, default: []] += [symbol]
64+
case let variable as Variable:
65+
globals[variable.name, default: []] += [symbol]
66+
default:
67+
continue
68+
}
69+
}
3270

33-
@Option(name: .customLong("base-url"),
34-
default: "/",
35-
help: "The base URL used for all relative URLs in generated documents.")
36-
var baseURL: String
71+
for (name, symbols) in globals {
72+
pages[path(for: name)] = GlobalPage(module: module, name: name, symbols: symbols)
3773
}
3874

39-
static var configuration = CommandConfiguration(abstract: "Generates Swift documentation")
40-
41-
@OptionGroup()
42-
var options: Options
43-
44-
func run() throws {
45-
let module = try Module(name: options.moduleName, paths: options.inputs)
46-
47-
let outputDirectoryURL = URL(fileURLWithPath: options.output)
48-
try fileManager.createDirectory(at: outputDirectoryURL, withIntermediateDirectories: true, attributes: fileAttributes)
49-
50-
do {
51-
let format = options.format
52-
53-
var pages: [String: Page] = [:]
54-
55-
var globals: [String: [Symbol]] = [:]
56-
for symbol in module.interface.topLevelSymbols.filter({ $0.isPublic }) {
57-
switch symbol.api {
58-
case is Class, is Enumeration, is Structure, is Protocol:
59-
pages[path(for: symbol)] = TypePage(module: module, symbol: symbol)
60-
case let `typealias` as Typealias:
61-
pages[path(for: `typealias`.name)] = TypealiasPage(module: module, symbol: symbol)
62-
case let function as Function where !function.isOperator:
63-
globals[function.name, default: []] += [symbol]
64-
case let variable as Variable:
65-
globals[variable.name, default: []] += [symbol]
66-
default:
67-
continue
68-
}
69-
}
70-
71-
for (name, symbols) in globals {
72-
pages[path(for: name)] = GlobalPage(module: module, name: name, symbols: symbols)
73-
}
74-
75-
guard !pages.isEmpty else { return }
76-
77-
if pages.count == 1, let page = pages.first?.value {
78-
let filename: String
79-
switch format {
80-
case .commonmark:
81-
filename = "Home.md"
82-
case .html:
83-
filename = "index.html"
84-
}
85-
86-
let url = outputDirectoryURL.appendingPathComponent(filename)
87-
try page.write(to: url, format: format, baseURL: options.baseURL)
88-
} else {
89-
switch format {
90-
case .commonmark:
91-
pages["Home"] = HomePage(module: module)
92-
pages["_Sidebar"] = SidebarPage(module: module)
93-
pages["_Footer"] = FooterPage()
94-
case .html:
95-
pages["Home"] = HomePage(module: module)
96-
}
97-
98-
try pages.map { $0 }.parallelForEach {
99-
let filename: String
100-
switch format {
101-
case .commonmark:
102-
filename = "\($0.key).md"
103-
case .html where $0.key == "Home":
104-
filename = "index.html"
105-
case .html:
106-
filename = "\($0.key)/index.html"
107-
}
108-
109-
let url = outputDirectoryURL.appendingPathComponent(filename)
110-
try $0.value.write(to: url, format: format, baseURL: options.baseURL)
111-
}
112-
}
113-
114-
if case .html = format {
115-
let cssData = try fetchRemoteCSS()
116-
let cssURL = outputDirectoryURL.appendingPathComponent("all.css")
117-
try writeFile(cssData, to: cssURL)
118-
}
119-
120-
121-
} catch {
122-
logger.error("\(error)")
75+
guard !pages.isEmpty else { return }
76+
77+
if pages.count == 1, let page = pages.first?.value {
78+
let filename: String
79+
switch format {
80+
case .commonmark:
81+
filename = "Home.md"
82+
case .html:
83+
filename = "index.html"
84+
}
85+
86+
let url = outputDirectoryURL.appendingPathComponent(filename)
87+
try page.write(to: url, format: format, baseURL: options.baseURL)
88+
} else {
89+
switch format {
90+
case .commonmark:
91+
pages["Home"] = HomePage(module: module)
92+
pages["_Sidebar"] = SidebarPage(module: module)
93+
pages["_Footer"] = FooterPage()
94+
case .html:
95+
pages["Home"] = HomePage(module: module)
96+
}
97+
98+
try pages.map { $0 }.parallelForEach {
99+
let filename: String
100+
switch format {
101+
case .commonmark:
102+
filename = "\($0.key).md"
103+
case .html where $0.key == "Home":
104+
filename = "index.html"
105+
case .html:
106+
filename = "\($0.key)/index.html"
123107
}
108+
109+
let url = outputDirectoryURL.appendingPathComponent(filename)
110+
try $0.value.write(to: url, format: format, baseURL: options.baseURL)
111+
}
124112
}
113+
114+
if case .html = format {
115+
let cssData = try fetchRemoteCSS()
116+
let cssURL = outputDirectoryURL.appendingPathComponent("all.css")
117+
try writeFile(cssData, to: cssURL)
118+
}
119+
120+
} catch {
121+
logger.error("\(error)")
122+
}
125123
}
124+
}
126125
}
127126

128127
func fetchRemoteCSS() throws -> Data {
129-
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.css")!
130-
return try Data(contentsOf: url)
128+
let url = URL(string: "https://raw.githubusercontent.com/SwiftDocOrg/swift-doc/master/Resources/all.min.css")!
129+
return try Data(contentsOf: url)
131130
}

0 commit comments

Comments
 (0)