콘텐츠로 이동

AI 던전 게임

먼저 새로운 모노레포를 생성합니다. 원하는 디렉토리에서 다음 명령어를 실행하세요:

Terminal window
npx create-nx-workspace@~21.0.3 dungeon-adventure --pm=pnpm --preset=@aws/nx-plugin --ci=skip

이 명령어는 dungeon-adventure 디렉토리 내에 NX 모노레포를 설정하며, 이후 vscode에서 열 수 있습니다. 구조는 다음과 같습니다:

  • 디렉터리.nx/
  • 디렉터리.vscode/
  • 디렉터리node_modules/
  • 디렉터리packages/ 하위 프로젝트가 위치할 곳
  • .gitignore
  • .npmrc
  • .prettierignore
  • .prettierrc
  • 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을 사용하여 다양한 하위 프로젝트를 생성할 준비가 되었습니다.

먼저 Game API를 생성합니다. 다음 단계에 따라 GameApi라는 tRPC API를 생성하세요:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#trpc-api
  5. 필수 매개변수 입력
    • name: GameApi
  6. 클릭 Generate

파일 트리에 새로운 파일들이 생성된 것을 확인할 수 있습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

이제 Fast API인 StoryApi를 생성합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - py#fast-api
  5. 필수 매개변수 입력
    • name: StoryApi
    • moduleName: story_api
  6. 클릭 Generate

파일 트리에 새로운 파일들이 생성된 것을 확인할 수 있습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

게임 상호작용용 UI를 생성합니다:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#react-website
  5. 필수 매개변수 입력
    • name: GameUI
  6. 클릭 Generate

파일 트리에 새로운 파일들이 생성되었습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

Amazon Cognito를 통한 인증 설정:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#react-website#auth
  5. 필수 매개변수 입력
    • cognitoDomain: game-ui
    • project: @dungeon-adventure/game-ui
    • allowSignup: true
  6. 클릭 Generate

파일 트리가 업데이트되었습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

Story API 연결 설정:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - api-connection
  5. 필수 매개변수 입력
    • sourceProject: @dungeon-adventure/game-ui
    • targetProject: dungeon_adventure.story_api
  6. 클릭 Generate

파일 트리가 업데이트되었습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

Game API 연결 설정:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - api-connection
  5. 필수 매개변수 입력
    • sourceProject: @dungeon-adventure/game-ui
    • targetProject: @dungeon-adventure/game-api
  6. 클릭 Generate

파일 트리가 업데이트되었습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

CDK 인프라 프로젝트 생성:

  1. 설치 Nx Console VSCode Plugin 아직 설치하지 않았다면
  2. VSCode에서 Nx 콘솔 열기
  3. 클릭 Generate (UI) "Common Nx Commands" 섹션에서
  4. 검색 @aws/nx-plugin - ts#infra
  5. 필수 매개변수 입력
    • name: infra
  6. 클릭 Generate

파일 트리가 업데이트되었습니다.

자세한 내용을 확인하려면 여기를 클릭하세요.

packages/infra/src/stacks/application-stack.ts를 업데이트하여 생성된 컨스트럭트를 인스턴스화합니다:

import {
GameApi,
GameUI,
StoryApi,
UserIdentity,
} from ':dungeon-adventure/common-constructs';
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class ApplicationStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
const userIdentity = new UserIdentity(this, 'UserIdentity');
const gameApi = new GameApi(this, 'GameApi', {
integrations: GameApi.defaultIntegrations(this).build(),
});
const storyApi = new StoryApi(this, 'StoryApi', {
integrations: StoryApi.defaultIntegrations(this).build(),
});
// grant our authenticated role access to invoke our APIs
[storyApi, gameApi].forEach((api) =>
api.grantInvokeAccess(userIdentity.identityPool.authenticatedRole),
);
// Ensure this is instantiated last so our runtime-config.json can be automatically configured
new GameUI(this, 'GameUI');
}
}

기본 통합을 사용하여 각 API 작업에 개별 람다 함수가 매핑됩니다.

이제 첫 빌드를 실행합니다
Terminal window
pnpm nx run-many --target build --all

프롬프트에서 Yes, sync the changes and run the tasks를 선택하여 타입스크립트 참조를 동기화합니다.

모든 빌드 아티팩트는 dist/ 폴더에 생성됩니다. 축하합니다! 던전 어드벤처 게임 코어 구현을 시작할 준비가 완료되었습니다. 🎉🎉🎉