| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Run tasks based on git diff files
Having this directory tree with the following files changed:
├── app ├────── components ├ ├── index.js ├ ├── app.jsx └── __tests__ ├ ├── app.spec.jsx └── package.json
run-when will check glob rules against it and run tasks if any changes have been made.
import runWhen from 'run-when';
runWhen([
{
glob: ['app/components/index.js', 'app/__tests__/**'],
task(paths) {
console.log('This will be called!');
}
},
{
glob: ['!package.json'],
task(paths) {
return Promise.resolve('You can return a promise from your task');
}
},
{
// Optionally pass changed files
changedFiles: () => Promise.resolve(['app/index.js', 'app/components/header.jsx']),
glob: ['app/components/**'],
task(paths) {
console.log(paths === ['app/components/header.jsx']);
}
}
]);$ run-when '["app/components/**", "app/utils/**"]' 'echo running tests... && yarn test'
By default run-when will use git to know which files have been changed. You can change that passing an array of files to changedFiles.
The library uses multimatch for the globbing matching (sindresorhus 😻). Just a quick overview:
Various patterns and expected matches.
type Files = Array<string>;interface Rule {
glob: Array<string>,
task: (results: Files) => void,
changedFiles?: () => Promise<Files>
}type runWhen = (rules: Array<Rule>) => Promise;$ yarn add run-when -D
| Back | FazBrowse Home | New Git URL |