{"id":15690806,"url":"https://github.com/bubkoo/run-shared-scripts","last_synced_at":"2025-05-07T23:25:29.219Z","repository":{"id":65335365,"uuid":"563630376","full_name":"bubkoo/run-shared-scripts","owner":"bubkoo","description":"Define and run shared npm scripts of a monorepo using Yarn workspaces, Bolt, Lerna or pnpm","archived":false,"fork":false,"pushed_at":"2022-12-16T08:17:11.000Z","size":162,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-02T10:24:15.636Z","etag":null,"topics":["ci-cd","monorepo","npm-scripts","shared-scripts"],"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/bubkoo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-11-09T02:01:16.000Z","updated_at":"2024-08-14T18:54:22.000Z","dependencies_parsed_at":"2023-01-29T11:47:18.440Z","dependency_job_id":null,"html_url":"https://github.com/bubkoo/run-shared-scripts","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Frun-shared-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Frun-shared-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Frun-shared-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bubkoo%2Frun-shared-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bubkoo","download_url":"https://codeload.github.com/bubkoo/run-shared-scripts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223817760,"owners_count":17207947,"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":["ci-cd","monorepo","npm-scripts","shared-scripts"],"created_at":"2024-10-03T18:16:24.098Z","updated_at":"2024-11-09T11:03:09.062Z","avatar_url":"https://github.com/bubkoo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cstrong\u003erun-shared-scripts\u003c/strong\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003eDefine and run shared scripts of a monorepo using Yarn workspaces, Bolt, Lerna or pnpm\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/bubkoo/run-shared-scripts?style=flat-square\" alt=\"MIT License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.typescriptlang.org\"\u003e\u003cimg alt=\"Language\" src=\"https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/bubkoo/run-shared-scripts/pulls\"\u003e\u003cimg alt=\"PRs Welcome\" src=\"https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/bubkoo/run-shared-scripts/actions/workflows/ci.yml\"\u003e\u003cimg alt=\"build\" src=\"https://img.shields.io/github/actions/workflow/status/bubkoo/run-shared-scripts/ci.yml?branch=master\u0026logo=github\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/run-shared-scripts\"\u003e\u003cimg alt=\"NPM Package\" src=\"https://img.shields.io/npm/v/run-shared-scripts.svg?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/run-shared-scripts\"\u003e\u003cimg alt=\"NPM Downloads\" src=\"https://img.shields.io/npm/dm/run-shared-scripts?logo=npm\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Install\n```shell\n$ npm install --save-dev run-shared-scripts\n```\n\n## Usage\n\nUsing [npm-scripts](https://docs.npmjs.com/misc/scripts) is a convenient way to run our CI/CD tasks, and we may have some similar `\"scripts\"` in a monorepo workspaces. Take the following monorepo for example.\n\n```\n.\n├── lerna.json\n├── package.json\n└── packages\n    ├── project-a\n    │   ├── index.js\n    │   ├── node_modules\n    │   └── package.json\n    ├── project-b\n    │   ├── index.js\n    │   ├── node_module\n    │   └── package.json\n    ...\n```\n\nThe `\"scripts\"` defined in `./packages/project-a/package.json` and `./packages/project-b/package.json` is similar.\n\n```json\n  \"scripts\": {\n    \"clean:build\": \"rimraf dist lib es\",\n    \"clean:coverage\": \"rimraf ./test/coverage\",\n    \"clean\": \"run-p clean:build clean:coverage\",\n    \"build:esm\": \"tsc --module esnext --target es2015 --outDir ./es\",\n    \"build:cjs\": \"tsc --module commonjs --target es5 --outDir ./lib\",\n    \"build:umd\": \"rollup -c\",\n    \"build:style\": \"../../scripts/build-style.js\",\n    \"build\": \"run-p build:style build:cjs build:esm build:umd\",\n    \"prebuild\": \"run-s lint clean\",\n    \"test\": \"jest\",\n    \"coveralls\": \"cat ./test/coverage/lcov.info | coveralls\",\n    \"pretest\": \"run-p clean:coverage\",\n    \"prepare\": \"yarn build\"\n  }\n```\n\n### Basic Usage\n\nThen we can use `run-shared-scripts` to define and run these similar `\"scripts\"`.\n\n1. Add `rss` config in the monorepo root's `./package.json` file.\n   \n```json\n  \"rss\": {\n    \"clean:build\": \"rimraf dist lib es\",\n    \"clean:coverage\": \"rimraf ./test/coverage\",\n    \"clean\": \"run-p clean:build clean:coverage\",\n    \"build:esm\": \"tsc --module esnext --target es2015 --outDir ./es\",\n    \"build:cjs\": \"tsc --module commonjs --target es5 --outDir ./lib\",\n    \"build:umd\": \"rollup -c\",\n    \"build:style\": {\n      \"file\": \"./scripts/build-style.js\" // path relative to monorepo's root directory\n    },\n    \"build\": \"run-p build:style build:cjs build:esm build:umd\",\n    \"prebuild\": \"run-s lint clean\",\n    \"test\": \"jest\",\n    \"coveralls\": \"cat ./test/coverage/lcov.info | coveralls\",\n    \"pretest\": \"run-p clean:coverage\",\n    \"prepare\": \"yarn build\"\n  }\n```\n\n**Note that** the `\"build:style\"` command define the task to run an executable file. The executable file path must be an absolute path or a path relative the monorepo's root directory.\n\n1. Replace with `rss` command in `./packages/project-a/package.json` and `./packages/project-b/package.json`.\n\n```json\n  \"scripts\": {\n    \"clean:build\": \"rss\",\n    \"clean:coverage\": \"rss\",\n    \"clean\": \"rss\",\n    \"build:esm\": \"rss\",\n    \"build:cjs\": \"rss\",\n    \"build:umd\": \"rss\",\n    \"build:style\": \"rss\",\n    \"build\": \"rss\",\n    \"prebuild\": \"rss\",\n    \"test\": \"rss\",\n    \"coveralls\": \"rss\",\n    \"pretest\": \"rss\",\n    \"prepare\": \"rss\"\n  }\n```\n\n### Run specified task\n\nThe `rss` command run the same named(the key of `\"scripts\"`) task by default. We can pass a task name to specify the task to run.\n\n```json\n  \"scripts\": {\n    \"clean\": \"rss clean:build\" // run \"clean:build\" task defined in the \"rss\" config\n  }\n```\n\n### Run with arguments\n\nArguments before `--` separator are `rss` command args.\n\n```json\n  \"scripts\": {\n    \"test\": \"rss --dry-run\" // dry-run model\n  }\n```\n\nArguments after  `--` separator will pass to task.\n\n```json\n  \"scripts\": {\n    \"test\": \"rss -- --watch\" // =\u003e \"jest --watch\"\n  }\n```\n\n### Argument placeholders\n\nWe can use placeholders to define the `\"rss\"` scripts.\n\n- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd.\n- `{@}` -- All arguments.\n- `{*}` -- All arguments as combined.\n- `{n=defaultValue}` -- An argument with default value. `n` is the n-th argument.\n\n```json\n  \"rss\": {\n    \"s1\": \"server --port {1}\",\n    \"s2\": \"server -a {1} --port {2}\",\n    \"s3\": \"server {@}\",\n    \"s4\": \"server {*}\",\n    \"s5\": \"server --port {1=8080}\",\n    \"s6\": \"server --port1 {1=8080} --port2 {1}\",\n    \"s7\": \"server -a {1=0.0.0.0} --port {2=8080}\"\n  }\n```\n\nThen pass your args in the `\"scripts\"`.\n\n```json\n  \"scripts\": {\n    \"s1\": \"rss -- 8080\",         // =\u003e \"server --port 8080\"\n    \"s2\": \"rss -- 0.0.0.0 8080\", // =\u003e \"server -a 0.0.0.0 --port 8080\"\n    \"s3\": \"rss -- -a 0.0.0.0 --port 8080\", // =\u003e \"server -a 0.0.0.0 --port 8080\"\n    \"s4\": \"rss -- -a 0.0.0.0 --port 8080\", // =\u003e \"server '-a 0.0.0.0 --port 8080'\"\n    \"s5-1\": \"rss s5\",         // =\u003e \"server --port 8080\"\n    \"s5-2\": \"rss s5 -- 9090\", // =\u003e \"server --port 9090\"\n    \"s6-1\": \"rss s6\",         // =\u003e \"server --port1 8080 --port2 8080\"\n    \"s6-1\": \"rss s6 -- 9090\", // =\u003e \"server --port1 9090 --port2 9090\"\n    \"s7-1\": \"rss s7\",                    // =\u003e \"server -a 0.0.0.0 --port 8080\"\n    \"s7-2\": \"rss s7 -- '' 9090\",         // =\u003e \"server -a 0.0.0.0 --port 9090\"\n    \"s7-3\": \"rss s7 -- 127.0.0.1 9090\",  // =\u003e \"server -a 127.0.0.1 --port 9090\"\n  }\n```\n\n## Contributing\n\nPlease let us know how can we help. Do check out [issues](https://github.com/bubkoo/run-shared-scripts/issues) for bug reports or suggestions first.\n\nTo become a contributor, please follow our [contributing guide](/CONTRIBUTING.md).\n\n\u003c!-- \u003ca href=\"https://github.com/bubkoo/run-shared-scripts/graphs/contributors\"\u003e\n  \u003cimg src=\"/CONTRIBUTORS.svg\" alt=\"Contributors\" width=\"740\" /\u003e\n\u003c/a\u003e --\u003e\n\n\n## License\n\nThe scripts and documentation in this project are released under the [MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Frun-shared-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbubkoo%2Frun-shared-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbubkoo%2Frun-shared-scripts/lists"}