matype / stylefmt

stylefmt is a tool that automatically formats stylesheets.
Other
2.1k stars 89 forks source link

how to specify multiple files in cli? #223

Closed noahehall closed 7 years ago

noahehall commented 7 years ago

./nodemodules/.bin/stylefmt -d -R ./src/*/_.css

gives error: cannot read property forEach of undefined

gucong3000 commented 7 years ago
./node_modules/.bin/stylefmt --help
Usage: stylefmt [options] input-name [output-name]

Options:

  -d, --diff             output diff against original file
  -l, --list             format list of space seperated files in place
  -R, --recursive        format files recursively
  -c, --config           path to a specific configuration file (JSON, YAML, or CommonJS)
  -b, --config-basedir   path to the directory that relative paths defining "extends"
  -v, --version          output the version number
  -h, --help             output usage information

-l, --list format list of space seperated files in place

noahehall commented 7 years ago

hi @gucong3000

i do not have a separeted list of files, is it possible to send in a glob

./nodemodules/.bin/stylefmt -d -R ./src/*/_.css

gucong3000 commented 7 years ago

LGM, I will push a PR to support glob

noahehall commented 7 years ago

Awesome!

gucong3000 commented 7 years ago

Already support glob in #232

@noahehall , you can have a try.

npm i -g gucong3000/stylefmt#glob_support
stylefmt -d -l test/sass/**/*.css "!**/*.out.css"
noahehall commented 7 years ago

just a note - if no .css files are found it throws error

Is it possible to silently fail if there aren't any css files ? or to show message vs throwing error.

I want to use this as part of my build process

noahehall commented 7 years ago

the following does not work for me:

./node_modules/.bin/stylefmt -d -l src/**/*.css "!**/*.out.css"

it returns: There is no difference with the original file.

fixable:

screen shot 2016-11-18 at 8 58 39 pm
gucong3000 commented 7 years ago

@noahehall

just a note - if no .css files are found it throws error

Is it possible to silently fail if there aren't any css files ? or to show message vs throwing error.

I want to use this as part of my build process

It will show a message if no file matched: Files glob patterns specified did not match any css files.

https://github.com/morishitter/stylefmt/blob/master/bin/cli.js#L103

the following does not work for me:

Try ./node_modules/.bin/stylefmt -l src/**/*.scss, maybe a wrong file extension used.

One more thing, use master branch: npm i morishitter/stylefmt

noahehall commented 7 years ago

still not working :(

./node_modules/.bin/stylefmt -l src/*/.css

returns: No files are formatted.

Here is the branch i am testing on: https://github.com/noahehall/udacity-trainschedule/tree/serviceworkers

gucong3000 commented 7 years ago

I didn't find any problems in your branch.

E:\work\udacity-trainschedule (serviceworkers) (udacity-trainschedule@0.1.1)
λ .\node_modules\.bin\stylefmt -l src/**/*.css
No files are formatted.

E:\work\udacity-trainschedule (serviceworkers) (udacity-trainschedule@0.1.1)
λ .\node_modules\.bin\stylefmt -l src/**/*.css --diff
src/components/forms/calendar.css
There is no difference with the original file.

src/components/forms/inputmoment.css
There is no difference with the original file.

src/components/forms/slider.css
There is no difference with the original file.

src/components/forms/time.css
There is no difference with the original file.

src/components/forms/variables.css
There is no difference with the original file.

src/containers/main/main.css
There is no difference with the original file.

src/containers/notfound/notfound.css
There is no difference with the original file.

src/containers/page/page.css
There is no difference with the original file.

src/containers/start/daypicker.css
There is no difference with the original file.

src/containers/start/start.css
There is no difference with the original file.

src/theme/colors.css
There is no difference with the original file.

Then I changed one of your file (src/containers/start/start.css), and try again.

image

image

If a file after format has no difference with original, CLI will not Overlay file.

danturu commented 7 years ago

@gucong3000 Is it possible to list with globs from npm scripts? The following script in a pure bash works fine: stylefmt --config .stylelintrc --list (src|packages)/**/*.css. But if I add it to the package's scripts it fails with the exit status 2 with a no error explanation.

Before v4 I did "lint:css:fix": "stylefmt --config .stylelintrc --list ls (src|packages)/**/*.css" and it worked fine. I definitely missed something obvious here.

noahehall commented 7 years ago

Got it. Sounds like I need to update the style rules, interesting thing is, in atom I am getting formatting errors.

Ill review tonight and post updates

gucong3000 commented 7 years ago

@rosendi Can you give me a test case?

danturu commented 7 years ago

@gucong3000 Just put in your package.json:

scripts: {
  "lint:css:fix": "stylefmt --config .stylelintrc --list (DIR1|DIR2)/**/*.css"
}

...then run npm run lint:css:fix and it will fail.

gucong3000 commented 7 years ago

@rosendi try postcss-cli

matype commented 7 years ago

@rosendi please try

scripts: {
  "lint:css:fix": "stylefmt --config .stylelintrc --recursive '(DIR1|DIR2)/**/*.css'"
}

recursive pathes using glob have to use with quotes e.g. '' because its shell is expanded as a wild card. and --list option is changed to --recursive (-r) when stylefmt v5 was released.

danturu commented 7 years ago

@morishitter Great! It works. Thank you!

P.S. The glob pattern should be {DIR1,DIR2}/**/*.css

matype commented 7 years ago

anytime :)

csmit175 commented 7 years ago

Hey i cant seem to get the glob format working. Im trying to run ./node_modules/.bin/stylefmt --recursive 'client/src/common/*/.less' but just keep getting a message saying files glob patterns specified did not match any css files. Please help!

sebelga commented 7 years ago

I just had the same problem and removed the quote mark '' around the path and it worked. stylefmt --config .stylelintrc --recursive src/app/**/*.scss

sapegin commented 7 years ago

Doesn’t work for me too but I have “TypeError: Cannot read property 'forEach' of undefined”

@sebelga When you omit quotes you’re using you shell expansion which may not work the same way on other platforms. Basically you just send a huge list of files to stylefmt ;-)