콘텐츠로 이동

모노레포 설정하기

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

워크스페이스 생성@aws/nx-workspace

pnpm create @aws/nx-workspace dungeon-adventure --iac=cdk
이 단계의 옵션2

필수

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

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

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

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

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

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

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

Loading the diagram…

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

생성된 구성 중 일부를 인스턴스화하기 위해 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

다음과 같은 메시지가 표시됩니다:

터미널 창
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, contain stale project references, or have duplicate project references.
[@aws/nx-plugin:ts#sync]: Some files are out of sync.
? 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 옵션을 선택하여 진행하세요. sync 제너레이터가 누락된 typescript 참조를 자동으로 추가하면서 IDE 관련 임포트 오류가 자동으로 해결되는 것을 확인할 수 있습니다!

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

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