@c-time/frelio-cli 3.6.0 → 3.7.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.
- package/README.md +28 -11
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.js +74 -54
- package/dist/core/git-operations.d.ts +22 -2
- package/dist/core/git-operations.js +72 -13
- package/dist/core/github.d.ts +20 -9
- package/dist/core/github.js +46 -24
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/index.js +5 -2
- package/dist/lib/resource-links.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -132,21 +132,36 @@ frelio init
|
|
|
132
132
|
|
|
133
133
|
対話式プロンプトで必要な情報を入力し、プロジェクトをセットアップする。
|
|
134
134
|
|
|
135
|
+
**リポジトリの作成・クローンは CLI の管轄外(Issue #325)。** 対象リポジトリは先にオペレーターが用意し、
|
|
136
|
+
作業フォルダへクローンしておく。`frelio init` は **そのフォルダ(カレント)の既存 `origin` をそのまま使い、
|
|
137
|
+
カレントフォルダに展開する**(リポジトリ名のサブフォルダは作らない)。
|
|
138
|
+
|
|
135
139
|
```bash
|
|
140
|
+
# 1. 対象リポジトリを用意(可視性・org 配属・ブランチ保護はオペレーターが設定)
|
|
141
|
+
# → GitHub で作成し、作業フォルダへクローン
|
|
142
|
+
git clone https://github.com/my-org/my-site.git my-site
|
|
143
|
+
cd my-site
|
|
144
|
+
|
|
145
|
+
# 2. その中で init を実行
|
|
136
146
|
frelio init
|
|
137
147
|
```
|
|
138
148
|
|
|
149
|
+
> **なぜ repo 作成をやめたか(Issue #325)**: 顧客 org にリポジトリを作るのはオペレーターの権限・判断の
|
|
150
|
+
> 領域で、作業者アカウントに作成権限が無いことも普通にある(`gh repo create` が権限エラーで `init` ごと落ちる)。
|
|
151
|
+
> repo の可視性・ブランチ保護・org 配属を CLI が勝手に決めるべきではなく、「既存 or 新規」「権限あり or なし」の
|
|
152
|
+
> 分岐を CLI が抱えると冪等性バグの温床になる。そこで **repo は既存前提** とし、CLI は scaffold に専念する。
|
|
153
|
+
|
|
139
154
|
#### やること
|
|
140
155
|
|
|
141
156
|
1. **前提チェック** — `gh`, `wrangler`, `git` がインストールされ、ログイン済みか確認
|
|
142
|
-
2.
|
|
143
|
-
3.
|
|
144
|
-
4. **コンテンツリポジトリのスキャフォールド** — GitHub から [`c-time/frelio-content-template`](https://github.com/c-time/frelio-content-template)
|
|
157
|
+
2. **カレントの検証** — git リポジトリかつ `origin` 設定済みであることを確認(無ければ案内して停止。`--skip-github` 時は省略)
|
|
158
|
+
3. **対話式プロンプト** — リポジトリ名(既定は origin から導出)、サイトタイトル、R2 設定などを入力(この時点では OAuth は聞かない)
|
|
159
|
+
4. **コンテンツリポジトリのスキャフォールド** — GitHub から [`c-time/frelio-content-template`](https://github.com/c-time/frelio-content-template) をダウンロードし、設定値を埋め込んでカレントへ展開(`frelio-data/`、`scripts/`、`.github/workflows/`、`vite.config.ts` 等)
|
|
145
160
|
5. **CMS Admin バンドルの展開** — 最新リリースから `admin/`(SPA)、`admin-worker/`、`workers/` を配置
|
|
146
161
|
6. **設定ファイル生成** — `admin/config.json`、`wrangler.content.toml`、`wrangler.admin.toml`
|
|
147
162
|
7. **Cloudflare セットアップ(deploy-first / Issue #261)** — R2 バケット作成 + **admin Worker を一度デプロイして公開ホスト(`<admin>.<アカウント>.workers.dev`)を確定**し、`previewUrl` 等の実在 URL を `config.json` に反映(`--admin-host` 指定時はこの自動検出をスキップ)
|
|
148
163
|
8. **GitHub OAuth App の案内** — ホスト確定後に**正確なコールバック URL**(`https://<adminホスト>/api/auth/callback`)を提示 → Client ID / Secret を入力 → `GITHUB_CLIENT_SECRET` を投入し admin Worker を再デプロイ
|
|
149
|
-
9.
|
|
164
|
+
9. **初回コミット & ブランチ作成** — カレントの既存 `origin` へ、**現在のブランチ**(`main`/`master` 等。`main` 固定ではない)で初回コミットし、`develop`/`admin`/`staging` ブランチを作成・push、デフォルトブランチを `develop` に設定(権限が無ければデフォルトブランチ変更はスキップ)。`--no-commit` / `--no-branches` / `--no-push` で個別に抑止できる
|
|
150
165
|
|
|
151
166
|
> **Issue #261**: workers.dev の URL は `<ワーカー名>.<アカウント部>.workers.dev`。アカウント部はアカウント固定値のため手入力させず、admin Worker の初回デプロイ出力から自動取得する。これにより OAuth コールバックが init 中に確定でき、独自ドメインは「終盤に `frelio set-domain` で後付け」という役割分担になる。
|
|
152
167
|
|
|
@@ -154,7 +169,7 @@ frelio init
|
|
|
154
169
|
|
|
155
170
|
| 項目 | CLI オプション | 説明 | 例 |
|
|
156
171
|
|------|---------------|------|----|
|
|
157
|
-
| リポジトリ名 | `--content-repo` | `owner/repo`
|
|
172
|
+
| リポジトリ名 | `--content-repo` | `owner/repo` 形式(省略時はカレントの `origin` から導出) | `my-org/my-site` |
|
|
158
173
|
| サイトタイトル | `--site-title` | 管理画面に表示される名前 | `My Website` |
|
|
159
174
|
| 本番 URL | `--production-url` | 公開サイトの URL(任意・通常は終盤に `set-domain` で設定) | `https://example.com` |
|
|
160
175
|
| ステージング独自ドメイン | `--staging-domain` | ステージングの独自ドメイン(任意・通常は空。空なら workers.dev プレビューを使う) | `staging-abc123.example.com` |
|
|
@@ -169,13 +184,16 @@ frelio init
|
|
|
169
184
|
#### オプション
|
|
170
185
|
|
|
171
186
|
```bash
|
|
172
|
-
#
|
|
173
|
-
frelio init --skip-github # GitHub
|
|
187
|
+
# git 操作の制御(Issue #325)
|
|
188
|
+
frelio init --skip-github # GitHub/git 連携を一括スキップ(origin 要件なし・commit/branch/push なし)。scaffold のみ
|
|
189
|
+
frelio init --no-commit # scaffold だけ行いコミットしない(変更はワークツリーに残す。branch/push も行わない)
|
|
190
|
+
frelio init --no-branches # develop/admin/staging ブランチを作らない(コミット・push はする)
|
|
191
|
+
frelio init --no-push # ローカルにコミット・ブランチ作成するが origin へ push しない
|
|
174
192
|
frelio init --skip-cloudflare # Cloudflare 操作をスキップ(後から設定する場合)
|
|
175
193
|
|
|
176
194
|
# パラメータ指定(非対話モード用)
|
|
177
195
|
frelio init \
|
|
178
|
-
--content-repo <owner/repo> #
|
|
196
|
+
--content-repo <owner/repo> # リポジトリ名(省略時はカレントの origin から導出)
|
|
179
197
|
--site-title <title> # サイトタイトル
|
|
180
198
|
--production-url <url> # 本番 URL(任意・通常は後から set-domain)
|
|
181
199
|
--staging-domain <domain> # ステージング独自ドメイン(任意・通常は空)
|
|
@@ -190,12 +208,11 @@ frelio init \
|
|
|
190
208
|
|
|
191
209
|
#### 非対話モード(AI エージェント / CI 向け)
|
|
192
210
|
|
|
193
|
-
|
|
211
|
+
事前に対象リポジトリをクローンしたフォルダ内で実行する前提。`--client-id`、`--client-secret`(または `--skip-oauth`)を指定すればプロンプトなしで実行される。`--content-repo` は省略するとカレントの `origin` から導出する。他のパラメータは省略するとデフォルト値が自動算出される。
|
|
194
212
|
|
|
195
213
|
```bash
|
|
196
|
-
#
|
|
214
|
+
# 最小構成(contentRepo はカレントの origin から導出)
|
|
197
215
|
frelio init \
|
|
198
|
-
--content-repo my-org/my-site \
|
|
199
216
|
--client-id Ov23liXXX \
|
|
200
217
|
--client-secret ghp_XXX
|
|
201
218
|
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
* UI 層(プロンプト、ログ出力、process.exit)はここに閉じる。
|
|
6
6
|
*/
|
|
7
7
|
type InitOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* Issue #325: すべての GitHub/git 連携をスキップ(純粋 scaffold のみ)。
|
|
10
|
+
* origin 要件チェック・commit・ブランチ作成・push を一括でスキップする。
|
|
11
|
+
* リポジトリの作成・クローンは元々行わない(オペレーターの管轄)。
|
|
12
|
+
*/
|
|
8
13
|
skipGithub?: boolean;
|
|
14
|
+
/** Issue #325: scaffold をコミットするか(既定 true、--no-commit で false)。false なら push/ブランチも行わない。 */
|
|
15
|
+
commit?: boolean;
|
|
16
|
+
/** Issue #325: develop/admin/staging ブランチを作成するか(既定 true、--no-branches で false)。 */
|
|
17
|
+
branches?: boolean;
|
|
18
|
+
/** Issue #325: origin へ push するか(既定 true、--no-push で false)。 */
|
|
19
|
+
push?: boolean;
|
|
9
20
|
skipCloudflare?: boolean;
|
|
10
21
|
contentRepo?: string;
|
|
11
22
|
siteTitle?: string;
|
package/dist/commands/init.js
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* UI 層(プロンプト、ログ出力、process.exit)はここに閉じる。
|
|
6
6
|
*/
|
|
7
7
|
import prompts from 'prompts';
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import path from 'node:path';
|
|
10
8
|
import { randomBytes } from 'node:crypto';
|
|
11
9
|
import { log, logStep, logSuccess, logError, logWarning } from '../lib/shell.js';
|
|
12
10
|
import { buildWorkerNames, deriveFromAdminHost, derivePreviewUrl, } from '../lib/templates.js';
|
|
@@ -15,7 +13,7 @@ import { validateContentRepo, validateR2PublicUrl, validateRequired, sanitizeClo
|
|
|
15
13
|
// core functions
|
|
16
14
|
import { checkPrerequisitesFor } from '../core/prerequisites.js';
|
|
17
15
|
import { buildConfig } from '../core/config.js';
|
|
18
|
-
import {
|
|
16
|
+
import { getOriginRepo, getAuthenticatedUser } from '../core/github.js';
|
|
19
17
|
import { createR2Bucket, setWorkerSecretByName, deployAdminWorker } from '../core/cloudflare.js';
|
|
20
18
|
import { setupContactWorker } from '../core/contact.js';
|
|
21
19
|
import { setupScheduledPublishWorker } from '../core/scheduled-publish.js';
|
|
@@ -23,7 +21,7 @@ import { setupFileDeliveryWorker } from '../core/file-delivery.js';
|
|
|
23
21
|
import { createFullContentStructure } from '../core/content-structure.js';
|
|
24
22
|
import { regenerateAllConfigFiles } from '../core/file-generators.js';
|
|
25
23
|
import { installBundle } from '../core/bundle.js';
|
|
26
|
-
import { initialCommitAndBranches, generateLockfile, getGitIdentity, setGitIdentity, } from '../core/git-operations.js';
|
|
24
|
+
import { initialCommitAndBranches, generateLockfile, getGitIdentity, setGitIdentity, isGitRepo, } from '../core/git-operations.js';
|
|
27
25
|
export async function initCommand(options) {
|
|
28
26
|
log('');
|
|
29
27
|
log('🚀 Frelio CMS プロジェクトセットアップ');
|
|
@@ -47,13 +45,41 @@ export async function initCommand(options) {
|
|
|
47
45
|
process.exit(1);
|
|
48
46
|
}
|
|
49
47
|
log('');
|
|
48
|
+
// ── 作業ディレクトリ = カレントフォルダ(Issue #325)──
|
|
49
|
+
// リポジトリの作成・クローンは CLI の管轄外。対象リポジトリはオペレーターが用意し、
|
|
50
|
+
// カレントフォルダへクローン済み(origin 設定済み)である前提。init はその既存 origin を
|
|
51
|
+
// 使ってカレントをプロジェクトルートとして展開する(リポジトリ名のサブフォルダは作らない)。
|
|
52
|
+
const projectDir = process.cwd();
|
|
53
|
+
const originRepo = getOriginRepo(projectDir);
|
|
54
|
+
// GitHub 連携を使う場合は「git リポジトリ+origin あり」を必須にし、無ければ案内して停止する。
|
|
55
|
+
// 暗黙に repo を作ったりクローンしたりはしない(Issue #325)。
|
|
56
|
+
if (!options.skipGithub) {
|
|
57
|
+
if (!isGitRepo(projectDir) || !originRepo) {
|
|
58
|
+
logError('カレントフォルダが git リポジトリでないか、origin リモートが設定されていません。');
|
|
59
|
+
log('');
|
|
60
|
+
log(' Frelio はリポジトリの作成・クローンを行いません(オペレーターの管轄)。');
|
|
61
|
+
log(' 先に対象リポジトリを用意し、作業フォルダへクローンしてから init を実行してください:');
|
|
62
|
+
log(' 1. GitHub で対象リポジトリを作成(可視性・org 配属・ブランチ保護はオペレーターが設定)');
|
|
63
|
+
log(' 2. git clone <repo> <作業フォルダ> && cd <作業フォルダ>');
|
|
64
|
+
log(' 3. frelio init');
|
|
65
|
+
log('');
|
|
66
|
+
log(' GitHub 連携なしで scaffold だけ行う場合は --skip-github を付けてください。');
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
50
70
|
// ── 対話式プロンプト ──
|
|
51
71
|
log('📝 プロジェクト設定:');
|
|
52
|
-
const config = await promptConfig(options);
|
|
72
|
+
const config = await promptConfig(options, originRepo);
|
|
53
73
|
if (!config) {
|
|
54
74
|
log('セットアップをキャンセルしました。');
|
|
55
75
|
process.exit(0);
|
|
56
76
|
}
|
|
77
|
+
// origin の owner/repo と --content-repo 指定が食い違う場合は警告(Issue #325)。
|
|
78
|
+
// origin が正本なので config.json 等に書かれる contentRepo との不一致は気づけるようにする。
|
|
79
|
+
if (!options.skipGithub && originRepo && config.contentRepo !== originRepo) {
|
|
80
|
+
logWarning(`指定の contentRepo "${config.contentRepo}" はカレントの origin "${originRepo}" と一致しません。`);
|
|
81
|
+
log(' config.json やワーカー名はこの contentRepo を基に生成されます。意図した値か確認してください。');
|
|
82
|
+
}
|
|
57
83
|
log('');
|
|
58
84
|
// ── お問い合わせ機能(任意)──
|
|
59
85
|
const contactInput = options.skipCloudflare ? null : await promptContact(config);
|
|
@@ -74,40 +100,12 @@ export async function initCommand(options) {
|
|
|
74
100
|
// deploy-first(admin を一度デプロイしてホストを得る)か --admin-host 指定の後に収集する。
|
|
75
101
|
// 非対話で Client ID/Secret が未指定の場合は promptConfig 時点で既に弾かれている。
|
|
76
102
|
// ── セットアップ実行 ──
|
|
103
|
+
// Issue #325: リポジトリ作成・クローンのステップは撤去。カレントの既存 origin をそのまま使う。
|
|
104
|
+
const willCommit = !options.skipGithub && options.commit !== false;
|
|
77
105
|
const totalSteps = getTotalSteps(options, !!contactInput, !!scheduleInput, !!fileDeliveryInput, !options.adminHost);
|
|
78
106
|
let step = 0;
|
|
79
|
-
// GitHub リポジトリ作成
|
|
80
|
-
if (!options.skipGithub) {
|
|
81
|
-
step++;
|
|
82
|
-
logStep(step, totalSteps, 'GitHub リポジトリ作成...');
|
|
83
|
-
const repoResult = createRepo(config.contentRepo);
|
|
84
|
-
if (repoResult.success) {
|
|
85
|
-
logSuccess(repoResult.data.alreadyExisted ? 'リポジトリは既に存在します' : 'リポジトリ作成完了');
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
logError(repoResult.error);
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// 作業ディレクトリ作成
|
|
93
|
-
const repoName = config.contentRepo.split('/')[1];
|
|
94
|
-
const projectDir = path.resolve(process.cwd(), repoName);
|
|
95
107
|
if (!options.skipGithub) {
|
|
96
|
-
|
|
97
|
-
logStep(step, totalSteps, 'リポジトリをクローン...');
|
|
98
|
-
const cloneResult = cloneRepo(config.contentRepo, projectDir);
|
|
99
|
-
if (cloneResult.success) {
|
|
100
|
-
logSuccess(cloneResult.data.alreadyExisted ? 'ディレクトリは既に存在します' : 'クローン完了');
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
logError(cloneResult.error);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
if (!fs.existsSync(projectDir)) {
|
|
109
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
110
|
-
}
|
|
108
|
+
logSuccess(`カレントの既存リポジトリに展開します(origin: ${originRepo})`);
|
|
111
109
|
}
|
|
112
110
|
// コンテンツリポジトリ初期構造(ワークフロー含む)
|
|
113
111
|
step++;
|
|
@@ -303,23 +301,39 @@ export async function initCommand(options) {
|
|
|
303
301
|
}
|
|
304
302
|
}
|
|
305
303
|
// git identity 確認(commit 直前 — 未設定だとデフォルト値で commit author が埋まるのを防ぐ)
|
|
306
|
-
if (
|
|
304
|
+
if (willCommit) {
|
|
307
305
|
step++;
|
|
308
306
|
logStep(step, totalSteps, 'git identity 確認...');
|
|
309
307
|
await ensureGitIdentity(projectDir, config.ownerUsername);
|
|
310
308
|
}
|
|
311
|
-
//
|
|
312
|
-
if (
|
|
309
|
+
// 初回コミット(+任意でブランチ作成・push)。Issue #325: git 操作は個別に制御できる。
|
|
310
|
+
if (willCommit) {
|
|
311
|
+
const createBranches = options.branches !== false;
|
|
312
|
+
const push = options.push !== false;
|
|
313
313
|
step++;
|
|
314
|
-
|
|
315
|
-
|
|
314
|
+
const label = createBranches
|
|
315
|
+
? push ? '初回コミット & ブランチ作成 & push...' : '初回コミット & ブランチ作成(push なし)...'
|
|
316
|
+
: push ? '初回コミット & push(ブランチ作成なし)...' : '初回コミット(ブランチ作成・push なし)...';
|
|
317
|
+
logStep(step, totalSteps, label);
|
|
318
|
+
const gitResult = initialCommitAndBranches(projectDir, config.contentRepo, {
|
|
319
|
+
createBranches,
|
|
320
|
+
push,
|
|
321
|
+
});
|
|
316
322
|
if (gitResult.success) {
|
|
317
|
-
|
|
323
|
+
const { branches, defaultBranch, pushed } = gitResult.data;
|
|
324
|
+
logSuccess(`コミット完了(ブランチ: ${branches.join(', ')}${pushed ? ' / push 済み' : ' / push なし'}` +
|
|
325
|
+
`${defaultBranch ? ` / default=${defaultBranch}` : ''})`);
|
|
326
|
+
if (pushed && createBranches && !defaultBranch) {
|
|
327
|
+
log(' ℹ デフォルトブランチの変更はスキップしました(権限が無い等)。必要なら GitHub 側で develop に設定してください。');
|
|
328
|
+
}
|
|
318
329
|
}
|
|
319
330
|
else {
|
|
320
331
|
logError(gitResult.error);
|
|
321
332
|
}
|
|
322
333
|
}
|
|
334
|
+
else if (!options.skipGithub) {
|
|
335
|
+
log(' ⏭ コミットをスキップしました(--no-commit)。scaffold はワークツリーに残っています。');
|
|
336
|
+
}
|
|
323
337
|
// ── 完了 ──
|
|
324
338
|
log('');
|
|
325
339
|
log('✅ セットアップ完了!');
|
|
@@ -757,22 +771,25 @@ async function promptContact(config) {
|
|
|
757
771
|
adminNotifySecret: randomBytes(24).toString('base64url'),
|
|
758
772
|
};
|
|
759
773
|
}
|
|
760
|
-
async function promptConfig(options) {
|
|
774
|
+
async function promptConfig(options, originRepo) {
|
|
761
775
|
const isInteractive = process.stdin.isTTY === true;
|
|
762
776
|
// Issue #319: --skip-oauth なら OAuth 資格情報は非対話の必須要件から外す
|
|
763
777
|
// (callback URL は admin Worker デプロイ後にしか確定しないため、後から set-oauth で注入)。
|
|
764
778
|
const oauthRequired = !options.skipOauth;
|
|
779
|
+
// Issue #325: contentRepo は --content-repo 指定 → カレントの origin → プロンプト の順で決める。
|
|
780
|
+
// GitHub 連携しない(--skip-github)場合は origin を参照しない。
|
|
781
|
+
const presetContentRepo = options.contentRepo ?? (options.skipGithub ? undefined : originRepo ?? undefined);
|
|
765
782
|
// 必須オプションが揃っている場合 → プロンプトスキップ
|
|
766
|
-
// (--skip-oauth 時は
|
|
767
|
-
if (
|
|
783
|
+
// (--skip-oauth 時は contentRepo(指定 or origin)だけで非対話実行できる)
|
|
784
|
+
if (presetContentRepo &&
|
|
768
785
|
(!oauthRequired || (options.clientId && options.clientSecret))) {
|
|
769
|
-
return buildConfigFromOptions(options);
|
|
786
|
+
return buildConfigFromOptions({ ...options, contentRepo: presetContentRepo });
|
|
770
787
|
}
|
|
771
788
|
// 非 TTY で必須オプション不足 → エラー終了
|
|
772
789
|
if (!isInteractive) {
|
|
773
790
|
const missing = [];
|
|
774
|
-
if (!
|
|
775
|
-
missing.push('--content-repo');
|
|
791
|
+
if (!presetContentRepo)
|
|
792
|
+
missing.push('--content-repo(または origin 設定済みのリポジトリ内で実行)');
|
|
776
793
|
if (oauthRequired && !options.clientId)
|
|
777
794
|
missing.push('--client-id');
|
|
778
795
|
if (oauthRequired && !options.clientSecret)
|
|
@@ -782,12 +799,13 @@ async function promptConfig(options) {
|
|
|
782
799
|
logError(' または OAuth を後回しにする: frelio init --content-repo owner/repo --skip-oauth');
|
|
783
800
|
process.exit(1);
|
|
784
801
|
}
|
|
785
|
-
//
|
|
802
|
+
// 対話モード(contentRepo は preset があればプロンプトせず、無ければ origin を初期値に入力)
|
|
786
803
|
const response = await prompts([
|
|
787
804
|
{
|
|
788
|
-
type:
|
|
805
|
+
type: presetContentRepo ? null : 'text',
|
|
789
806
|
name: 'contentRepo',
|
|
790
807
|
message: 'リポジトリ名 (owner/repo):',
|
|
808
|
+
initial: originRepo ?? '',
|
|
791
809
|
validate: (v) => validateContentRepo(v),
|
|
792
810
|
},
|
|
793
811
|
{
|
|
@@ -816,7 +834,7 @@ async function promptConfig(options) {
|
|
|
816
834
|
name: 'r2BucketName',
|
|
817
835
|
message: 'R2 バケット名:',
|
|
818
836
|
initial: (_prev, values) => {
|
|
819
|
-
const repo = (
|
|
837
|
+
const repo = (presetContentRepo || values.contentRepo)?.split('/')[1] || 'site';
|
|
820
838
|
return `${sanitizeCloudflareName(repo)}-files`;
|
|
821
839
|
},
|
|
822
840
|
},
|
|
@@ -847,7 +865,7 @@ async function promptConfig(options) {
|
|
|
847
865
|
},
|
|
848
866
|
},
|
|
849
867
|
], { onCancel: () => process.exit(0) });
|
|
850
|
-
const contentRepo =
|
|
868
|
+
const contentRepo = presetContentRepo || response.contentRepo;
|
|
851
869
|
if (!contentRepo)
|
|
852
870
|
return null;
|
|
853
871
|
const repoName = contentRepo.split('/')[1];
|
|
@@ -929,8 +947,10 @@ function buildConfigFromOptions(options) {
|
|
|
929
947
|
}
|
|
930
948
|
function getTotalSteps(options, withContact = false, withSchedule = false, withFileDelivery = false, willDeployAdmin = false) {
|
|
931
949
|
let steps = 4; // content structure (includes workflows), bundle, config files, lockfile
|
|
932
|
-
|
|
933
|
-
|
|
950
|
+
// Issue #325: repo 作成・クローンのステップは撤去。commit する場合のみ git identity + commit の2ステップ。
|
|
951
|
+
const willCommit = !options.skipGithub && options.commit !== false;
|
|
952
|
+
if (willCommit)
|
|
953
|
+
steps += 2; // git identity, commit(+branches/push)
|
|
934
954
|
if (!options.skipCloudflare) {
|
|
935
955
|
steps += 1; // R2 bucket 作成
|
|
936
956
|
if (willDeployAdmin)
|
|
@@ -2,9 +2,29 @@
|
|
|
2
2
|
* core/git-operations — Git コミット・ブランチ・プッシュ操作
|
|
3
3
|
*/
|
|
4
4
|
import { type OperationResult } from './types.js';
|
|
5
|
-
|
|
5
|
+
/** 現在チェックアウト中のブランチ名(例: main / master / develop)。取得できなければ null。 */
|
|
6
|
+
export declare function currentBranch(projectDir: string): string | null;
|
|
7
|
+
export type CommitAndBranchOptions = {
|
|
8
|
+
/** develop / admin / staging ブランチを作成するか(Issue #325: オプトアウト可)。既定 true。 */
|
|
9
|
+
createBranches?: boolean;
|
|
10
|
+
/** origin へ push するか(Issue #325: オプトアウト可)。既定 true。 */
|
|
11
|
+
push?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* カレントフォルダの既存リポジトリ(origin 設定済み前提)へ scaffold をコミットし、
|
|
15
|
+
* 必要に応じてブランチ作成・push する(Issue #325)。
|
|
16
|
+
*
|
|
17
|
+
* 従来との違い:
|
|
18
|
+
* - リポジトリ作成・クローンはしない(オペレーターの管轄)。
|
|
19
|
+
* - push 先ブランチを `main` 固定にせず、現在のブランチ(main/master 等)を使う。
|
|
20
|
+
* - ブランチ作成・push はオプションで個別に制御できる。
|
|
21
|
+
* - 既存ブランチ・差分なし・デフォルトブランチ変更の権限不足は致命にせずスキップ/警告に留める
|
|
22
|
+
* (repo の可視性・ブランチ保護・default branch はオペレーターの判断領域)。
|
|
23
|
+
*/
|
|
24
|
+
export declare function initialCommitAndBranches(projectDir: string, contentRepo: string, options?: CommitAndBranchOptions): OperationResult<{
|
|
6
25
|
branches: string[];
|
|
7
|
-
defaultBranch: string;
|
|
26
|
+
defaultBranch: string | null;
|
|
27
|
+
pushed: boolean;
|
|
8
28
|
}>;
|
|
9
29
|
/**
|
|
10
30
|
* package-lock.json を生成する(`npm install --package-lock-only`)。
|
|
@@ -7,23 +7,82 @@ import { exec } from '../lib/shell.js';
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
// Initial commit + branch creation
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
|
-
|
|
10
|
+
/** 現在チェックアウト中のブランチ名(例: main / master / develop)。取得できなければ null。 */
|
|
11
|
+
export function currentBranch(projectDir) {
|
|
12
|
+
try {
|
|
13
|
+
const name = exec('git rev-parse --abbrev-ref HEAD', { cwd: projectDir, silent: true });
|
|
14
|
+
return name && name !== 'HEAD' ? name : null;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** ステージ済みの変更があるか(`git diff --cached --quiet` が非ゼロ=変更あり)。 */
|
|
21
|
+
function hasStagedChanges(projectDir) {
|
|
22
|
+
try {
|
|
23
|
+
exec('git diff --cached --quiet', { cwd: projectDir, silent: true });
|
|
24
|
+
return false; // 終了コード0=差分なし
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return true; // 非ゼロ=差分あり
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* カレントフォルダの既存リポジトリ(origin 設定済み前提)へ scaffold をコミットし、
|
|
32
|
+
* 必要に応じてブランチ作成・push する(Issue #325)。
|
|
33
|
+
*
|
|
34
|
+
* 従来との違い:
|
|
35
|
+
* - リポジトリ作成・クローンはしない(オペレーターの管轄)。
|
|
36
|
+
* - push 先ブランチを `main` 固定にせず、現在のブランチ(main/master 等)を使う。
|
|
37
|
+
* - ブランチ作成・push はオプションで個別に制御できる。
|
|
38
|
+
* - 既存ブランチ・差分なし・デフォルトブランチ変更の権限不足は致命にせずスキップ/警告に留める
|
|
39
|
+
* (repo の可視性・ブランチ保護・default branch はオペレーターの判断領域)。
|
|
40
|
+
*/
|
|
41
|
+
export function initialCommitAndBranches(projectDir, contentRepo, options = {}) {
|
|
42
|
+
const { createBranches = true, push = true } = options;
|
|
11
43
|
try {
|
|
12
44
|
exec('git add -A', { cwd: projectDir, silent: true });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
45
|
+
// 差分が無ければコミットしない(再実行や scaffold 変更なしのケース)
|
|
46
|
+
if (hasStagedChanges(projectDir)) {
|
|
47
|
+
exec('git commit -m "Initial Frelio CMS setup"', { cwd: projectDir, silent: true });
|
|
48
|
+
}
|
|
49
|
+
// 現在のブランチ(empty repo をクローンした直後はコミットで誕生した名前になる)
|
|
50
|
+
const base = currentBranch(projectDir) ?? 'main';
|
|
51
|
+
// develop, admin, staging ブランチ作成(既存・現在ブランチと同名はスキップ)
|
|
52
|
+
const created = [];
|
|
53
|
+
if (createBranches) {
|
|
54
|
+
for (const branch of ['develop', 'admin', 'staging']) {
|
|
55
|
+
if (branch === base)
|
|
56
|
+
continue;
|
|
57
|
+
try {
|
|
58
|
+
exec(`git branch ${branch}`, { cwd: projectDir, silent: true });
|
|
59
|
+
created.push(branch);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// 既に存在 → スキップ
|
|
63
|
+
}
|
|
64
|
+
}
|
|
18
65
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exec(`git push -u origin ${
|
|
66
|
+
let pushed = false;
|
|
67
|
+
let defaultBranch = null;
|
|
68
|
+
if (push) {
|
|
69
|
+
exec(`git push -u origin ${base}`, { cwd: projectDir, silent: true });
|
|
70
|
+
for (const branch of created) {
|
|
71
|
+
exec(`git push -u origin ${branch}`, { cwd: projectDir, silent: true });
|
|
72
|
+
}
|
|
73
|
+
pushed = true;
|
|
74
|
+
// デフォルトブランチを develop に(best-effort。権限が無ければオペレーター任せ)。
|
|
75
|
+
if (createBranches) {
|
|
76
|
+
try {
|
|
77
|
+
exec(`gh repo edit ${contentRepo} --default-branch develop`, { silent: true });
|
|
78
|
+
defaultBranch = 'develop';
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// 権限不足等 → 変更しない(致命にしない)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
23
84
|
}
|
|
24
|
-
|
|
25
|
-
exec(`gh repo edit ${contentRepo} --default-branch develop`, { silent: true });
|
|
26
|
-
return ok({ branches: ['main', ...branches], defaultBranch: 'develop' });
|
|
85
|
+
return ok({ branches: [base, ...created], defaultBranch, pushed });
|
|
27
86
|
}
|
|
28
87
|
catch (e) {
|
|
29
88
|
return fail(`Git 操作失敗: ${e.message}`, 'EXEC_FAILED');
|
package/dist/core/github.d.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* core/github — GitHub
|
|
2
|
+
* core/github — GitHub 連携(読み取り中心)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Issue #325: リポジトリの「作成」「クローン」は CLI の管轄外にした。
|
|
5
|
+
* 対象リポジトリはオペレーターが用意し、カレントフォルダへクローン済み(origin 設定済み)
|
|
6
|
+
* である前提で、init はその既存 origin を使ってカレントフォルダへ展開する。
|
|
5
7
|
*/
|
|
6
8
|
import { type OperationResult } from './types.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/**
|
|
10
|
+
* git remote URL(SSH / HTTPS どちらも)から `owner/repo` を取り出す純粋関数。
|
|
11
|
+
* 解釈できなければ null。末尾の `.git` は除去する。
|
|
12
|
+
*
|
|
13
|
+
* 対応形式:
|
|
14
|
+
* - `https://github.com/owner/repo.git`
|
|
15
|
+
* - `https://github.com/owner/repo`
|
|
16
|
+
* - `git@github.com:owner/repo.git`
|
|
17
|
+
* - `ssh://git@github.com/owner/repo.git`
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseOriginRepo(remoteUrl: string): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* カレント(projectDir)の git `origin` から `owner/repo` を取得する。
|
|
22
|
+
* origin が無い/git 管理下でない場合は null。
|
|
23
|
+
*/
|
|
24
|
+
export declare function getOriginRepo(projectDir: string): string | null;
|
|
14
25
|
export declare function getAuthenticatedUser(): OperationResult<{
|
|
15
26
|
username: string;
|
|
16
27
|
}>;
|
package/dist/core/github.js
CHANGED
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* core/github — GitHub
|
|
2
|
+
* core/github — GitHub 連携(読み取り中心)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Issue #325: リポジトリの「作成」「クローン」は CLI の管轄外にした。
|
|
5
|
+
* 対象リポジトリはオペレーターが用意し、カレントフォルダへクローン済み(origin 設定済み)
|
|
6
|
+
* である前提で、init はその既存 origin を使ってカレントフォルダへ展開する。
|
|
5
7
|
*/
|
|
6
|
-
import fs from 'node:fs';
|
|
7
8
|
import { ok, fail } from './types.js';
|
|
8
9
|
import { exec } from '../lib/shell.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
/**
|
|
11
|
+
* git remote URL(SSH / HTTPS どちらも)から `owner/repo` を取り出す純粋関数。
|
|
12
|
+
* 解釈できなければ null。末尾の `.git` は除去する。
|
|
13
|
+
*
|
|
14
|
+
* 対応形式:
|
|
15
|
+
* - `https://github.com/owner/repo.git`
|
|
16
|
+
* - `https://github.com/owner/repo`
|
|
17
|
+
* - `git@github.com:owner/repo.git`
|
|
18
|
+
* - `ssh://git@github.com/owner/repo.git`
|
|
19
|
+
*/
|
|
20
|
+
export function parseOriginRepo(remoteUrl) {
|
|
21
|
+
const url = remoteUrl.trim();
|
|
22
|
+
if (!url)
|
|
23
|
+
return null;
|
|
24
|
+
// scp 形式: git@host:owner/repo(.git)
|
|
25
|
+
const scp = url.match(/^[^@]+@[^:]+:(.+?)(?:\.git)?$/);
|
|
26
|
+
if (scp)
|
|
27
|
+
return normalizeOwnerRepo(scp[1]);
|
|
28
|
+
// URL 形式: scheme://[user@]host/owner/repo(.git)
|
|
29
|
+
const m = url.match(/^[a-z]+:\/\/[^/]+\/(.+?)(?:\.git)?$/i);
|
|
30
|
+
if (m)
|
|
31
|
+
return normalizeOwnerRepo(m[1]);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function normalizeOwnerRepo(pathPart) {
|
|
35
|
+
const segments = pathPart.replace(/\/+$/, '').split('/').filter(Boolean);
|
|
36
|
+
if (segments.length < 2)
|
|
37
|
+
return null;
|
|
38
|
+
// owner/repo(末尾2セグメント)。GitHub の owner/repo 以外のパスは想定しない。
|
|
39
|
+
const owner = segments[segments.length - 2];
|
|
40
|
+
const repo = segments[segments.length - 1];
|
|
41
|
+
return `${owner}/${repo}`;
|
|
21
42
|
}
|
|
22
|
-
|
|
43
|
+
/**
|
|
44
|
+
* カレント(projectDir)の git `origin` から `owner/repo` を取得する。
|
|
45
|
+
* origin が無い/git 管理下でない場合は null。
|
|
46
|
+
*/
|
|
47
|
+
export function getOriginRepo(projectDir) {
|
|
48
|
+
let url = '';
|
|
23
49
|
try {
|
|
24
|
-
|
|
25
|
-
exec(`gh repo clone ${contentRepo} ${repoName}`, { silent: true });
|
|
26
|
-
return ok({ path: projectDir, alreadyExisted: false });
|
|
50
|
+
url = exec('git remote get-url origin', { cwd: projectDir, silent: true });
|
|
27
51
|
}
|
|
28
|
-
catch
|
|
29
|
-
|
|
30
|
-
return ok({ path: projectDir, alreadyExisted: true }, true);
|
|
31
|
-
}
|
|
32
|
-
return fail(`クローン失敗: ${error.message}`, 'EXEC_FAILED');
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
33
54
|
}
|
|
55
|
+
return parseOriginRepo(url);
|
|
34
56
|
}
|
|
35
57
|
export function getAuthenticatedUser() {
|
|
36
58
|
try {
|
package/dist/core/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { readConfig, writeConfig, updateConfig, validateConfig, buildConfig, } f
|
|
|
11
11
|
export type { EditableConfigFields, ConfigValidationError } from './config.js';
|
|
12
12
|
export { checkGit, checkGhCli, checkWrangler, checkPrerequisitesFor, } from './prerequisites.js';
|
|
13
13
|
export type { PrerequisiteTarget } from './prerequisites.js';
|
|
14
|
-
export {
|
|
14
|
+
export { parseOriginRepo, getOriginRepo, getAuthenticatedUser } from './github.js';
|
|
15
15
|
export { createR2Bucket, setWorkerSecretByName, setupCloudflareResources, } from './cloudflare.js';
|
|
16
16
|
export type { CloudflareSetupResult } from './cloudflare.js';
|
|
17
17
|
export { createFullContentStructure } from './content-structure.js';
|
package/dist/core/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { readConfig, writeConfig, updateConfig, validateConfig, buildConfig, } f
|
|
|
13
13
|
// Prerequisites — ツール別チェック
|
|
14
14
|
export { checkGit, checkGhCli, checkWrangler, checkPrerequisitesFor, } from './prerequisites.js';
|
|
15
15
|
// GitHub
|
|
16
|
-
export {
|
|
16
|
+
export { parseOriginRepo, getOriginRepo, getAuthenticatedUser } from './github.js';
|
|
17
17
|
// Cloudflare
|
|
18
18
|
export { createR2Bucket, setWorkerSecretByName, setupCloudflareResources, } from './cloudflare.js';
|
|
19
19
|
// Content structure
|
package/dist/index.js
CHANGED
|
@@ -22,8 +22,11 @@ program
|
|
|
22
22
|
.version(pkg.version);
|
|
23
23
|
program
|
|
24
24
|
.command('init')
|
|
25
|
-
.description('Initialize
|
|
26
|
-
.option('--skip-github', 'Skip GitHub
|
|
25
|
+
.description('Initialize Frelio CMS in the CURRENT folder of an already-cloned repo (scaffold, deploy admin, set up R2). Does NOT create or clone the repo — prepare it first (#325)')
|
|
26
|
+
.option('--skip-github', 'Skip all GitHub/git integration (no origin requirement, no commit/branches/push). Scaffold only')
|
|
27
|
+
.option('--no-commit', 'Scaffold without committing (leaves changes in the working tree; implies no branches/push) (#325)')
|
|
28
|
+
.option('--no-branches', 'Do not create develop/admin/staging branches (#325)')
|
|
29
|
+
.option('--no-push', 'Commit locally but do not push to origin (#325)')
|
|
27
30
|
.option('--skip-cloudflare', 'Skip Cloudflare setup (R2 bucket, Worker secrets)')
|
|
28
31
|
.option('--content-repo <repo>', 'Repository name (owner/repo)')
|
|
29
32
|
.option('--site-title <title>', 'Site title')
|
|
@@ -14,7 +14,7 @@ export type ResourceLinkSection = {
|
|
|
14
14
|
links: ResourceLink[];
|
|
15
15
|
};
|
|
16
16
|
export type ResourceLinkOptions = {
|
|
17
|
-
/** GitHub
|
|
17
|
+
/** GitHub 連携を行ったか(既存リポジトリを使用。--skip-github で false) */
|
|
18
18
|
github: boolean;
|
|
19
19
|
/** Cloudflare リソースを wrangler で作成したか(--skip-cloudflare で false) */
|
|
20
20
|
cloudflare: boolean;
|