@pluginfinity/cli 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/run.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { program } from "./program.js";
2
2
  import { CliRuntime } from "@effected/cli";
3
+ import { CurrentDistribution, distributionSuffix } from "@effected/engine";
3
4
  import { ToolDiscoveryLive } from "@pluginfinity/engine";
4
5
  import { Effect } from "effect";
5
- import { CurrentDistribution, distributionSuffix } from "@effected/engine";
6
6
 
7
7
  //#region src/cli/run.ts
8
8
  /**
package/commands/build.js CHANGED
@@ -1,8 +1,11 @@
1
- import { reportConfigError } from "../render/config-error.js";
1
+ import { buildJson, buildLines } from "../render/build.js";
2
+ import { reportFindings } from "../render/config-error.js";
2
3
  import { allFlag, configFlag, pathArgument, targetFlag, toSelection } from "./shared.js";
3
4
  import { Command, Flag } from "effect/cli";
4
- import { build, isConfigError } from "@pluginfinity/engine";
5
- import { Effect } from "effect";
5
+ import { CurrentDistribution } from "@effected/engine";
6
+ import { Audience } from "@effected/env";
7
+ import { ENGINE_VERSION, build } from "@pluginfinity/engine";
8
+ import { Console, Effect, Option } from "effect";
6
9
 
7
10
  //#region src/commands/build.ts
8
11
  /** `pluginfinity build [path]`: regenerate `builds/<id>/` from source. */
@@ -14,12 +17,22 @@ const buildCommand = (launch) => Command.make("build", {
14
17
  config: configFlag
15
18
  }, (input) => Effect.gen(function* () {
16
19
  const selection = yield* toSelection(launch, input);
17
- yield* build({
20
+ const builds = yield* build({
18
21
  selection,
19
22
  targets: input.target,
20
23
  check: input.check
21
- }).pipe(Effect.catchIf(isConfigError, reportConfigError));
22
- })).pipe(Command.withDescription("Regenerate builds/<id>/ from source"));
24
+ });
25
+ if ((yield* Audience).kind === "human") for (const line of buildLines(builds, input.check)) yield* Console.log(line);
26
+ else {
27
+ const distribution = yield* CurrentDistribution;
28
+ yield* Console.log(JSON.stringify({
29
+ engine_version: ENGINE_VERSION,
30
+ distribution: Option.getOrNull(distribution),
31
+ ok: true,
32
+ builds: builds.map(buildJson)
33
+ }));
34
+ }
35
+ }).pipe(reportFindings)).pipe(Command.withDescription("Regenerate builds/<id>/ from source"));
23
36
 
24
37
  //#endregion
25
38
  export { buildCommand };
@@ -2,9 +2,9 @@ import { allFlag, configFlag, pathArgument, toSelection } from "./shared.js";
2
2
  import { doctorJson, doctorLines } from "../render/doctor.js";
3
3
  import { CliExit } from "@effected/cli";
4
4
  import { Command, Flag } from "effect/cli";
5
+ import { Audience } from "@effected/env";
5
6
  import { runDoctor } from "@pluginfinity/engine";
6
7
  import { Console, Effect } from "effect";
7
- import { Audience } from "@effected/env";
8
8
 
9
9
  //#region src/commands/doctor.ts
10
10
  /** `pluginfinity doctor [path]`: report on the environment. */
@@ -1,8 +1,11 @@
1
- import { reportConfigError } from "../render/config-error.js";
1
+ import { validateLines } from "../render/build.js";
2
+ import { reportFindings } from "../render/config-error.js";
2
3
  import { allFlag, configFlag, pathArgument, targetFlag, toSelection } from "./shared.js";
3
4
  import { Command, Flag } from "effect/cli";
4
- import { isConfigError, validate } from "@pluginfinity/engine";
5
- import { Effect } from "effect";
5
+ import { CurrentDistribution } from "@effected/engine";
6
+ import { Audience } from "@effected/env";
7
+ import { ENGINE_VERSION, validate } from "@pluginfinity/engine";
8
+ import { Console, Effect, Option } from "effect";
6
9
 
7
10
  //#region src/commands/validate.ts
8
11
  /** `pluginfinity validate [path]`: pluginfinity's own checks, then each host's CLI. */
@@ -14,12 +17,22 @@ const validateCommand = (launch) => Command.make("validate", {
14
17
  noHost: Flag.Boolean("no-host").pipe(Flag.withDefault(false), Flag.withDescription("skip the host CLIs"))
15
18
  }, (input) => Effect.gen(function* () {
16
19
  const selection = yield* toSelection(launch, input);
17
- yield* validate({
20
+ const validations = yield* validate({
18
21
  selection,
19
22
  targets: input.target,
20
23
  skipHosts: input.noHost
21
- }).pipe(Effect.catchIf(isConfigError, reportConfigError));
22
- })).pipe(Command.withDescription("Run pluginfinity's own checks, then each host's CLI"));
24
+ });
25
+ if ((yield* Audience).kind === "human") for (const line of validateLines(validations)) yield* Console.log(line);
26
+ else {
27
+ const distribution = yield* CurrentDistribution;
28
+ yield* Console.log(JSON.stringify({
29
+ engine_version: ENGINE_VERSION,
30
+ distribution: Option.getOrNull(distribution),
31
+ ok: true,
32
+ validations
33
+ }));
34
+ }
35
+ }).pipe(reportFindings)).pipe(Command.withDescription("Run pluginfinity's own checks, then each host's CLI"));
23
36
 
24
37
  //#endregion
