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

Commit

Permalink
Embed generated CSS in Swift raw string literal (#288)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mattt committed Jun 1, 2021
1 parent 131e23b commit 5d0d3bc
Show file tree
Hide file tree
Showing 10 changed files with 4,024 additions and 3,414 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.node/package-lock.json -diff -merge
.node/package-lock.json linguist-generated=true

Resources/all.min.css -diff -merge
Resources/all.min.css linguist-generated=true
Sources/swift-doc/Generated/* -diff -merge
Sources/swift-doc/Generated/* linguist-generated=true
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ jobs:
- name: Test assets
run: |
cd .node
OLD=`cksum ../Resources/all.min.css`
OLD=`cksum ../Sources/swift-doc/Generated/CSS.swift`
npm run build
NEW=`cksum ../Resources/all.min.css`
NEW=`cksum ../Sources/swift-doc/Generated/CSS.swift`
if [[ "$OLD" != "$NEW" ]]; then
echo "Regenerated assets differ from committed version"
exit -1
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
xcuserdata/
.swiftpm

Resources/*.css
!Resources/*.min.css

# NodeJS
## Logs
logs
Expand Down
31 changes: 31 additions & 0 deletions .node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require("fs");
const path = require('path');
const postcss = require("postcss");

const source = "../Assets/css/all.css";
const destination = "../Sources/swift-doc/Generated/CSS.swift";

const input = fs.readFileSync(source);

postcss([
require("postcss-preset-env")({
stage: 0,
features: {
"matches-pseudo-class": false,
},
}),
require("cssnano")({
preset: "default",
}),
])
.process(input, { from: source, to: destination })
.then((result) => {
const output = [
`// This file was automatically generated and should not be edited.`,
`let css: String = #"${result.css}"#`,
].join("\n\n") + "\n";

fs.mkdir(path.dirname(destination), () => {
fs.writeFileSync(destination, output);
});
});
Loading

0 comments on commit 5d0d3bc

Please sign in to comment.