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

Commit 5d0d3bc

Browse files
committed
Embed generated CSS in Swift raw string literal (#288)
* Replace postcss CLI usage with custom script Write generated CSS to Swift file using raw string literal * Update README * Update .gitattributes * Update .gitignore * Update validate-assets job in CI workflow * Update generated CSS * Formatting * Consolidate watch scripts
1 parent 131e23b commit 5d0d3bc

File tree

10 files changed

+4024
-3414
lines changed

10 files changed

+4024
-3414
lines changed

.gitattributes

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.node/package-lock.json -diff -merge
22
.node/package-lock.json linguist-generated=true
33

4-
Resources/all.min.css -diff -merge
5-
Resources/all.min.css linguist-generated=true
4+
Sources/swift-doc/Generated/* -diff -merge
5+
Sources/swift-doc/Generated/* linguist-generated=true

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ jobs:
176176
- name: Test assets
177177
run: |
178178
cd .node
179-
OLD=`cksum ../Resources/all.min.css`
179+
OLD=`cksum ../Sources/swift-doc/Generated/CSS.swift`
180180
npm run build
181-
NEW=`cksum ../Resources/all.min.css`
181+
NEW=`cksum ../Sources/swift-doc/Generated/CSS.swift`
182182
if [[ "$OLD" != "$NEW" ]]; then
183183
echo "Regenerated assets differ from committed version"
184184
exit -1

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
xcuserdata/
66
.swiftpm
77

8-
Resources/*.css
9-
!Resources/*.min.css
10-
118
# NodeJS
129
## Logs
1310
logs

.node/index.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const fs = require("fs");
2+
const path = require('path');
3+
const postcss = require("postcss");
4+
5+
const source = "../Assets/css/all.css";
6+
const destination = "../Sources/swift-doc/Generated/CSS.swift";
7+
8+
const input = fs.readFileSync(source);
9+
10+
postcss([
11+
require("postcss-preset-env")({
12+
stage: 0,
13+
features: {
14+
"matches-pseudo-class": false,
15+
},
16+
}),
17+
require("cssnano")({
18+
preset: "default",
19+
}),
20+
])
21+
.process(input, { from: source, to: destination })
22+
.then((result) => {
23+
const output = [
24+
`// This file was automatically generated and should not be edited.`,
25+
`let css: String = #"${result.css}"#`,
26+
].join("\n\n") + "\n";
27+
28+
fs.mkdir(path.dirname(destination), () => {
29+
fs.writeFileSync(destination, output);
30+
});
31+
});

0 commit comments

Comments
 (0)