phuedx / pinc

A network connection conditioner for a handful of low-end devices in my home office
MIT License
16 stars 3 forks source link

Share flow ids between the node process and the setup script #2

Closed joakin closed 8 years ago

joakin commented 8 years ago

From irc review:

I think it is worth sharing the profile ids between the node process and the bash script somehow https://github.com/phuedx/micro-device-lab/blob/dev/src/profiles.js#L8-L13 so that you don't have to implicitly keep them in sync the ids with the setup script ones.

I think the easiest way would be a script that exports the profiles and ids as environment variables, such script would get called at the beginning of script/setup and in package.json when npm starting:

  "scripts": {
    "start": "./scripts/env && node index.js"
  }
 cd "$(dirname "$0")/.."

+script/env
 script/bootstrap

Not exactly sure about that script/env would set. I know there's bash dictionaries but I'm not sure how those would be read in node with process.env.

Is there an easy way to load a JSON file into a bash script?

Any opinions?

joakin commented 8 years ago

I've found https://github.com/dominictarr/JSON.sh, we could have a json file with the profiles and profile data and read it in bash and do stuff with it.

Another option is converting script/setup to a node script with shebang, and then server and setup script can share a json file for example.

phuedx commented 8 years ago

Another option is converting script/setup to a node script with shebang, and then server and setup script can share a json file for example.

That is my preference. Right now, my priority is a functioning UI, with developer happiness (including documentation) and flexibility a close second and third respectively.

joakin commented 8 years ago

Open to PR about this?

On Fri, Jan 22, 2016, 13:10 Sam Smith notifications@github.com wrote:

Another option is converting script/setup to a node script with shebang, and then server and setup script can share a json file for example.

That is my preference. Right now, my priority is a functioning UI, with developer happiness (including documentation) and flexibility a close second and third respectively.

— Reply to this email directly or view it on GitHub https://github.com/phuedx/micro-device-lab/issues/2#issuecomment-173901325 .

phuedx commented 8 years ago

Open to PR about this?

Thanks for the offer but I'm hoping to take cues (and take the time to learn) from joakin/stack – React, webpack, and material-ui.

joakin commented 8 years ago

@phuedx Sure! I think I wasn't clear enough, I was asking if you'd be interested in a PR about sharing profiles and IDs in setup and server.

phuedx commented 8 years ago

1470435 encodes the network throttling profiles in profiles.json. Converting script/setup to a Node.js script that reads from that file would be neato!

phuedx commented 8 years ago

@joakin I didn't know about child_process.execSync Iuntil 24 hours ago.