Skip to content

Commit

Permalink
Windows ユーザーの開発環境のセットアップ手順を更新 (#897)
Browse files Browse the repository at this point in the history
ありがとうございます!
  • Loading branch information
icoxfog417 authored Feb 21, 2025
1 parent b6d0b9d commit dc3ea3c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
12 changes: 11 additions & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ npm run web:devw
> [!TIP]
> バックエンドの環境を切り替えて利用したい際は、cdk.json の context.env を変更するか、`npm run web:devw --env=dev2` のようにコマンドライン引数で指定してください。
### その他のユーザー (Windows 等)
### Windows ユーザー
Windows ユーザー用に開発環境を立ち上げる PowerShell スクリプト `web_devw_win.ps1` を用意しており、`web:devww` から起動できます (`w` が一つ多い)。`setup-env.sh` を PowerShell に置き換えたのに近いスクリプトで、`aws` コマンドは必要ですが `jq` は必要ありません。
```bash
npm run web:devww
```
正常に実行されれば http://localhost:5173 で起動しますので、ブラウザからアクセスしてみてください。AWS のプロファイルは `-profile` で指定できますが、Windows 上で引数を指定する際は `npm run web:devww '--' -profile dev` といったように `--` をシングルクウォートで囲ってください。これは `npm` の既知の不具合になります ([Issue 3136](https://github.com/npm/cli/issues/3136#issuecomment-2632044780))。

### その他のユーザー

手動で環境変数を設定することも可能です。ただし、数が多いため、基本的には前述した `npm run web:devw` の方法を推奨します。
手動で設定する場合は `.env` ファイルを `/packages/web/.env` に作成し、以下のように環境変数を設定してください。
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test": "run-s web:test",
"root:lint": "npx prettier --write .",
"web:devw": "source ./setup-env.sh ${npm_config_env} && VITE_APP_VERSION=${npm_package_version} npm -w packages/web run dev",
"web:devww": "powershell ./web_devw_win.ps1",
"web:dev": "VITE_APP_VERSION=${npm_package_version} npm -w packages/web run dev",
"web:build": "VITE_APP_VERSION=${npm_package_version} npm -w packages/web run build",
"web:lint": "npm -w packages/web run lint",
Expand Down
83 changes: 83 additions & 0 deletions web_devw_win.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Stop on errors
$ErrorActionPreference = "Stop"

# Get environment and profile from command line arguments
[string]$environment = $null
[string]$profile = "default"

# Check if environment was provided as a parameter
for ($i = 0; $i -lt $args.Count; $i++) {
if ($args[$i] -eq "-environment" -or $args[$i] -eq "--environment" -or $args[$i] -eq "-env" -or $args[$i] -eq "--env") {
if ($i + 1 -lt $args.Count) {
$environment = $args[$i + 1]
$i++
}
}
elseif ($args[$i] -eq "-profile" -or $args[$i] -eq "--profile") {
if ($i + 1 -lt $args.Count) {
$profile = $args[$i + 1]
$i++
}
}
}

if ([string]::IsNullOrEmpty($environment)) {
# Parse packages/cdk/cdk.json and get context.env if environment is not provided
Write-Host "No environment provided, using context.env"
Write-Host "If you want to specify the environment, please run with argument -env <env>"
$environment = (Get-Content -Raw -Path "packages/cdk/cdk.json" | ConvertFrom-Json).context.env
}
else {
Write-Host "Using environment: $environment"
}

Write-Host "Using AWS profile: $profile"

$STACK_NAME = "GenerativeAiUseCasesStack$environment"
Write-Host "Using stack output for $STACK_NAME"

function Extract-Value {
param (
[string]$stackOutputJson,
[string]$key
)
return ($stackOutputJson | ConvertFrom-Json).Stacks[0].Outputs |
Where-Object { $_.OutputKey -eq $key } |
Select-Object -ExpandProperty OutputValue
}

# Add the profile parameter to the AWS CLI command
$stack_output = aws cloudformation describe-stacks --stack-name $STACK_NAME --profile $profile --output json

if ($null -eq $stack_output) {
Write-Host "No stack output found for stack: $STACK_NAME. Please check the environment (-env) and profile (-profile) parameters."
exit 1
}

$env:VITE_APP_VERSION= (Get-Content -Raw -Path ".\package.json" | ConvertFrom-Json).version
$env:VITE_APP_API_ENDPOINT = Extract-Value $stack_output "ApiEndpoint"
$env:VITE_APP_REGION = Extract-Value $stack_output "Region"
$env:VITE_APP_USER_POOL_ID = Extract-Value $stack_output "UserPoolId"
$env:VITE_APP_USER_POOL_CLIENT_ID = Extract-Value $stack_output "UserPoolClientId"
$env:VITE_APP_IDENTITY_POOL_ID = Extract-Value $stack_output "IdPoolId"
$env:VITE_APP_PREDICT_STREAM_FUNCTION_ARN = Extract-Value $stack_output "PredictStreamFunctionArn"
$env:VITE_APP_FLOW_STREAM_FUNCTION_ARN = Extract-Value $stack_output "InvokeFlowFunctionArn"
$env:VITE_APP_FLOWS = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($(Extract-Value $stack_output "Flows")))
$env:VITE_APP_RAG_ENABLED = Extract-Value $stack_output "RagEnabled"
$env:VITE_APP_RAG_KNOWLEDGE_BASE_ENABLED = Extract-Value $stack_output "RagKnowledgeBaseEnabled"
$env:VITE_APP_AGENT_ENABLED = Extract-Value $stack_output "AgentEnabled"
$env:VITE_APP_SELF_SIGN_UP_ENABLED = Extract-Value $stack_output "SelfSignUpEnabled"
$env:VITE_APP_MODEL_REGION = Extract-Value $stack_output "ModelRegion"
$env:VITE_APP_MODEL_IDS = Extract-Value $stack_output "ModelIds"
$env:VITE_APP_IMAGE_MODEL_IDS = Extract-Value $stack_output "ImageGenerateModelIds"
$env:VITE_APP_ENDPOINT_NAMES = Extract-Value $stack_output "EndpointNames"
$env:VITE_APP_SAMLAUTH_ENABLED = Extract-Value $stack_output "SamlAuthEnabled"
$env:VITE_APP_SAML_COGNITO_DOMAIN_NAME = Extract-Value $stack_output "SamlCognitoDomainName"
$env:VITE_APP_SAML_COGNITO_FEDERATED_IDENTITY_PROVIDER_NAME = Extract-Value $stack_output "SamlCognitoFederatedIdentityProviderName"
$env:VITE_APP_AGENT_NAMES = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($(Extract-Value $stack_output "AgentNames")))
$env:VITE_APP_INLINE_AGENTS = Extract-Value $stack_output "InlineAgents"
$env:VITE_APP_USE_CASE_BUILDER_ENABLED = Extract-Value $stack_output "UseCaseBuilderEnabled"
$env:VITE_APP_OPTIMIZE_PROMPT_FUNCTION_ARN = Extract-Value $stack_output "OptimizePromptFunctionArn"
$env:VITE_APP_HIDDEN_USE_CASES = Extract-Value $stack_output "HiddenUseCases"

npm -w packages/web run dev

0 comments on commit dc3ea3c

Please sign in to comment.