postcss / postcss-cli

CLI for postcss
Other
840 stars 93 forks source link

Added the --rename option. #250

Closed tobiastom closed 5 years ago

tobiastom commented 5 years ago

This pull requests adds a new --rename option.

The idea is to be able to transform multiple files and store them in the same directory as the source, but not to replace the source file.

A possible use case would be the following:

postcss site/plugins/*/index.modules.css --rename index.js

This would parse all the index.modules.css files, transform them and store them in their original directory with the name index.js.

This can also be combined with the --dir option:

postcss site/plugins/*/index.modules.css --dir dist --rename index.js

This would keep the original directory structure inside the destination directory, but rename all the files to index.js (and not index.modules.js).

tobiastom commented 5 years ago

I honestly have no idea why the builds fail. If I run npm run test locally everything seems to work fine.

I "only" get the following error, but that one I also get when I run the tests inside my master branch:

$ npm run test

> postcss-cli@6.0.1 pretest /…/postcss-cli
> npm run clean && npm run format

> postcss-cli@6.0.1 clean /…/postcss-cli
> node test/helpers/clean.js

> postcss-cli@6.0.1 format /…/postcss-cli
> npm run prettier -- --write && eslint . --fix

> postcss-cli@6.0.1 prettier /…/postcss-cli
> prettier --single-quote --no-semi **/*.{js,md} "--write"

lib/args.js 53ms
lib/depGraph.js 8ms
test/base.js 10ms
test/cli.js 6ms
test/config.js 13ms
test/dir.js 9ms
test/error.js 23ms
test/ext.js 12ms
test/glob.js 7ms
test/map.js 12ms
test/misc.js 7ms
test/parser.js 5ms
test/replace.js 9ms
test/stdin.js 12ms
test/stdout.js 6ms
test/stringifier.js 4ms
test/syntax.js 7ms
test/use.js 5ms
test/watch.js 39ms
CHANGELOG.md 99ms
README.md 29ms

> postcss-cli@6.0.1 test /…/postcss-cli
> nyc ava -v

  ✖ Couldn't find any files to test

  0 tests passed
  1 uncaught exception
RyanZim commented 5 years ago

Honestly, this feels like an edge case; there's only so many cases we can support. If we add this, then somebody's going to want a way to rename files, but somehow based on the original name. The complexity just goes up from there. For special cases, at the end of the day, sometimes you'll have to use custom scripts to get what you want. (i.e. glob for files yourself, and call postcss-cli with just the input and output file directly.

tobiastom commented 5 years ago

I completely agree with you in terms of complexity and possible later additions. In terms of an edge case I kind of disagree because if you glob many files, they will most likely follow a similar naming scheme. This would provide the flexibility to use them easily.

Thank you for taking the time to provide some feedback.