콘텐츠로 이동

모노레포 설정하기

새 모노레포를 생성하려면 원하는 디렉토리 내에서 다음 명령을 실행하세요:

Terminal window
pnpm create @aws/nx-workspace dungeon-adventure --iac=cdk

이렇게 하면 dungeon-adventure 디렉토리 내에 NX 모노레포가 설정됩니다. VSCode에서 디렉토리를 열면 다음과 같은 파일 구조를 볼 수 있습니다:

  • 디렉터리.nx/
  • 디렉터리.vscode/
  • 디렉터리node_modules/
  • 디렉터리packages/ 하위 프로젝트가 위치할 곳
  • .gitignore
  • biome.json Biome의 린팅 및 포맷팅 설정
  • nx.json Nx CLI 및 모노레포 기본값 설정
  • package.json 모든 노드 의존성이 정의됨
  • pnpm-lock.yaml 또는 bun.lock, yarn.lock, package-lock.json (패키지 매니저에 따라)
  • pnpm-workspace.yaml pnpm 사용 시
  • README.md
  • tsconfig.base.json 모든 노드 기반 하위 프로젝트가 이를 확장함
  • tsconfig.json
  • aws-nx-plugin.config.mts Nx Plugin for AWS 설정

작업 2: 던전 어드벤처 게임 스캐폴딩하기

섹션 제목: “작업 2: 던전 어드벤처 게임 스캐폴딩하기”

워크스페이스가 준비되면 게임의 하위 프로젝트들(Game API, Story Agent, Inventory MCP 서버, 게임 데이터베이스, 웹사이트)과 이들을 연결하는 연결을 스캐폴딩합니다. 두 가지 방법이 있습니다:

  • 빠른 방법 — 아래 다이어그램에서 명령을 직접 복사하여 실행합니다. 동일한 시작점에 도달하는 가장 빠른 방법입니다.
  • 단계별 방법 — 아래 섹션을 펼쳐 각 제너레이터를 직접 실행하고 각각이 생성하는 것을 정확히 확인합니다.

아래 다이어그램은 던전 어드벤처 워크스페이스 그 자체입니다: 이 모듈에서 구축할 모든 프로젝트, 컴포넌트, 연결이 포함되어 있습니다. Copy commands를 눌러 전체 시리즈를 가져온 다음 작업 1에서 생성한 dungeon-adventure 디렉토리 내에서 실행하세요.

Loading the diagram…

단계별 방법: 각 제너레이터를 직접 실행하고 생성되는 것을 확인하기

작업 3: 인프라스트럭처 업데이트

섹션 제목: “작업 3: 인프라스트럭처 업데이트”

생성된 구성 요소 일부를 인스턴스화하기 위해 packages/infra/src/stacks/application-stack.ts를 업데이트합니다:

import {
GameApi,
GameUI,
InventoryMcpServer,
StoryAgent,
UserIdentity,
} from '@dungeon-adventure/common-constructs';
import { Stack, StackProps, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class ApplicationStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const userIdentity = new UserIdentity(this, 'UserIdentity');
const gameApi = new GameApi(this, 'GameApi', {
integrations: GameApi.defaultIntegrations(this).build(),
});
const mcpServer = new InventoryMcpServer(this, 'InventoryMcpServer');
// Use Cognito for user authentication with the agent
const storyAgent = new StoryAgent(this, 'StoryAgent', {
identity: userIdentity,
});
new CfnOutput(this, 'StoryAgentArn', {
value: storyAgent.agentCoreRuntime.agentRuntimeArn,
});
new CfnOutput(this, 'InventoryMcpArn', {
value: mcpServer.agentCoreRuntime.agentRuntimeArn,
});
// Grant the agent permissions to invoke our mcp server
mcpServer.grantInvokeAccess(storyAgent);
// Grant the authenticated role access to invoke the api
gameApi.grantInvokeAccess(userIdentity.identityPool.authenticatedRole);
new GameUI(this, 'GameUI');
}
}
이제 처음으로 코드를 빌드할 시간입니다

명령줄을 사용하여 먼저 린트 문제를 수정하기 위해 다음 명령을 실행합니다:

Terminal window
pnpm lint

그런 다음 전체 빌드를 위해 다음 명령을 실행합니다:

Terminal window
pnpm build

다음과 같은 프롬프트가 표시됩니다:

Terminal window
NX The workspace is out of sync
[@nx/js:typescript-sync]: Some TypeScript configuration files are missing project references to the projects they depend on or contain outdated project references.
This will result in an error in CI.
? Would you like to sync the identified changes to get your workspace up to date?
Yes, sync the changes and run the tasks
No, run the tasks without syncing the changes

이 메시지는 NX가 자동으로 업데이트할 수 있는 일부 파일을 감지했음을 나타냅니다. 이 경우 참조 프로젝트에 대한 TypeScript 참조가 설정되지 않은 tsconfig.json 파일을 가리킵니다.

Yes, sync the changes and run the tasks 옵션을 선택하여 진행합니다. 동기화 생성기가 누락된 TypeScript 참조를 자동으로 추가하므로 모든 IDE 관련 가져오기 오류가 자동으로 해결됩니다!

모든 빌드 아티팩트는 이제 모노레포 루트에 위치한 dist/ 폴더 내에서 사용할 수 있습니다. 이는 @aws/nx-plugin으로 생성된 프로젝트를 사용할 때의 표준 관행으로, 생성된 파일로 파일 트리를 오염시키지 않습니다. 파일을 정리하려는 경우 빌드 아티팩트가 파일 트리 전체에 흩어져 있을 걱정 없이 dist/ 폴더를 삭제하면 됩니다.

축하합니다! AI 던전 어드벤처 게임의 핵심 구현을 시작하는 데 필요한 모든 하위 프로젝트를 생성했습니다. 🎉🎉🎉