💻 システム開発

11_scale-brand_分離依頼

最終更新 2026年06月24日 / 31_システム開発部/分離プロジェクト依頼書/11_scale-brand_分離依頼.md

依頼書: SCALE Base から「Brand & PR + AI CMO」を独立プロジェクトに分離

新しい Claude Code セッション宛て。コピペでそのまま実行可能。完了後 Slack #system_scalebase で大串に報告。


あなたが実行すること

SCALE Base モノリス内の Brand & PR 機能 + AI CMO 機能(細川さん専用)scale-brand プロジェクトに分離。
完了後 scale-base のサイドバー「Brand & PR」をクリックすると新プロジェクトを開く。

注: scale-base の lib/systems.ts で AI CMO は brand 配下のサブセクション(/cmo)になっているので一緒に移植する。

並行セッションでの開発は無いので落ち着いて作業 OK。


SCALE Base 全体情報

項目 内容
scale-base ローカル /Users/oogushiyuuki/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base/
scale-base 本番 https://scale-base.pages.dev/
Framework Next.js 15+(App Router)
デプロイ Cloudflare Pages(bash scripts/deploy.sh
共有データ Worker https://scale-task-cron.y-ogushi.workers.dev
認証 lib/auth-context.tsx の DEMO_USERS 固定

進捗チェックリスト

  • [ ] ローカル ~/Library/CloudStorage/.../AI/scale-brand/ 作成
  • [ ] Next.js + Tailwind 雛形
  • [ ] scale-base 共通設定コピー
  • [ ] brand + cmo 関連コード移植
  • [ ] パスをトップレベル化
  • [ ] レイアウト + 認証
  • [ ] ローカル動作確認
  • [ ] Cloudflare Pages project scale-brand 作成 + デプロイ
  • [ ] scale-base の systems.ts で brand に externalUrl + 旧コード退避
  • [ ] scale-base 再デプロイ
  • [ ] Slack 完了報告

Step 1: 雛形

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/
npx create-next-app@latest scale-brand --typescript --tailwind --app --src-dir=false --import-alias="@/*" --no-eslint
cd scale-brand

Step 2: 共通設定コピー

SRC=~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
cp "$SRC/tailwind.config.ts" ./
cp "$SRC/app/globals.css" ./app/globals.css
mkdir -p lib
cp "$SRC/lib/auth-context.tsx" ./lib/
cp "$SRC/lib/tasks-api.tsx" ./lib/ 2>/dev/null || true

Step 3: brand + cmo コード移植

mkdir -p app components functions/api
# brand
cp -r "$SRC/app/(dashboard)/brand/." ./app/
# cmo は brand 配下の cmo/ サブディレクトリに
mkdir -p ./app/cmo
cp -r "$SRC/app/(dashboard)/cmo/." ./app/cmo/ 2>/dev/null || true
cp -r "$SRC/components/brand" ./components/ 2>/dev/null || true
cp -r "$SRC/components/cmo" ./components/ 2>/dev/null || true
cp "$SRC"/lib/brand-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/lib/cmo-*.ts ./lib/ 2>/dev/null || true
cp "$SRC"/functions/api/brand*.ts ./functions/api/ 2>/dev/null || true
cp "$SRC"/functions/api/cmo*.ts ./functions/api/ 2>/dev/null || true

Step 4: パスをトップレベル化

旧 /brand               → 新 /
旧 /brand/monitor       → 新 /monitor
旧 /brand/pr            → 新 /pr
旧 /brand/settings      → 新 /settings
旧 /cmo                 → 新 /cmo (そのまま)
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/brand/|'/|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/brand/|"/|g' {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' "s|'/brand'|'/'|g" {} \;
find ./app ./components ./lib -type f \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i '' 's|"/brand"|"/"|g' {} \;

Step 5: ルートレイアウト

app/layout.tsx

import './globals.css';
import { AuthProvider } from '@/lib/auth-context';

export const metadata = { title: 'SCALE Brand & PR' };

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="ja">
      <body className="bg-bg text-text">
        <AuthProvider>
          <header className="sticky top-0 z-30 bg-bg2 border-b border-border px-4 py-2 flex items-center justify-between">
            <a href="https://scale-base.pages.dev/home/" className="text-xs text-text2 hover:text-text">← SCALE Base に戻る</a>
            <span className="text-sm font-bold text-text">Brand & PR</span>
          </header>
          <main className="p-4 md:p-6">{children}</main>
        </AuthProvider>
      </body>
    </html>
  );
}

