Skip to content

Commit 3c3940d

Browse files
committed
chore: init
0 parents  commit 3c3940d

28 files changed

+8585
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[Makefile]
16+
indent_style = tab

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.github/workflows/ci.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: 👷 CI
2+
on:
3+
pull_request_target:
4+
push:
5+
branches:
6+
- master
7+
- next
8+
- next-major
9+
- alpha
10+
- beta
11+
jobs:
12+
ci:
13+
strategy:
14+
matrix:
15+
node: [14, 16, 18]
16+
os: [ubuntu-latest, windows-latest]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- name: ⤵️ Checkout
20+
uses: actions/checkout@v3
21+
22+
- name: 🎉 Setup nodejs
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: 16.x
26+
27+
- name: 🎉 Setup pnpm
28+
uses: pnpm/action-setup@v2
29+
with:
30+
version: 7
31+
run_install: false
32+
33+
- name: 🚧 Install
34+
run: pnpm install --no-frozen-lockfile --ignore-scripts
35+
36+
- run: cd example
37+
38+
- name: 🚧 Install
39+
run: pnpm install --no-frozen-lockfile --ignore-scripts
40+
41+
- name: 🚀 Build
42+
run: pnpm run build
43+
44+
- name: ✅ Test
45+
run: pnpm run test

