Code Monkey home page Code Monkey logo

gulp-svg-fill's Introduction

gulp-svg-fill


⚠️ No longer supported

This library is no longer being maintained and the git repo has been archived.


Illustration of an SVG shape being filled with a color

Gulp plugin that takes SVG files and fills their shapes with a single colour using svg-fill. It can also be configured with multiple colours, in which case it will output as many SVG files as there are colours, per single input SVG file.

Usage

Requirements

  • Node.js >= 14

Installation

npm install --save-dev gulp-svg-fill

Basic usage

In your gulpfile.js (using Gulp v4):

const gulp = require('gulp');
const svgFill = require('gulp-svg-fill');

function colorSvgs() {
  return gulp.src('src/**/*.svg')
    .pipe(svgFill({
      colors: {
        'Red': '#FF0000',
        'Green': '#00FF00',
        'Blue': '#0000FF'
      }
    }))
    .pipe(gulp.dest('dist/'));
}

module.exports = {
  default: colorSvgs
};

The above example will create 3 new SVG files - one filled in red, one in greeen and the other in blue - for each source SVG file found in the source directory.

For example, if the src/ folder contained logo.svg, then after running Gulp, the dist/ folder would contain:

  • logo_red.svg
  • logo_green.svg
  • logo_blue.svg

Options

gulp-svg-fill expects an options object to be passed in. It supports the following properties:

  • colors (mandatory): An object mapping color names to color values.
    • Must contain at least one color.
    • Values may be RGB hex strings or instances of Color (see color NPM package)
  • renameFn (optional): A function to generate per-color filenames.
    • Should have a signature of: (fileStem: string, colorName: string) => string
      • fileStem is the name part of the input SVG filepath - i.e. without the file extension. For example, if the full file path is path/to/fancy-logo.svg, then the file stem passed into the rename function will be fancy-logo.
      • colorName is the property name of a colour defined in colors. For instance, if your colors object looks like { 'Rebecca Purple': '#663399' }, then colorName would be Rebecca Purple.
    • If omittied, a default rename function is used which takes the original file stem and appends an underscore followed by the kebab-case version of the color name. E.g. if the input file is fancy-logo.svg, the output for the color Rebecca Purple would be fancy-logo_rebecca-purple.svg.

Development

Setup

Clone this repo and npm install its dependencies:

git clone [email protected]:c1rrus/gulp-svg-fill.git

cd svg-fill/

npm install

Building

npm run build

This will transpile the TypeScript source code (in the src/) directory and output the results to dist/.

For development convenience, you can alternatively watch the source files and automatically trigger rebuilds when they change:

npm run watch

Running tests

npm run test

We use Jest for the tests. Each module's unit tests is located alongside its [module name].ts file as [module name].test.ts.

Linting

To help keep code consistent and avoid common gotchas, we lint our code using typescript-eslint. To run it do:

npm run lint

Commit message formatting

All commit messages must follow the Conventional Commits standard as we use automated release tools that rely on this. Commit messages are linted to check this and your CI builds will fail if your messages don't conform.

To make composing suitable commit messages easier, this repo is Commitizen friendly. We strongly recommend using commitizen rather than using git directly. To use it, simply run:

npm run commit

...and follow the prompts in your terminal.

gulp-svg-fill's People

Contributors

c1rrus avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar

gulp-svg-fill's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://x-access-token:[secure]@github.com/c1rrus/gulp-svg-fill.git.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

An in-range update of @types/color is breaking the build 🚨

The devDependency @types/color was updated from 3.0.0 to 3.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/color is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Specifying multiple colors does not generate multiple files

gulp.task('svg', function() {
  return gulp.src(['src/images/*.svg'])
    .pipe(svg_fill({
      colors: {
        black: '#000000',
        white: '#ffffff',
        red: '#ff0000'
      }
    }))
    .pipe(gulp.dest('./extension/images'));
});

A couple of console.logs told me that currentFile.stem is undefined so the rename is likely failing.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/c1rrus/gulp-svg-fill.git.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.