postcss / postcss-cli

CLI for postcss
Other
836 stars 93 forks source link

Option to exclude directories with `--dir` #332

Closed AlexWayfer closed 4 years ago

AlexWayfer commented 4 years ago

Hello.

I have a directory, like assets/styles/, with .pcss files.

But also I have assets/styles/functions/ directory with .js files for postcss-functions.

And I use PostCSS like this:

postcss assets/styles/ -d public/styles/ --base assets/styles/ --ext=css

But I'm getting the error:

CssSyntaxError: /home/alex/Projects/ruby/test/foo_bar/assets/styles/functions/inputs-with-types.js:2:2: Unknown word

  1 | function inputsWithTypes(...types) {
> 2 |   return types.map(type => `input[type="${type}"]`).join(', ')
    |   ^
  3 | }
  4 | 

So, I want to exclude this sub-directory from processing or exclude .js files.

RyanZim commented 4 years ago

-d is for the output directory, that part is fine. Your problem is that you're passing a directory instead of a glob as the input. This should work, assuming all your .pcss files are in assets/styles/, and not in any subdirectories there:

postcss assets/styles/*.pcss -d public/styles/ --base assets/styles/ --ext=css

If you need to search subdirectories for .pcss files:

postcss "assets/styles/**/*.pcss" -d public/styles/ --base assets/styles/ --ext=css

^ Note that the glob is quoted here, since globstar (**) support isn't universal to all shells, so quoting forces postcss-cli to expand the glob, to ensure it works correctly on all systems.

AlexWayfer commented 4 years ago

OK, thank you, it works.

sKopheK commented 3 years ago

Hi, I'm struggling to make compilation run for all file with exception of one directory:

css
- a
-- a.css
- exclude
-- b.css
- c.css
- d.css

i.e. I'd like to compile a/a.css, c.sss, d.css without specifying them explicitly. The exclude directory is the only one starting with e so I was thinking of using:

postcss css/[!e]**/*.css

but then it does not include c.css and d.css as they're in root. Any ideas please?

RyanZim commented 3 years ago

@sKopheK There might be a more clever way to do it, but the simplest solution is to just pass two globs, like so:

postcss css/!(exclude)/**/*.css css/*.css
sKopheK commented 3 years ago

@sKopheK There might be a more clever way to do it, but the simplest solution is to just pass two globs, like so:

postcss css/!(exclude)/**/*.css css/*.css

hi, @RyanZim. thanks for the reply and the solution: didn't know you can specify more input parameters, docs do not mention it. i might have forgotten to mention that I'm specifying a npm task for which it's not possible to use the suggested expression !(exlude)

"scripts": {
    "postcss": "postcss css/!(exclude)/**/*.css"
}
RyanZim commented 3 years ago

I'm specifying a npm task for which it's not possible to use the suggested expression !(exclude)

Why is it not possible?

sKopheK commented 3 years ago
/*.css was unexpected at this time.

@Win10 cmdline and vs code

RyanZim commented 3 years ago

Windows doesn't support globstar (**), so you have to double-quote your globs so that postcss-cli can interpret them. Double-quotes must be escaped in JSON (\").

"postcss": "postcss \"css/!(exclude)/**/*.css\""
sKopheK commented 3 years ago

double star ** was not an issue - npm seems to take care of them, but the double quotes I somehow missed - thought of using single quotes instead, but only the double ones work. thanks!

On Tue, Jan 19, 2021 at 12:04 AM Ryan Zimmerman notifications@github.com wrote:

Windows doesn't support globstar (**), so you have to double-quote your globs so that postcss-cli can interpret them. Double-quotes must be escaped in JSON (\").

"postcss": "postcss \"css/!(exclude)/*/.css\""

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/postcss/postcss-cli/issues/332#issuecomment-762521844, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMIXJPZ27RQB4SPDDTTDD3S2TEABANCNFSM4QDR45DA .

-- Libor Pečinka

tel.: +420 776 838 276