create-einja-app 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1041 -0
- package/dist/cli.js.map +1 -0
- package/package.json +62 -0
- package/templates/turborepo-pandacss/.biomeignore +15 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/biome-format.sh +49 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/design-doc-check.sh +61 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/detect-secrets.sh +62 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/large-file-warning.sh +42 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/playwright-resize.sh +36 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/typecheck.sh +37 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/unset-volta-recursion.sh +32 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/validate-git-commit.sh +239 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/warn-index-ts.sh +34 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/warn-relative-import.sh +48 -0
- package/templates/turborepo-pandacss/.claude/settings.json +174 -0
- package/templates/turborepo-pandacss/.claude/skills/create-einja-app-release/SKILL.md +186 -0
- package/templates/turborepo-pandacss/.claude/skills/dev-cli-release/SKILL.md +173 -0
- package/templates/turborepo-pandacss/.cursor/commands/spec-create.md +227 -0
- package/templates/turborepo-pandacss/.cursor/commands/start-dev.md +98 -0
- package/templates/turborepo-pandacss/.cursor/commands/task-exec.md +287 -0
- package/templates/turborepo-pandacss/.cursor/commands/task-vibe-kanban-loop.md +532 -0
- package/templates/turborepo-pandacss/.cursor/commands/update-docs-by-task-specs.md +448 -0
- package/templates/turborepo-pandacss/.cursor/mcp.json +45 -0
- package/templates/turborepo-pandacss/.cursor/rules/api-rules.mdc +171 -0
- package/templates/turborepo-pandacss/.cursor/rules/api-test-rules.mdc +181 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-code.mdc +70 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-commit-rules.mdc +174 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-design.mdc +12 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-rules.mdc +231 -0
- package/templates/turborepo-pandacss/.cursor/rules/error-handling-rules.mdc +188 -0
- package/templates/turborepo-pandacss/.cursor/rules/refactor-rules.mdc +93 -0
- package/templates/turborepo-pandacss/.dockerignore +126 -0
- package/templates/turborepo-pandacss/.einja-sync.json +35 -0
- package/templates/turborepo-pandacss/.env.ci +25 -0
- package/templates/turborepo-pandacss/.env.example +35 -0
- package/templates/turborepo-pandacss/.env.personal.example +27 -0
- package/templates/turborepo-pandacss/.envrc +4 -0
- package/templates/turborepo-pandacss/.gitattributes +5 -0
- package/templates/turborepo-pandacss/.husky/pre-commit +1 -0
- package/templates/turborepo-pandacss/.lintstagedrc.js +24 -0
- package/templates/turborepo-pandacss/.mcp.json +45 -0
- package/templates/turborepo-pandacss/.node-version +1 -0
- package/templates/turborepo-pandacss/.templateignore +60 -0
- package/templates/turborepo-pandacss/.vscode/extensions.json +3 -0
- package/templates/turborepo-pandacss/CLAUDE.md +415 -0
- package/templates/turborepo-pandacss/README.md +322 -0
- package/templates/turborepo-pandacss/apps/web/middleware.ts +28 -0
- package/templates/turborepo-pandacss/apps/web/next.config.ts +10 -0
- package/templates/turborepo-pandacss/apps/web/package.json +80 -0
- package/templates/turborepo-pandacss/apps/web/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/apps/web/postcss.config.cjs +6 -0
- package/templates/turborepo-pandacss/apps/web/public/file.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/globe.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/next.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/vercel.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/window.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/dashboard/page.tsx +79 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/data/_components/UserTable.tsx +203 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/data/page.tsx +57 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/layout-client.tsx +31 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/layout.tsx +17 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/profile/page.tsx +59 -0
- package/templates/turborepo-pandacss/apps/web/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/templates/turborepo-pandacss/apps/web/src/app/api/auth/signup/route.ts +70 -0
- package/templates/turborepo-pandacss/apps/web/src/app/error.tsx +106 -0
- package/templates/turborepo-pandacss/apps/web/src/app/favicon.ico +0 -0
- package/templates/turborepo-pandacss/apps/web/src/app/global-error.tsx +110 -0
- package/templates/turborepo-pandacss/apps/web/src/app/globals.css +121 -0
- package/templates/turborepo-pandacss/apps/web/src/app/layout.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/app/not-found.tsx +54 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.module.css +165 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.test.tsx +52 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.tsx +284 -0
- package/templates/turborepo-pandacss/apps/web/src/app/signin/page.tsx +296 -0
- package/templates/turborepo-pandacss/apps/web/src/app/signup/page.tsx +395 -0
- package/templates/turborepo-pandacss/apps/web/src/application/use-cases/UserUseCases.test.ts +229 -0
- package/templates/turborepo-pandacss/apps/web/src/application/use-cases/UserUseCases.ts +115 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/login-button.tsx +35 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/logout-button.tsx +24 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/user-avatar.test.tsx +68 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/user-avatar.tsx +43 -0
- package/templates/turborepo-pandacss/apps/web/src/components/dashboard/dashboard-stats.tsx +128 -0
- package/templates/turborepo-pandacss/apps/web/src/components/providers/query-provider.tsx +30 -0
- package/templates/turborepo-pandacss/apps/web/src/components/providers/session-provider.tsx +12 -0
- package/templates/turborepo-pandacss/apps/web/src/components/shared/Sidebar.tsx +175 -0
- package/templates/turborepo-pandacss/apps/web/src/components/shared/header.tsx +166 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/accordion.tsx +64 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/alert-dialog.tsx +135 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/alert.tsx +60 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/aspect-ratio.tsx +9 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/avatar.tsx +41 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/badge.tsx +39 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/breadcrumb.tsx +101 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/button.tsx +56 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/card.tsx +75 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/checkbox.tsx +29 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/data-table.tsx +189 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dialog-hook.tsx +210 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dialog.tsx +129 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/drawer.tsx +124 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dropdown-menu.tsx +228 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/form.tsx +152 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/hover-card.tsx +38 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/input.tsx +21 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/label.tsx +21 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/pagination.tsx +105 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/popover.tsx +42 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/progress.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/select.tsx +170 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/separator.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/skeleton.tsx +13 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/sonner.tsx +25 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/table.tsx +92 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/tabs.tsx +54 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/textarea.tsx +18 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/tooltip.tsx +57 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/typography.tsx +158 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/auth/guard.ts +36 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/auth/index.ts +22 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/prisma.ts +3 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/utils.ts +6 -0
- package/templates/turborepo-pandacss/apps/web/test/globals.d.ts +1 -0
- package/templates/turborepo-pandacss/apps/web/test/matchers.d.ts +1 -0
- package/templates/turborepo-pandacss/apps/web/test/setup.ts +22 -0
- package/templates/turborepo-pandacss/apps/web/tsconfig.json +37 -0
- package/templates/turborepo-pandacss/apps/web/vitest.config.ts +20 -0
- package/templates/turborepo-pandacss/apps/web/vitest.d.ts +2 -0
- package/templates/turborepo-pandacss/biome.json +60 -0
- package/templates/turborepo-pandacss/components.json +21 -0
- package/templates/turborepo-pandacss/docker-compose.yml +27 -0
- package/templates/turborepo-pandacss/middleware.ts +32 -0
- package/templates/turborepo-pandacss/next.config.ts +10 -0
- package/templates/turborepo-pandacss/package-lock.json +9346 -0
- package/templates/turborepo-pandacss/package.json +64 -0
- package/templates/turborepo-pandacss/packages/config/package.json +41 -0
- package/templates/turborepo-pandacss/packages/config/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/packages/config/src/index.ts +24 -0
- package/templates/turborepo-pandacss/packages/config/src/worktree-config-loader.ts +129 -0
- package/templates/turborepo-pandacss/packages/config/src/worktree-config.ts +75 -0
- package/templates/turborepo-pandacss/packages/config/tsconfig.build.json +19 -0
- package/templates/turborepo-pandacss/packages/config/tsconfig.json +24 -0
- package/templates/turborepo-pandacss/packages/config/typescript/base.json +19 -0
- package/templates/turborepo-pandacss/packages/front-core/package.json +24 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/config.ts +84 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/index.ts +5 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/types/next-auth.d.ts +20 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/utils.ts +29 -0
- package/templates/turborepo-pandacss/packages/front-core/src/context/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/src/hooks/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/src/index.ts +4 -0
- package/templates/turborepo-pandacss/packages/front-core/src/utils/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/tsconfig.json +14 -0
- package/templates/turborepo-pandacss/packages/server-core/package.json +32 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma/schema.prisma +102 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma/seed.ts +67 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma.config.ts +8 -0
- package/templates/turborepo-pandacss/packages/server-core/src/__generated__/fabbrica/index.d.ts +270 -0
- package/templates/turborepo-pandacss/packages/server-core/src/__generated__/fabbrica/index.js +484 -0
- package/templates/turborepo-pandacss/packages/server-core/src/core/result.test.ts +78 -0
- package/templates/turborepo-pandacss/packages/server-core/src/core/result.ts +53 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/.gitkeep +0 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/entities/User.test.ts +232 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/entities/User.ts +105 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/repository-interfaces/IUserRepository.ts +101 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/client.ts +15 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/mappers/UserMapper.test.ts +278 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/mappers/UserMapper.ts +103 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/repositories/UserRepository.test.ts +317 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/repositories/UserRepository.ts +169 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/factories/index.ts +22 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/factories/user.factory.ts +123 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/fixtures/users.ts +92 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/helpers/date.ts +49 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/helpers/password.ts +50 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/index.ts +26 -0
- package/templates/turborepo-pandacss/packages/server-core/tsconfig.json +14 -0
- package/templates/turborepo-pandacss/packages/server-core/vitest.config.ts +15 -0
- package/templates/turborepo-pandacss/packages/ui/package.json +37 -0
- package/templates/turborepo-pandacss/packages/ui/src/accordion.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/alert-dialog.tsx +157 -0
- package/templates/turborepo-pandacss/packages/ui/src/alert.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/aspect-ratio.tsx +11 -0
- package/templates/turborepo-pandacss/packages/ui/src/avatar.tsx +53 -0
- package/templates/turborepo-pandacss/packages/ui/src/badge.tsx +46 -0
- package/templates/turborepo-pandacss/packages/ui/src/breadcrumb.tsx +108 -0
- package/templates/turborepo-pandacss/packages/ui/src/button.tsx +59 -0
- package/templates/turborepo-pandacss/packages/ui/src/card.tsx +92 -0
- package/templates/turborepo-pandacss/packages/ui/src/checkbox.tsx +32 -0
- package/templates/turborepo-pandacss/packages/ui/src/data-table.tsx +216 -0
- package/templates/turborepo-pandacss/packages/ui/src/dialog-hook.tsx +226 -0
- package/templates/turborepo-pandacss/packages/ui/src/dialog.tsx +143 -0
- package/templates/turborepo-pandacss/packages/ui/src/drawer.tsx +135 -0
- package/templates/turborepo-pandacss/packages/ui/src/dropdown-menu.tsx +257 -0
- package/templates/turborepo-pandacss/packages/ui/src/form.tsx +168 -0
- package/templates/turborepo-pandacss/packages/ui/src/hover-card.tsx +44 -0
- package/templates/turborepo-pandacss/packages/ui/src/input.tsx +21 -0
- package/templates/turborepo-pandacss/packages/ui/src/label.tsx +24 -0
- package/templates/turborepo-pandacss/packages/ui/src/lib/utils.ts +6 -0
- package/templates/turborepo-pandacss/packages/ui/src/pagination.tsx +126 -0
- package/templates/turborepo-pandacss/packages/ui/src/popover.tsx +48 -0
- package/templates/turborepo-pandacss/packages/ui/src/progress.tsx +31 -0
- package/templates/turborepo-pandacss/packages/ui/src/select.tsx +185 -0
- package/templates/turborepo-pandacss/packages/ui/src/separator.tsx +28 -0
- package/templates/turborepo-pandacss/packages/ui/src/skeleton.tsx +13 -0
- package/templates/turborepo-pandacss/packages/ui/src/sonner.tsx +25 -0
- package/templates/turborepo-pandacss/packages/ui/src/table.tsx +116 -0
- package/templates/turborepo-pandacss/packages/ui/src/tabs.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/textarea.tsx +18 -0
- package/templates/turborepo-pandacss/packages/ui/src/tooltip.tsx +61 -0
- package/templates/turborepo-pandacss/packages/ui/src/typography.tsx +187 -0
- package/templates/turborepo-pandacss/packages/ui/tsconfig.json +20 -0
- package/templates/turborepo-pandacss/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/pnpm-lock.yaml +9032 -0
- package/templates/turborepo-pandacss/pnpm-workspace.yaml +11 -0
- package/templates/turborepo-pandacss/postcss.config.cjs +6 -0
- package/templates/turborepo-pandacss/prisma/schema.prisma +82 -0
- package/templates/turborepo-pandacss/public/file.svg +1 -0
- package/templates/turborepo-pandacss/public/globe.svg +1 -0
- package/templates/turborepo-pandacss/public/next.svg +1 -0
- package/templates/turborepo-pandacss/public/vercel.svg +1 -0
- package/templates/turborepo-pandacss/public/window.svg +1 -0
- package/templates/turborepo-pandacss/scripts/cli-template-update.ts +387 -0
- package/templates/turborepo-pandacss/scripts/env-show.ts +129 -0
- package/templates/turborepo-pandacss/scripts/env.ts +555 -0
- package/templates/turborepo-pandacss/scripts/init.sh +92 -0
- package/templates/turborepo-pandacss/scripts/setup-dev.ts +640 -0
- package/templates/turborepo-pandacss/scripts/template-update.ts +277 -0
- package/templates/turborepo-pandacss/scripts/worktree/dev.ts +872 -0
- package/templates/turborepo-pandacss/test/globals.d.ts +1 -0
- package/templates/turborepo-pandacss/test/setup.ts +22 -0
- package/templates/turborepo-pandacss/tsconfig.json +46 -0
- package/templates/turborepo-pandacss/turbo.json +57 -0
- package/templates/turborepo-pandacss/vitest.config.ts +20 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 環境変数設定ウィザード
|
|
3
|
+
*
|
|
4
|
+
* 対話的に環境変数を設定・更新するCLIツール
|
|
5
|
+
* 使用方法: pnpm env
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { execSync } from "node:child_process";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import * as p from "@clack/prompts";
|
|
12
|
+
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
|
|
15
|
+
// ファイルパス
|
|
16
|
+
const ENV_PATH = path.join(cwd, ".env");
|
|
17
|
+
const ENV_LOCAL_PATH = path.join(cwd, ".env.local");
|
|
18
|
+
const ENV_PERSONAL_PATH = path.join(cwd, ".env.personal");
|
|
19
|
+
const ENV_PERSONAL_EXAMPLE_PATH = path.join(cwd, ".env.personal.example");
|
|
20
|
+
const ENV_KEYS_PATH = path.join(cwd, ".env.keys");
|
|
21
|
+
|
|
22
|
+
// 環境定義
|
|
23
|
+
interface EnvironmentConfig {
|
|
24
|
+
name: string;
|
|
25
|
+
file: string;
|
|
26
|
+
privateKeyEnv: string;
|
|
27
|
+
description: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ENVIRONMENTS: EnvironmentConfig[] = [
|
|
31
|
+
{
|
|
32
|
+
name: "local",
|
|
33
|
+
file: ".env.local",
|
|
34
|
+
privateKeyEnv: "DOTENV_PRIVATE_KEY_LOCAL",
|
|
35
|
+
description: "ローカル開発環境",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "development",
|
|
39
|
+
file: ".env.development",
|
|
40
|
+
privateKeyEnv: "DOTENV_PRIVATE_KEY_DEVELOPMENT",
|
|
41
|
+
description: "開発環境",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "staging",
|
|
45
|
+
file: ".env.staging",
|
|
46
|
+
privateKeyEnv: "DOTENV_PRIVATE_KEY_STAGING",
|
|
47
|
+
description: "ステージング環境",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "production",
|
|
51
|
+
file: ".env.production",
|
|
52
|
+
privateKeyEnv: "DOTENV_PRIVATE_KEY_PRODUCTION",
|
|
53
|
+
description: "本番環境",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "ci",
|
|
57
|
+
file: ".env.ci",
|
|
58
|
+
privateKeyEnv: "DOTENV_PRIVATE_KEY_CI",
|
|
59
|
+
description: "CI環境",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 環境変数ファイルを読み込んでパース
|
|
65
|
+
*/
|
|
66
|
+
function parseEnvFile(filePath: string): Record<string, string> {
|
|
67
|
+
if (!fs.existsSync(filePath)) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
71
|
+
const result: Record<string, string> = {};
|
|
72
|
+
|
|
73
|
+
for (const line of content.split("\n")) {
|
|
74
|
+
const trimmed = line.trim();
|
|
75
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
76
|
+
|
|
77
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
78
|
+
if (match) {
|
|
79
|
+
const key = match[1].trim();
|
|
80
|
+
let value = match[2].trim();
|
|
81
|
+
// クォートを除去
|
|
82
|
+
if (
|
|
83
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
84
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
85
|
+
) {
|
|
86
|
+
value = value.slice(1, -1);
|
|
87
|
+
}
|
|
88
|
+
result[key] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 環境変数ファイルに値を設定
|
|
96
|
+
*/
|
|
97
|
+
function setEnvValue(filePath: string, key: string, value: string): void {
|
|
98
|
+
let content = "";
|
|
99
|
+
if (fs.existsSync(filePath)) {
|
|
100
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const regex = new RegExp(`^${key}=.*$`, "m");
|
|
104
|
+
if (regex.test(content)) {
|
|
105
|
+
content = content.replace(regex, `${key}=${value}`);
|
|
106
|
+
} else {
|
|
107
|
+
content = content.trim() + `\n${key}=${value}\n`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
fs.writeFileSync(filePath, content);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 現在の環境変数の状態を表示
|
|
115
|
+
*/
|
|
116
|
+
function showStatus(): void {
|
|
117
|
+
p.note(
|
|
118
|
+
[
|
|
119
|
+
"📁 ファイル状態:",
|
|
120
|
+
` .env : ${fs.existsSync(ENV_PATH) ? "✅ 存在" : "❌ なし"}`,
|
|
121
|
+
` .env.local : ${fs.existsSync(ENV_LOCAL_PATH) ? "✅ 存在" : "❌ なし"}`,
|
|
122
|
+
` .env.personal : ${fs.existsSync(ENV_PERSONAL_PATH) ? "✅ 存在" : "❌ なし"}`,
|
|
123
|
+
` .env.keys : ${fs.existsSync(ENV_KEYS_PATH) ? "✅ 存在" : "❌ なし"}`,
|
|
124
|
+
"",
|
|
125
|
+
"🔑 主要な環境変数:",
|
|
126
|
+
].join("\n"),
|
|
127
|
+
"環境変数の状態"
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const envPersonal = parseEnvFile(ENV_PERSONAL_PATH);
|
|
131
|
+
const env = parseEnvFile(ENV_PATH);
|
|
132
|
+
|
|
133
|
+
const checkVars = [
|
|
134
|
+
{ key: "GITHUB_TOKEN", file: ".env.personal" },
|
|
135
|
+
{ key: "DATABASE_URL", file: ".env" },
|
|
136
|
+
{ key: "AUTH_SECRET", file: ".env" },
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
for (const { key, file } of checkVars) {
|
|
140
|
+
const value = file === ".env.personal" ? envPersonal[key] : env[key];
|
|
141
|
+
const status = value ? "✅ 設定済み" : "❌ 未設定";
|
|
142
|
+
const masked = value ? `${value.slice(0, 8)}...` : "-";
|
|
143
|
+
console.log(` ${key}: ${status} (${masked})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 個人トークンを設定
|
|
149
|
+
*/
|
|
150
|
+
async function setupPersonalTokens(): Promise<void> {
|
|
151
|
+
// .env.personal がなければ作成
|
|
152
|
+
if (!fs.existsSync(ENV_PERSONAL_PATH)) {
|
|
153
|
+
if (fs.existsSync(ENV_PERSONAL_EXAMPLE_PATH)) {
|
|
154
|
+
fs.copyFileSync(ENV_PERSONAL_EXAMPLE_PATH, ENV_PERSONAL_PATH);
|
|
155
|
+
p.log.success(".env.personal を作成しました");
|
|
156
|
+
} else {
|
|
157
|
+
fs.writeFileSync(ENV_PERSONAL_PATH, "# 個人用トークン\n");
|
|
158
|
+
p.log.success(".env.personal を新規作成しました");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const current = parseEnvFile(ENV_PERSONAL_PATH);
|
|
163
|
+
|
|
164
|
+
// GITHUB_TOKEN
|
|
165
|
+
const currentGithubToken = current.GITHUB_TOKEN;
|
|
166
|
+
const githubTokenStatus = currentGithubToken
|
|
167
|
+
? `現在: ${currentGithubToken.slice(0, 8)}...`
|
|
168
|
+
: "未設定";
|
|
169
|
+
|
|
170
|
+
const updateGithubToken = await p.confirm({
|
|
171
|
+
message: `GITHUB_TOKEN を設定しますか? (${githubTokenStatus})`,
|
|
172
|
+
initialValue: !currentGithubToken,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (p.isCancel(updateGithubToken)) {
|
|
176
|
+
p.cancel("キャンセルしました");
|
|
177
|
+
process.exit(0);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (updateGithubToken) {
|
|
181
|
+
p.log.info("GitHub Personal Access Token を入力してください");
|
|
182
|
+
p.log.info("取得方法: https://github.com/settings/tokens/new");
|
|
183
|
+
p.log.info("必要なスコープ: repo, read:org");
|
|
184
|
+
|
|
185
|
+
const token = await p.password({
|
|
186
|
+
message: "GITHUB_TOKEN:",
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (p.isCancel(token)) {
|
|
190
|
+
p.cancel("キャンセルしました");
|
|
191
|
+
process.exit(0);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (token) {
|
|
195
|
+
setEnvValue(ENV_PERSONAL_PATH, "GITHUB_TOKEN", token);
|
|
196
|
+
p.log.success("GITHUB_TOKEN を設定しました");
|
|
197
|
+
|
|
198
|
+
// トークンの検証を試みる
|
|
199
|
+
try {
|
|
200
|
+
const result = execSync(
|
|
201
|
+
`curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token ${token}" https://api.github.com/user`,
|
|
202
|
+
{ encoding: "utf-8" }
|
|
203
|
+
).trim();
|
|
204
|
+
if (result === "200") {
|
|
205
|
+
p.log.success("✅ トークンの検証に成功しました");
|
|
206
|
+
} else {
|
|
207
|
+
p.log.warn(`⚠️ トークンの検証に失敗しました (HTTP ${result})`);
|
|
208
|
+
}
|
|
209
|
+
} catch {
|
|
210
|
+
p.log.warn("⚠️ トークンの検証をスキップしました");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 他のトークン(オプション)
|
|
216
|
+
const addMore = await p.confirm({
|
|
217
|
+
message: "他のトークンも設定しますか? (OPENAI_API_KEY, ANTHROPIC_API_KEY等)",
|
|
218
|
+
initialValue: false,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
if (p.isCancel(addMore)) {
|
|
222
|
+
p.cancel("キャンセルしました");
|
|
223
|
+
process.exit(0);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (addMore) {
|
|
227
|
+
const keyName = await p.text({
|
|
228
|
+
message: "環境変数名を入力:",
|
|
229
|
+
placeholder: "OPENAI_API_KEY",
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (p.isCancel(keyName) || !keyName) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const keyValue = await p.password({
|
|
237
|
+
message: `${keyName}:`,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (p.isCancel(keyValue)) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (keyValue) {
|
|
245
|
+
setEnvValue(ENV_PERSONAL_PATH, keyName, keyValue);
|
|
246
|
+
p.log.success(`${keyName} を設定しました`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
p.note(
|
|
251
|
+
"direnv allow を実行するか、新しいターミナルを開くと反映されます",
|
|
252
|
+
"💡 次のステップ"
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* .env.keysから指定された環境の秘密鍵を取得
|
|
258
|
+
*/
|
|
259
|
+
function getPrivateKey(privateKeyEnv: string): string | null {
|
|
260
|
+
if (!fs.existsSync(ENV_KEYS_PATH)) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const keys = parseEnvFile(ENV_KEYS_PATH);
|
|
264
|
+
return keys[privateKeyEnv] || null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 環境設定を変更(汎用)
|
|
269
|
+
*/
|
|
270
|
+
async function updateEnvironmentSettings(env: EnvironmentConfig): Promise<void> {
|
|
271
|
+
const envFilePath = path.join(cwd, env.file);
|
|
272
|
+
|
|
273
|
+
if (!fs.existsSync(envFilePath)) {
|
|
274
|
+
p.log.error(`${env.file} が見つかりません`);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (!fs.existsSync(ENV_KEYS_PATH)) {
|
|
279
|
+
p.log.error(".env.keys が見つかりません(秘密鍵が必要です)");
|
|
280
|
+
p.log.info("チームから .env.keys を共有してもらってください");
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const privateKey = getPrivateKey(env.privateKeyEnv);
|
|
285
|
+
if (!privateKey) {
|
|
286
|
+
p.log.error(`.env.keys に ${env.privateKeyEnv} が見つかりません`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 本番環境の場合は追加確認
|
|
291
|
+
if (env.name === "production") {
|
|
292
|
+
p.log.warn("⚠️ 本番環境の設定を変更しようとしています");
|
|
293
|
+
const confirmProd = await p.confirm({
|
|
294
|
+
message: "本当に本番環境の設定を変更しますか?",
|
|
295
|
+
initialValue: false,
|
|
296
|
+
});
|
|
297
|
+
if (p.isCancel(confirmProd) || !confirmProd) {
|
|
298
|
+
p.cancel("キャンセルしました");
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
p.note(
|
|
304
|
+
[
|
|
305
|
+
`${env.description}(${env.file})を変更します。`,
|
|
306
|
+
"",
|
|
307
|
+
"手順:",
|
|
308
|
+
`1. ${env.file} を復号`,
|
|
309
|
+
"2. エディタで編集",
|
|
310
|
+
"3. 再暗号化",
|
|
311
|
+
"4. git commit & push",
|
|
312
|
+
].join("\n"),
|
|
313
|
+
`📝 ${env.description}の変更`
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const proceed = await p.confirm({
|
|
317
|
+
message: "続行しますか?",
|
|
318
|
+
initialValue: true,
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
if (p.isCancel(proceed) || !proceed) {
|
|
322
|
+
p.cancel("キャンセルしました");
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const spinner = p.spinner();
|
|
327
|
+
const tmpPath = path.join(cwd, `${env.file}.tmp`);
|
|
328
|
+
const backupPath = path.join(cwd, `${env.file}.bak`);
|
|
329
|
+
|
|
330
|
+
// dotenvx実行時の環境変数
|
|
331
|
+
const dotenvxEnv = { ...process.env, [env.privateKeyEnv]: privateKey };
|
|
332
|
+
|
|
333
|
+
try {
|
|
334
|
+
// 1. 復号
|
|
335
|
+
spinner.start(`${env.file} を復号中...`);
|
|
336
|
+
const decrypted = execSync(`dotenvx decrypt -f ${env.file} --stdout`, {
|
|
337
|
+
cwd,
|
|
338
|
+
encoding: "utf-8",
|
|
339
|
+
env: dotenvxEnv,
|
|
340
|
+
});
|
|
341
|
+
fs.writeFileSync(tmpPath, decrypted);
|
|
342
|
+
spinner.stop(`${env.file} を復号しました`);
|
|
343
|
+
|
|
344
|
+
// 2. エディタで開く
|
|
345
|
+
const editor = process.env.EDITOR || "vi";
|
|
346
|
+
|
|
347
|
+
// vi/vimの場合はファイル先頭に使い方ヘルプをコメントとして追加
|
|
348
|
+
const vimHelpMarker = "# === ↓↓↓ ここから下を編集(この行より上は保存時に自動削除)↓↓↓ ===";
|
|
349
|
+
if (editor === "vi" || editor === "vim") {
|
|
350
|
+
const vimHelp = `# ┌─────────────────────────────────────────────────┐
|
|
351
|
+
# │ vi/vim の基本操作 │
|
|
352
|
+
# ├─────────────────────────────────────────────────┤
|
|
353
|
+
# │ 【編集モードに入る】 │
|
|
354
|
+
# │ i ... カーソル位置から入力開始 │
|
|
355
|
+
# │ a ... カーソルの次の位置から入力開始 │
|
|
356
|
+
# │ o ... 次の行に新しい行を挿入して入力開始 │
|
|
357
|
+
# │ │
|
|
358
|
+
# │ 【編集モードから出る】 │
|
|
359
|
+
# │ Esc ... ノーマルモードに戻る │
|
|
360
|
+
# │ │
|
|
361
|
+
# │ 【保存・終了】(Escを押してから) │
|
|
362
|
+
# │ :wq ... 保存して終了 │
|
|
363
|
+
# │ :w ... 保存のみ │
|
|
364
|
+
# │ :q! ... 保存せず強制終了 │
|
|
365
|
+
# │ │
|
|
366
|
+
# │ 【カーソル移動】 │
|
|
367
|
+
# │ h j k l または 矢印キー │
|
|
368
|
+
# └─────────────────────────────────────────────────┘
|
|
369
|
+
${vimHelpMarker}
|
|
370
|
+
|
|
371
|
+
`;
|
|
372
|
+
const currentContent = fs.readFileSync(tmpPath, "utf-8");
|
|
373
|
+
fs.writeFileSync(tmpPath, vimHelp + currentContent);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
p.log.info(`${editor} で ${env.file}.tmp を開きます...`);
|
|
377
|
+
|
|
378
|
+
execSync(`${editor} ${env.file}.tmp`, {
|
|
379
|
+
cwd,
|
|
380
|
+
stdio: "inherit",
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// 3. 編集確認
|
|
384
|
+
const confirmSave = await p.confirm({
|
|
385
|
+
message: "変更を保存しますか?",
|
|
386
|
+
initialValue: true,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
if (p.isCancel(confirmSave) || !confirmSave) {
|
|
390
|
+
fs.unlinkSync(tmpPath);
|
|
391
|
+
p.log.info("変更をキャンセルしました");
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 4. バックアップ作成 → リネーム → 再暗号化
|
|
396
|
+
spinner.start("再暗号化中...");
|
|
397
|
+
|
|
398
|
+
// vi/vimヘルプコメントを削除(ファイル先頭から)
|
|
399
|
+
if (editor === "vi" || editor === "vim") {
|
|
400
|
+
let content = fs.readFileSync(tmpPath, "utf-8");
|
|
401
|
+
const markerIndex = content.indexOf(vimHelpMarker);
|
|
402
|
+
if (markerIndex !== -1) {
|
|
403
|
+
// マーカー行の次の改行以降を残す
|
|
404
|
+
const afterMarker = markerIndex + vimHelpMarker.length;
|
|
405
|
+
content = content.substring(afterMarker).replace(/^\n+/, "");
|
|
406
|
+
}
|
|
407
|
+
fs.writeFileSync(tmpPath, content);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// 元のファイルをバックアップ
|
|
411
|
+
fs.copyFileSync(envFilePath, backupPath);
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
// テンポラリファイルを元のファイルにリネーム
|
|
415
|
+
fs.unlinkSync(envFilePath);
|
|
416
|
+
fs.renameSync(tmpPath, envFilePath);
|
|
417
|
+
|
|
418
|
+
// 暗号化
|
|
419
|
+
execSync(`dotenvx encrypt -f ${env.file}`, {
|
|
420
|
+
cwd,
|
|
421
|
+
stdio: "pipe",
|
|
422
|
+
env: dotenvxEnv,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// 成功したらバックアップを削除
|
|
426
|
+
fs.unlinkSync(backupPath);
|
|
427
|
+
spinner.stop("再暗号化が完了しました");
|
|
428
|
+
} catch (encryptError) {
|
|
429
|
+
// 暗号化失敗時はバックアップから復元
|
|
430
|
+
spinner.stop("暗号化に失敗しました");
|
|
431
|
+
if (fs.existsSync(backupPath)) {
|
|
432
|
+
fs.copyFileSync(backupPath, envFilePath);
|
|
433
|
+
fs.unlinkSync(backupPath);
|
|
434
|
+
p.log.info("元のファイルを復元しました");
|
|
435
|
+
}
|
|
436
|
+
throw encryptError;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
p.note(
|
|
440
|
+
[
|
|
441
|
+
`git add ${env.file}`,
|
|
442
|
+
`git commit -m "chore: ${env.description}設定を更新"`,
|
|
443
|
+
"git push",
|
|
444
|
+
"",
|
|
445
|
+
env.name === "local"
|
|
446
|
+
? "チームメンバーは git pull 後に pnpm dev:setup で反映"
|
|
447
|
+
: "変更はデプロイ時に反映されます",
|
|
448
|
+
].join("\n"),
|
|
449
|
+
"💡 次のステップ"
|
|
450
|
+
);
|
|
451
|
+
} catch (error) {
|
|
452
|
+
spinner.stop("エラーが発生しました");
|
|
453
|
+
// テンポラリファイルを削除
|
|
454
|
+
if (fs.existsSync(tmpPath)) {
|
|
455
|
+
fs.unlinkSync(tmpPath);
|
|
456
|
+
}
|
|
457
|
+
// バックアップも削除
|
|
458
|
+
if (fs.existsSync(backupPath)) {
|
|
459
|
+
fs.unlinkSync(backupPath);
|
|
460
|
+
}
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* 環境選択メニューを表示
|
|
467
|
+
*/
|
|
468
|
+
async function selectEnvironment(): Promise<void> {
|
|
469
|
+
// 利用可能な環境をチェック
|
|
470
|
+
const availableEnvs = ENVIRONMENTS.filter((env) => {
|
|
471
|
+
const envFilePath = path.join(cwd, env.file);
|
|
472
|
+
const hasFile = fs.existsSync(envFilePath);
|
|
473
|
+
const hasKey = getPrivateKey(env.privateKeyEnv) !== null;
|
|
474
|
+
return hasFile && hasKey;
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
if (availableEnvs.length === 0) {
|
|
478
|
+
p.log.error("編集可能な環境がありません");
|
|
479
|
+
p.log.info("環境ファイルと秘密鍵が必要です");
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const envOptions = availableEnvs.map((env) => ({
|
|
484
|
+
value: env.name,
|
|
485
|
+
label: env.description,
|
|
486
|
+
hint: env.file,
|
|
487
|
+
}));
|
|
488
|
+
|
|
489
|
+
const selectedEnv = await p.select({
|
|
490
|
+
message: "編集する環境を選択してください",
|
|
491
|
+
options: envOptions,
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
if (p.isCancel(selectedEnv)) {
|
|
495
|
+
p.cancel("キャンセルしました");
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const env = ENVIRONMENTS.find((e) => e.name === selectedEnv);
|
|
500
|
+
if (env) {
|
|
501
|
+
await updateEnvironmentSettings(env);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* メイン処理
|
|
507
|
+
*/
|
|
508
|
+
async function main(): Promise<void> {
|
|
509
|
+
p.intro("🔧 環境変数設定ウィザード");
|
|
510
|
+
|
|
511
|
+
const action = await p.select({
|
|
512
|
+
message: "何をしますか?",
|
|
513
|
+
options: [
|
|
514
|
+
{
|
|
515
|
+
value: "personal",
|
|
516
|
+
label: "個人トークンを設定",
|
|
517
|
+
hint: "GITHUB_TOKEN, API_KEY等",
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
value: "environment",
|
|
521
|
+
label: "環境設定を変更",
|
|
522
|
+
hint: "local, staging, production, ci 等",
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
value: "status",
|
|
526
|
+
label: "現在の状態を確認",
|
|
527
|
+
hint: "環境変数の設定状況を表示",
|
|
528
|
+
},
|
|
529
|
+
],
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
if (p.isCancel(action)) {
|
|
533
|
+
p.cancel("キャンセルしました");
|
|
534
|
+
process.exit(0);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
switch (action) {
|
|
538
|
+
case "personal":
|
|
539
|
+
await setupPersonalTokens();
|
|
540
|
+
break;
|
|
541
|
+
case "environment":
|
|
542
|
+
await selectEnvironment();
|
|
543
|
+
break;
|
|
544
|
+
case "status":
|
|
545
|
+
showStatus();
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
p.outro("✅ 完了");
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
main().catch((error: unknown) => {
|
|
553
|
+
p.log.error(`エラーが発生しました: ${error}`);
|
|
554
|
+
process.exit(1);
|
|
555
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# init.sh - 初回セットアップ(Volta/Node/pnpm導入)
|
|
4
|
+
#
|
|
5
|
+
# 使い方:
|
|
6
|
+
# ./scripts/init.sh
|
|
7
|
+
#
|
|
8
|
+
# ※ 初回のみ実行。2回目以降は不要です。
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
set -e
|
|
12
|
+
|
|
13
|
+
# 色定義
|
|
14
|
+
BLUE='\033[34m'
|
|
15
|
+
GREEN='\033[32m'
|
|
16
|
+
YELLOW='\033[33m'
|
|
17
|
+
GRAY='\033[90m'
|
|
18
|
+
NC='\033[0m'
|
|
19
|
+
|
|
20
|
+
log_success() { echo -e "${GREEN}✓${NC} $1"; }
|
|
21
|
+
log_warn() { echo -e "${YELLOW}⚠${NC} $1"; }
|
|
22
|
+
log_step() { echo -e "\n${BLUE}Step $1:${NC} $2"; }
|
|
23
|
+
|
|
24
|
+
# スクリプトのディレクトリに移動
|
|
25
|
+
cd "$(dirname "$0")/.."
|
|
26
|
+
|
|
27
|
+
echo -e "${BLUE}"
|
|
28
|
+
echo "=========================================="
|
|
29
|
+
echo " 初回セットアップ"
|
|
30
|
+
echo "=========================================="
|
|
31
|
+
echo -e "${NC}"
|
|
32
|
+
|
|
33
|
+
# Step 1: Voltaの確認とインストール
|
|
34
|
+
log_step 1 "Voltaのインストール..."
|
|
35
|
+
|
|
36
|
+
if ! command -v volta &> /dev/null; then
|
|
37
|
+
curl -fsSL https://get.volta.sh | bash -s -- --skip-setup
|
|
38
|
+
export VOLTA_HOME="$HOME/.volta"
|
|
39
|
+
export PATH="$VOLTA_HOME/bin:$PATH"
|
|
40
|
+
log_success "Voltaをインストールしました"
|
|
41
|
+
else
|
|
42
|
+
log_success "Voltaは既にインストール済み"
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Volta PATHを設定
|
|
46
|
+
export VOLTA_HOME="$HOME/.volta"
|
|
47
|
+
export PATH="$VOLTA_HOME/bin:$PATH"
|
|
48
|
+
export VOLTA_FEATURE_PNPM=1
|
|
49
|
+
|
|
50
|
+
# Step 2: シェル設定
|
|
51
|
+
log_step 2 "シェル設定..."
|
|
52
|
+
|
|
53
|
+
SHELL_NAME=$(basename "$SHELL")
|
|
54
|
+
case "$SHELL_NAME" in
|
|
55
|
+
zsh) RC_FILE="$HOME/.zshrc" ;;
|
|
56
|
+
bash) RC_FILE="$HOME/.bashrc" ;;
|
|
57
|
+
*) RC_FILE="" ;;
|
|
58
|
+
esac
|
|
59
|
+
|
|
60
|
+
if [ -n "$RC_FILE" ] && ! grep -q "VOLTA_FEATURE_PNPM" "$RC_FILE" 2>/dev/null; then
|
|
61
|
+
echo -e "\n# Volta - pnpm support\nexport VOLTA_FEATURE_PNPM=1" >> "$RC_FILE"
|
|
62
|
+
log_success "シェル設定を追加しました"
|
|
63
|
+
else
|
|
64
|
+
log_success "シェル設定は既に完了"
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
# Step 3: Node.js/pnpmインストール
|
|
68
|
+
log_step 3 "Node.js/pnpmのインストール..."
|
|
69
|
+
|
|
70
|
+
NODE_VERSION=$(grep -o '"node": *"[^"]*"' package.json | grep -o '[0-9.]*')
|
|
71
|
+
PNPM_VERSION=$(grep -o '"pnpm": *"[^"]*"' package.json | grep -o '[0-9.]*')
|
|
72
|
+
|
|
73
|
+
volta install node@"$NODE_VERSION"
|
|
74
|
+
volta install pnpm@"$PNPM_VERSION"
|
|
75
|
+
log_success "Node.js $NODE_VERSION, pnpm $PNPM_VERSION をインストールしました"
|
|
76
|
+
|
|
77
|
+
# Step 4: 依存関係インストール
|
|
78
|
+
log_step 4 "依存関係のインストール..."
|
|
79
|
+
|
|
80
|
+
pnpm install
|
|
81
|
+
log_success "依存関係をインストールしました"
|
|
82
|
+
|
|
83
|
+
# 完了
|
|
84
|
+
echo ""
|
|
85
|
+
echo -e "${GREEN}=========================================="
|
|
86
|
+
echo -e "✅ 初回セットアップ完了!"
|
|
87
|
+
echo -e "==========================================${NC}"
|
|
88
|
+
echo ""
|
|
89
|
+
echo "次のステップ:"
|
|
90
|
+
echo -e " 1. ターミナルを再起動: ${BLUE}exec \$SHELL${NC}"
|
|
91
|
+
echo -e " 2. 環境セットアップ: ${BLUE}pnpm dev:setup${NC}"
|
|
92
|
+
echo ""
|