Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/app-builder/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@effectify/app-builder-cli",
"version": "0.0.0",
"type": "module",
"bin": {
"effectify-app-builder": "./dist/src/main.js"
},
"dependencies": {
"@effectify/app-builder-generation": "workspace:*",
"tslib": "catalog:"
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ const workspacePath = (workspace: string): Effect.Effect<string, GenerateInputEr
: Effect.succeed(target)
}

const outputPath = (workspace: string, path: string): string => {
const outputPath = (workspace: string, path: string, roots: ReadonlyArray<string>): string => {
const segments = safeSegments(path, safeOutputSegment)
const isOwned = TodoPreset.isTodoTopologyPath(path)
const isOwned = TodoPreset.isTodoTopologyPath(path, roots)
if (segments === undefined || !isOwned) {
throw new GenerateHostError({ reason: "generated topology contains an unsafe output path" })
}
Expand Down Expand Up @@ -118,7 +118,7 @@ const prevalidate = async (
for (const file of [...topology.files].sort((left, right) => left.path.localeCompare(right.path))) {
if (paths.has(file.path)) throw new GenerateConflictError({ path: file.path })
paths.add(file.path)
const target = outputPath(workspace, file.path)
const target = outputPath(workspace, file.path, topology.roots)
const output = { content: file.content, path: file.path, target }
await requireSafeDirectories(workspace, output)
const existing = await existingEntry(target)
Expand Down
8 changes: 8 additions & 0 deletions packages/app-builder/cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env node

import { realpathSync } from "node:fs"
import { readFile } from "node:fs/promises"
import { pathToFileURL } from "node:url"
import * as Effect from "effect/Effect"
import {
type CliCommand,
Expand Down Expand Up @@ -171,3 +175,7 @@ export const runNodeCli = (args: ReadonlyArray<string> = process.argv.slice(2)):
process.exitCode = code
return code
})

if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
await runNodeCli()
}
33 changes: 25 additions & 8 deletions packages/app-builder/cli/tests/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ const generateRequest = (workspace: string) => ({
workspace,
},
})
const customGenerateRequest = (workspace: string) => ({
...generateRequest(workspace),
payload: {
...generateRequest(workspace).payload,
intent: {
...request.payload,
naming: {
workspace: "operations-workspace",
npmScope: "@acme",
domain: { id: "operations", name: "Operations" },
entity: { id: "task", singular: "Task", plural: "Tasks" },
entrypoint: { id: "admin-console", name: "AdminConsole" },
},
},
},
})

const main = () => Effect.promise<MainModule>(() => import(new URL("../src/main.js", import.meta.url).href))

Expand Down Expand Up @@ -166,7 +182,7 @@ effect("R16 prerequisite generates deterministic consumer output through the pub

return Effect.gen(function* () {
yield* Effect.promise(() => rm(workspacePath, { force: true, recursive: true }))
const input = JSON.stringify(generateRequest(workspace))
const input = JSON.stringify(customGenerateRequest(workspace))

return yield* Effect.gen(function* () {
const first = yield* invoke(["generate", "--events=jsonl"], input)
Expand Down Expand Up @@ -195,20 +211,21 @@ effect("R16 prerequisite generates deterministic consumer output through the pub
})
expect(firstTerminal.result.writtenPaths).not.toEqual([])
expect(
yield* Effect.promise(() => readFile(join(workspacePath, "apps/todo-cli/src/index.ts"), "utf8")),
yield* Effect.promise(() => readFile(join(workspacePath, "apps/admin-console/src/index.ts"), "utf8")),
).toContain("createLiveRuntime")

const { Generation } = yield* publicSurface()
const direct = yield* Generation.TodoGeneration.composeTodoAtomic(Generation.TodoPreset.DefaultTodoRenderContext)
const rootPaths = new Set<string>(Generation.TodoGeneration.WorkspaceRootFiles)
const rootFiles = direct.contributions.filter((file) => rootPaths.has(file.path))
const direct = yield* Generation.TodoPreset.createTodoTopology(
yield* Generation.Planner.planTodo(customGenerateRequest(workspace).payload.intent),
)
const rootFiles = direct.files.filter((file) =>
Generation.TodoGeneration.WorkspaceRootFiles.some((path) => path === file.path),
)

expect(rootFiles).toHaveLength(5)
expect(firstTerminal.result.writtenPaths).toEqual(expect.arrayContaining(rootFiles.map((file) => file.path)))
for (const file of rootFiles) {
expect(yield* Effect.promise(() => readFile(join(workspacePath, file.path), "utf8"))).toBe(
new TextDecoder().decode(file.bytes),
)
expect(yield* Effect.promise(() => readFile(join(workspacePath, file.path), "utf8"))).toBe(file.content)
}

const second = yield* invoke(["generate"], input)
Expand Down
6 changes: 6 additions & 0 deletions packages/app-builder/e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
},
"test": {
"executor": "nx:run-commands",
"dependsOn": [
{
"projects": ["@effectify/app-builder-cli"],
"target": "build"
}
],
"options": {
"command": "../../../node_modules/.bin/vitest run --config vitest.config.mts",
"cwd": "packages/app-builder/e2e"
Expand Down
Loading
Loading