question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CLI: Execute command only on changed files

See original GitHub issue

I 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:open
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Baudin999commented, Jan 28, 2016

@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:

"watch:js": "babel ./src/ --out-dir ./out/ --watch "

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…

onchange ./src/**/*.html -- bash ./scripts/training/temp.sh {{changed}}

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.

0reactions
TomasVotrubacommented, Feb 18, 2017

@elado Thanks for the answer. I try to use gulp, but it’s been kinda buggy - https://gist.github.com/TomasVotruba/dba01f73c2a502bbc4d693eeedc26a3a Almost there 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found