Skip to content

Commit 471ebe7

Browse files
committed
chore(docs): add docs on inferred actions
1 parent 89e1f9c commit 471ebe7

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

docs/docs/actions-and-defaults.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ By default, Compas will watch your package.json files and determine if it needs
88
to reinstall your dependencies. This way your local environment always matches
99
the required dependency versions.
1010

11-
Other actions, like automatically spinning up development dependencies in Docker
12-
need to be configured explicitly. See the respective integrations for how this
13-
works.
14-
1511
## Configuration
1612

1713
Compas is configurable via a JSON file at `config/compas.json`. An empty config
@@ -36,4 +32,29 @@ and return back to the menu. When a process is running, you can restart it with
3632
'R' or kill the running process by pressing 'K'.
3733

3834
The configuration file is automatically reloaded on changes, assuming that the
39-
syntax is correct.
35+
syntax is correct. Allowing you to iterate on it and expand your
36+
[workspace](/docs/workspaces.html).
37+
38+
## Inferred actions
39+
40+
Compas tries to give you a good experience without any configuration. This is
41+
why Compas automatically infers some standard actions based on your project
42+
setup.
43+
44+
These inferred actions are only added when no action with the same or similar
45+
name is defined. For example, 'Lint' is only added if both 'Lint' and 'Format'
46+
are not configured.
47+
48+
- 'Dev' is automatically populated from the package.json scripts.
49+
- 'Lint' defaults to the 'format' script defined in your package.json OR the
50+
'lint' script defined in your package.json OR to `compas lint` if the
51+
`@compas/cli` package is installed.
52+
- 'Test' is based on the 'test' script in your package.json OR to `compas test`
53+
if the `@compas/cli` package is installed.
54+
55+
## Other integrations
56+
57+
Compas supports much more. Like automatically starting Docker containers for
58+
services that your development environment needs, or running the code generators
59+
automatically on changes (not yet implemented). For more information, checkout
60+
the [integrations](/docs/integrations/docker.md).

docs/docs/workspaces.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ that Compas executes are now also done relative to that directory. You can
2222
create another config in `$root/packages/shared/config/compas.json` to define
2323
custom actions for that specific project and to add even more nested projects.
2424

25+
Navigation to subprojects is automatically added:
26+
27+
![Navigation from the root project](/workspace-navigation-home.png)
28+
2529
Compas also allows projects to be in a sibling directory:
2630

2731
```json [config/compas.json]
@@ -47,3 +51,4 @@ you are currently working on.
4751
truth. So the most efficient way of developing is to always start Compas from
4852
the same project and to navigate inside Compas to other projects when
4953
necessary.
54+
- Only 9 subprojects are supported currently.
5.17 KB
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { readFile } from "node:fs/promises";
2+
import { pathJoin } from "@compas/stdlib";
3+
4+
/**
5+
* Try to infer the lint command for a specific directory
6+
*
7+
* @param {string} rootDirectory
8+
* @returns {Promise<string[]|undefined>}
9+
*/
10+
export async function inferActionLint(rootDirectory = "") {
11+
const usesCompas = await inferUsesLegacyCompasCli(rootDirectory);
12+
13+
if (usesCompas) {
14+
// TODO: use package manager
15+
return ["npx", "compas", "lint"];
16+
}
17+
18+
const packageJsonFile = pathJoin(rootDirectory, "package.json");
19+
20+
if (!packageJsonFile) {
21+
return undefined;
22+
}
23+
24+
const file = JSON.parse(await readFile(packageJsonFile, "utf-8"));
25+
const command = file.scripts?.format ?? file.scripts?.lint;
26+
27+
if (!command) {
28+
return undefined;
29+
}
30+
31+
return command.split(" ");
32+
}
33+
34+
/**
35+
* Check if the project uses the legacy Compas CLI provided by @compas/cli.
36+
*
37+
* This is done based on the following rules:
38+
*
39+
* - @compas/cli is installed in the project
40+
* - No lint or format script in the package.json
41+
*
42+
* @param {string} rootDirectory
43+
* @returns {Promise<boolean>}
44+
*/
45+
export async function inferUsesLegacyCompasCli(rootDirectory = "") {
46+
const packageJsonFile = pathJoin(rootDirectory, "package.json");
47+
48+
if (!packageJsonFile) {
49+
return false;
50+
}
51+
52+
const file = JSON.parse(await readFile(packageJsonFile, "utf-8"));
53+
54+
if (
55+
!file.dependencies["@compas/cli"] &&
56+
!file.devDependencies["@compas/cli"]
57+
) {
58+
return false;
59+
}
60+
61+
return !file.scripts["lint"] && !file.scripts["format"];
62+
}

0 commit comments

Comments
 (0)