{"id":18256176,"url":"https://github.com/serapath/scenario-simulator","last_synced_at":"2025-04-08T22:27:02.672Z","repository":{"id":66204132,"uuid":"330066292","full_name":"serapath/scenario-simulator","owner":"serapath","description":"start multiple `\u003cappfile\u003e.js` processes based on a `\u003cscenario\u003e.json` file","archived":false,"fork":false,"pushed_at":"2021-08-15T21:57:45.000Z","size":25,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T17:48:33.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/scenario-simulator","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serapath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-16T02:17:45.000Z","updated_at":"2021-08-15T21:57:48.000Z","dependencies_parsed_at":"2023-06-10T15:30:32.175Z","dependency_job_id":null,"html_url":"https://github.com/serapath/scenario-simulator","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"bfc676dd2db2fd702b19e1101a6e8b885bbe8443"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fscenario-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fscenario-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fscenario-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serapath%2Fscenario-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serapath","download_url":"https://codeload.github.com/serapath/scenario-simulator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247937267,"owners_count":21021221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T10:20:21.962Z","updated_at":"2025-04-08T22:27:02.655Z","avatar_url":"https://github.com/serapath.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scenario-simulator\nstart multiple `\u003ccmdfile\u003e.js` processes based on a `\u003cscenario\u003e.json` file\n\n# define\n`npm install scenario-simulator`\n\nfor example make a new project folder `\u003cproject\u003e`\n```js\n// \u003cproject\u003e/package.json\n{\n  \"private\": true,\n  \"name\": \"example\",\n  \"version\": \"0.0.0\",\n  \"description\": \"scenario-simulator demo\",\n  \"dependencies\": {\n    \"scenario-simulator\": \"^0.0.0\"\n  },\n  \"scripts\": {\n    \"start\": \"simulate\"\n  }\n}\n\n```\n\nall file paths further below are prefixed with:\n* `\u003cproject\u003e/demo` (where `./demo` is the default)\n\nThis can be changed to something else (e.g. `./examples`),\nby setting an environment variable explicitly:\n```js\n{\n  \"scripts\": {\n    \"start\": \"SIM=examples simulate\"\n  }\n}\n```\n\nInstead of the default (`./demo`) we are using `./examples`\n\n---\n\nwith `\u003cproject\u003e/demo/node_modules/_start.js`\n```js\nconst firestarter = 5\nmodule.exports = function start (index) {\n  if (index === firestarter) { // e.g. to choose init logic\n    console.log(`\n      i am the fire starter \u003cnode ${firestarter}\u003e\n      edit logic to kick off the scenario if you want :-)`)\n  }\n}\n```\n\nwith `\u003cproject\u003e/demo/scenario/cmd/app1.js`\n\n```js\nconst start = require('_start')\nconst simulate = require('scenario-simulator')\nconst { pid, list } = simulate(chunk =\u003e {\n  console.log({ message: chunk.toString() }) // e.g. { message: 'asdf' }\n})\nconsole.log({ pid, list })\n// e.g.\n// { pid: 'app1:34955', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\nstart(list.indexOf(pid))\n```\n\nand `\u003cproject\u003e/demo/scenario/cmd/app2.js`\n```js\nconst start = require('_start')\nconst simulate = require('scenario-simulator')\nconst { pid, list } = simulate(chunk =\u003e console.log('hello'))\nstart(list.indexOf(pid))\n```\nand a first scenario file\n\n```js\n// \u003cproject\u003e/scenario/1.json\n{\n  \"app1.js\": 5, // amount of instances of `app1.js`\n  \"app2.js\": 3, // amount of instances of `app2.js`\n  // ...\n}\n```\n\n# use\n**usage** `simulate \u003cscenario-name\u003e [\u003cport\u003e]`\n\nThe following describes how to start the simulator, which launches multiple process instances according to the scenario file.\nIt then shows how to send messages to individual processes, which they can listen and react to.\nThe purpose of sending messages is to simulate local user input in one particular process.\n\n```bash\nnpm start\n# [ROOT] ERROR:\n#  missing `scenario_name` argument\nnpm start foo\n# [ROOT] ERROR:\n#  Error: Cannot find module '\u003cproject\u003e/scenario/foo.json'\n# Require stack:\n# - \u003cproject\u003e/node_modules/scenario-simulator/src/scenario-simulator.js\n# ...\nnpm start 1\n# [ROOT] COMMANDS:\n#   \"/help\": {\n#     \"args\": \"\",\n#     \"demo\": \"/help\",\n#     \"info\": \"(to see this message)\"\n#   },\n#   \"/\u003cnode\u003e \u003ctext message\u003e\": {\n#     \"args\": {\n#       \"\u003cnode\u003e\": {\n#         \"0\": \"app1:36659\",\n#         \"1\": \"app1:36660\",\n#         \"2\": \"app1:36661\",\n#         \"3\": \"app1:36662\",\n#         \"4\": \"app1:36663\",\n#         \"5\": \"app2:36664\",\n#         \"6\": \"app2:36665\",\n#         \"7\": \"app2:36666\"\n#       },\n#       \"\u003ctext message\u003e\": \"string\"\n#     },\n#     \"demo\": \"/0 hello world\",\n#     \"info\": \"send \u003ctext message\u003e to \u003cnode\u003e with a process name\"\n#   }\n\n# [ROOT] ----------------------------------------\n# [app1:34955] { pid: 'app1:34955', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\n# [app1:34957] { pid: 'app1:34957', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\n# [app1:34956] { pid: 'app1:34956', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\n# [app1:34958] { pid: 'app1:34958', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\n# [app1:34959] { pid: 'app1:34959', list: ['app1:36659','app1:36660','app1:36661','app1:36662','app1:36663','app2:36664','app2:36665','app2:36666'] }\n\n\u003cctrl-c\u003e\n\nnpm start 1 foo\n# [ROOT] ERROR:\n#  optional `port` argument must be a number\n\nnpm start 1 999111\n# [ROOT] ERROR:\n#  try: 0 \u003c port \u003c 65534\n\nnpm start 1 9000\n# [ROOT] COMMANDS:\n#   \"/help\": {\n#     \"args\": \"\",\n#     \"demo\": \"/help\",\n#     \"info\": \"(to see this message)\"\n#   },\n#   \"/\u003cnode\u003e \u003ctext message\u003e\": {\n#     \"args\": {\n#       \"\u003cnode\u003e\": {\n#         \"0\": \"app1:9000\",\n#         \"1\": \"app1:9001\",\n#         \"2\": \"app1:9002\",\n#         \"3\": \"app1:9003\",\n#         \"4\": \"app1:9004\",\n#         \"5\": \"app2:9005\",\n#         \"6\": \"app2:9006\",\n#         \"7\": \"app2:9007\"\n#       },\n#       \"\u003ctext message\u003e\": \"string\"\n#     },\n#     \"demo\": \"/0 hello world\",\n#     \"info\": \"send \u003ctext message\u003e to \u003cnode\u003e with a process name\"\n#   }\n\n# [ROOT] ----------------------------------------\n# [app1:9000] { pid: 'app1:9000', list: ['app1:9000','app1:9001','app1:9002','app1:9003','app1:9004','app2:9005','app2:9006','app2:9007'] }\n# [app1:9002] { pid: 'app1:9002', list: ['app1:9000','app1:9001','app1:9002','app1:9003','app1:9004','app2:9005','app2:9006','app2:9007'] }\n# [app1:9001] { pid: 'app1:9001', list: ['app1:9000','app1:9001','app1:9002','app1:9003','app1:9004','app2:9005','app2:9006','app2:9007'] }\n# [app1:9003] { pid: 'app1:9003', list: ['app1:9000','app1:9001','app1:9002','app1:9003','app1:9004','app2:9005','app2:9006','app2:9007'] }\n# [app1:9004] { pid: 'app1:9004', list: ['app1:9000','app1:9001','app1:9002','app1:9003','app1:9004','app2:9005','app2:9006','app2:9007'] }\n# [app2:45450] i am the fire starter \u003cnode 5\u003e, edit logic to kick off the scenario if you want :-)\n\n\nasdf\n# [ROOT] type: `/help`\n\n/help\n# [ROOT] COMMANDS:\n#   \"/help\": {\n#     \"args\": \"\",\n#     \"demo\": \"/help\",\n#     \"info\": \"(to see this message)\"\n#   },\n#   \"/\u003cnode\u003e \u003ctext message\u003e\": {\n#     \"args\": {\n#       \"\u003cnode\u003e\": {\n#         \"0\": \"app1:9000\",\n#         \"1\": \"app1:9001\",\n#         \"2\": \"app1:9002\",\n#         \"3\": \"app1:9003\",\n#         \"4\": \"app1:9004\",\n#         \"5\": \"app2:9005\",\n#         \"6\": \"app2:9006\",\n#         \"7\": \"app2:9007\"\n#       },\n#       \"\u003ctext message\u003e\": \"string\"\n#     },\n#     \"demo\": \"/0 hello world\",\n#     \"info\": \"send \u003ctext message\u003e to \u003cnode\u003e with a process name\"\n#   }\n\n/10 asdf\n# [ROOT] not a valid \u003cnode\u003e number: /10\n\n/0 asdf\n# [app1:9000] { message: 'asdf' }\n\n\u003cctrl-c\u003e\n```\n\n# contribute\n```bash\ngit clone https://github.com/serapath/scenario-simulator.git\ncd scenario-simulator\nnpm install\nnpm link # adds itself as a global command for npm scripts\nnpm link scenario-simulator # installs itself as a local dependency to be requireable\nnpm start # follow README instructions above\n# edit `./app` and `./scenario` for better testing data\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserapath%2Fscenario-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserapath%2Fscenario-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserapath%2Fscenario-simulator/lists"}