Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Andrew-Colman/wksp
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Colman committed Aug 31, 2021
2 parents 433bc89 + 1ed3e04 commit 9592ed5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Andrew Colman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 41 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ yarn workspaces extension

**Install**

```ps
```
npm i -g wksp
```

**then**

```ps
```
wksp <cmd>
```

Expand All @@ -37,10 +37,37 @@ wksp <cmd>
if your current directory is the workspace root you can specify the name

`wksp -n my-app <cmd> `
```
wksp -n my-app <cmd>
```

> shorthand for: yarn workspace \<name> \<cmd>
**Variadic arguments**

Variadic arguments are supported, (any arguments for the command)

```sh
wksp add react react-dom react-router
# cli cmd args...
```

**Passing options**

Options that are specific to yarn, require an `--` `--options`

```sh
wksp add tailwindcss postcss autoprefixer -- --dev
# cli cmd args... -- yarn options
```

this applies when running scripts

```sh
wksp start -- --port 3002 --watch
# cli cmd -- script options
```

<!-- ## Features
- alias
Expand All @@ -60,15 +87,23 @@ projects/
/ui-lib/
```

```ps
```
wksp start -n client
```
>--name

> --name
### project

cwd: `.../monorepo/projects/server`

`wksp start`
```
wksp start
```

> wksp will detect the package name related with this folder and run the start script defined in package.json
---

Have a great idea how we can extend yarn workspaces features ?
[suggest here](https://github.com/Andrew-Colman/wksp/issues/new)
10 changes: 8 additions & 2 deletions src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ program

.option('-n, --name <name> ', 'project name (as in package.json)')
.argument('[command]', "package script you'd like to run")

.action((command: string, options: any) => wksp(command, options));
.argument(
'[variadic...]',
"variadic arguments you'd like to pass to script"
)

.action((command: string, variadic: string[], options: any) =>
wksp(command, variadic, options)
);

//verify updates
program.hook('postAction', async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/wksp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ const execa = require('execa');

require('jsonc-require');

export async function wksp(command: string, options: { name: string }) {
export async function wksp(
command: string,
variadic: string[],
options: { name: string }
) {
try {
const name = options.name ?? getPackageName();
const cmd = command ?? '';
const args = variadic ?? '';

execa('yarn', ['workspace', name, cmd], {
execa('yarn', ['workspace', name, cmd, ...args], {
stdio: 'inherit',
}); //
} catch (error) {
Expand Down

0 comments on commit 9592ed5

Please sign in to comment.