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

Added new CLI and convertFile method to API #8

Merged
merged 3 commits into from
Oct 27, 2017
Merged

Added new CLI and convertFile method to API #8

merged 3 commits into from
Oct 27, 2017

Conversation

neocotic
Copy link
Owner

This PR delivers what was requested in #2.

I've added a new CLI which has the following usage:

Usage: convert-svg-to-png [options] [files...]


  Options:

    -V, --version              output the version number
    --no-color                 disables color output
    -b, --base-url <url>       specify base URL to use for all relative URLs in SVG
    -f, --filename <filename>  specify name the for target PNG file when processing STDIN
    --height <value>           specify height for PNG
    --width <value>            specify width for PNG
    -h, --help                 output usage information

I've also added a new convertFile method to the API which is utilized by the CLI but, I believe, will also be useful to consumers.

CLI

The CLI can work in the following ways:

  • SVG file paths are specified and are converted to a new PNG file placed in the same directory, where the file name is the same as the original except that the file extension, whatever it is (we don't care if it's .svg/.pony), is replaced with .png
    • Glob patterns can be specified in quotes for cross-platform globbing
    • URLs created from each file path is used as the default base URLs
  • SVG is piped to STDIN:
    • If -f, --filename option is specified, the resulting PNG buffer will be written to that file
    • Otherwise, the PNG buffer will be piped to STDOUT
    • process.cwd() is used as default base URL

The -b, --base-url option will always take precedence over the defaults mentioned above.

convertFile(sourceFilePath[, options])

The new convertFile API method is a simple wrapper around the existing convert method that reads the SVG buffer from a specified file path and writes the converted PNG buffer to another file path. It takes the same options with the additional of a targetFilePath option, which can be specified to control where the PNG buffer is written. If omitted, the target file will be derived from sourceFilePath in the same way as described in the first point of the CLI section above.

It's also worth noting that, if the baseFile and baseUrl options are both omitted, a file URL created from sourceFilePath will be used as the base URL instead of defaulting to process.cwd() as is done for the standard convert method.

@neocotic neocotic added this to the 0.2.0 milestone Oct 27, 2017
@neocotic neocotic self-assigned this Oct 27, 2017
@neocotic neocotic changed the base branch from master to develop October 27, 2017 15:08
@neocotic neocotic merged commit 8079987 into develop Oct 27, 2017
@neocotic neocotic deleted the cli branch October 27, 2017 15:09
neocotic added a commit that referenced this pull request Oct 27, 2017
@neocotic neocotic mentioned this pull request Oct 27, 2017
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant