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

Commit 1edee3b

Browse files
committed
Replace postcss CLI usage with custom script
Write generated CSS to Swift file using raw string literal
1 parent 0b98f22 commit 1edee3b

File tree

12 files changed

+4033
-3423
lines changed

12 files changed

+4033
-3423
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ jobs:
161161
- name: Test assets
162162
run: |
163163
cd .node
164-
OLD=`cksum ../Resources/all.min.css`
164+
OLD=`cksum ../Sources/swift-doc/Generated/CSS.swift`
165165
npm run build
166-
NEW=`cksum ../Resources/all.min.css`
166+
NEW=`cksum ../Sources/swift-doc/Generated/CSS.swift`
167167
if [[ "$OLD" != "$NEW" ]]; then
168168
echo "Regenerated assets differ from committed version"
169169
exit -1

.gitignore

Lines changed: 0 additions & 3 deletions
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

Lines changed: 31 additions & 0 deletions
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)