Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting context via command line #52

Closed
RyanZim opened this issue Jan 4, 2017 · 9 comments
Closed

Allow setting context via command line #52

RyanZim opened this issue Jan 4, 2017 · 9 comments
Milestone

Comments

@RyanZim
Copy link
Collaborator

RyanZim commented Jan 4, 2017

As mentioned in #51.

Currently, we have --env to allow setting process.env.NODE_ENV for postcss.config.js. We also have command-line flags to override the syntax, parser, stringifier, & map options specified in the config.

We should have an additional command-line flag to allow passing other values via ctx to postcss.config.js.

My strawman proposal:

postcss --ctx {doIt: true, someKey: 'somevalue'}

This needs discussion.

@RyanZim RyanZim added this to the v3.0.0 milestone Jan 4, 2017
@RyanZim
Copy link
Collaborator Author

RyanZim commented Feb 3, 2017

@michael-ciniawsky ping?

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Feb 3, 2017

I currently expose the config.options to ctx

postcss src/index.sss -o dest/index.css -p sugarss -m -e 'production' 
module.exports = ({ options, file, env }) => ({
   parser: file.extname === '.sss' ? options.parser : false
   map: options.map || { inline: true }
   plugins: {
     'postcss-import': { root: file.dirname }
     'cssnano': env === 'prodution' ? {} : false
   }
})

The following is not working and is a mess, how did postcss-cli v2 --use work ? Something like options.plugins.key = value would still be valuable though. For --use and postcss.config.js

postcss -u || --ctx  { key: value }

@RyanZim
Copy link
Collaborator Author

RyanZim commented Feb 4, 2017

@michael-ciniawsky So what are we doing here?

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Feb 5, 2017

Options can be set via the CLI, only plugin options must be defined in the config itself

postcss -m -p -t -s

postcss.config.js

module.exports = (ctx) => ({
   map: cts.options.map || fallback,
   parser: ctx.options.parser || fallback,
   syntax: ctx.options. syntax,
   stringifier: ctx.options.stringifier
   plugins: {...plugins}
})

@RyanZim
Copy link
Collaborator Author

RyanZim commented Feb 6, 2017

So we don't need custom context?

@michael-ciniawsky
Copy link
Contributor

Well It would into the direction like -- ctx ctx.key value which is similiar to -u plugin.option value and we decided to not support atm. In the future we can try to add the -u .. to the context e.g ctx.option.plugins

module.exports = (ctx) => ({
   map: cts.options.map || fallback,
   parser: ctx.options.parser || fallback,
   syntax: ctx.options. syntax,
   stringifier: ctx.options.stringifier,
   plugins: { 
     'posthtml-plugin': ctx.options.plugin
   }
})

@RyanZim
Copy link
Collaborator Author

RyanZim commented Feb 7, 2017

In the future we can try to add the -u .. to the context e.g ctx.option.plugins

👍 Perhaps should be ctx.plugins, but, yeah.


Can you document what's currently available via ctx?

@michael-ciniawsky
Copy link
Contributor

Yep ctx.plugins of course 😛 . yep I will make docs about it

@michael-ciniawsky
Copy link
Contributor

Fixed by #86

@RyanZim RyanZim closed this as completed Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants