{"id":16070771,"url":"https://github.com/amoshydra/tasker-js-runner","last_synced_at":"2025-03-17T17:30:24.909Z","repository":{"id":29706710,"uuid":"122550114","full_name":"amoshydra/tasker-js-runner","owner":"amoshydra","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-03T22:41:19.000Z","size":2173,"stargazers_count":14,"open_issues_count":19,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-28T01:49:17.286Z","etag":null,"topics":["amoshydra-profile-category-reference","amoshydra-profile-category-tasker","javascript","pet-project","tasker"],"latest_commit_sha":null,"homepage":"","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/amoshydra.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}},"created_at":"2018-02-22T23:56:32.000Z","updated_at":"2025-01-04T14:08:52.000Z","dependencies_parsed_at":"2023-01-14T15:30:28.365Z","dependency_job_id":null,"html_url":"https://github.com/amoshydra/tasker-js-runner","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshydra%2Ftasker-js-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshydra%2Ftasker-js-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshydra%2Ftasker-js-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoshydra%2Ftasker-js-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amoshydra","download_url":"https://codeload.github.com/amoshydra/tasker-js-runner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243864808,"owners_count":20360357,"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":["amoshydra-profile-category-reference","amoshydra-profile-category-tasker","javascript","pet-project","tasker"],"created_at":"2024-10-09T07:07:06.192Z","updated_at":"2025-03-17T17:30:24.414Z","avatar_url":"https://github.com/amoshydra.png","language":"JavaScript","readme":"# Tasker JS Runner\n- Write Tasker task as Javascript module\n- Map profile name to module\n- Auto refresh script during development mode\n\n# Guide\n## Installation\nwith npm\n```\nnpm install tasker-js-runner --save\n```\n\nwith yarn\n```\nyarn add tasker-js-runner\n```\n### Usage\n\n#### Defining profile map `index.js`\n```javascript\nimport TaskerJs from 'tasker-js-runner';\n\n// Tasker Javascript modules\nimport notification from './modules/notification';\n\n// Construct Tasker JS and pass in mapping information as an Object\nnew TaskerJs({\n  // Profile name: module\n  'Notification:All': notification,\n});\n\n```\n\n#### Defining a module `modules/notification`\nA module should contain an `enter` and an `exit` function.  \nThe 2 functions will receive all the local variables from the profile's task\nvia `locals` and a reference Tasker's global object via `tasker`.\n\n```javascript\nexport default {\n  enter(locals, tasker) {\n    // Example: Accessing local variables %anapp and %antitle from AutoNotification\n    const content = locals.anapp + ' ' + locals.antitle;\n\n    // Tasker's function can be accessed via the `tasker` object.\n    tasker.setClip(content);\n\n    // If you wish, you can also omit `tasker` by calling Tasker's function directly.\n    // Behind the scene, `tasker` is mapped to the `window` object where the\n    // Tasker's function live.\n    flash('content');\n  },\n\n  exit(locals, tasker) {}\n};\n```\n\n#### Asynchronous Execution\n\nAll module functions are wrapped inside a Promise, which will gracefully exit at the end of execution.  \nTo ensure proper task exiting while running asynchronous code, always return a promise.\n```javascript\nexport default {\n  enter(locals, tasker) {\n\n    return new Promise((resolve, reject) =\u003e {\n      setTimeout(() =\u003e {\n        if (tasker.global('BLUE') === 'on') {\n          resolve();\n        } else {\n          reject();\n        }\n      }, 1000);\n    });\n\n  },\n  ...\n}\n```\n\nOtherwise, you can also permaturely terminte the script. This will immediately stop the script from executing.\n```javascript\nexport default {\n  enter(locals, tasker) {\n\n    setTimeout(() =\u003e {\n      tasker.exit()\n    }, 1000);\n\n  },\n  ...\n}\n```\n\n## Sample project\nhttps://github.com/amoshydra/tasker-js-runner-project\n\n## Setup on Tasker\n\n### Installing\n1. Import the 3 tasks from the [`tasker-imports` folder](https://github.com/amoshydra/tasker-js-runner/tree/master/tasker-imports) into Tasker\n    - `TJS_Development_Toggle.tsk.xml`\n    - `TJS_RunScript.tsk.xml`\n    - `TJS_UpdateScript.tsk.xml`\n2. Run [TJS_Development_Toggle] inside Tasker to set up the required global variables.  \n  When [TJS_Development_Toggle] is run for the first time, it will set up all the necessary Global variables for Tasker-JS to run.\n    - `%TJS_ENV` - Control the environment Tasker-JS-Runner to run `development`/`production`.\n    - `%TJS_DEV_REMOTE` - The remote address where the your project script (a seperate project that make use of this library) will be downloaded. You will need to change the value of this variable in this task to match the IP of your project.\n    - `%TJS_LOCAL_PATH` - The location where the project script will be saved (default to `Documents/tasker-js-runner.js`)\n\n### Using\n1. Create a Tasker named profile (i.e. `Notification:All`) and select `TJS:RunScript` as its task.\n2. Tasker-JS-Runner will detect the profile name and execute the Javascipt module that's mapped into `Notification:All` in the Profile Map (see example from [above](#defining-profile-map-indexjs)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoshydra%2Ftasker-js-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famoshydra%2Ftasker-js-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoshydra%2Ftasker-js-runner/lists"}