.github/workflows/release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: 🚀 Release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- next
7+
- next-major
8+
- alpha
9+
- beta
10+
jobs:
11+
run:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: ⤵️ Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: 🎉 Setup nodejs
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 16.x
21+
22+
- name: 🎉 Setup pnpm
23+
uses: pnpm/action-setup@v2
24+
with:
25+
version: 7
26+
run_install: false
27+
28+
- name: 🌱 Get pnpm store directory
29+
id: pnpm-cache
30+
shell: bash
31+
run: |
32+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
33+
34+
- name: 🚸 Setup pnpm cache
35+
uses: actions/cache@v3
36+
with:
37+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
41+
42+
- name: 🚧 Install
43+
run: pnpm install --no-frozen-lockfile --ignore-scripts
44+
45+
- name: 🔑 Generate Token
46+
uses: wow-actions/use-app-token@v1
47+
with:
48+
app_id: ${{ secrets.APP_ID }}
49+
private_key: ${{ secrets.PRIVATE_KEY }}
50+
env_name: bot_token
51+
52+
- name: 📦 Semantic Release
53+
uses: cycjimmy/semantic-release-action@v2
54+
id: semantic
55+
with:
56+
extends: "@bubkoo/semantic-release-config"
57+
extra_plugins: |
58+
@semantic-release/changelog
59+
@semantic-release/git
60+
env:
61+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
62+
GITHUB_TOKEN: ${{ env.bot_token }}
63+
GIT_AUTHOR_NAME: your-bot
64+
GIT_AUTHOR_EMAIL: [email protected]
65+
GIT_COMMITTER_NAME: your-bot
66+
GIT_COMMITTER_EMAIL: [email protected]

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.vscode
3+
.idea
4+
.turbo
5+
npm-debug.log
6+
yarn-error.log
7+
lerna-debug.log
8+
node_modules
9+
*.pem
10+
!mock-cert.pem

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 bubkoo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# run-shared-scripts
2+
3+
<p align="center"><strong>run-shared-scripts</strong></p>
4+
<p align="center">Define and run shared scripts of a monorepo using Yarn workspaces, Bolt, Lerna or pnpm</p>
5+
6+
<p align="center">
7+
<a href="/LICENSE"><img src="https://img.shields.io/github/license/bubkoo/run-shared-scripts?style=flat-square" alt="MIT License"></a>
8+
<a href="https://www.typescriptlang.org"><img alt="Language" src="https://img.shields.io/badge/language-TypeScript-blue.svg?style=flat-square"></a>
9+
<a href="https://github.com/bubkoo/run-shared-scripts/pulls"><img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square"></a>
10+
</p>
11+
12+
<p align="center">
13+
<a href="https://github.com/bubkoo/run-shared-scripts/actions/workflows/release.yml"><img alt="build" src="https://img.shields.io/github/workflow/status/bubkoo/run-shared-scripts/%F0%9F%9A%80%E3%80%80Release/master?logo=github&style=flat-square"></a>
14+
<a href="https://www.npmjs.com/package/run-shared-scripts"><img alt="NPM Package" src="https://img.shields.io/npm/v/run-shared-scripts.svg?style=flat-square"></a>
15+
<a href="https://www.npmjs.com/package/run-shared-scripts"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/run-shared-scripts?logo=npm&style=flat-square"></a>
16+
</p>
17+
18+
## Install
19+
```shell
20+
$ npm install --save-dev run-shared-scripts
21+
```
22+
23+
## Usage
24+
25+
Using [npm-scripts](https://docs.npmjs.com/misc/scripts) is a convenient way to our CI/CD tasks, and we may have some similar `"scripts"` in a monorepo. Take the following monorepo for example.
26+
27+
```
28+
.
29+
├── lerna.json
30+
├── package.json
31+
└── packages
32+
├── project-a
33+
│ ├── index.js
34+
│ ├── node_modules
35+
│ └── package.json
36+
├── project-b
37+
│ ├── index.js
38+
│ ├── node_module
39+
│ └── package.json
40+
...
41+
```
42+
43+
The `"scripts"` property defined in `./packages/project-a/package.json` and `./packages/project-b/package.json` is similar.
44+
45+
```json
46+
"scripts": {
47+
"clean:build": "rimraf dist lib es",
48+
"clean:coverage": "rimraf ./test/coverage",
49+
"clean": "run-p clean:build clean:coverage",
50+
"build:esm": "tsc --module esnext --target es2015 --outDir ./es",
51+
"build:cjs": "tsc --module commonjs --target es5 --outDir ./lib",
52+
"build:umd": "rollup -c",
53+
"build:style": "../../scripts/build-style.js",
54+
"build": "run-p build:style build:cjs build:esm build:umd",
55+
"prebuild": "run-s lint clean",
56+
"test": "jest",
57+
"coveralls": "cat ./test/coverage/lcov.info | coveralls",
58+
"pretest": "run-p clean:coverage",
59+
"prepare": "yarn build"
60+
}
61+
```
62+
63+
### Basic Usage
64+
65+
Then we can use `run-shared-scripts` to define and run these similar `"scripts"`.
66+
67+
1. Add `rss` config in the monorepo root's `./package.json` file.
68+
```json
69+
"rss": {
70+
"clean:build": "rimraf dist lib es",
71+
"clean:coverage": "rimraf ./test/coverage",
72+
"clean": "run-p clean:build clean:coverage",
73+
"build:esm": "tsc --module esnext --target es2015 --outDir ./es",
74+
"build:cjs": "tsc --module commonjs --target es5 --outDir ./lib",
75+
"build:umd": "rollup -c",
76+
"build:style": { "file": "./scripts/build-style.js" },
77+
"build": "run-p build:style build:cjs build:esm build:umd",
78+
"prebuild": "run-s lint clean",
79+
"test": "jest",
80+
"coveralls": "cat ./test/coverage/lcov.info | coveralls",
81+
"pretest": "run-p clean:coverage",
82+
"prepare": "yarn build"
83+
}
84+
```
85+
86+
**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.
87+
88+
2. Replace with `rss` command in `./packages/project-a/package.json` and `./packages/project-b/package.json`.
89+
90+
```json
91+
"scripts": {
92+
"clean:build": "rss",
93+
"clean:coverage": "rss",
94+
"clean": "rss",
95+
"build:esm": "rss",
96+
"build:cjs": "rss",
97+
"build:umd": "rss",
98+
"build:style": "rss",
99+
"build": "rss",
100+
"prebuild": "rss",
101+
"test": "rss",
102+
"coveralls": "rss",
103+
"pretest": "rss",
104+
"prepare": "rss"
105+
}
106+
```
107+
108+
### Run specified task
109+
110+
The `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.
111+
112+
```json
113+
"scripts": {
114+
"clean": "rss clean:build" // will run "clean:build" task defined in the "rss" config
115+
}
116+
```
117+
118+
### Run with arguments
119+
120+
Any arguments following `--` will pass to task.
121+
122+
```json
123+
"scripts": {
124+
"test": "rss -- --watch" // run jest in watch mode
125+
}
126+
```
127+
128+
## Contributing
129+
130+
Please 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.
131+
132+
To become a contributor, please follow our [contributing guide](/CONTRIBUTING.md).
133+
134+
<!-- <a href="https://github.com/bubkoo/run-shared-scripts/graphs/contributors">
135+
<img src="/CONTRIBUTORS.svg" alt="Contributors" width="740" />
136+
</a> -->
137+
138+
139+
## License
140+
141+
The scripts and documentation in this project are released under the [MIT License](LICENSE)

bin/rss.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
import meow from 'meow'
4+
import { run } from '../lib/index.js'
5+
6+
const inputs = process.argv.slice(2)
7+
const split = inputs.indexOf('--')
8+
const argv = split >= 0 ? inputs.slice(0, split) : inputs
9+
const args = split >= 0 ? inputs.slice(split + 1) : []
10+
11+
const cli = meow(
12+
`
13+
Usage
14+
$ rss [task] [options] [-- args]
15+
16+
Run shared script with optional task name.
17+
18+
Options
19+
--dry-run ·········· Set the flag to run task in dry-run mode.
20+
--version ·········· Show version info.
21+
--help ············· Show help info.
22+
23+
Examples
24+
$ rss build
25+
$ rss build --dry-run
26+
$ rss build --dry-run -- -w
27+
`,
28+
{
29+
flags: {
30+
dryRun: {
31+
type: 'boolean',
32+
default: false,
33+
},
34+
},
35+
argv,
36+
importMeta: import.meta,
37+
allowUnknownFlags: true,
38+
version: true,
39+
},
40+
)
41+
42+
const cmd = cli.input[0] || process.env.npm_lifecycle_event
43+
44+
run(cmd, args, cli.flags)

example/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

example/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.DS_Store
2+
.vscode
3+
.idea
4+
.turbo
5+
npm-debug.log
6+
yarn-error.log
7+
lerna-debug.log
8+
node_modules
9+
coverage
10+
lib
11+
es
12+
dist
13+
*.pem
14+
!mock-cert.pem
15+
tmp
16+
test/coverage
17+
packages/**/src/style/raw.ts

0 commit comments

Comments
 (0)