I am trying to make Nodemon run two different commands depending on which file changed. I tried using nodemon.json and invoking it using nodemon nodemon.json (because it didn't seem to be getting picked up just by nodemon):
{
"watch": "nodemon.json,main.js,index.js",
"execMap": {
"main.js": "electron .",
"index.js": "echo todo",
"nodemon.json": "echo Nodemon config reloaded"
}
}
Nodemon doesn't pick up any changes with this setup. I think I might have a problem in the watch glob. When I remove it (so it watches everything I think by default), then file changes are getting picked up, but Nodemon only ever executes node index.js. I never speficied that anywhere so I assume that's the default and the execMap is not being honored? Is it only for extensions?
I am not sure how to craft a config which takes these two different paths. Is it even possible with Nodemon?
The execMap property seems to be intended to support non-default file extensions.
According to the docs
...you can define your own default executables using the execMap
property. This is particularly useful if you're working with a
language that isn't supported by default by nodemon
One thing you can do is run multiple nodemon processes, one for each file/directory, from a script, like:
nodemon -w "path1/" -x "<command 1>" &
nodemon -w "path2/" -x "<command 2>"
Related
I am working on a docker containerized c++ project that has defined shell scripts to setup the environment (using "source") for compiling and debugging. They have a lot of environment variables and could change at anytime so it would be hard to move them all into the launch.json file (and tedious to keep up with) so I need to call them before compiling or debugging.
The scripts only need to run once so if there was a way to run them after connection to the container that would be the best solution, however I cannot find anything like that.
I have tried to use the "preLaunchTask" in the launcher to run a task before debugging but it seems that the task's shell is different from the debug shell.
Is there anyway to handle this?
For the moment I am using a task to generate a .env file
printenv > ${workspaceFolder}/.preenv && . ${workspaceFolder}/setupEnv &&
printenv > ${workspaceFolder}/.postenv && grep -vFf
${workspaceFolder}/.preenv ${workspaceFolder}/.postenv >
${workspaceFolder}/.env
I have VSCode mount a directory as the container's homedir, and then put a .bash_profile file containing the necessary setups (or other suitable shell startup file) in that directory.
My /path/to/.devcontainer/devcontainer.json includes:
"mounts": [
"source=${localWorkspaceFolder}/.devcontainer/home,target=/home/username,type=bind,consistency=delegated"
],
"remoteUser": "username",
"userEnvProbe": "loginShell", // Ensures .bash_profile fires
Then my /path/to/.devcontainer/home/.bash_profile contains the necessary invocations to set my environment.
I'm working on a Yocto based system. My problem is that I can't start my programm written in C++ and the webserver (node.js) at the same time right after the boot of my device.
I already tried this in /etc/init.d:
#! /bin/bash
/home/ProjectFolder/myProject
cd /home/myapp && DEBUG=myapp:* npm start
exit 0
I changed the rights after creating the script by
chmod +x ./startProg.sh
After that I linked it by
update-rc.d startProg.sh defaults
After reboot the system only starts the C++-programm. I tried some other possibilities like seperating the two comands in different shell-scripts, but that didn't work out any better.
Is there any option I missed or did I make any mistake trying to put those two processes into the autostart?
This of course isn't a C++ or Node.js question. A shell script is a list of commands that are executed in order, unless specified otherwise. So your shell script runs your two programs in the order specified, first myProject and when that's done npm will be started.
This is the same as what would happen from the prompt and the solution is the same: /home/ProjectFolder/myProject &
This is script content, located in /etc/init.d/myserviced:
#!/lib/init/init-d-script
DAEMON="/usr/local/bin/myprogram.py"
NAME="myserviced"
DESC="The description of my service"
When I start the service (either by calling it directly or by calling sudo service myserviced start), I can see program myprogram.py run, but it did not return to command prompt.
I guess there must be something that I misunderstood, so what is it?
The system is Debian, running on a Raspberry Pi.
After more works, I finally solved this issue. There are 2 major reasons:
init-d-script actually calls start-stop-daemon, who don't work well with scripts specified via --exec option. When killing scripts, you should only specify --name option. However, as init-d-script always fill --exec option, it cannot be used with script daemons. I have to write the sysv script by myself.
start-stop-daemon won't magically daemonize the thing you provide. So the executable provided to start-stop-daemon should be daemonized itself, but not a regular program.
I've been using, in equal amounts, Fedora and Ubuntu for well over a decade now, and there's one minor but irritating difference I noticed from their installs of midnight commander. When you change dirs inside it using Fedora, then exit, it has done the chdir for you but in Ubuntu it keeps it at the place you started. Googling threw up a solution for older Ubuntus here: http://ptspts.blogspot.co.uk/2010/01/how-to-make-midnight-commander-exit-to.html but trying that fails on 16. When I say fails, I mean the commands are accepted without complaint but it doesn't change mc's behaviour in Ubuntu.
The other responses are fine, but I feel like they are unsatisfying, here is my solution, which I think is the simplest:
Put this line into your ~/.profile
alias mc='source /usr/lib/mc/mc-wrapper.sh'
Create an executable with the following content:
MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$"
/usr/bin/mc -P "$MC_PWD_FILE" "$#"
if test -r "$MC_PWD_FILE"; then
MC_PWD="`cat "$MC_PWD_FILE"`"
if test -n "$MC_PWD" && test -d "$MC_PWD"; then
cd "$MC_PWD"
fi
unset MC_PWD
fi
rm -f "$MC_PWD_FILE"
unset MC_PWD_FILE
Then define an alias pointing to that executable:
alias mc='. ~/.config/mc/exitcwd'
Don't forget to apply the alias:
source ~/.bashrc
Simple:
mcedit ~/.profile
Add this line at the end of file:
alias mc='source /usr/lib/mc/mc-wrapper.sh'
Type this command to execute changes
source ~/.profile
Then, to save both sides of mc windows, click at the top of MC
Options -> Panel options -> Auto save panels setup
Here, in the article Use Midnight Commander like a pro, explains how to do it.
Basically, you have to create an alias for mc-wrapper.sh.
While it's not exactly an answer to your question: just use ctrl+o to drop to the shell. It doesn't really quit mc, but that has the benefit that you can just hit ctrl+o again to go back where you were in mc.
For Ubuntu put this to .bashrc:
alias mc='. /usr/lib/mc/mc-wrapper.sh'
then:
source ~/.bashrc
(or relaunch the console)
I want to add that this only works by existing with F10. If you exit by typing exit the path will not be preserved.
When i tried to run following python code:
setlocale(locale.LC_ALL,"")
print getlocale()
The result is that it works fine if i run the script from Terminal.
But in eclipse/pydev with the same python compiler(python 2.7),it always return (none,none), any idea?
As you have already guessed from our conversation in the comments, this behavior is related to the environment. If you run Eclipse from the Terminal, you will get the same results you get when running Python directly from the Terminal.
So, your program is actually working fine. Depending on what you want to do, you don't need to worry about anything.
However, if you want to reconfigure your environment (system-wide or for all programs launched from the GUI, for example), you can do that in the appropriate files, using this answer as a guide.
For example, you may want to set the variables LANG and LC_ALL in one of those files, mimicking the configuration that is shown when you run the command locale from the Terminal. Assuming you want en_US with UTF-8, that added lines would look like:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8