Skip to content

Commit

Permalink
add reporting of tsc and tsx errors, closes #66 (#67)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxwell Brown <[email protected]>
  • Loading branch information
gcanti and IMax153 committed Apr 8, 2024
1 parent 20a0ed1 commit b9bfab0
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 76 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-pears-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/docgen": patch
---

add reporting of `tsc` and `tsx` errors, closes #66
95 changes: 50 additions & 45 deletions docs/modules/Configuration.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,74 @@ Added in v1.0.0
<h2 class="text-delta">Table of contents</h2>

- [service](#service)
- [Configuration](#configuration)
- [Configuration (interface)](#configuration-interface)
- [Configuration (class)](#configuration-class)
- [ConfigurationSchema](#configurationschema)
- [ConfigurationShape (interface)](#configurationshape-interface)

---

# service

## Configuration
## Configuration (class)

**Signature**

```ts
export declare const Configuration: Context.Tag<Configuration, Configuration>
export declare class Configuration
```

Added in v1.0.0

## Configuration (interface)
## ConfigurationSchema

**Signature**

```ts
export declare const ConfigurationSchema: Schema.struct<{
$schema: Schema.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>
projectHomepage: Schema.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>
srcDir: Schema.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>
outDir: Schema.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>
theme: Schema.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>
enableSearch: Schema.PropertySignature<"?:", boolean | undefined, never, "?:", boolean | undefined, never>
enforceDescriptions: Schema.PropertySignature<"?:", boolean | undefined, never, "?:", boolean | undefined, never>
enforceExamples: Schema.PropertySignature<"?:", boolean | undefined, never, "?:", boolean | undefined, never>
enforceVersion: Schema.PropertySignature<"?:", boolean | undefined, never, "?:", boolean | undefined, never>
exclude: Schema.PropertySignature<
"?:",
readonly string[] | undefined,
never,
"?:",
readonly string[] | undefined,
never
>
parseCompilerOptions: Schema.PropertySignature<
"?:",
string | { readonly [x: string]: unknown } | undefined,
never,
"?:",
string | { readonly [x: string]: unknown } | undefined,
never
>
examplesCompilerOptions: Schema.PropertySignature<
"?:",
string | { readonly [x: string]: unknown } | undefined,
never,
"?:",
string | { readonly [x: string]: unknown } | undefined,
never
>
}>
```

Added in v1.0.0

## ConfigurationShape (interface)

**Signature**

```ts
export interface Configuration {
export interface ConfigurationShape {
readonly projectName: string
readonly projectHomepage: string
readonly srcDir: string
Expand All @@ -54,42 +98,3 @@ export interface Configuration {
```

Added in v1.0.0

## ConfigurationSchema

**Signature**

```ts
export declare const ConfigurationSchema: Schema.Schema<
{
readonly $schema?: string
readonly projectHomepage?: string
readonly srcDir?: string
readonly outDir?: string
readonly theme?: string
readonly enableSearch?: boolean
readonly enforceDescriptions?: boolean
readonly enforceExamples?: boolean
readonly enforceVersion?: boolean
readonly exclude?: readonly string[]
readonly parseCompilerOptions?: string | { readonly [x: string]: unknown }
readonly examplesCompilerOptions?: string | { readonly [x: string]: unknown }
},
{
readonly $schema?: string
readonly projectHomepage?: string
readonly srcDir?: string
readonly outDir?: string
readonly theme?: string
readonly enableSearch?: boolean
readonly enforceDescriptions?: boolean
readonly enforceExamples?: boolean
readonly enforceVersion?: boolean
readonly exclude?: readonly string[]
readonly parseCompilerOptions?: string | { readonly [x: string]: unknown }
readonly examplesCompilerOptions?: string | { readonly [x: string]: unknown }
}
>
```
Added in v1.0.0
11 changes: 5 additions & 6 deletions docs/modules/File.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ Represents a file which can be optionally overwriteable.
**Signature**
```ts
export interface File
extends Data.Data<{
readonly path: string
readonly content: string
readonly isOverwriteable: boolean
}> {}
export interface File {
readonly path: string
readonly content: string
readonly isOverwriteable: boolean
}
```

Added in v1.0.0
3 changes: 1 addition & 2 deletions docs/modules/Markdown.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Added in v1.0.0
**Signature**

```ts
export declare const printModule: (module: Domain.Module, order: number) => Effect.Effect<never, never, string>
export declare const printModule: (module: Domain.Module, order: number) => Effect.Effect<string>
```
**Example**
Expand All @@ -36,7 +36,6 @@ import { Option } from "effect"

const doc = Domain.createNamedDoc("tests", Option.none(), Option.some("1.0.0"), false, [], Option.none())
const m = Domain.createModule(doc, ["src", "tests.ts"], [], [], [], [], [], [], [])
console.log(Markdown.printModule(m, 0))
```

Added in v1.0.0
20 changes: 10 additions & 10 deletions docs/modules/Parser.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Added in v1.0.0
**Signature**

```ts
export declare const parseClasses: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Class[]>
export declare const parseClasses: Effect.Effect<Domain.Class[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -42,7 +42,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseConstants: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Constant[]>
export declare const parseConstants: Effect.Effect<Domain.Constant[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -52,7 +52,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseExports: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Export[]>
export declare const parseExports: Effect.Effect<Domain.Export[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -64,7 +64,7 @@ Added in v1.0.0
```ts
export declare const parseFiles: (
files: ReadonlyArray<File.File>
) => Effect.Effect<Process.Process | Configuration.Configuration | Path.Path, string[][], Domain.Module[]>
) => Effect.Effect<Domain.Module[], string[][], Process.Process | Configuration.Configuration | Path.Path>
```
Added in v1.0.0
Expand All @@ -74,7 +74,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseFunctions: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Function[]>
export declare const parseFunctions: Effect.Effect<Domain.Function[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -84,7 +84,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseInterfaces: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Interface[]>
export declare const parseInterfaces: Effect.Effect<Domain.Interface[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -95,9 +95,9 @@ Added in v1.0.0
```ts
export declare const parseModule: Effect.Effect<
Configuration.Configuration | Path.Path | Source,
Domain.Module,
string[],
Domain.Module
Configuration.Configuration | Path.Path | Source
>
```
Expand All @@ -108,7 +108,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseNamespaces: Effect.Effect<Configuration.Configuration | Source, string[], Domain.Namespace[]>
export declare const parseNamespaces: Effect.Effect<Domain.Namespace[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
Expand All @@ -118,7 +118,7 @@ Added in v1.0.0
**Signature**
```ts
export declare const parseTypeAliases: Effect.Effect<Configuration.Configuration | Source, string[], Domain.TypeAlias[]>
export declare const parseTypeAliases: Effect.Effect<Domain.TypeAlias[], string[], Configuration.Configuration | Source>
```
Added in v1.0.0
20 changes: 10 additions & 10 deletions docs/modules/Process.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Added in v1.0.0
- [layer](#layer)
- [layer](#layer-1)
- [service](#service)
- [Process](#process)
- [Process (interface)](#process-interface)
- [Process (class)](#process-class)
- [ProcessShape (interface)](#processshape-interface)

---

Expand All @@ -27,34 +27,34 @@ Added in v1.0.0
**Signature**

```ts
export declare const layer: Layer.Layer<never, never, Process>
export declare const layer: Layer.Layer<Process, never, never>
```
Added in v1.0.0
# service
## Process
## Process (class)
**Signature**
```ts
export declare const Process: Context.Tag<Process, Process>
export declare class Process
```

Added in v1.0.0

## Process (interface)
## ProcessShape (interface)

Represents a handle to the currently executing process.

**Signature**

```ts
export interface Process {
readonly cwd: Effect.Effect<never, never, string>
readonly platform: Effect.Effect<never, never, string>
readonly argv: Effect.Effect<never, never, Array<string>>
export interface ProcessShape {
readonly cwd: Effect.Effect<string>
readonly platform: Effect.Effect<string>
readonly argv: Effect.Effect<Array<string>>
}
```

Expand Down
3 changes: 2 additions & 1 deletion src/CLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as ValidationError from "@effect/cli/ValidationError"
import * as Schema from "@effect/schema/Schema"
import * as TreeFormatter from "@effect/schema/TreeFormatter"
import * as Config from "effect/Config"
import * as Effect from "effect/Effect"
import * as Either from "effect/Either"
import * as ReadonlyArray from "effect/ReadonlyArray"
import * as Configuration from "./Configuration.js"
Expand Down Expand Up @@ -175,7 +176,7 @@ export const docgenCommand = Command.make("docgen", options)

/** @internal */
export const cli = docgenCommand.pipe(
Command.withHandler(() => Core.program),
Command.withHandler(() => Effect.scoped(Core.program)),
Command.provideEffect(Configuration.Configuration, (args) => Configuration.load(args)),
Command.run({
name: "docgen",
Expand Down
54 changes: 52 additions & 2 deletions src/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import * as CommandExecutor from "@effect/platform/CommandExecutor"
import * as FileSystem from "@effect/platform/FileSystem"
import * as Path from "@effect/platform/Path"
import chalk from "chalk"
import * as Chunk from "effect/Chunk"
import * as Effect from "effect/Effect"
import * as ReadonlyArray from "effect/ReadonlyArray"
import * as Stream from "effect/Stream"
import * as String from "effect/String"
import * as Glob from "glob"
import * as Configuration from "./Configuration.js"
Expand Down Expand Up @@ -273,8 +275,31 @@ const runTscOnExamples = Effect.gen(function*(_) {
const tsconfig = path.normalize(path.join(cwd, config.outDir, "examples", "tsconfig.json"))
const exe = platform === "win32" ? "tsc.cmd" : "tsc"
const command = Command.make(exe, "--noEmit", "--project", tsconfig)

yield* _(Effect.logDebug("Running tsc on examples..."))
yield* _(Effect.asUnit(executor.exitCode(command)))

const [stdout, exitCode] = yield* _(
executor.start(command),
Effect.flatMap((process) =>
Effect.all([
process.stdout.pipe(
Stream.decodeText("utf-8"),
Stream.splitLines,
Stream.runCollect,
Effect.map(Chunk.toReadonlyArray)
),
process.exitCode
], { concurrency: 2 })
)
)

if (exitCode !== 0) {
yield* _(
new DocgenError({
message: `Something went wrong while running tsc on examples:\n\n${stdout.join("\n")}`
})
)
}
})

/**
Expand All @@ -293,8 +318,33 @@ const runTsxOnExamples = Effect.gen(function*(_) {
const index = path.join(examples, "index.ts")
const exe = platform === "win32" ? "tsx.cmd" : "tsx"
const command = Command.make(exe, "--tsconfig", tsconfig, index)

yield* _(Effect.logDebug("Running tsx on examples..."))
yield* _(Effect.asUnit(executor.exitCode(command)))

const [stdout, exitCode] = yield* _(
executor.start(command),
Effect.flatMap((process) =>
Effect.all([
process.stderr.pipe(
Stream.decodeText("utf-8"),
Stream.splitLines,
Stream.runCollect,
Effect.map(Chunk.toReadonlyArray)
),
process.exitCode
], { concurrency: 2 })
)
)

if (exitCode !== 0) {
yield* _(
Effect.fail(
new DocgenError({
message: `Something went wrong while running tsx on examples:\n\n${stdout.join("\n")}`
})
)
)
}
})

const writeExamplesToOutDir = (examples: ReadonlyArray<File.File>) =>
Expand Down

0 comments on commit b9bfab0

Please sign in to comment.