@react-vector-graphics/core
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,1 +1,2 @@ | ||
export { getLogger } from './logging'; | ||
export { run as default } from './main'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var logging_1 = require("./logging"); | ||
exports.getLogger = logging_1.getLogger; | ||
var main_1 = require("./main"); | ||
exports.default = main_1.run; |
@@ -1,4 +0,5 @@ | ||
import { Configuration } from '@react-vector-graphics/types'; | ||
export declare const run: ({ config, }: { | ||
import { Configuration, Logger } from '@react-vector-graphics/types'; | ||
export declare const run: ({ config, logger, }: { | ||
config: Configuration; | ||
logger?: Logger | undefined; | ||
}) => Promise<void>; |
@@ -14,2 +14,3 @@ "use strict"; | ||
const plugins_1 = require("./plugins"); | ||
const logging_1 = require("./logging"); | ||
const normalizePluginParams = (codeOrParams, prevParams) => { | ||
@@ -21,5 +22,7 @@ if (typeof codeOrParams === 'string') { | ||
}; | ||
exports.run = ({ config, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.run = ({ config, logger = logging_1.getLogger(), }) => __awaiter(void 0, void 0, void 0, function* () { | ||
logger.info('options:', config.options); | ||
const pluginArgs = [{}]; | ||
for (const plugin of plugins_1.getPlugins(config)) { | ||
logger.info('plugin:', plugin); | ||
const [pluginFn, pluginConfig] = yield Promise.all([ | ||
@@ -30,3 +33,3 @@ plugins_1.resolvePlugin(plugin), | ||
const results = yield Promise.all(pluginArgs.splice(0).map((args) => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield pluginFn(args.code, pluginConfig, args.state, console); | ||
const result = yield pluginFn(args.code, pluginConfig, args.state, logger); | ||
return (Array.isArray(result) ? result : [result]) | ||
@@ -33,0 +36,0 @@ .filter(Boolean) |
{ | ||
"name": "@react-vector-graphics/core", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Core library of react-vector-graphics", | ||
@@ -32,4 +32,3 @@ "author": "Top Hat <opensource@tophat.com>", | ||
"@svgr/core": "^5.2.0" | ||
}, | ||
"gitHead": "c8b2d96b50fe0688ab52b1c2df49c32e2dc823b9" | ||
} | ||
} |
# `@react-vector-graphics/core` | ||
This config files for this package should be backwards compatible with `@svgr/svgr` | ||
## Usage | ||
```js | ||
const rgvCore = require("@react-vector-graphics/core").default; | ||
const myPlugin = require("./myPlugin"); | ||
const config = { | ||
plugins: [ | ||
"@react-vector-graphics/plugin-assets", | ||
myPlugin, | ||
"@svgr/plugin-svgo" | ||
], | ||
options: { | ||
"assets/globPattern": "./assets/*.svg" | ||
}, | ||
svgoConfig: { | ||
multipass: true | ||
} | ||
}; | ||
rvgCore({ config, logger: console }); | ||
``` | ||
### Configuration | ||
This is an super set of the [`svgr` configuration](https://react-svgr.com/docs/configuration-files/). | ||
See `@react-vector-graphics/types` for definitions. | ||
#### `plugins` | ||
The plugins that will be run in order. These can be module names as strings which will then imported to get the underlying function or functions that will be called directly with the options and other parameters | ||
#### `options` | ||
The options that the plugins will be initiated with. It is a good idea to namespace the path in the `config.options` to prevent collisions between independent plugins. | ||
```json | ||
{ | ||
"plugins": ["myPlugin", "other-plugin"], | ||
"options": { | ||
"myPlugin/shrink": false, | ||
"otherPlugin/shrink": true | ||
} | ||
} | ||
``` | ||
### Plugins | ||
Plugins are functions that will be called with the following parameters in order. | ||
#### `code` | ||
A string representing the svg file that has been read and modified so far | ||
#### `config` | ||
The initial configuration object, see [config](#configuration). | ||
#### `state` | ||
The current state of execution, can be modified by plugins to pass information to other plugins further down in the execution chain. The namespacing recommendation as the [`options`](#options) applies. | ||
#### `logger` | ||
This is an optional argument that allows the plugin to log output with custom levels. | ||
_NOTE_: this is not guaranteed to exist and defaults to `console`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12
109
73
7849
1