Skip to content

Commit

Permalink
feat(list): add Lerna list as optional command
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed May 22, 2022
1 parent 7d4116b commit 65f810c
Show file tree
Hide file tree
Showing 74 changed files with 1,718 additions and 26 deletions.
41 changes: 21 additions & 20 deletions README.md
Expand Up @@ -9,7 +9,7 @@
[![codecov](https://codecov.io/gh/ghiscoding/lerna-lite/branch/main/graph/badge.svg)](https://codecov.io/gh/ghiscoding/lerna-lite)
[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)
[![NPM downloads](https://img.shields.io/npm/dm/@lerna-lite/cli.svg)](https://www.npmjs.com/package/@lerna-lite/cli)
[![npm](https://img.shields.io/npm/v/@lerna-lite/cli.svg?logo=npm&logoColor=fff&label=npm&color=limegreen)](https://www.npmjs.com/package/@lerna-lite/cli)
[![npm](https://img.shields.io/npm/v/@lerna-lite/cli.svg?logo=npm&logoColor=fff&label=npm)](https://www.npmjs.com/package/@lerna-lite/cli)

## Lerna-Lite is a super light version of the original [Lerna](https://github.com/lerna/lerna)

Expand All @@ -24,12 +24,13 @@
- [Troubleshooting](https://github.com/ghiscoding/lerna-lite/wiki/Troubleshooting)
- Commands
- included with CLI
- 🧰 [`init`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init#readme) - create a new Lerna-Lite repo (creates `lerna.json` and a workspace structure)
- 🛠️ [`init`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init#readme) - create a new Lerna-Lite repo (creates `lerna.json` and a workspace structure)
- 💻 [`info`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/info#readme) - print local environment information (useful when opening new issue)
- ☁️ [`publish`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish#readme) - publish every workspace packages that changed
- 📑 [`version`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version#readme) - create new version for each workspace packages
- optional (**separate install**)
- 👷 [`exec`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec#readme) - execute shell command in each workspace package
- 📖 [`list`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/list#readme) - list local packages
- 🏃 [`run`](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run#readme) - run npm script in each workspace packages

---
Expand All @@ -44,7 +45,7 @@ If you use this new feature, please take 30sec. to fill in this small [poll #156
[MIT License](LICENSE)

## About Lerna-Lite
Lerna-Lite differs from the original [Lerna](https://github.com/lerna/lerna) in the sense that it only has a limited set of commands from Lerna which itself has 15 commands while Lerna-Lite only includes 6 of them (and 2 of them are even optional). Lerna was originally built as an all-in-one tool, however nowadays Workspaces are available in all dependency managers (npm, yarn, pnpm) and the need for that all-in-one tool including built-in workspaces functionality is no longer needed. Lerna-Lite is built around that new fact and its CLI only includes the `publish` and `version` commands, while there are other commands available (like `exec` and `run`) they are totally optional and you won't download them unless you opt-in. So in summary it is more modular than the original Lerna and it may seem like a small change but it does make it more versatile (with smaller downloads and less dependencies) to use with other tools like Turborepo, pnpm and others...
Lerna-Lite differs from the original [Lerna](https://github.com/lerna/lerna) in the sense that it only has a limited set of commands from Lerna which itself has 15 commands while Lerna-Lite only includes half of them (and a few are optional). Lerna was originally built as an all-in-one tool, however nowadays Workspaces are available in all dependency managers (npm, yarn, pnpm) and the need for that all-in-one tool including built-in workspaces functionality is no longer needed. Lerna-Lite is built around that new fact and its CLI only includes the `publish` and `version` commands, while there are other commands available (like `exec`, `list` and `run`) they are totally optional and you won't download them unless you opt-in. So in summary it is more modular than the original Lerna and it may seem like a small change but it does make it more versatile (with smaller downloads and less dependencies) to use with other tools like Turborepo, pnpm and others...

As a summary, Lerna-Lite assumes, and requires, to pre-setup a Workspace through your favorite package manager (NPM, pnpm, Yarn) that will take care of the symlinks (Lerna-Lite does **not include** the `bootstrap`, neither `link` commands hence the need for a workspace pre-setup), so make sure that your workspace is properly setup before installing Lerna-Lite.

Expand All @@ -54,7 +55,7 @@ Lerna-Lite differs from the original [Lerna](https://github.com/lerna/lerna) in
Mainly for the following reasons:
1. the original Lerna was no longer maintained (dependencies were out of date)
2. create a smaller lib that is more modular than the original Lerna
- the lib is smaller since we only copied 6 out of 15 commands from Lerna (some are optional). We don't need all packages of Lerna anymore since NPM Workspaces (or other technologies) came out.
- the lib is smaller since we only copied half Lerna's commands (few are optional). We don't need all packages of Lerna anymore since NPM Workspaces (or other technologies) came out.
- the main goal of this fork is to keep `version` and `publish` commands and make anything else as optional packages
3. rewritten the lib in TypeScript
4. replicate a few opened PR from Lerna and also add new feature
Expand All @@ -70,6 +71,7 @@ Mainly for the following reasons:

#### [Exec](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec) and [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) commands (optional)
- [Exec](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec#readme) is an optional package that will help you execute shell commands in parallel and in topological order.
- [List](https://github.com/ghiscoding/lerna-lite/tree/main/packages/list#readme) is an optional package that will list all workspace local packages
- [Run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run#readme) is an optional package that will help you run npm script in parallel and in topological order.

### README Badge
Expand Down Expand Up @@ -107,11 +109,12 @@ If you are new to Lerna-Lite, you could also run the [lerna init](https://github

| Command | Install | Description | Included |
|---------|-------------|-------------| ---------|
| 🧰 [init](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init#readme) | `npm i @lerna-lite/cli -D -W` | create/initialize a new Lerna-Lite repo | Yes |
| 🛠️ [init](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init#readme) | `npm i @lerna-lite/cli -D -W` | create/initialize a new Lerna-Lite repo | Yes |
| 💻 [info](https://github.com/ghiscoding/lerna-lite/tree/main/packages/info#readme) | `npm i @lerna-lite/cli -D -W` | print local environment information | Yes |
| 📑 [version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version#readme) | `npm i @lerna-lite/cli -D -W` | create new version for each workspace package | Yes |
| ☁️ [publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish#readme) | `npm i @lerna-lite/cli -D -W` | publish each workspace package | Yes |
| 👷 [exec](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec#readme) | `npm i @lerna-lite/exec -D -W` | execute an command in each workspace package | Optional |
| 📖 [list](https://github.com/ghiscoding/lerna-lite/tree/main/packages/list#readme) | `npm i @lerna-lite/list -D -W` | list local packages | Optional |
| 🏃 [run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run#readme) | `npm i @lerna-lite/run -D -W` | run npm script in each workspace package | Optional |

**Note:** the default `lerna` CLI is only including 4 built-in commands (`init`,`info`,`publish`,`version`), while the (`exec`,`run`) commands are optional and must be installed separately as shown below.
Expand Down Expand Up @@ -159,17 +162,14 @@ npm uninstall lerna -W # OR yarn remove lerna -W
npm uninstall -g lerna # OR yarn global remove lerna
```
2. install Lerna-Lite CLI to get access to `init`, `info`, `version` and `publish` commands
- `exec` and `run` commands are **optional** and can be installed separately as shown below
- `exec`, `list` and `run` commands are **optional** and can be installed separately as shown below
```sh
# Lerna CLI (includes `init`, `info`, `version` and `publish` commands)
npm install @lerna-lite/cli -D -W
```
3. optionally install `exec` and/or `run` commands
3. optionally install `exec`, `list` and/or `run` commands
```sh
# optionally install `exec` command
npm install @lerna-lite/exec -D -W

# optionally install `run` command
# optionally install `exec`, `list` and/or `run` command(s)
npm install @lerna-lite/run -D -W
```

Expand Down Expand Up @@ -197,12 +197,13 @@ If you have problems running the lib and your problems are related to Git comman

| Package Name | Version | Description | Changes |
| -------------| ------- | ----------- | ------- |
| [@lerna-lite/cli](https://github.com/ghiscoding/lerna-lite/tree/main/packages/cli) | [![npm](https://img.shields.io/npm/v/@lerna-lite/cli.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/cli) | Lerna-Lite Init/Info/Version/Publish comands CLI | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/cli/CHANGELOG.md) |
| [@lerna-lite/info](https://github.com/ghiscoding/lerna-lite/tree/main/packages/info) | [![npm](https://img.shields.io/npm/v/@lerna-lite/info.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/info) | Print local environment information | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/info/CHANGELOG.md) |
| [@lerna-lite/init](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init) | [![npm](https://img.shields.io/npm/v/@lerna-lite/init.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/init) | create a new Lerna-Lite repo | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/init/CHANGELOG.md) |
| [@lerna-lite/core](https://github.com/ghiscoding/lerna-lite/tree/main/packages/core) | [![npm](https://img.shields.io/npm/v/@lerna-lite/core.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/core) | Lerna-Lite core & shared methods | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/core/CHANGELOG.md) |
| [@lerna-lite/exec-run-common](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec-run-common) | [![npm](https://img.shields.io/npm/v/@lerna-lite/exec-run-common.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/exec-run-common) | Lerna-Lite Exec/Run commands common code | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/exec-run-common/CHANGELOG.md) |
| [@lerna-lite/publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) | [![npm](https://img.shields.io/npm/v/@lerna-lite/publish.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/publish) | Publish packages in the current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/publish/CHANGELOG.md) |
| [@lerna-lite/version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) | [![npm](https://img.shields.io/npm/v/@lerna-lite/version.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/version) | Bump Version & write Changelogs | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/version/CHANGELOG.md) |
| [@lerna-lite/exec](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec) | [![npm](https://img.shields.io/npm/v/@lerna-lite/exec.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/exec) | Execute shell command in current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/exec/CHANGELOG.md) |
| [@lerna-lite/run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) | [![npm](https://img.shields.io/npm/v/@lerna-lite/run.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/run) | Run npm scripts in current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/run/CHANGELOG.md) |
| [@lerna-lite/cli](https://github.com/ghiscoding/lerna-lite/tree/main/packages/cli) | [![npm](https://img.shields.io/npm/v/@lerna-lite/cli.svg)](https://www.npmjs.com/package/@lerna-lite/cli) | Lerna-Lite Init/Info/Version/Publish comands CLI | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/cli/CHANGELOG.md) |
| [@lerna-lite/core](https://github.com/ghiscoding/lerna-lite/tree/main/packages/core) | [![npm](https://img.shields.io/npm/v/@lerna-lite/core.svg)](https://www.npmjs.com/package/@lerna-lite/core) | Lerna-Lite core & shared methods | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/core/CHANGELOG.md) |
| [@lerna-lite/info](https://github.com/ghiscoding/lerna-lite/tree/main/packages/info) | [![npm](https://img.shields.io/npm/v/@lerna-lite/info.svg)](https://www.npmjs.com/package/@lerna-lite/info) | Print local environment information | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/info/CHANGELOG.md) |
| [@lerna-lite/init](https://github.com/ghiscoding/lerna-lite/tree/main/packages/init) | [![npm](https://img.shields.io/npm/v/@lerna-lite/init.svg)](https://www.npmjs.com/package/@lerna-lite/init) | create a new Lerna-Lite repo | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/init/CHANGELOG.md) |
| [@lerna-lite/exec-run-common](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec-run-common) | [![npm](https://img.shields.io/npm/v/@lerna-lite/exec-run-common.svg)](https://www.npmjs.com/package/@lerna-lite/exec-run-common) | Lerna-Lite Exec/Run commands common code | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/exec-run-common/CHANGELOG.md) |
| [@lerna-lite/publish](https://github.com/ghiscoding/lerna-lite/tree/main/packages/publish) | [![npm](https://img.shields.io/npm/v/@lerna-lite/publish.svg)](https://www.npmjs.com/package/@lerna-lite/publish) | Publish packages in the current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/publish/CHANGELOG.md) |
| [@lerna-lite/version](https://github.com/ghiscoding/lerna-lite/tree/main/packages/version) | [![npm](https://img.shields.io/npm/v/@lerna-lite/version.svg)](https://www.npmjs.com/package/@lerna-lite/version) | Bump Version & write Changelogs | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/version/CHANGELOG.md) |
| [@lerna-lite/exec](https://github.com/ghiscoding/lerna-lite/tree/main/packages/exec) | [![npm](https://img.shields.io/npm/v/@lerna-lite/exec.svg)](https://www.npmjs.com/package/@lerna-lite/exec) | Execute shell command in current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/exec/CHANGELOG.md) |
| [@lerna-lite/list](https://github.com/ghiscoding/lerna-lite/tree/main/packages/list) | [![npm](https://img.shields.io/npm/v/@lerna-lite/list.svg)](https://www.npmjs.com/package/@lerna-lite/list) | List local packages | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/list/CHANGELOG.md) |
| [@lerna-lite/run](https://github.com/ghiscoding/lerna-lite/tree/main/packages/run) | [![npm](https://img.shields.io/npm/v/@lerna-lite/run.svg)](https://www.npmjs.com/package/@lerna-lite/run) | Run npm scripts in current workspace | [changelog](https://github.com/ghiscoding/lerna-lite/blob/main/packages/run/CHANGELOG.md) |
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -98,6 +98,7 @@
"./packages/publish",
"./packages/exec-run-common",
"./packages/exec",
"./packages/list",
"./packages/run",
"./packages/cli"
]
Expand Down
67 changes: 67 additions & 0 deletions packages/cli/src/cli-commands/cli-list-commands.ts
@@ -0,0 +1,67 @@
import { filterOptions } from '../filter-options';

/** @ts-ignore */
const group = 'Command Options:';

/**
* @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
*/
exports.command = 'list';
exports.describe = 'List local packages';
exports.aliases = ['ls', 'la', 'll'];

exports.builder = (yargs) => {
yargs.options({
json: {
group,
describe: 'Show information as a JSON array',
type: 'boolean',
},
ndjson: {
group,
describe: 'Show information as newline-delimited JSON',
type: 'boolean',
},
a: {
group,
describe: 'Show private packages that are normally hidden',
type: 'boolean',
alias: 'all',
},
l: {
group,
describe: 'Show extended information',
type: 'boolean',
alias: 'long',
},
p: {
group,
describe: 'Show parseable output instead of columnified view',
type: 'boolean',
alias: 'parseable',
},
toposort: {
group,
describe: 'Sort packages in topological order instead of lexical by directory',
type: 'boolean',
},
graph: {
group,
describe: 'Show dependency graph as a JSON-formatted adjacency list',
type: 'boolean',
},
});

return filterOptions(yargs);
};

exports.handler = async function handler(argv) {
try {
const { ListCommand } = await import('@lerna-lite/list');
new ListCommand(argv);
} catch (e) {
console.error(
'"@lerna-lite/list" is optional and was not found. Please install it with `npm install @lerna-lite/list -D -W`'
);
}
};
2 changes: 2 additions & 0 deletions packages/cli/src/lerna-entry.ts
Expand Up @@ -4,6 +4,7 @@ const pkg = require('../package.json');
const execCmd = require('./cli-commands/cli-exec-commands');
const initCmd = require('./cli-commands/cli-init-commands');
const infoCmd = require('./cli-commands/cli-info-commands');
const listCmd = require('./cli-commands/cli-list-commands');
const publishCmd = require('./cli-commands/cli-publish-commands');
const runCmd = require('./cli-commands/cli-run-commands');
const versionCmd = require('./cli-commands/cli-version-commands');
Expand All @@ -17,6 +18,7 @@ export function lerna(argv: any[]) {
.command(execCmd)
.command(infoCmd)
.command(initCmd)
.command(listCmd)
.command(publishCmd)
.command(runCmd)
.command(versionCmd)
Expand Down

0 comments on commit 65f810c

Please sign in to comment.