Read the statement by Michael Teeuw here.
Use .JSON as a module config value?
-
@drippyer I don’t know about putting the code IN config.js,but you can add another step to the script that starts mm and create the updated config.js
installers/mm.sh is the normal start script
it does
#!/bin/bash # This file is still here to keep PM2 working on older installations. cd ~/MagicMirror # add your script here node xxx.js DISPLAY=:0 npm start
make your original config.js config.model
and merge your user info to get config.js -
@sdetweil Thanks for the info!
Ok, I see. That could definitely work.
I went ahead and scrapped the code from above and converted it to a bash script that is executed before the
cd ./MagicMirror
(pretty sure I’ve had this setup running since beforeinstallers/mm.sh
was actually provided lol). I admit the bash script is suuuper rough and was written with my symlinked config files in mind but it gets the job done!- makes an intermediate copy of
config.js
- grabs the content of the of the json
- declares variable containing config variable to be replaced
- prepends the variable string to the json content
- uses perl/regex to search for the variable in the intermediate file and replace it
- makes a backup of
config.js
just in case - moves intermediate copy to working version
#!/bin/bash cp /home/pi/mmConfig/config.js /home/pi/mmConfig/config.inter mapfile < /home/pi/mmConfig/user_list.json variableName="userNameFilter" replace="${variableName}: ${MAPFILE[@]}" perl -0777 -pi -e "s/${variableName}: {((.|\n)*?)}/${replace}/g" /home/pi/mmConfig/config.inter mv --backup=numbered /home/pi/mmConfig/config.js /home/pi/mmConfig/config_backups mv /home/pi/mmConfig/config.inter /home/pi/mmConfig/config.js
And that successfully allows for the data to be read in! Thank you!
Sadly, it did break
pm2
watching config (which kinda makes sense to avoid a loop) and if I’m modifying the config I’m already in the command line and apm2 restart mm
isn’t too bad I suppose ¯\_(ツ)_/¯Edit: I’m realizing I should add a check to make sure it doesn’t perform either
mv
if the file is the same. New to-do lol! - makes an intermediate copy of
-
@drippyer you could change the pm2 setup to not watch config.js
… -
@sdetweil I might have been a bit unclear haha. The break was pm2 no longer watching config.js, not a loop. My bad about that misunderstanding.
-
@drippyer got it…