Step 6: 認証ガード

'use client';
import { useEffect } from 'react';
import { useAuth } from '@/lib/auth-context';

export default function Page() {
  const { user, isLoading } = useAuth();
  useEffect(() => {
    if (!isLoading && !user) window.location.href = 'https://scale-base.pages.dev/';
  }, [user, isLoading]);
  // ...
}

Step 7: ローカル確認 + deploy.sh

npm run dev
mkdir -p scripts
cat > scripts/deploy.sh <<'EOF'
#!/bin/bash
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
TS=$(date +%Y-%m-%d_%H%M%S)
mkdir -p "$ROOT/../scale-brand-backups"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-brand-backups/scale-brand_${TS}_pre-deploy.tar.gz" -C "$ROOT" .
rm -rf .next out
NODE_OPTIONS="--max-old-space-size=8192" npx next build
npx wrangler pages deploy out --project-name=scale-brand --branch=main --commit-message="scale-brand deploy"
tar --exclude='node_modules' --exclude='.next' --exclude='out' --exclude='.wrangler' \
  -czf "$ROOT/../scale-brand-backups/scale-brand_${TS}_post-deploy.tar.gz" -C "$ROOT" .
echo "✓ Deploy complete → https://scale-brand.pages.dev/"
EOF
chmod +x scripts/deploy.sh

Step 8: Cloudflare Pages 作成 + デプロイ

npx wrangler pages project create scale-brand --production-branch=main
bash scripts/deploy.sh

Step 9: scale-base 側更新

scale-base/lib/systems.ts の brand エントリ:

{
  id: 'brand',
  name: 'Brand & PR',
  shortName: 'Brand',
  icon: Megaphone,
  color: '#db2777',
  bgColor: 'rgba(219,39,119,0.15)',
  sections: [],
  externalUrl: 'https://scale-brand.pages.dev/',
},

SYSTEM_ABSORBEDcmo: 'brand' の行は削除(cmo は brand 配下の sub に内包済みなので)。

旧コード退避:

cd ~/Library/CloudStorage/GoogleDrive-y-ogushi@scale-group.co.jp/マイドライブ/AI/scale-base
mkdir -p _archived_apps
mv "app/(dashboard)/brand" "_archived_apps/brand_$(date +%Y%m%d)"
mv "app/(dashboard)/cmo" "_archived_apps/cmo_$(date +%Y%m%d)" 2>/dev/null || true
mv "components/brand" "_archived_apps/components_brand_$(date +%Y%m%d)" 2>/dev/null || true
mv "components/cmo" "_archived_apps/components_cmo_$(date +%Y%m%d)" 2>/dev/null || true
mkdir -p _archived_apps/lib_brand _archived_apps/functions_brand
mv lib/brand-*.ts lib/cmo-*.ts _archived_apps/lib_brand/ 2>/dev/null || true
mv functions/api/brand*.ts functions/api/cmo*.ts _archived_apps/functions_brand/ 2>/dev/null || true
npx next build
bash scripts/deploy.sh

Step 10: 動作確認 + Slack 報告

#system_scalebase に:

:white_check_mark: scale-brand 分離完了
URL: https://scale-brand.pages.dev/ (AI CMO は /cmo 配下に内包)

依頼者: 大串 / 最終更新: 2026-04-29