Skip to content

Commit

Permalink
feat(compas): reimplement zakmes, add package manager support
Browse files Browse the repository at this point in the history
- Mainly moved tui + cache + watcher to development only code.
- Manage all the state in a single `state` class.
- Add all integrations as singular things. Every integration can react to cache changes, config changes, file changes or keypress inputs. File changes are debounced automatically and need to be registered by the integration.
- Support running in multiple root directories.

There are some optimizations to be made, but implementing a reactive and cache enabled integration should be pretty straight-forward.
  • Loading branch information
dirkdev98 committed Aug 29, 2023
1 parent 3773403 commit 07f28e6
Show file tree
Hide file tree
Showing 34 changed files with 2,201 additions and 1,834 deletions.
6 changes: 2 additions & 4 deletions docs/docs/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ 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.
For sibling projects, Compas runs the inferred package manager in each
project.
- 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
Expand Down
35 changes: 31 additions & 4 deletions gen/compas.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function applyCompasStructure(generator) {

projects: T.array()
.values(T.string())
.optional()
.default(`[]`)
.docs(
"Relative paths to projects. Each project is expected to provide their own configuration.",
),
Expand All @@ -51,7 +51,7 @@ export function applyCompasStructure(generator) {
shortcut: T.string(),
command: T.array().values(T.string()).min(1),
})
.optional()
.default(`[]`)
.docs("Available actions for this project."),
};

Expand All @@ -68,8 +68,35 @@ export function applyCompasStructure(generator) {
.loose(),

T.object("cache").keys({
version: T.string(),
config: T.reference("compas", "resolvedConfig").optional(),
version: T.string().docs("Compas version, used for cache invalidations."),

config: T.reference("compas", "resolvedConfig")
.optional()
.docs(
"The resolved config. Managed by {@link ConfigLoaderIntegration}.",
),

rootDirectories: T.array()
.values(T.string())
.optional()
.min(1)
.docs(
"Resolved project root directories. Managed by {@link RootDirectoriesIntegration}.",
),

cachesCleaned: T.bool()
.optional()
.docs(
"Did clean caches from project directories. Managed by {@link CacheCleanupIntegration}.",
),

packageManagerInstallCommand: T.generic()
.keys(T.string())
.values(T.array().values(T.string()))
.optional()
.docs(
"The inferred package install command per rootDirectory. Managed by {@link PackageManagerIntegration}.",
),
}),
);
}
50 changes: 38 additions & 12 deletions packages/compas/src/cli/bin.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
#!/usr/bin/env node

import { existsSync } from "node:fs";
import { isNil } from "@compas/stdlib";
import { configLoadEnvironment } from "../config.js";
import { newLogger } from "@compas/stdlib";
import { configLoadEnvironment } from "../shared/config.js";
import {
debugDisable,
debugEnable,
debugPrint,
logger,
loggerEnable,
} from "../shared/output.js";

// Just execute some temporary command matching
const args = process.argv.slice(2);
const debug = args.includes("--debug");

if (debug) {
args.splice(args.indexOf("--debug"), 1);
await debugEnable();
} else {
debugDisable();
}

debugPrint({
argv: process.argv,
args,
});

if (args.length === 0) {
if (!existsSync("./package.json")) {
// eslint-disable-next-line no-console
console.log(`Please run 'npx compas@latest init' to install Compas.`);
} else {
// TODO: check if we are in a project or someone forgot to run 'compas init'.
// TODO: check if we are in a project with Compas installed or if we should nudge the user to run Compas init. We probably want to do this differently in the different modes.

// TODO: debug
const env = await configLoadEnvironment(false);

const env = await configLoadEnvironment("", !isNil(process.env.NODE_ENV));
debugPrint(env);

if (env.isCI) {
const { ciMode } = await import("../main/ci/index.js");
Expand All @@ -34,15 +49,26 @@ if (args.length === 0) {
await developmentMode(env);
}
}
} else if (args.length === 1) {
if (args[0] === "init") {
const { initCompas } = await import("../main/init/compas.js");
await initCompas();
}
} else {
// eslint-disable-next-line no-console
console.log(`Unsupported command. Available commands:
const command = args.join(" ");
const env = await configLoadEnvironment(true);

loggerEnable(
newLogger({
ctx: {
type: env.appName,
},
}),
);

if (command === "init") {
const { initCompas } = await import("../main/init/compas.js");
await initCompas(env);
} else {
// eslint-disable-next-line no-console
logger.info(`Unsupported command. Available commands:
- compas
- compas init`);
}
}
207 changes: 0 additions & 207 deletions packages/compas/src/config.js

This file was deleted.

Loading

0 comments on commit 07f28e6

Please sign in to comment.