CLI: Execute command only on changed files
See original GitHub issueI use npm tasks as a build tool, I have these two tasks:
"scripts": {
"build:js": "babel -d lib/ src/",
"watch:js": "watch 'npm run build:js' src/"
}
Is there a way, using CLI, to execute babel
only on a changed file? Something like:
"scripts": {
"build:js": "babel -d lib/$CHANGED_FILE src/$CHANGED_FILE",
"watch:js": "watch --only-changed 'npm run build:js' src/"
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:7
Top Results From Across the Web
linux - How to execute a command whenever a file changes?
I want something very simple, something I will leave running on a terminal and close it whenever I'm finished working with that file....
Read more >git - Execute command on every changed file - Stack Overflow
I want to execute command on files reports.coffee and tools.coffee . I don't want to use find because files can change in different...
Read more >How to Execute Command When File Changes in Linux?
Run command when any file in lib or src changes. “-w” option watches a specific file or directory in the system.
Read more >Execute a Command Whenever File or Directory Changes
if multiple changes happen during the sleep, the algorithm will execute the command only once; CTRL+C should terminate the script at any time, ......
Read more >Bash script to monitor file change and execute command
Linux provides a nice interface for monitoring all file system events like creating, modifying, removing files. The interface is inotify ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@elado as far as I know there is no convenient way. I’ve been struggling with this myself. But a lot of packages provide a watch themselves, babel is one of them:
Another option is to not use the CLI and write out the watchTree code by hand in a file and run this as part of your build script.
Yet another option (this is the one I use) is to use the onchange package, it does not feel efficient, but it works…
The
{{changed}}
is the file path of the file changed. I pass this into another script, but that might be just a bit redundant.PS, does not work with newly added files.
Hope it helps.
@elado Thanks for the answer. I try to use gulp, but it’s been kinda buggy - https://gist.github.com/TomasVotruba/dba01f73c2a502bbc4d693eeedc26a3a Almost there 😃