-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(docs): try another way for runnable scss module demos
- Loading branch information
Showing
9 changed files
with
132 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { type FakeScssModule } from "../src/utils/fakeScssModules.js"; | ||
|
||
/** | ||
* Mutable cache | ||
*/ | ||
export const scssModulesCache = new Map<string, FakeScssModule>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { readFile, writeFile } from "node:fs/promises"; | ||
import { basename } from "node:path"; | ||
import { compileScssModule } from "../../src/utils/compileScssModule.js"; | ||
import { format } from "../../src/utils/format.js"; | ||
import { scssModulesCache } from "../codeCache.js"; | ||
import { GENERATED_FILE_BANNER } from "../constants.js"; | ||
|
||
const SCSS_MODULES_PATH = "src/constants/scssModulesLookup.ts"; | ||
|
||
export async function createScssModule(scssModulePath: string): Promise<void> { | ||
const scss = await readFile(scssModulePath, "utf8"); | ||
const fileName = basename(scssModulePath); | ||
const baseName = fileName.replace(".module.scss", ""); | ||
const css = await compileScssModule({ | ||
scss, | ||
baseName, | ||
}); | ||
|
||
scssModulesCache.set(scssModulePath, { | ||
css, | ||
scss, | ||
baseName, | ||
fileName, | ||
}); | ||
} | ||
|
||
export async function createScssModuleFile(): Promise<void> { | ||
const contents = await format(`${GENERATED_FILE_BANNER} | ||
import "server-only"; | ||
import { type FakeScssModule } from "../utils/fakeScssModules.js"; | ||
export const SCSS_MODULES: Record<string, FakeScssModule> = | ||
${JSON.stringify(Object.fromEntries(scssModulesCache.entries()))}; | ||
`); | ||
|
||
await writeFile(SCSS_MODULES_PATH, contents); | ||
} | ||
|
||
export async function updateScssModule(scssModulePath: string): Promise<void> { | ||
await createScssModule(scssModulePath); | ||
await createScssModuleFile(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters