Skip to content

Commit

Permalink
Merge pull request #28 from NotNinja/develop
Browse files Browse the repository at this point in the history
0.3.2 Release
  • Loading branch information
neocotic authored Nov 21, 2017
2 parents 5c2360f + b0f88ff commit c1cd433
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.3.2, 2017.11.21

* Error being thrown caused by lost context for CLI [#24](https://github.com/NotNinja/convert-svg/issues/24)
* Pass custom arguments to puppeteer [#25](https://github.com/NotNinja/convert-svg/issues/25) [#27](https://github.com/NotNinja/convert-svg/issues/27)
* Bump puppeteer to v0.13.0 [#26](https://github.com/NotNinja/convert-svg/issues/26)

## Version 0.3.1, 2017.11.03

* Error thrown as context is lost for API methods when using destructuring imports [#22](https://github.com/NotNinja/convert-svg/issues/22)
Expand Down
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.4.0",
"version": "0.3.1",
"lerna": "2.5.1",
"version": "0.3.2",
"packages": [
"packages/*"
],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "convert-svg",
"license": "MIT",
"devDependencies": {
"eslint": "^4.10.0",
"eslint": "^4.11.0",
"eslint-config-notninja": "^0.2.3",
"lerna": "^2.4.0",
"lerna": "^2.5.1",
"mocha": "^4.0.1"
},
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions packages/convert-svg-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-svg-core",
"version": "0.3.1",
"version": "0.3.2",
"description": "Supports converting SVG into another format using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
Expand Down Expand Up @@ -30,15 +30,17 @@
"file-url": "^2.0.2",
"get-stdin": "^5.0.1",
"glob": "^7.1.2",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"pollock": "^0.1.0",
"puppeteer": "^0.12.0",
"puppeteer": "^0.13.0",
"tmp": "0.0.33"
},
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"mocha": "^4.0.1",
"sinon": "^4.0.2"
"sinon": "^4.1.2"
},
"main": "src/index.js",
"engines": {
Expand Down
46 changes: 37 additions & 9 deletions packages/convert-svg-core/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

'use strict';

const omit = require('lodash.omit');
const pick = require('lodash.pick');

const Converter = require('./Converter');

const _provider = Symbol('provider');
Expand Down Expand Up @@ -65,16 +68,16 @@ class API {
* provided and this information could not be derived from <code>input</code>.
*
* @param {Buffer|string} input - the SVG input to be converted to another format
* @param {Converter~ConvertOptions} [options] - the options to be used
* @param {API~ConvertOptions} [options] - the options to be used
* @return {Promise.<Buffer, Error>} A <code>Promise</code> that is resolved with the converted output buffer.
* @public
*/
async convert(input, options) {
const converter = this.createConverter();
const converter = this.createConverter(pick(options, 'puppeteer'));
let output;

try {
output = await converter.convert(input, options);
output = await converter.convert(input, omit(options, 'puppeteer'));
} finally {
await converter.destroy();
}
Expand All @@ -101,16 +104,16 @@ class API {
* writing the output file.
*
* @param {string} inputFilePath - the path of the SVG file to be converted to another file format
* @param {Converter~ConvertFileOptions} [options] - the options to be used
* @param {API~ConvertFileOptions} [options] - the options to be used
* @return {Promise.<string, Error>} A <code>Promise</code> that is resolved with the output file path.
* @public
*/
async convertFile(inputFilePath, options) {
const converter = this.createConverter();
const converter = this.createConverter(pick(options, 'puppeteer'));
let outputFilePath;

try {
outputFilePath = await converter.convertFile(inputFilePath, options);
outputFilePath = await converter.convertFile(inputFilePath, omit(options, 'puppeteer'));
} finally {
await converter.destroy();
}
Expand All @@ -119,7 +122,7 @@ class API {
}

/**
* Creates an instance of {@link Converter}.
* Creates an instance of {@link Converter} using the <code>options</code> provided.
*
* It is important to note that, after the first time either {@link Converter#convert} or
* {@link Converter#convertFile} are called, a headless Chromium instance will remain open until
Expand All @@ -130,11 +133,12 @@ class API {
* files in another format and then destroy it afterwards. It's not recommended to keep an instance around for too
* long, as it will use up resources.
*
* @param {API~CreateConverterOptions} [options] - the options to be used
* @return {Converter} A newly created {@link Converter} instance.
* @public
*/
createConverter() {
return new Converter(this.provider);
createConverter(options) {
return new Converter(this.provider, options);
}

/**
Expand All @@ -160,3 +164,27 @@ class API {
}

module.exports = API;

/**
* The options that can be passed to {@link API#convertFile}.
*
* @typedef {Converter~ConvertFileOptions} API~ConvertFileOptions
* @property {Object} [puppeteer] - The options that are to be passed directly to <code>puppeteer.launch</code> when
* creating the <code>Browser</code> instance.
*/

/**
* The options that can be passed to {@link API#convert}.
*
* @typedef {Converter~ConvertOptions} API~ConvertOptions
* @property {Object} [puppeteer] - The options that are to be passed directly to <code>puppeteer.launch</code> when
* creating the <code>Browser</code> instance.
*/

/**
* The options that can be passed to {@link API#createConverter}.
*
* @typedef {Converter~Options} API~CreateConverterOptions
* @property {Object} [puppeteer] - The options that are to be passed directly to <code>puppeteer.launch</code> when
* creating the <code>Browser</code> instance.
*/
2 changes: 1 addition & 1 deletion packages/convert-svg-core/src/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CLI {
*/
async parse(args = []) {
const command = this[_command].parse(args);
const converter = new Converter();
const converter = new Converter(this[_provider]);
const options = this[_parseOptions]();

try {
Expand Down
18 changes: 15 additions & 3 deletions packages/convert-svg-core/src/Converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const _destroyed = Symbol('destroyed');
const _getDimensions = Symbol('getDimensions');
const _getPage = Symbol('getPage');
const _getTempFile = Symbol('getTempFile');
const _options = Symbol('options');
const _page = Symbol('page');
const _parseOptions = Symbol('parseOptions');
const _provider = Symbol('provider');
Expand Down Expand Up @@ -71,13 +72,16 @@ const _validate = Symbol('validate');
class Converter {

/**
* Creates an instance of {@link Converter} using the specified <code>provider</code>.
* Creates an instance of {@link Converter} using the specified <code>provider</code> and the <code>options</code>
* provided.
*
* @param {Provider} provider - the {@link Provider} to be used
* @param {Converter~Options} [options] - the options to be used
* @public
*/
constructor(provider) {
constructor(provider, options) {
this[_provider] = provider;
this[_options] = Object.assign({}, options);
this[_destroyed] = false;
}

Expand Down Expand Up @@ -266,7 +270,7 @@ html { background-color: ${provider.getBackgroundColor(options)}; }

async [_getPage](html) {
if (!this[_browser]) {
this[_browser] = await puppeteer.launch();
this[_browser] = await puppeteer.launch(this[_options].puppeteer);
this[_page] = await this[_browser].newPage();
}

Expand Down Expand Up @@ -417,3 +421,11 @@ module.exports = Converter;
* @property {number|string} [width] - The width of the output to be generated. If omitted, an attempt will be made to
* derive the width from the SVG input.
*/

/**
* The options that can be passed to {@link Converter}.
*
* @typedef {Object} Converter~Options
* @property {Object} [puppeteer] - The options that are to be passed directly to <code>puppeteer.launch</code> when
* creating the <code>Browser</code> instance.
*/
4 changes: 2 additions & 2 deletions packages/convert-svg-test-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-svg-test-helper",
"version": "0.3.0",
"version": "0.3.2",
"description": "Helper for testing convert-svg-core implementations",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
Expand Down Expand Up @@ -33,7 +33,7 @@
"lodash.clonedeep": "^4.5.0",
"mocha": "^4.0.1",
"rimraf": "^2.6.2",
"sinon": "^4.0.2"
"sinon": "^4.1.2"
},
"main": "src/index.js",
"engines": {
Expand Down
14 changes: 12 additions & 2 deletions packages/convert-svg-to-jpeg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ element or no `width` and/or `height` options were provided and this information
| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. |
| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. |
| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. |
| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
| `quality` | Number | `100` | Quality of the output to be generated. |
| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). |
| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. |

The `puppeteer` option is not available when calling this method on a `Converter` instance created using
`createConverter`.

#### Example

``` javascript
Expand Down Expand Up @@ -144,16 +148,22 @@ const { convertFile} = require('convert-svg-to-jpeg');
})();
```

### `createConverter()`
### `createConverter([options])`

Creates an instance of `Converter`.
Creates an instance of `Converter` using the `options` provided.

It is important to note that, after the first time either `Converter#convert` or `Converter#convertFile` are called, a
headless Chromium instance will remain open until `Converter#destroy` is called. This is done automatically when using
the `API` convert methods, however, when using `Converter` directly, it is the responsibility of the caller. Due to the
fact that creating browser instances is expensive, this level of control allows callers to reuse a browser for multiple
conversions. It's not recommended to keep an instance around for too long, as it will use up resources.

#### Options

| Option | Type | Default | Description |
| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- |
| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |

#### Example

``` javascript
Expand Down
6 changes: 3 additions & 3 deletions packages/convert-svg-to-jpeg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-svg-to-jpeg",
"version": "0.3.1",
"version": "0.3.2",
"description": "Converts SVG to JPEG using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
Expand All @@ -26,11 +26,11 @@
"url": "https://github.com/NotNinja/convert-svg.git"
},
"dependencies": {
"convert-svg-core": "^0.3.1"
"convert-svg-core": "^0.3.2"
},
"devDependencies": {
"chai": "^4.1.2",
"convert-svg-test-helper": "^0.3.0",
"convert-svg-test-helper": "^0.3.2",
"mocha": "^4.0.1"
},
"bin": {
Expand Down
Binary file modified packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions packages/convert-svg-to-png/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ element or no `width` and/or `height` options were provided and this information
| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. |
| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. |
| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. |
| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). |
| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. |

The `puppeteer` option is not available when calling this method on a `Converter` instance created using
`createConverter`.

#### Example

``` javascript
Expand Down Expand Up @@ -142,16 +146,22 @@ const { convertFile} = require('convert-svg-to-png');
})();
```

### `createConverter()`
### `createConverter([options])`

Creates an instance of `Converter`.
Creates an instance of `Converter` using the `options` provided.

It is important to note that, after the first time either `Converter#convert` or `Converter#convertFile` are called, a
headless Chromium instance will remain open until `Converter#destroy` is called. This is done automatically when using
the `API` convert methods, however, when using `Converter` directly, it is the responsibility of the caller. Due to the
fact that creating browser instances is expensive, this level of control allows callers to reuse a browser for multiple
conversions. It's not recommended to keep an instance around for too long, as it will use up resources.

#### Options

| Option | Type | Default | Description |
| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- |
| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |

#### Example

``` javascript
Expand Down
6 changes: 3 additions & 3 deletions packages/convert-svg-to-png/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "convert-svg-to-png",
"version": "0.3.1",
"version": "0.3.2",
"description": "Converts SVG to PNG using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
Expand All @@ -25,11 +25,11 @@
"url": "https://github.com/NotNinja/convert-svg.git"
},
"dependencies": {
"convert-svg-core": "^0.3.1"
"convert-svg-core": "^0.3.2"
},
"devDependencies": {
"chai": "^4.1.2",
"convert-svg-test-helper": "^0.3.0",
"convert-svg-test-helper": "^0.3.2",
"mocha": "^4.0.1"
},
"bin": {
Expand Down
Binary file modified packages/convert-svg-to-png/test/fixtures/expected/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/convert-svg-to-png/test/fixtures/expected/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/convert-svg-to-png/test/fixtures/expected/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c1cd433

Please sign in to comment.