25
38
  export { validateCommand };
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { CliExit } from "@effected/cli";
2
2
  import { ToolDiscovery } from "@effected/commands";
3
3
  import { Audience } from "@effected/env";
4
4
  import { NotImplemented } from "@pluginfinity/engine";
5
- import { Effect } from "effect";
5
+ import { Effect, PlatformError } from "effect";
6
6
  import { CliError, Command } from "effect/cli";
7
7
  import { Distribution } from "@effected/engine";
8
8
  import "effect/process";
@@ -39,7 +39,7 @@ interface ProgramDeps extends LaunchFacts {
39
39
  *
40
40
  * @public
41
41
  */
42
- export declare const program: (args: ReadonlyArray<string>, deps: ProgramDeps) => Effect.Effect<void, CliError.CliError | NotImplemented, Audience | CliExit | ToolDiscovery | Command.Environment>;
42
+ export declare const program: (args: ReadonlyArray<string>, deps: ProgramDeps) => Effect.Effect<void, CliError.CliError | NotImplemented | PlatformError.PlatformError, Audience | CliExit | ToolDiscovery | Command.Environment>;
43
43
  //#endregion
44
44
  //#region src/cli/run.d.ts
45
45
  /**
package/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { run } from "./cli/run.js";
2
2
  import { CLI_VERSION } from "./version.js";
3
- import { Effect, Option, Runtime } from "effect";
4
3
  import { CurrentDistribution } from "@effected/engine";
4
+ import { Effect, Option, Runtime } from "effect";
5
5
  import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
6
6
  import * as NodeServices from "@effect/platform-node/NodeServices";
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluginfinity/cli",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "private": false,
5
5
  "description": "The pluginfinity command-line front end. Install the pluginfinity package to get the pluginfinity bin.",
6
6
  "keywords": [
@@ -48,9 +48,9 @@
48
48
  "@effected/glob": "^0.10.0",
49
49
  "@effected/semver": "^0.11.0",
50
50
  "@effected/walker": "^0.15.0",
51
- "@pluginfinity/core": "0.0.1",
52
- "@pluginfinity/engine": "0.0.1",
53
- "@pluginfinity/targets": "0.0.1",
51
+ "@pluginfinity/core": "0.1.0",
52
+ "@pluginfinity/engine": "0.1.0",
53
+ "@pluginfinity/targets": "0.1.0",
54
54
  "effect": "^4.0.0",
55
55
  "jiti": "^2.6.1"
56
56
  },
@@ -0,0 +1,18 @@
1
+ //#region src/render/build.ts
2
+ const counts = (build) => `${build.plan.added.length} added, ${build.plan.changed.length} changed, ${build.plan.removed.length} removed`;
3
+ /** One line per target build a person reads. */
4
+ const buildLines = (builds, check) => builds.map((build) => check ? `✓ ${build.target}: ${build.out} is up to date` : build.plan.clean ? `✓ ${build.target}: ${build.out} unchanged` : `✓ ${build.target}: ${build.out} (${counts(build)})`);
5
+ /** The JSON shape of one target build. */
6
+ const buildJson = (build) => ({
7
+ config: build.config,
8
+ target: build.target,
9
+ out: build.out,
10
+ added: build.plan.added,
11
+ changed: build.plan.changed,
12
+ removed: build.plan.removed
13
+ });
14
+ /** One line per target validation a person reads. */
15
+ const validateLines = (validations) => validations.map((validation) => `✓ ${validation.target}: ${validation.out} ${validation.host === "passed" ? "passed the host check" : "is current (host check skipped)"}`);
16
+
17
+ //#endregion
18
+ export { buildJson, buildLines, validateLines };
@@ -1,11 +1,13 @@
1
1
  import { CliExit } from "@effected/cli";
2
- import { ENGINE_VERSION } from "@pluginfinity/engine";
3
- import { Console, Effect, Option } from "effect";
4
2
  import { CurrentDistribution } from "@effected/engine";
5
3
  import { Audience } from "@effected/env";
4
+ import { ENGINE_VERSION, isBuildError, isConfigError } from "@pluginfinity/engine";
5
+ import { Console, Effect, Option } from "effect";
6
6
 
7
7
  //#region src/render/config-error.ts
8
- /** Report a config error for the current audience and record exit code 1. */
8
+ /** Whether `error` is a finding {@link reportConfigError} reports. */
9
+ const isFinding = (error) => isConfigError(error) || isBuildError(error);
10
+ /** Report a config or build error for the current audience and record exit code 1. */
9
11
  const reportConfigError = (error) => Effect.gen(function* () {
10
12
  if ((yield* Audience).kind === "human") {
11
13
  yield* Console.error(`✗ ${error.message}`);
@@ -26,6 +28,11 @@ const reportConfigError = (error) => Effect.gen(function* () {
26
28
  }
27
29
  yield* CliExit.set(1);
28
30
  });
31
+ /**
32
+ * Report every config or build error `self` fails with, passing any other
33
+ * failure through.
34
+ */
35
+ const reportFindings = (self) => self.pipe(Effect.catch((error) => isFinding(error) ? reportConfigError(error) : Effect.fail(error)));
29
36
 
30
37
  //#endregion
31
- export { reportConfigError };
38
+ export { isFinding, reportConfigError, reportFindings };
package/version.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * with this package's own version, so this is not a runtime environment read.
9
9
  * `"0.0.0"` is the unbuilt-source fallback.
10
10
  */
11
- const CLI_VERSION = "0.0.1";
11
+ const CLI_VERSION = "0.1.0";
12
12
 
13
13
  //#endregion
14
14
  export { CLI_VERSION };