Skip to content

Commit

Permalink
chore(docs): write some docs on the new CLI
Browse files Browse the repository at this point in the history
Most of it is not yet built, but should work as described once done.
  • Loading branch information
dirkdev98 committed Aug 20, 2023
1 parent 778f918 commit 37b81c3
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 29 deletions.
35 changes: 32 additions & 3 deletions docs/.vitepress/config.js
Expand Up @@ -116,6 +116,7 @@ function getHomeSidebar() {
return [
{
text: "Generators",
collapsed: false,
items: [
{
text: "Introduction",
Expand All @@ -131,6 +132,7 @@ function getHomeSidebar() {
},
{
text: "Build a custom structure",
collapsed: false,
items: [
{
text: "Types and validators",
Expand All @@ -152,6 +154,7 @@ function getHomeSidebar() {
},
{
text: "Using the generated code",
collapsed: false,
items: [
{
text: "Koa router",
Expand All @@ -172,6 +175,7 @@ function getHomeSidebar() {

{
text: "Features",
collapsed: false,
items: [
{
text: "Getting started",
Expand Down Expand Up @@ -234,11 +238,34 @@ function getHomeSidebar() {
},

{
text: "Features (alpha)",
text: "Docs (alpha)",
collapsed: true,
items: [
{
text: "Introduction",
link: "/docs/introduction.html",
text: "What is Compas?",
link: "/docs/what-is-compas.html",
},
{
text: "Getting started",
link: "/docs/getting-started.html",
},
{
text: "Actions and defaults",
link: "/docs/actions-and-defaults.html",
},
{
text: "Workspaces",
link: "/docs/workspaces.html",
},
{
text: "Integrations",
collapsed: false,
items: [
{
text: "Docker",
link: "/docs/integrations/docker.html",
},
],
},
],
},
Expand All @@ -247,6 +274,7 @@ function getHomeSidebar() {

{
text: "References",
collapsed: true,
items: [
{
text: "Compas configuration",
Expand All @@ -270,6 +298,7 @@ function getExamplesSidebar() {

return {
text: "Examples",
collapsed: true,
items: [
{
text: "Introduction",
Expand Down
39 changes: 39 additions & 0 deletions docs/docs/actions-and-defaults.md
@@ -0,0 +1,39 @@
# Actions and defaults

Compas will do a few things automatically for you when it is running. These are
called integrations. Some of them only run once configured. Others are enabled
by default.

By default, Compas will watch your package.json files and determine if it needs
to reinstall your dependencies. This way your local environment always matches
the required dependency versions.

Other actions, like automatically spinning up development dependencies in Docker
need to be configured explicitly. See the respective integrations for how this
works.

## Configuration

Compas is configurable via a JSON file at `config/compas.json`. An empty config
file is automatically created in your project when you run Compas. In this
config file, you can configure custom actions. These actions will be available
when Compas is running and can be executed via the configured shortcuts.

```json
{
"actions": [
{
"name": "Lint",
"shortcut": "L",
"command": ["npm", "run", "lint"]
}
]
}
```

Now when you press 'L' when Compas is running, it will run the defined command
and return back to the menu. When a process is running, you can restart it with
'R' or kill the running process by pressing 'K'.

The configuration file is automatically reloaded on changes, assuming that the
syntax is correct.
87 changes: 87 additions & 0 deletions docs/docs/getting-started.md
@@ -0,0 +1,87 @@
# Getting started

::: danger

This is still in development. In some cases, docs exist but the features haven't
been released yet.

Provide feedback and suggestions in
https://github.com/compasjs/compas/issues/2774.

:::

::: warning

This documentation uses `compas` as the CLI tool. However, to not interfere with
the stable [CLI](/features/cli.md), the alpha CLI is called `zakmes`.

:::

## Installation

Compas can install itself with:

```shell
npx compas@latest install
```

**In an empty directory**:

Compas creates a package.json, installs the necessary dependencies via npm and
initializes a Git repository.

**Existing project**:

Compas infers the used package manager (npm, yarn or pnpm), adds itself as a
dependency and executes an installation. If Compas is already installed in your
project, Compas will try to update itself to the latest available version.

::: info

In the alpha period, use `npx -p compas zakmes@latest install`.

:::

Off to a great start!

## Development setup

For development, we recommend setting up an 'alias' in your local login file
(`.bashrc`, `.zshrc`, etc). This allows you to execute `compas` with a prefix
like `npx compas` or `yarn compas`.

Add the following line to your `~/.bashrc` or `~/.zhsrc` (or the corresponding
file for your shell).

::: code-group

```shell [npm]
alias compas='npx compas'
```

```shell [yarn]
alias compas='yarn compas'
```

```shell [pnpm]
alias compas='pnpm compas'
```

:::

Close and reopen your terminal for this to take effect.

::: info

As an early user, you probably want to add another variant for `zakmes`.

:::

## Usage

```shell
compas
```

That is it. Let's take a look at some of the things that Compas will do by
default.
5 changes: 5 additions & 0 deletions docs/docs/integrations/docker.md
@@ -0,0 +1,5 @@
# Docker

- `compas init docker`
- Config file
- Resetting the containers
25 changes: 0 additions & 25 deletions docs/docs/introduction.md

This file was deleted.

5 changes: 5 additions & 0 deletions docs/docs/what-is-compas.md
@@ -0,0 +1,5 @@
# What is Compas?

- New CLI
- Existing packages
- Existing CLI
51 changes: 51 additions & 0 deletions docs/docs/workspaces.md
@@ -0,0 +1,51 @@
# Workspaces

Compas comes with out-of-the-box support for workspaces. All
[actions and defaults](/docs/actions-and-defaults.html) from the previous
chapter are executed for the known projects in a workspace. Allowing you to run
Compas once and get the benefits for all projects that you are working on
simultaneously.

## Enabling workspaces

The configuration file `config/compas.json` allows you to define related
projects, for example:

```json [config/compas.json]
{
"projects": ["packages/shared"]
}
```

This registers a sub project in `$root/packages/shared`. All automatic actions
that Compas executes are now also done relative to that directory. You can
create another config in `$root/packages/shared/config/compas.json` to define
custom actions for that specific project and to add even more nested projects.

Compas also allows projects to be in a sibling directory:

```json [config/compas.json]
{
"projects": ["../project-frontend"]
}
```

In this case, the sibling directory is optional and not loaded if it can not be
found. It is also allowed to create recursive project references, so you can set
up Compas in all individual projects, and it automatically includes the other
projects when they are found. Giving the same experience no matter which project
you are currently working on.

## Limitations

- Compas only supports a single package manager (npm, yarn or pnpm) in a
workspace.
- Compas assumes that nested projects are also setup correctly in your package
manager and only runs installation (e.g `npm install`) in the root project.
For sibling projects, Compas runs the package manager in all individual
projects, but it is still limited to a single package manager.
- Compas stores its cache in the project that you started Compas in and removes
the cache from referenced projects. This way Compas has a single source of
truth. So the most efficient way of developing is to always start Compas from
the same project and to navigate inside Compas to other projects when
necessary.
2 changes: 1 addition & 1 deletion packages/compas/src/output/tui.js
Expand Up @@ -172,7 +172,7 @@ export function tuiEnable() {
});

// Resize listener
process.stdout.on("resize", () => tuiPaintLayout());
// process.stdout.on("resize", () => tuiPaintLayout());

// Input setup + listener
emitKeypressEvents(process.stdin);
Expand Down

0 comments on commit 37b81c3

Please sign in to comment.