@karnov/ifchanged
v1.0.9
Published
Only run provided command if a source has changed
Downloads
8
Readme
ifchanged
Conditionally run a command if watched files have changed, for instance:
ifchanged yarn buildRunning the above multiple times will only result in executing 'yarn build' if a source file has changed since last run, otherwise it is a noop.
To specify which files to watch:
ifchanged --watch="src/**/*.js"If multiple steps depend on whether the files have changed:
ifchanged --step=build yarn build
ifchanged --step=build:docs yarn build:docsTo provide flags to the command, use '--' to separate them from flags to ifchanged:
ifchanged --step=build -- yarn run build --step=docs
Options:
--help Show help [boolean]
--version Show version number [boolean]
--watch, -w Pattern to watch for changes using glob syntax.
[default: ["src/**/*.js","tests/**/*.js","node_modules/**/package.json"]]
--rootDir, -r Root directory to watch.
[default: "/home/mike/Private/ifchanged"]
--cache, -c Path to save internal ifchanged data to.
[default: "/home/mike/Private/ifchanged/.ifchanged_cache"]
--step, -s Step name. Makes it possible to run several steps when the
watched files have changed. [string]
--config Path to JSON config file
[default: "/home/mike/Private/ifchanged/.ifchanged.json"]CAVEATS
Watching different file sets
Providing different '--watch' settings between runs won't work as expected unless a different '--cache' is provided as well:
ifchanged --watch=src/*.js yarn build
ifchanged --watch=docs/*.mdx yarn build:docsThe above will not work since the same cache is being used to watch two different sets of files. To get the expected result, provide a different cache to at least one of the calls:
ifchanged --watch=src/*.js yarn build
ifchanged --watch=docs/*.mdx --cache=.ifchanged-docs yarn build:docsSub-second changes
To optimize for performance, ifchanged only uses file modification times and sizes to check if a new run is required. Since mtime only has a resolution of seconds, ifchange can't detect changes where it is being run with a second or less between each run.
Developing
Download and run tests
git clone [email protected]:karnov/ifchanged
cd ifchanged
yarn
yarn testPublishing
yarn publishRemember to log in first. If publishing fails, make sure that you have access to the karnov organization at npmjs.com.
Reporting bugs
https://github.com/karnov/ifchanged/issues
Author
Michael Zedeler [email protected].
Copyright and license
Copyright Karnov Group A/S 2018, licensed under MIT license.
