# yarn-workspace-commands

> Local Automator for yarn workspaces

Latest version **1.0.11** (published 2018-10-25) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install yarn-workspace-commands
pnpm add yarn-workspace-commands
yarn add yarn-workspace-commands
bun add yarn-workspace-commands
```

Provides the command `ywc`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2018-10-25 |
| First published | 2018-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vishnu Sankar |
| Maintainers | iamvishnusankar |
| Keywords | yarn, yarn-workspace, monorepo, ci, cli |

## Links

- npm: https://www.npmjs.com/package/yarn-workspace-commands
- Repository: https://github.com/iamvishnusankar/yarn-workspace-commands
- Homepage: https://github.com/iamvishnusankar/yarn-workspace-commands#readme
- Issues: https://github.com/iamvishnusankar/yarn-workspace-commands/issues
- npm.io page: https://npm.io/package/yarn-workspace-commands

## Dependencies (2)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [chalk](https://npm.io/package/chalk.md) ^2.4.1

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.11 (latest) — 2018-10-25
- 1.0.10 — 2018-10-24
- 1.0.9 — 2018-10-23
- 1.0.8 — 2018-10-22
- 1.0.7 — 2018-10-22
- 1.0.6 — 2018-10-22
- 1.0.5 — 2018-10-21
- 1.0.4 — 2018-10-21
- 1.0.3 — 2018-10-21
- 1.0.2 — 2018-10-21
- 1.0.1 — 2018-10-21

## README

# yarn-workspace-commands [![npm](https://img.shields.io/npm/dt/:package.svg?style=flat-square)](https://www.npmjs.com/package/yarn-workspace-commands)

Local Automator for yarn workspaces. Yarn-Workspace-Commands lets you to run a set of commands for local dev/ci build on all workspace packages folder.

## Basic Usage

Install package on workspace root

```
yarn add yarn-workspace-commands -D -W
```

Define commands `ywc.config.json`

```
{
    "[command_key]": {

         /* Array of commands to execute */
        "commands": "string[]",

        /* Execute in parallel mode. Default : false */
        "parallel": "boolean",

        /* Execute only on root folder. Default : false */
        "rootCommand": "boolean"
    }
}
```

Execute

```shell
# command_key defined in ywc.config.json
yarn ywc <command_key>
```

### Detailed Setup Instructions

#### 1. Setup Yarn Workspace

For further info on setting up yarn workspace : [Setting Up Yarn Workspace](https://yarnpkg.com/lang/en/docs/workspaces/#toc-how-to-use-it)

```json
{
    "private": true,
    "workspaces": ["packages/*", "app/*"]
}
```

or

```json
{
    "private": true,
    "workspaces": {
        "packages": ["packages/*", "app/*"],
        "nohoist": []
    }
}
```

#### 2. Install Package

```cmd
yarn add yarn-workspace-commands -D -W
```

#### 3. Create `ywc.config.json` in workspace root

Set `rootCommand : true` to make the commands run only on root folder.

```json
{
    "test_command_1": {
        "commands": [
            "echo command 1",
            "echo command 2",
            "echo command 3",
            "echo command 4"
        ]
    },
    "test_command_2": {
        "commands": ["echo command 5", "ls"]
    },
    "test_command_3": {
        "commands": ["yarn test_root_command"],
        "rootCommand": true
    }
}
```

#### 4. Add script to `package.json` in workspace root

```json
{
    "scripts": {
        "test_ywc": "ywc test_command_1 test_command_2 test_command_3",
        "test_root_command": "echo hello world root command"
    }
}
```

#### 5. Run the commands

```cmd
yarn test_ywc
```

## Practical Example

If you have a yarn workspace and want to perform a clean build of all local packages after the installation of new modules.

-   Add the following to `ywc.config.json`

    ```json
    {
        "build": {
            "commands": ["yarn build"]
        },
        "clean": {
            "commands": ["rm -rf dist", "rm -rf build"]
        }
    }
    ```

-   Add the following script to `package.json` in workspace root

    ```json
    {
        "scripts": {
            "postinstall": "ywc clean build"
        }
    }
    ```

## Environment Variables

Since the command execution is taking place under node environment, All environment variables available to `process.env` can be used as inline arguments.

Example : Package versioning

-   `ywc.config.json`

    ```json
    {
        "test-env": {
            "commands": ["echo ${NODE_ENV} ${NODE}"]
        },
        "set-version": {
            "commands": [
                "npm version --no-git-tag-version ${BUILD_BUILDNUMBER}"
            ]
        }
    }
    ```

-   Add the set version script to `package.json`

    ```json
    {
        "scripts": {
            "set-version": "ywc set-version"
        }
    }
    ```

-   Run the command to update version of all packages
    ```json
    yarn set-version
    ```

---
_Source: https://npm.io/package/yarn-workspace-commands · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
