Skip to content

Commit

Permalink
refactor: merge @utilies/mod+generated.css with @utilies/mod.css
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Jun 10, 2024
1 parent 2e2e31f commit d7b6ff6
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 198 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"serve": "deno run --allow-net --allow-read --allow-env --allow-sys --watch app/mod.ts serve",
"build": "deno run --allow-net --allow-read --allow-env --allow-sys --allow-write=.pages,dist app/mod.ts build",
"generate": "deno task generate:utilities",
"generate:utilities": "deno run --allow-write=styles/@utilities/mod+generated.css styles/@utilities/generate.ts",
"generate:utilities": "deno run --allow-read=styles/@utilities/mod.css --allow-write=styles/@utilities/mod.css styles/@utilities/generate.ts",
"lint": "deno lint",
"fmt": "deno task fmt:ts && deno task fmt:css",
"fmt:check": "deno task fmt:ts:check && deno task fmt:css:check",
Expand Down
11 changes: 8 additions & 3 deletions styles/@utilities/generate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromFileUrl } from "jsr:@std/path/from-file-url"
const rules = ["/* This file is auto-generated, please do not edit manually */"]
const rules = []
const values = [0, .125, .25, .5, .75, 1, 1.25, 1.5, 1.75, 2, 3, 4].map((value) => `${value}`.replace(/^0./, "."))

// Margin and padding utilities
Expand All @@ -12,7 +12,7 @@ for (const property of ["margin", "padding"]) {
rule += `${property}: ${value}rem;`
break
case "x":
rule += `${property}-left: ${value}rem; ${property}-right: ${value}rem;`
rule += `${property}-right: ${value}rem; ${property}-left: ${value}rem;`
break
case "y":
rule += `${property}-top: ${value}rem; ${property}-bottom: ${value}rem;`
Expand Down Expand Up @@ -46,4 +46,9 @@ for (const property of ["spacing"]) {
}

// Save generated CSS
await Deno.writeTextFile(fromFileUrl(import.meta.resolve("./mod+generated.css")), rules.join("\n"))
let css = await Deno.readTextFile(fromFileUrl(import.meta.resolve("./mod.css")))
css = css.replace(/(\/\* This section is auto-generated, please do not edit manually \*\/)[\s\S]*(\/\* --- \*\/)/, `$1${rules.join("\n")}$2`)
await Deno.writeTextFile(fromFileUrl(import.meta.resolve("./mod.css")), css)

/* This section is auto-generated, please do not edit manually */
/* --- */
193 changes: 0 additions & 193 deletions styles/@utilities/mod+generated.css

This file was deleted.

Loading

0 comments on commit d7b6ff6

Please sign in to comment.