{"id":22685505,"url":"https://github.com/himanoa/class-name-extractor","last_synced_at":"2026-02-14T06:31:01.037Z","repository":{"id":265805527,"uuid":"896422929","full_name":"himanoa/class-name-extractor","owner":"himanoa","description":"ClassNameExtractor solves these problems by providing FFI setup that can extract class names by parsing CSS for safe style resolution, and by providing functionality to place CSS in the `output` directory.","archived":false,"fork":false,"pushed_at":"2025-01-09T13:05:44.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T22:42:48.749Z","etag":null,"topics":["css","purescript"],"latest_commit_sha":null,"homepage":"https://github.com/himanoa/class-name-extractor","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/himanoa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-30T10:20:45.000Z","updated_at":"2025-01-09T13:05:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1edafce-f12a-46be-aae2-eae1a267ce51","html_url":"https://github.com/himanoa/class-name-extractor","commit_stats":null,"previous_names":["himanoa/class-name-extractor"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/himanoa/class-name-extractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/himanoa%2Fclass-name-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/himanoa%2Fclass-name-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/himanoa%2Fclass-name-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/himanoa%2Fclass-name-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/himanoa","download_url":"https://codeload.github.com/himanoa/class-name-extractor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/himanoa%2Fclass-name-extractor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29438757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T05:24:35.651Z","status":"ssl_error","status_checked_at":"2026-02-14T05:24:34.830Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","purescript"],"created_at":"2024-12-09T22:15:17.933Z","updated_at":"2026-02-14T06:31:01.030Z","avatar_url":"https://github.com/himanoa.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ClassNameExtractor\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![npm version](https://badge.fury.io/js/@himanoa%2Fclass-name-extractor.svg)](https://badge.fury.io/js/@himanoa%2Fclass-name-extractor)\n[![Test](https://github.com/himanoa/class-name-extractor/actions/workflows/ci.yml/badge.svg)](https://github.com/himanoa/class-name-extractor/actions/workflows/ci.yml)\n\nWhen using [Vite's CSS Modules feature](https://vitejs.dev/guide/features#css-modules) with PureScript, there are two main issues:\n1. Since PureScript cannot directly import CSS, you need to prepare JavaScript code using [FFI](https://github.com/purescript/documentation/blob/master/guides/FFI.md) to import CSS and retrieve styles based on class name information, making it accessible from PureScript.\n2. While `spago build` can output the JavaScript file that imports CSS and the compiled PureScript results to `output/`, the CSS files imported by JavaScript are not placed in `output`. As a result, Vite cannot resolve the CSS import part, causing build errors.\n\nClassNameExtractor solves these problems by providing FFI setup that can extract class names by parsing CSS for safe style resolution, and by providing functionality to place CSS in the `output` directory.\n\n## Installation\n\nIf you want to use the internal implementation as a library, please install it from `spago`:\n```bash\nspago install class-name-extractor\n```\n\nIf you want to use this tool as a CLI tool, install it from the NPM registry with the following command:\n```bash\nnpm install -D @himanoa/class-name-extractor\n```\n\n## Usage\n\n### Basic Usage\n\nFirst, prepare your CSS module file. The file should use the `.module.css` extension:\n\n```css\n/* src/components/Button/styles.module.css */\n.foo {\n  display: flex\n}\n.bar {\n  background-color: black;\n}\n```\n\nThen, run the class-name-extractor command with the following arguments:\n```bash\nclass-name-extractor \u003ccss-file-path\u003e \u003cpurescript-module-name\u003e\n```\n\n- `\u003ccss-file-path\u003e`: Path to your CSS module file (e.g., `src/components/Button/styles.module.css`)\n- `\u003cpurescript-module-name\u003e`: The PureScript module name where you want to use these styles (e.g., `YourProject.Components.Button`)\n\nExample:\n```bash\nclass-name-extractor src/components/Button/styles.module.css YourProject.Components.Button.Styles\n```\n\n### Generated Files\n\nThe command will generate three files:\n\n1. JavaScript FFI file:\n```javascript\n/* src/components/Button/Styles.js */\n\nimport s from './styles.module.css'\nexport const _styles = (name) =\u003e {\n  return s[name]\n}\n```\nThis file imports the CSS module and provides a function to access the class names.\n\n2. PureScript module file:\n```purescript\n-- src/components/Button/Styles.purs\nmodule YourProject.Components.Button.Styles (foo, bar) where\n\nforeign import _styles :: String -\u003e String\n\nfoo :: String\nfoo = _styles \"foo\"\nbar :: String\nbar = _styles \"bar\"\n```\nThis file exports the class names as PureScript functions that can be imported in your components.\n\n3. CSS file in output directory:\n```css\n/* output/YourProject.Components.Button.Styles/styles.module.css */\n\n.foo {\n  display: flex\n}\n.bar {\n  background-color: black;\n}\n```\nThis is a copy of your CSS file placed in the output directory for Vite to properly resolve the imports.\n\n### Using in Your Components\n\nYou can use the generated styles in your PureScript components like this:\n\n```purescript\nmodule YourProject.Components.Button.Component where\n\nimport YourProject.Components.Button.Styles as Styles\n\nbutton :: JSX\nbutton = element \"div\" { className: Styles.foo } [ text \"Button\" ]\n```\n\nThis ensures that:\n- The class names are available as PureScript functions\n- The CSS is properly imported and bundled by Vite\n- You don't need to manually manage the FFI setup for CSS modules\n\n## Feedback and Contributions\n\nIf you find any bugs or issues while using the tool, please create an Issue.\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhimanoa%2Fclass-name-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhimanoa%2Fclass-name-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhimanoa%2Fclass-name-extractor/lists"}