activeguild / vite-plugin-sass-dts

This is a plugin that automatically creates a type file when using the CSS module type-safely.
MIT License
120 stars 19 forks source link

Only generate types in CI? #91

Closed aakagi closed 2 months ago

aakagi commented 8 months ago

Is there a way to generate the type definitions only in CI?

I would prefer to .gitignore the files locally and re-generate them in CI. Is this possible to do?

activeguild commented 8 months ago

@aakagi What kind of use do you want to make of it?

aakagi commented 8 months ago
  1. I would like to have the *.scss.d.ts files generated locally, for local type-safety while developing.
  2. I do not want to have to commit the file changes to git. I would like to add *.scss.d.ts to my .gitignore.
  3. I want to run a command in my github actions CI script to generate these types because I do not want the build to succeed if there are any typescript errors.

It would be nice to be able to run a command like this to check type safety:

# Generate types
yarn vite-plugin-sass-dts # [--args]

# Check type safety
yarn tsc

Is it easy to add a command like this?

activeguild commented 8 months ago

Understood, I'll see what I can do.

activeguild commented 8 months ago

@aakagi

I'll need a configuration file for execution in cli, but I'm not sure.

aakagi commented 2 months ago

I figured out a solution that works!

I wrote a script that checks to make sure each .module.scss file has a sibling .module.scss.d.ts file, and throws an error if it doesn't, or if a "rogue" one is found.

The script I wrote also allows you to pass in a --fix flag which updates the file timestamp for .module.scss files that are missing a sibling .module.scss.d.ts file, which then causes vite-plugin-sass-dts to generate the file 😄. The --fix flag will also delete any "rogue" .module.scss.d.ts files that are found.

You can read through the full implementation here: https://gist.github.com/aakagi/d0c9954b1ec617b9b6ab150d7d78a892