@c-time/frelio-cli 2.4.0 → 2.5.0

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.
@@ -1,119 +0,0 @@
1
- /**
2
- * frelio add-staging - ステージング環境(プレビュー用ブランチ)の追加
3
- *
4
- * core/* の関数を呼ぶ薄いオーケストレーター。
5
- */
6
- import prompts from 'prompts';
7
- import { log, logStep, logSuccess, logError } from '../lib/shell.js';
8
- import { validateStagingName } from '../lib/validators.js';
9
- import { checkGit } from '../core/prerequisites.js';
10
- import { isGitRepo, createBranch, checkWorkflowBranchCoverage } from '../core/git-operations.js';
11
- import { readConfig } from '../core/config.js';
12
- export async function addStagingCommand(options) {
13
- log('');
14
- log('🌿 ステージング環境の追加');
15
- log('');
16
- // 前提チェック
17
- const gitCheck = checkGit();
18
- if (!gitCheck.success) {
19
- logError(gitCheck.error);
20
- process.exit(1);
21
- }
22
- const projectDir = process.cwd();
23
- if (!isGitRepo(projectDir)) {
24
- logError('Git リポジトリ内で実行してください。');
25
- process.exit(1);
26
- }
27
- // Pages プロジェクト名を config.json から取得
28
- let contentWorkerName = '';
29
- const configResult = readConfig(projectDir);
30
- if (configResult.success && configResult.data.config) {
31
- contentWorkerName = configResult.data.config.contentWorkerName || '';
32
- }
33
- // ステージング名の取得
34
- const isInteractive = process.stdin.isTTY === true;
35
- let stagingName;
36
- if (options.name) {
37
- const nameCheck = validateStagingName(options.name);
38
- if (nameCheck !== true) {
39
- logError(`--name: ${nameCheck}`);
40
- process.exit(1);
41
- }
42
- stagingName = options.name;
43
- }
44
- else {
45
- if (!isInteractive) {
46
- logError('非対話モードでは --name が必須です。');
47
- logError('使用例: frelio add-staging --name preview1');
48
- process.exit(1);
49
- }
50
- const response = await prompts([
51
- {
52
- type: 'text',
53
- name: 'name',
54
- message: 'ステージング名(staging-{name} のブランチが作成されます):',
55
- validate: (v) => validateStagingName(v),
56
- },
57
- ], { onCancel: () => process.exit(0) });
58
- if (!response.name) {
59
- log('キャンセルしました。');
60
- process.exit(0);
61
- }
62
- stagingName = response.name;
63
- }
64
- const branchName = `staging-${stagingName}`;
65
- log('');
66
- const totalSteps = 2;
67
- let step = 0;
68
- // Step 1: Git ブランチ作成
69
- step++;
70
- logStep(step, totalSteps, `ブランチ "${branchName}" を作成...`);
71
- const branchResult = createBranch(projectDir, branchName, 'origin/develop');
72
- if (branchResult.success) {
73
- logSuccess(branchResult.data.alreadyExisted
74
- ? `ブランチ "${branchName}" はリモートに既に存在します`
75
- : `ブランチ "${branchName}" を作成・プッシュしました`);
76
- }
77
- else {
78
- logError(branchResult.error);
79
- process.exit(1);
80
- }
81
- // Step 2: build-staging.yml のブランチリスト確認
82
- step++;
83
- logStep(step, totalSteps, 'GitHub Actions ワークフローを確認...');
84
- const workflowCheck = checkWorkflowBranchCoverage(projectDir, branchName);
85
- if (workflowCheck.success) {
86
- if (workflowCheck.data.covered) {
87
- logSuccess('ワークフローは既に対応済みです(ワイルドカードまたは明示列挙)');
88
- }
89
- else {
90
- log(` ⚠ .github/workflows/build-staging.yml の branches に "${branchName}" を追加してください:`);
91
- log('');
92
- log(' branches:');
93
- log(' - staging');
94
- log(` - ${branchName} # ← 追加`);
95
- log('');
96
- log(' または、CMS 管理画面の基本設定 → ファイル所在一覧からワークフローを再生成してください。');
97
- }
98
- }
99
- else {
100
- log(' ⚠ .github/workflows/build-staging.yml が見つかりません。手動で確認してください。');
101
- }
102
- // 完了
103
- log('');
104
- log('✅ ステージング環境の追加が完了しました!');
105
- log('');
106
- log(` ブランチ: ${branchName}`);
107
- if (contentWorkerName) {
108
- // GitHub Actions の wrangler versions upload --preview-alias が生成するプレビューエイリアス URL。
109
- // 初回の Actions デプロイ完了後に有効になる(workers.dev サブドメイン登録済みが前提)。
110
- log(` プレビュー URL: https://${branchName}-${contentWorkerName}.<subdomain>.workers.dev`);
111
- log(' (GitHub Actions の初回デプロイ後に有効)');
112
- }
113
- log('');
114
- log(' 残りの手動作業:');
115
- log(' - CMS 管理画面の /staging ページでステージングブランチを登録');
116
- log(' - カスタムドメインが必要な場合は Cloudflare Worker のカスタムドメイン設定(Settings → Domains & Routes)');
117
- log(' - Cloudflare Access でアクセス制限を設定(推奨)');
118
- log('');
119
- }