@c-time/frelio-cli 1.8.1 → 2.0.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 +60 -97
- package/dist/commands/add-staging.js +8 -8
- package/dist/commands/init.d.ts +1 -4
- package/dist/commands/init.js +37 -108
- package/dist/commands/set-domain.js +1 -1
- package/dist/commands/set-mode.js +1 -6
- package/dist/commands/update.d.ts +2 -2
- package/dist/commands/update.js +3 -8
- package/dist/core/__fixtures__/template/worker/index.d.ts +4 -0
- package/dist/core/__fixtures__/template/worker/index.js +6 -0
- package/dist/core/bundle.js +14 -12
- package/dist/core/cloudflare.d.ts +26 -11
- package/dist/core/cloudflare.js +28 -30
- package/dist/core/config.js +25 -6
- package/dist/core/file-generators.d.ts +16 -13
- package/dist/core/file-generators.js +34 -52
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.js +2 -4
- package/dist/core/migrations/pages-to-workers-issue184.d.ts +18 -0
- package/dist/core/migrations/pages-to-workers-issue184.js +70 -0
- package/dist/core/migrations/registry.js +8 -1
- package/dist/core/site-mode.d.ts +5 -6
- package/dist/core/site-mode.js +5 -6
- package/dist/core/status.js +1 -2
- package/dist/core/template-refresh.d.ts +8 -2
- package/dist/core/template-refresh.js +63 -22
- package/dist/core/types.d.ts +0 -2
- package/dist/index.js +1 -4
- package/dist/lib/npm-registry.d.ts +4 -4
- package/dist/lib/npm-registry.js +4 -4
- package/dist/lib/resource-links.d.ts +1 -1
- package/dist/lib/resource-links.js +4 -4
- package/dist/lib/template-renderer.js +3 -6
- package/dist/lib/templates.d.ts +33 -57
- package/dist/lib/templates.js +82 -579
- package/package.json +3 -3
- package/dist/core/terraform.d.ts +0 -7
- package/dist/core/terraform.js +0 -47
package/dist/commands/init.js
CHANGED
|
@@ -8,7 +8,7 @@ import prompts from 'prompts';
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { log, logStep, logSuccess, logError } from '../lib/shell.js';
|
|
11
|
-
import { generateStagingDomain,
|
|
11
|
+
import { generateStagingDomain, buildWorkerNames, } from '../lib/templates.js';
|
|
12
12
|
import { buildResourceLinks } from '../lib/resource-links.js';
|
|
13
13
|
import { validateContentRepo, validateR2PublicUrl, validateRequired } from '../lib/validators.js';
|
|
14
14
|
// core functions
|
|
@@ -19,7 +19,6 @@ import { setupCloudflareResources } from '../core/cloudflare.js';
|
|
|
19
19
|
import { setupContactWorker } from '../core/contact.js';
|
|
20
20
|
import { createFullContentStructure } from '../core/content-structure.js';
|
|
21
21
|
import { regenerateAllConfigFiles } from '../core/file-generators.js';
|
|
22
|
-
import { generateTerraformFiles } from '../core/terraform.js';
|
|
23
22
|
import { installBundle } from '../core/bundle.js';
|
|
24
23
|
import { initialCommitAndBranches, getGitIdentity, setGitIdentity, } from '../core/git-operations.js';
|
|
25
24
|
export async function initCommand(options) {
|
|
@@ -31,7 +30,7 @@ export async function initCommand(options) {
|
|
|
31
30
|
const targets = ['git'];
|
|
32
31
|
if (!options.skipGithub)
|
|
33
32
|
targets.push('github');
|
|
34
|
-
if (!options.skipCloudflare
|
|
33
|
+
if (!options.skipCloudflare)
|
|
35
34
|
targets.push('cloudflare');
|
|
36
35
|
const prereqs = checkPrerequisitesFor(targets);
|
|
37
36
|
if (prereqs.success) {
|
|
@@ -54,7 +53,7 @@ export async function initCommand(options) {
|
|
|
54
53
|
}
|
|
55
54
|
log('');
|
|
56
55
|
// ── お問い合わせ機能(任意)──
|
|
57
|
-
const contactInput = options.skipCloudflare
|
|
56
|
+
const contactInput = options.skipCloudflare ? null : await promptContact(config);
|
|
58
57
|
log('');
|
|
59
58
|
// ── OAuth App 案内 ──
|
|
60
59
|
log('🔑 GitHub OAuth App:');
|
|
@@ -67,9 +66,10 @@ export async function initCommand(options) {
|
|
|
67
66
|
log(' ⚠ OAuth App は GitHub の Web UI で作成が必要です。');
|
|
68
67
|
log(' → https://github.com/settings/developers');
|
|
69
68
|
log(' → New OAuth App:');
|
|
70
|
-
log(` - Application name: ${config.siteTitle || config.
|
|
71
|
-
log(` - Homepage URL: https://${config.
|
|
72
|
-
log(` - Callback URL: https://${config.
|
|
69
|
+
log(` - Application name: ${config.siteTitle || config.adminWorkerName} CMS`);
|
|
70
|
+
log(` - Homepage URL: https://${config.adminWorkerName}.<your-subdomain>.workers.dev`);
|
|
71
|
+
log(` - Callback URL: https://${config.adminWorkerName}.<your-subdomain>.workers.dev/api/auth/callback`);
|
|
72
|
+
log(' (<your-subdomain> は管理画面 Worker 初回デプロイ後に確定する workers.dev サブドメイン。独自ドメイン運用ならそのドメインに読み替え)');
|
|
73
73
|
log(' - Enable Device Flow: チェックしない(Disable のまま。Frelio は認可コードフローを使用)');
|
|
74
74
|
log('');
|
|
75
75
|
const oauthResponse = await prompts([
|
|
@@ -153,7 +153,7 @@ export async function initCommand(options) {
|
|
|
153
153
|
logError(bundleResult.error);
|
|
154
154
|
log(' ℹ リリースが公開されていない場合は、手動でバンドルを展開してください。');
|
|
155
155
|
log(' npm pack @c-time/frelio-cms で取得した tarball を展開し、');
|
|
156
|
-
log(' package/dist/(
|
|
156
|
+
log(' package/dist/(worker を除く)を admin/、package/dist/worker を admin-worker/、');
|
|
157
157
|
log(' package/workers を workers/ に配置します。');
|
|
158
158
|
}
|
|
159
159
|
// 設定ファイル生成
|
|
@@ -167,26 +167,14 @@ export async function initCommand(options) {
|
|
|
167
167
|
logError(configResult.error);
|
|
168
168
|
process.exit(1);
|
|
169
169
|
}
|
|
170
|
-
// Cloudflare セットアップ
|
|
171
|
-
if (options.
|
|
172
|
-
step++;
|
|
173
|
-
logStep(step, totalSteps, 'Terraform ファイル生成...');
|
|
174
|
-
const tfResult = generateTerraformFiles(projectDir, config);
|
|
175
|
-
if (tfResult.success) {
|
|
176
|
-
logSuccess('Terraform ファイル生成完了(terraform/)');
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
logError(tfResult.error);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else if (!options.skipCloudflare) {
|
|
170
|
+
// Cloudflare セットアップ
|
|
171
|
+
if (!options.skipCloudflare) {
|
|
183
172
|
step++;
|
|
184
173
|
logStep(step, totalSteps, 'Cloudflare セットアップ...');
|
|
185
174
|
const secret = config.githubClientSecret;
|
|
186
|
-
const
|
|
187
|
-
const cfResult = setupCloudflareResources(config, secret, cfToken);
|
|
175
|
+
const cfResult = setupCloudflareResources(config, secret);
|
|
188
176
|
if (cfResult.success) {
|
|
189
|
-
const { r2Bucket,
|
|
177
|
+
const { r2Bucket, secrets, needsWorkersDevSubdomain } = cfResult.data;
|
|
190
178
|
if (r2Bucket.success) {
|
|
191
179
|
logSuccess(r2Bucket.alreadyExisted
|
|
192
180
|
? `R2 バケット "${config.r2BucketName}" は既に存在します`
|
|
@@ -195,30 +183,20 @@ export async function initCommand(options) {
|
|
|
195
183
|
else {
|
|
196
184
|
logError(r2Bucket.error);
|
|
197
185
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
: `Pages プロジェクト "${config.pagesProjectName}"(コンテンツ配信)作成完了`);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
logError(contentPages.error);
|
|
205
|
-
}
|
|
206
|
-
if (adminPages.success) {
|
|
207
|
-
logSuccess(adminPages.alreadyExisted
|
|
208
|
-
? `Pages プロジェクト "${config.adminPagesProjectName}" は既に存在します`
|
|
209
|
-
: `Pages プロジェクト "${config.adminPagesProjectName}"(管理画面)作成完了`);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
logError(adminPages.error);
|
|
213
|
-
}
|
|
186
|
+
// Issue #184: Worker は wrangler deploy 時に自動作成される(事前作成は不要)。
|
|
187
|
+
// admin Worker のシークレット(GITHUB_CLIENT_SECRET)は
|
|
188
|
+
// wrangler secret put が Worker を自動作成して設定する(初回デプロイ前でも可)。
|
|
214
189
|
for (const s of secrets) {
|
|
215
190
|
if (s.success) {
|
|
216
|
-
logSuccess('シークレット設定完了');
|
|
191
|
+
logSuccess('admin Worker シークレット設定完了');
|
|
217
192
|
}
|
|
218
193
|
else {
|
|
219
194
|
logError(s.error);
|
|
220
195
|
}
|
|
221
196
|
}
|
|
197
|
+
if (needsWorkersDevSubdomain) {
|
|
198
|
+
log(' ℹ staging プレビュー URL(<branch>-<worker>.<subdomain>.workers.dev)は、admin Worker の初回デプロイで workers.dev サブドメインが登録されてから有効になります。');
|
|
199
|
+
}
|
|
222
200
|
}
|
|
223
201
|
}
|
|
224
202
|
// お問い合わせワーカー(任意)
|
|
@@ -266,15 +244,15 @@ export async function initCommand(options) {
|
|
|
266
244
|
log('');
|
|
267
245
|
log('✅ セットアップ完了!');
|
|
268
246
|
log('');
|
|
269
|
-
log(` 管理画面: https://${config.
|
|
247
|
+
log(` 管理画面: https://${config.adminWorkerName}.<your-subdomain>.workers.dev/(admin Worker 初回デプロイ後)`);
|
|
270
248
|
// カスタムドメイン未設定時は staging ブランチのプレビューエイリアス(GitHub Actions の
|
|
271
|
-
// wrangler
|
|
272
|
-
log(` プレビュー: ${config.previewUrl || `https://staging
|
|
249
|
+
// wrangler versions upload --preview-alias で生成)を案内する。
|
|
250
|
+
log(` プレビュー: ${config.previewUrl || `https://staging-${config.contentWorkerName}.<your-subdomain>.workers.dev`}`);
|
|
273
251
|
log('');
|
|
274
252
|
// 作成したリソースへのリンク(確認・設定変更の導線)
|
|
275
253
|
const resourceSections = buildResourceLinks(config, {
|
|
276
254
|
github: !options.skipGithub,
|
|
277
|
-
cloudflare: !options.
|
|
255
|
+
cloudflare: !options.skipCloudflare,
|
|
278
256
|
});
|
|
279
257
|
if (resourceSections.length > 0) {
|
|
280
258
|
log('🔗 作成したリソース:');
|
|
@@ -286,27 +264,14 @@ export async function initCommand(options) {
|
|
|
286
264
|
}
|
|
287
265
|
log('');
|
|
288
266
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
log(' 3. terraform init');
|
|
294
|
-
log(' 4. terraform plan');
|
|
295
|
-
log(' 5. terraform apply');
|
|
296
|
-
log('');
|
|
297
|
-
log(' 残りの手動作業:');
|
|
298
|
-
log(` 1. コンテンツ配信 Pages(${config.pagesProjectName})にリポジトリを接続`);
|
|
299
|
-
log(` 2. 管理画面 Pages(${config.adminPagesProjectName})にリポジトリを接続(admin ブランチ)`);
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
log(' 残りの手動作業:');
|
|
303
|
-
log(` 1. コンテンツ配信 Pages(${config.pagesProjectName})にリポジトリを接続`);
|
|
304
|
-
log(` 2. 管理画面 Pages(${config.adminPagesProjectName})にリポジトリを接続(admin ブランチ)`);
|
|
305
|
-
}
|
|
267
|
+
log(' 残りの手動作業:');
|
|
268
|
+
log(' 1. GitHub Actions シークレットを設定: CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID');
|
|
269
|
+
log(' 2. admin ブランチへ push して管理画面 Worker を初回デプロイ(workers.dev サブドメインが登録される)');
|
|
270
|
+
log(' 3. staging ブランチへ push してコンテンツのプレビュー、main で本番デプロイ');
|
|
306
271
|
if (config.stagingDomain) {
|
|
307
|
-
log(`
|
|
272
|
+
log(` 4. プレビュー用カスタムドメインを設定: ${config.stagingDomain}`);
|
|
308
273
|
}
|
|
309
|
-
log(` ${config.stagingDomain ? '
|
|
274
|
+
log(` ${config.stagingDomain ? '5' : '4'}. ステージングのアクセス制限を設定(Cloudflare Access 推奨)`);
|
|
310
275
|
log('');
|
|
311
276
|
}
|
|
312
277
|
// ---------------------------------------------------------------------------
|
|
@@ -377,7 +342,10 @@ async function promptContact(config) {
|
|
|
377
342
|
}, { onCancel: () => process.exit(0) });
|
|
378
343
|
if (!enable.value)
|
|
379
344
|
return null;
|
|
380
|
-
|
|
345
|
+
// Issue #184: 管理画面は Worker(<admin>.<subdomain>.workers.dev)配信。サブドメインは
|
|
346
|
+
// 初回デプロイまで未確定のため暫定値を入れる。確定後に CMS 基本設定 / contact worker の
|
|
347
|
+
// ADMIN_INBOX_URL を実 URL(または独自ドメイン)へ更新する。
|
|
348
|
+
const adminInboxUrl = `https://${config.adminWorkerName}.workers.dev/inbox`;
|
|
381
349
|
const base = await prompts([
|
|
382
350
|
{
|
|
383
351
|
type: 'text',
|
|
@@ -557,36 +525,6 @@ async function promptConfig(options) {
|
|
|
557
525
|
return userResult.success ? userResult.data.username : '';
|
|
558
526
|
},
|
|
559
527
|
},
|
|
560
|
-
{
|
|
561
|
-
type: options.cloudflareAccountId !== undefined
|
|
562
|
-
? null
|
|
563
|
-
: () => {
|
|
564
|
-
log('');
|
|
565
|
-
log(' ℹ Cloudflare アカウント ID / API トークン(デプロイ管理機能 / Issue #27)');
|
|
566
|
-
log(' 管理画面のデプロイ履歴で Cloudflare Pages のデプロイ一覧・削除を行うために使用します。');
|
|
567
|
-
log(' アカウント ID: Cloudflare ダッシュボードの URL や任意ページの右サイドバーで確認できます。');
|
|
568
|
-
log(' 未入力なら空欄のまま Enter(後から admin/config.json と wrangler.toml で設定可)');
|
|
569
|
-
return 'text';
|
|
570
|
-
},
|
|
571
|
-
name: 'cloudflareAccountId',
|
|
572
|
-
message: 'Cloudflare アカウント ID (任意):',
|
|
573
|
-
initial: '',
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
type: options.cloudflareApiToken !== undefined
|
|
577
|
-
? null
|
|
578
|
-
: () => {
|
|
579
|
-
log('');
|
|
580
|
-
log(' ℹ Cloudflare API トークン(任意・シークレット)');
|
|
581
|
-
log(' スコープ: Account → Cloudflare Pages: Edit(一覧取得+削除に必要)');
|
|
582
|
-
log(' Dashboard → My Profile → API Tokens → Create Token で発行できます。');
|
|
583
|
-
log(' 管理画面 Pages プロジェクトのシークレットとして登録されます(コミットされません)。');
|
|
584
|
-
return 'password';
|
|
585
|
-
},
|
|
586
|
-
name: 'cloudflareApiToken',
|
|
587
|
-
message: 'Cloudflare API トークン (任意):',
|
|
588
|
-
initial: '',
|
|
589
|
-
},
|
|
590
528
|
], { onCancel: () => process.exit(0) });
|
|
591
529
|
const contentRepo = options.contentRepo || response.contentRepo;
|
|
592
530
|
if (!contentRepo)
|
|
@@ -594,7 +532,7 @@ async function promptConfig(options) {
|
|
|
594
532
|
const repoName = contentRepo.split('/')[1];
|
|
595
533
|
const stagingDomain = options.stagingDomain ?? response.stagingDomain ?? '';
|
|
596
534
|
const previewUrl = stagingDomain ? `https://${stagingDomain}` : '';
|
|
597
|
-
const {
|
|
535
|
+
const { contentWorkerName, adminWorkerName } = buildWorkerNames(repoName, options.randomSuffix ?? true);
|
|
598
536
|
const config = {
|
|
599
537
|
contentRepo,
|
|
600
538
|
githubClientId: options.clientId || '',
|
|
@@ -603,20 +541,15 @@ async function promptConfig(options) {
|
|
|
603
541
|
previewUrl,
|
|
604
542
|
r2BucketName: options.r2BucketName ?? response.r2BucketName ?? `${repoName}-files`,
|
|
605
543
|
r2PublicUrl: options.r2PublicUrl ?? response.r2PublicUrl ?? '',
|
|
606
|
-
|
|
607
|
-
|
|
544
|
+
contentWorkerName,
|
|
545
|
+
adminWorkerName,
|
|
608
546
|
ownerUsername: options.ownerUsername ?? response.ownerUsername ?? '',
|
|
609
547
|
stagingDomain,
|
|
610
|
-
cloudflareAccountId: options.cloudflareAccountId ?? response.cloudflareAccountId ?? '',
|
|
611
548
|
saveTimezone: '+09:00',
|
|
612
549
|
};
|
|
613
550
|
if (options.clientSecret) {
|
|
614
551
|
config.githubClientSecret = options.clientSecret;
|
|
615
552
|
}
|
|
616
|
-
const cloudflareApiToken = options.cloudflareApiToken ?? response.cloudflareApiToken;
|
|
617
|
-
if (cloudflareApiToken) {
|
|
618
|
-
config.cloudflareApiToken = cloudflareApiToken;
|
|
619
|
-
}
|
|
620
553
|
return config;
|
|
621
554
|
}
|
|
622
555
|
function buildConfigFromOptions(options) {
|
|
@@ -629,7 +562,6 @@ function buildConfigFromOptions(options) {
|
|
|
629
562
|
r2BucketName: options.r2BucketName,
|
|
630
563
|
r2PublicUrl: options.r2PublicUrl,
|
|
631
564
|
ownerUsername: options.ownerUsername,
|
|
632
|
-
cloudflareAccountId: options.cloudflareAccountId,
|
|
633
565
|
randomSuffix: options.randomSuffix,
|
|
634
566
|
});
|
|
635
567
|
if (!result.success) {
|
|
@@ -647,16 +579,13 @@ function buildConfigFromOptions(options) {
|
|
|
647
579
|
return {
|
|
648
580
|
...config,
|
|
649
581
|
githubClientSecret: options.clientSecret,
|
|
650
|
-
cloudflareApiToken: options.cloudflareApiToken,
|
|
651
582
|
};
|
|
652
583
|
}
|
|
653
584
|
function getTotalSteps(options, withContact = false) {
|
|
654
585
|
let steps = 3; // content structure (includes workflows), bundle, config files
|
|
655
586
|
if (!options.skipGithub)
|
|
656
587
|
steps += 4; // create repo, clone, git identity, commit/push
|
|
657
|
-
if (options.
|
|
658
|
-
steps += 1;
|
|
659
|
-
else if (!options.skipCloudflare)
|
|
588
|
+
if (!options.skipCloudflare)
|
|
660
589
|
steps += 1;
|
|
661
590
|
if (withContact)
|
|
662
591
|
steps += 1;
|
|
@@ -130,7 +130,7 @@ export async function setDomainCommand(options) {
|
|
|
130
130
|
log(' 次の手動作業:');
|
|
131
131
|
log(' 1. 差分を確認して develop へ commit / push');
|
|
132
132
|
log(' (wrangler.toml [vars] はデプロイ時に自動適用される / Issue #23)');
|
|
133
|
-
log(' 2. Cloudflare
|
|
133
|
+
log(' 2. Cloudflare Dashboard → 対象 Worker → Settings → Domains & Routes でカスタムドメインを追加(本番 + プレビュー)');
|
|
134
134
|
log(' 3. R2 公開バケットのカスタムドメインを設定(独自ドメイン化した場合)');
|
|
135
135
|
log(' 4. GitHub OAuth App の Homepage / Callback URL を新ドメインに更新');
|
|
136
136
|
log(' 5. file-upload Worker を別運用している場合は再デプロイ:');
|
|
@@ -29,13 +29,8 @@ export async function setModeCommand(mode) {
|
|
|
29
29
|
log(` - ${p}`);
|
|
30
30
|
}
|
|
31
31
|
log('');
|
|
32
|
-
log(' ⚠
|
|
33
|
-
log(' 変更を反映するにはコンテンツ Pages の再デプロイが必要です:');
|
|
32
|
+
log(' ⚠ siteMode は worker/site-mode.ts に焼き込まれます。反映にはコンテンツの再デプロイが必要です:');
|
|
34
33
|
log(' 1. 差分を develop へ commit / push');
|
|
35
34
|
log(' 2. CMS の「直接デプロイ」フロー、または該当ブランチへの push でコンテンツを再デプロイ');
|
|
36
35
|
log('');
|
|
37
|
-
log(' 💡 最速の切替(キルスイッチ等で再ビルドを避けたい場合):');
|
|
38
|
-
log(' - wrangler.toml の SITE_MODE を変更し `wrangler pages deploy public --project-name=<content>` で再デプロイ');
|
|
39
|
-
log(' - もしくは Cloudflare Dashboard の Pages → 該当プロジェクト → Settings → Variables で SITE_MODE を変更し再デプロイ');
|
|
40
|
-
log('');
|
|
41
36
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* frelio update - CMS Admin バンドル+テンプレートの更新
|
|
3
3
|
*
|
|
4
|
-
* - バンドル: core/bundle の updateBundle(admin/
|
|
4
|
+
* - バンドル: core/bundle の updateBundle(admin/ SPA・admin-worker/・workers/)
|
|
5
5
|
* - テンプレート: core/template-refresh の refreshTemplates(.github ワークフロー /
|
|
6
|
-
*
|
|
6
|
+
* AGENTS.md / CLAUDE.md / wrangler.content.toml / wrangler.admin.toml / worker/site-mode.ts)
|
|
7
7
|
*/
|
|
8
8
|
type UpdateOptions = {
|
|
9
9
|
version?: string;
|
package/dist/commands/update.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* frelio update - CMS Admin バンドル+テンプレートの更新
|
|
3
3
|
*
|
|
4
|
-
* - バンドル: core/bundle の updateBundle(admin/
|
|
4
|
+
* - バンドル: core/bundle の updateBundle(admin/ SPA・admin-worker/・workers/)
|
|
5
5
|
* - テンプレート: core/template-refresh の refreshTemplates(.github ワークフロー /
|
|
6
|
-
*
|
|
6
|
+
* AGENTS.md / CLAUDE.md / wrangler.content.toml / wrangler.admin.toml / worker/site-mode.ts)
|
|
7
7
|
*/
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
@@ -69,7 +69,7 @@ export async function updateCommand(options) {
|
|
|
69
69
|
log('');
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
log(' 📥 テンプレート(ワークフロー / functions / wrangler)を再生成中...');
|
|
72
|
+
log(' 📥 テンプレート(ワークフロー / AI 文書 / functions / wrangler)を再生成中...');
|
|
73
73
|
const refresh = await refreshTemplates(projectDir, config, {
|
|
74
74
|
force: options.force,
|
|
75
75
|
});
|
|
@@ -92,9 +92,4 @@ export async function updateCommand(options) {
|
|
|
92
92
|
log(' develop へマージしただけでは反映されません。次のように admin を進めてください:');
|
|
93
93
|
log(' git push origin origin/develop:admin # develop はメインブランチ名に読み替え');
|
|
94
94
|
log('');
|
|
95
|
-
log(' ℹ デプロイ管理機能(Issue #27)を使う場合は次の環境変数が必要です:');
|
|
96
|
-
log(' • CLOUDFLARE_API_TOKEN … 管理画面 Pages のシークレット(wrangler pages secret put)');
|
|
97
|
-
log(' • CLOUDFLARE_ACCOUNT_ID … wrangler.toml の [vars]');
|
|
98
|
-
log(' • PAGES_PROJECT_NAME … wrangler.toml の [vars](コンテンツ配信 Pages プロジェクト名)');
|
|
99
|
-
log('');
|
|
100
95
|
}
|
package/dist/core/bundle.js
CHANGED
|
@@ -14,12 +14,14 @@ export async function installBundle(projectDir, version) {
|
|
|
14
14
|
try {
|
|
15
15
|
const release = version ? await getRelease(version) : await getLatestRelease();
|
|
16
16
|
const tarPath = await downloadTarball(release, tmpDir);
|
|
17
|
-
const { adminDir,
|
|
17
|
+
const { adminDir, adminWorkerDir, workersDir } = await extractNpmTarball(tarPath, tmpDir);
|
|
18
18
|
if (fs.existsSync(adminDir)) {
|
|
19
|
-
|
|
19
|
+
// dist/ 直下の worker/(バンドル済み admin Worker)は SPA には含めない(別途配置)
|
|
20
|
+
copyDir(adminDir, path.join(projectDir, 'admin'), ['worker']);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// Issue #184 Phase 2: バンドル済み管理画面 Worker を admin-worker/ に配置
|
|
23
|
+
if (fs.existsSync(adminWorkerDir)) {
|
|
24
|
+
copyDir(adminWorkerDir, path.join(projectDir, 'admin-worker'));
|
|
23
25
|
}
|
|
24
26
|
if (fs.existsSync(workersDir)) {
|
|
25
27
|
copyDir(workersDir, path.join(projectDir, 'workers'));
|
|
@@ -51,19 +53,19 @@ export async function updateBundle(projectDir, version) {
|
|
|
51
53
|
try {
|
|
52
54
|
const release = version ? await getRelease(version) : await getLatestRelease();
|
|
53
55
|
const tarPath = await downloadTarball(release, tmpDir);
|
|
54
|
-
const { adminDir: srcAdminDir,
|
|
56
|
+
const { adminDir: srcAdminDir, adminWorkerDir: srcAdminWorkerDir, workersDir: srcWorkersDir, } = await extractNpmTarball(tarPath, tmpDir);
|
|
55
57
|
// admin/ 置き換え
|
|
56
58
|
if (fs.existsSync(srcAdminDir)) {
|
|
57
59
|
fs.rmSync(adminDir, { recursive: true, force: true });
|
|
58
|
-
copyDir(srcAdminDir, adminDir, ['
|
|
60
|
+
copyDir(srcAdminDir, adminDir, ['worker']);
|
|
59
61
|
}
|
|
60
|
-
//
|
|
61
|
-
const
|
|
62
|
-
if (fs.existsSync(
|
|
63
|
-
if (fs.existsSync(
|
|
64
|
-
fs.rmSync(
|
|
62
|
+
// 管理画面 Worker(Issue #184 Phase 2)置き換え: admin-worker/
|
|
63
|
+
const adminWorkerDestDir = path.join(projectDir, 'admin-worker');
|
|
64
|
+
if (fs.existsSync(srcAdminWorkerDir)) {
|
|
65
|
+
if (fs.existsSync(adminWorkerDestDir)) {
|
|
66
|
+
fs.rmSync(adminWorkerDestDir, { recursive: true, force: true });
|
|
65
67
|
}
|
|
66
|
-
copyDir(
|
|
68
|
+
copyDir(srcAdminWorkerDir, adminWorkerDestDir);
|
|
67
69
|
}
|
|
68
70
|
// workers/ 置き換え
|
|
69
71
|
const workersDestDir = path.join(projectDir, 'workers');
|
|
@@ -7,10 +7,14 @@ import { type ProjectConfig, type OperationResult } from './types.js';
|
|
|
7
7
|
export declare function createR2Bucket(bucketName: string): OperationResult<{
|
|
8
8
|
alreadyExisted: boolean;
|
|
9
9
|
}>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Worker のシークレットを名前指定で設定する(Issue #184)。
|
|
12
|
+
*
|
|
13
|
+
* `wrangler secret put <name> --name <workerName>`。**Worker が未デプロイの場合は失敗する**
|
|
14
|
+
* (Workers のシークレットは存在する Worker にのみ設定できる)。init では初回デプロイ後に
|
|
15
|
+
* 再実行する案内を出す(fail を握りつぶさず呼び出し側へ返す)。
|
|
16
|
+
*/
|
|
17
|
+
export declare function setWorkerSecretByName(workerName: string, secretName: string, secretValue: string): OperationResult;
|
|
14
18
|
/** D1 データベースを作成し database_id を返す(冪等: 既存はその ID を返す) */
|
|
15
19
|
export declare function createD1Database(name: string): OperationResult<{
|
|
16
20
|
databaseId: string;
|
|
@@ -22,12 +26,23 @@ export type CloudflareSetupResult = {
|
|
|
22
26
|
r2Bucket: OperationResult<{
|
|
23
27
|
alreadyExisted: boolean;
|
|
24
28
|
}>;
|
|
25
|
-
|
|
26
|
-
alreadyExisted: boolean;
|
|
27
|
-
}>;
|
|
28
|
-
adminPages: OperationResult<{
|
|
29
|
-
alreadyExisted: boolean;
|
|
30
|
-
}>;
|
|
29
|
+
/** admin Worker へのシークレット投入結果(未デプロイだと失敗→init が再実行を案内)。 */
|
|
31
30
|
secrets: OperationResult[];
|
|
31
|
+
/** preview URL に必要な workers.dev サブドメインの案内(自動登録はしない)。 */
|
|
32
|
+
needsWorkersDevSubdomain: boolean;
|
|
32
33
|
};
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Cloudflare リソースをセットアップする(Issue #184: Workers 構成)。
|
|
36
|
+
*
|
|
37
|
+
* Pages プロジェクトの事前作成は不要(Worker は `wrangler deploy` で自動作成)。
|
|
38
|
+
* ここでは R2 バケット作成と、admin Worker のシークレット投入のみ行う。
|
|
39
|
+
*
|
|
40
|
+
* 注意:
|
|
41
|
+
* - Worker シークレットは **Worker が存在(初回デプロイ済み)してから**設定できる。init 時点で
|
|
42
|
+
* まだ未デプロイなら失敗するため、init は失敗時に「初回デプロイ後に再実行」を案内する。
|
|
43
|
+
* - staging プレビュー URL(`<branch>-<worker>.<subdomain>.workers.dev`)には、アカウントの
|
|
44
|
+
* workers.dev サブドメイン登録が必要。admin Worker は workers_dev=true のため初回デプロイで
|
|
45
|
+
* 自動登録される(未登録のうちは content の preview URL が出ない点に注意)。
|
|
46
|
+
* - GITHUB_CLIENT_ID は wrangler.admin.toml の [vars] で配るためシークレット不要。
|
|
47
|
+
*/
|
|
48
|
+
export declare function setupCloudflareResources(config: ProjectConfig, githubClientSecret?: string): OperationResult<CloudflareSetupResult>;
|
package/dist/core/cloudflare.js
CHANGED
|
@@ -21,30 +21,22 @@ export function createR2Bucket(bucketName) {
|
|
|
21
21
|
return fail(`R2 バケット作成失敗: ${msg}`, 'EXEC_FAILED');
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const msg = error.message;
|
|
33
|
-
if (msg.includes('already exists') || msg.includes('A project with this name already exists')) {
|
|
34
|
-
return ok({ alreadyExisted: true }, true);
|
|
35
|
-
}
|
|
36
|
-
return fail(`Pages プロジェクト作成失敗: ${msg}`, 'EXEC_FAILED');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export function setPagesSecret(projectName, secretName, secretValue) {
|
|
24
|
+
/**
|
|
25
|
+
* Worker のシークレットを名前指定で設定する(Issue #184)。
|
|
26
|
+
*
|
|
27
|
+
* `wrangler secret put <name> --name <workerName>`。**Worker が未デプロイの場合は失敗する**
|
|
28
|
+
* (Workers のシークレットは存在する Worker にのみ設定できる)。init では初回デプロイ後に
|
|
29
|
+
* 再実行する案内を出す(fail を握りつぶさず呼び出し側へ返す)。
|
|
30
|
+
*/
|
|
31
|
+
export function setWorkerSecretByName(workerName, secretName, secretValue) {
|
|
40
32
|
try {
|
|
41
|
-
exec(`echo "${secretValue}" | wrangler
|
|
33
|
+
exec(`echo "${secretValue}" | wrangler secret put ${secretName} --name ${workerName}`, {
|
|
42
34
|
silent: true,
|
|
43
35
|
});
|
|
44
36
|
return okVoid();
|
|
45
37
|
}
|
|
46
38
|
catch (e) {
|
|
47
|
-
return fail(`${secretName}
|
|
39
|
+
return fail(`${secretName} の設定に失敗しました(Worker: ${workerName})。初回デプロイ後に再実行してください: ${e.message}`, 'EXEC_FAILED');
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
42
|
/** `wrangler d1 create` の出力 or `d1 info` から database_id を抜き出す */
|
|
@@ -94,20 +86,26 @@ export function setWorkerSecret(secretName, secretValue, cwd) {
|
|
|
94
86
|
return fail(`${secretName} の設定に失敗しました: ${e.message}`, 'EXEC_FAILED');
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Cloudflare リソースをセットアップする(Issue #184: Workers 構成)。
|
|
91
|
+
*
|
|
92
|
+
* Pages プロジェクトの事前作成は不要(Worker は `wrangler deploy` で自動作成)。
|
|
93
|
+
* ここでは R2 バケット作成と、admin Worker のシークレット投入のみ行う。
|
|
94
|
+
*
|
|
95
|
+
* 注意:
|
|
96
|
+
* - Worker シークレットは **Worker が存在(初回デプロイ済み)してから**設定できる。init 時点で
|
|
97
|
+
* まだ未デプロイなら失敗するため、init は失敗時に「初回デプロイ後に再実行」を案内する。
|
|
98
|
+
* - staging プレビュー URL(`<branch>-<worker>.<subdomain>.workers.dev`)には、アカウントの
|
|
99
|
+
* workers.dev サブドメイン登録が必要。admin Worker は workers_dev=true のため初回デプロイで
|
|
100
|
+
* 自動登録される(未登録のうちは content の preview URL が出ない点に注意)。
|
|
101
|
+
* - GITHUB_CLIENT_ID は wrangler.admin.toml の [vars] で配るためシークレット不要。
|
|
102
|
+
*/
|
|
103
|
+
export function setupCloudflareResources(config, githubClientSecret) {
|
|
98
104
|
const r2Bucket = createR2Bucket(config.r2BucketName);
|
|
99
|
-
const contentPages = createPagesProject(config.pagesProjectName, 'main');
|
|
100
|
-
const adminPages = createPagesProject(config.adminPagesProjectName, 'admin');
|
|
101
105
|
const secrets = [];
|
|
106
|
+
// OAuth シークレットは admin Worker のシークレットに設定する。
|
|
102
107
|
if (githubClientSecret) {
|
|
103
|
-
secrets.push(
|
|
104
|
-
secrets.push(setPagesSecret(config.pagesProjectName, 'GITHUB_CLIENT_ID', config.githubClientId));
|
|
105
|
-
}
|
|
106
|
-
// デプロイ管理機能(Issue #27)の Cloudflare API トークン。
|
|
107
|
-
// functions/api/deployments は管理画面 Pages プロジェクト(deploy-admin.yml の配信先)で
|
|
108
|
-
// 実行されるため、トークンは adminPagesProjectName のシークレットに設定する。
|
|
109
|
-
if (cloudflareApiToken) {
|
|
110
|
-
secrets.push(setPagesSecret(config.adminPagesProjectName, 'CLOUDFLARE_API_TOKEN', cloudflareApiToken));
|
|
108
|
+
secrets.push(setWorkerSecretByName(config.adminWorkerName, 'GITHUB_CLIENT_SECRET', githubClientSecret));
|
|
111
109
|
}
|
|
112
|
-
return ok({ r2Bucket,
|
|
110
|
+
return ok({ r2Bucket, secrets, needsWorkersDevSubdomain: true });
|
|
113
111
|
}
|
package/dist/core/config.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { ok, okVoid, fail, } from './types.js';
|
|
10
|
-
import { generateStagingDomain,
|
|
10
|
+
import { generateStagingDomain, buildWorkerNames } from '../lib/templates.js';
|
|
11
11
|
import { validateContentRepo, validateR2PublicUrl, } from '../lib/validators.js';
|
|
12
12
|
/** read-only フィールド(updateConfig で上書き不可) */
|
|
13
13
|
const READ_ONLY_FIELDS = ['contentRepo', 'githubClientId'];
|
|
@@ -23,13 +23,33 @@ export function readConfig(projectDir) {
|
|
|
23
23
|
}
|
|
24
24
|
try {
|
|
25
25
|
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
26
|
-
const
|
|
26
|
+
const parsed = JSON.parse(raw);
|
|
27
|
+
// 後方互換(Issue #191): 旧キー pagesProjectName / adminPagesProjectName を
|
|
28
|
+
// 新キー contentWorkerName / adminWorkerName へ正規化する(既存リポジトリの config.json 対応)。
|
|
29
|
+
const config = normalizeWorkerNameKeys(parsed);
|
|
27
30
|
return ok({ config, path: configPath });
|
|
28
31
|
}
|
|
29
32
|
catch (e) {
|
|
30
33
|
return fail(`config.json の読み込みに失敗: ${e.message}`, 'EXEC_FAILED');
|
|
31
34
|
}
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 旧 Pages 由来の config キー(pagesProjectName / adminPagesProjectName)を、
|
|
38
|
+
* 新キー(contentWorkerName / adminWorkerName)へ移し替える(Issue #191・後方互換)。
|
|
39
|
+
* 新キーが既にあればそれを優先し、旧キーは取り除く。
|
|
40
|
+
*/
|
|
41
|
+
function normalizeWorkerNameKeys(obj) {
|
|
42
|
+
const out = { ...obj };
|
|
43
|
+
if (out.contentWorkerName == null && typeof out.pagesProjectName === 'string') {
|
|
44
|
+
out.contentWorkerName = out.pagesProjectName;
|
|
45
|
+
}
|
|
46
|
+
if (out.adminWorkerName == null && typeof out.adminPagesProjectName === 'string') {
|
|
47
|
+
out.adminWorkerName = out.adminPagesProjectName;
|
|
48
|
+
}
|
|
49
|
+
delete out.pagesProjectName;
|
|
50
|
+
delete out.adminPagesProjectName;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
33
53
|
// ---------------------------------------------------------------------------
|
|
34
54
|
// Write (full)
|
|
35
55
|
// ---------------------------------------------------------------------------
|
|
@@ -103,7 +123,7 @@ export function buildConfig(params) {
|
|
|
103
123
|
const repoName = params.contentRepo.split('/')[1];
|
|
104
124
|
const stagingDomain = params.stagingDomain ?? generateStagingDomain(params.productionUrl || '');
|
|
105
125
|
const previewUrl = stagingDomain ? `https://${stagingDomain}` : '';
|
|
106
|
-
const {
|
|
126
|
+
const { contentWorkerName, adminWorkerName } = buildWorkerNames(repoName, params.randomSuffix ?? true);
|
|
107
127
|
const config = {
|
|
108
128
|
contentRepo: params.contentRepo,
|
|
109
129
|
githubClientId: params.githubClientId || '',
|
|
@@ -112,11 +132,10 @@ export function buildConfig(params) {
|
|
|
112
132
|
previewUrl,
|
|
113
133
|
r2BucketName: params.r2BucketName ?? `${repoName}-files`,
|
|
114
134
|
r2PublicUrl: params.r2PublicUrl || '',
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
contentWorkerName,
|
|
136
|
+
adminWorkerName,
|
|
117
137
|
ownerUsername: params.ownerUsername || '',
|
|
118
138
|
stagingDomain,
|
|
119
|
-
cloudflareAccountId: params.cloudflareAccountId || '',
|
|
120
139
|
saveTimezone: params.saveTimezone || '+09:00',
|
|
121
140
|
};
|
|
122
141
|
return ok({ config });
|