Giter Site home page Giter Site logo

paulmelnikow / chainsmoker Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 2.29 MB

Elegant, generically typed, boolean micromatch for lists of file paths

License: MIT License

TypeScript 100.00%
minimatch micromatch path-matching filematch keyed-paths typescript

chainsmoker's Introduction

chainsmoker

version license types build code style

Elegant, generically typed, boolean micromatch for lists of file paths in TypeScript.

  • Works with CommonJS and ES Modules, too.
  • Safer and more concise than using .filter() and .length.
  • Designed for concise syntax in dangerfiles but not tied to them in any way.

I'm pleased to say as of Danger.js 7.1, this helper is vendored into Danger and accessible as danger.fileMatch.

Usage

const { danger, fail, message, warn } = require('danger')
const chainsmoker = require('chainsmoker')

// In this example, these are all arrays of relative paths.
const fileMatch = chainsmoker({
  created: danger.git.created_files,
  modified: danger.git.modified_files,
  updated: danger.git.modified_files.concat(danger.git.created_files),
  deleted: danger.git.deleted_files,
})

const documentation = fileMatch(
  '**/*.md',
  'lib/all-badge-examples.js',
  'frontend/components/usage.js'
)
const packageJson = fileMatch('package.json')
const packageLock = fileMatch('package-lock.json')
const helpers = fileMatch('lib/**/*.js', '!**.spec.js')
const helperTests = fileMatch('lib/**/*.spec.js')

// This is `true` whenever there are matches in the corresponding path array.
if (documentation.updated) {
  message('We :heart: our [documentarians](http://www.writethedocs.org/)!')
}

if (packageJson.modified && !packageLock.modified) {
  warn('This PR modified package.json, but not package-lock.json')
}

if (helpers.created && !helperTests.created) {
  warn('This PR added helper modules in lib/ but not accompanying tests.')
} else if (helpers.updated && !helperTests.updated) {
  warn('This PR modified helper modules in lib/ but not accompanying tests.')
}

fileMatch.getKeyedPatterns()

Return an object containing arrays of matched files instead of the usual boolean values.

Installation

Requires Node 8+.

npm install --save-dev chainsmoker

Contribute

Pull requests welcome!

Support

If you are having issues, please let me know.

The name 🚬

The name was inspired by the idea of a chainable file-set object using minimatch. It's also for Danger… maybe that was part of the inspiration.

I ended up with something simpler that doesn't rely on chaining, though I kept the name.

Acknowledgements

Thanks to @orta for reviewing this and shipping it with Danger.

License

The project is licensed under the MIT license.

chainsmoker's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar paulmelnikow avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.