@c-time/frelio-cli 1.4.12 → 1.4.13

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.
@@ -19,6 +19,8 @@ type InitOptions = {
19
19
  clientSecret?: string;
20
20
  cloudflareAccountId?: string;
21
21
  cloudflareApiToken?: string;
22
+ /** Pages プロジェクト名のランダム hex サフィックス(Issue #138)。既定 true、--no-random-suffix で false。 */
23
+ randomSuffix?: boolean;
22
24
  };
23
25
  export declare function initCommand(options: InitOptions): Promise<void>;
24
26
  export {};
@@ -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 } from '../lib/templates.js';
11
+ import { generateStagingDomain, buildPagesProjectNames, } 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
@@ -450,6 +450,7 @@ async function promptConfig(options) {
450
450
  const repoName = contentRepo.split('/')[1];
451
451
  const stagingDomain = options.stagingDomain ?? response.stagingDomain ?? '';
452
452
  const previewUrl = stagingDomain ? `https://${stagingDomain}` : '';
453
+ const { pagesProjectName, adminPagesProjectName } = buildPagesProjectNames(repoName, options.randomSuffix ?? true);
453
454
  const config = {
454
455
  contentRepo,
455
456
  githubClientId: options.clientId || '',
@@ -458,8 +459,8 @@ async function promptConfig(options) {
458
459
  previewUrl,
459
460
  r2BucketName: options.r2BucketName ?? response.r2BucketName ?? `${repoName}-files`,
460
461
  r2PublicUrl: options.r2PublicUrl ?? response.r2PublicUrl ?? '',
461
- pagesProjectName: repoName,
462
- adminPagesProjectName: `${repoName}-admin`,
462
+ pagesProjectName,
463
+ adminPagesProjectName,
463
464
  ownerUsername: options.ownerUsername ?? response.ownerUsername ?? '',
464
465
  stagingDomain,
465
466
  cloudflareAccountId: options.cloudflareAccountId ?? response.cloudflareAccountId ?? '',
@@ -485,6 +486,7 @@ function buildConfigFromOptions(options) {
485
486
  r2PublicUrl: options.r2PublicUrl,
486
487
  ownerUsername: options.ownerUsername,
487
488
  cloudflareAccountId: options.cloudflareAccountId,
489
+ randomSuffix: options.randomSuffix,
488
490
  });
489
491
  if (!result.success) {
490
492
  logError(result.error);
@@ -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 } from '../lib/templates.js';
10
+ import { generateStagingDomain, buildPagesProjectNames } 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'];
@@ -103,6 +103,7 @@ export function buildConfig(params) {
103
103
  const repoName = params.contentRepo.split('/')[1];
104
104
  const stagingDomain = params.stagingDomain ?? generateStagingDomain(params.productionUrl || '');
105
105
  const previewUrl = stagingDomain ? `https://${stagingDomain}` : '';
106
+ const { pagesProjectName, adminPagesProjectName } = buildPagesProjectNames(repoName, params.randomSuffix ?? true);
106
107
  const config = {
107
108
  contentRepo: params.contentRepo,
108
109
  githubClientId: params.githubClientId || '',
@@ -111,8 +112,8 @@ export function buildConfig(params) {
111
112
  previewUrl,
112
113
  r2BucketName: params.r2BucketName ?? `${repoName}-files`,
113
114
  r2PublicUrl: params.r2PublicUrl || '',
114
- pagesProjectName: repoName,
115
- adminPagesProjectName: `${repoName}-admin`,
115
+ pagesProjectName,
116
+ adminPagesProjectName,
116
117
  ownerUsername: params.ownerUsername || '',
117
118
  stagingDomain,
118
119
  cloudflareAccountId: params.cloudflareAccountId || '',
@@ -70,6 +70,13 @@ export function changeDomain(projectDir, change) {
70
70
  merged.previewUrl = change.previewUrl;
71
71
  merged.stagingDomain = change.previewUrl ? safeHostname(change.previewUrl) : '';
72
72
  }
73
+ // templatePreviewBaseUrl(Issue #140): 自動既定(空 or 旧 previewUrl と一致)なら
74
+ // 新 previewUrl に追従させる。ユーザーがカスタムした値(Basic 認証付き等)は
75
+ // {...existing} の spread で保持され、ここでは上書きしない。
76
+ if (!existing.templatePreviewBaseUrl ||
77
+ existing.templatePreviewBaseUrl === existing.previewUrl) {
78
+ merged.templatePreviewBaseUrl = merged.previewUrl;
79
+ }
73
80
  // バリデーション(失敗時は何も書かない)
74
81
  const validation = validateConfig(merged);
75
82
  if (!validation.success)
@@ -48,4 +48,9 @@ export type BuildConfigParams = {
48
48
  cloudflareAccountId?: string;
49
49
  /** 保存タイムゾーン(ISO 8601 オフセット表記、例 "+09:00")。issue #92 */
50
50
  saveTimezone?: string;
51
+ /**
52
+ * Pages プロジェクト名にランダム hex サフィックスを付けるか(Issue #138)。
53
+ * 既定(未指定)は true。false で従来の単純名(`<repo>` / `<repo>-admin`)を使う。
54
+ */
55
+ randomSuffix?: boolean;
51
56
  };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ program
35
35
  .option('--client-secret <secret>', 'GitHub OAuth Client Secret')
36
36
  .option('--cloudflare-account-id <id>', 'Cloudflare Account ID(デプロイ管理機能 / Issue #27)')
37
37
  .option('--cloudflare-api-token <token>', 'Cloudflare API Token(Pages:Edit・デプロイ一覧/削除に使用)')
38
+ .option('--no-random-suffix', 'Pages プロジェクト名にランダム hex サフィックスを付けない(従来の単純名 <repo> / <repo>-admin を使う)')
38
39
  .action(initCommand);
39
40
  program
40
41
  .command('update')
@@ -23,6 +23,8 @@ export function projectConfigToVars(config) {
23
23
  siteTitle: config.siteTitle,
24
24
  productionUrl: config.productionUrl,
25
25
  previewUrl: config.previewUrl,
26
+ // ビジュアル編集・プレビューのベース URL(Issue #140)。未指定なら previewUrl を既定。
27
+ templatePreviewBaseUrl: config.templatePreviewBaseUrl || config.previewUrl,
26
28
  fileUploadUrl: '/api/storage',
27
29
  pagesProjectName: config.pagesProjectName,
28
30
  adminPagesProjectName: config.adminPagesProjectName,
@@ -7,6 +7,11 @@ export type ProjectConfig = {
7
7
  siteTitle: string;
8
8
  productionUrl: string;
9
9
  previewUrl: string;
10
+ /**
11
+ * ビジュアル編集・プレビューでコンテンツ資産(CSS/画像)を読み込むベース URL(Issue #140)。
12
+ * 未指定なら生成時に previewUrl を既定値として出力する。
13
+ */
14
+ templatePreviewBaseUrl?: string;
10
15
  r2BucketName: string;
11
16
  r2PublicUrl: string;
12
17
  pagesProjectName: string;
@@ -35,6 +40,24 @@ export declare function deriveContentPagesDev(config: ProjectConfig): string;
35
40
  * ランダムな8文字のハッシュを生成(URL推測を困難にする)
36
41
  */
37
42
  export declare function generateHash(): string;
43
+ /**
44
+ * ランダムな8桁の16進サフィックスを生成(4バイト → hex)。
45
+ * Pages プロジェクト名の世界的な衝突(Cloudflare の自動 `-mg1` 等)を避け、
46
+ * `<project>.pages.dev` のプレビュー URL を推測困難にする(Issue #138)。
47
+ */
48
+ export declare function generateHexSuffix(): string;
49
+ /**
50
+ * Cloudflare Pages プロジェクト名(content 用・admin 用)を導出する(Issue #138)。
51
+ * randomSuffix=true なら content/admin それぞれに**別々の** hex サフィックスを付ける
52
+ * (片方の名前が露出しても、もう片方を推測されないようにする)。
53
+ *
54
+ * 例: ("website", true) → { pagesProjectName: "website-1a2b3c4d",
55
+ * adminPagesProjectName: "website-admin-e5f6a7b8" }
56
+ */
57
+ export declare function buildPagesProjectNames(repoName: string, randomSuffix: boolean): {
58
+ pagesProjectName: string;
59
+ adminPagesProjectName: string;
60
+ };
38
61
  /**
39
62
  * productionUrl からステージング用の推測困難なカスタムサブドメインを生成する。
40
63
  * 例: https://example.com → staging-a3f9c2kp.example.com
@@ -36,6 +36,33 @@ export function generateHash() {
36
36
  }
37
37
  return hash;
38
38
  }
39
+ /**
40
+ * ランダムな8桁の16進サフィックスを生成(4バイト → hex)。
41
+ * Pages プロジェクト名の世界的な衝突(Cloudflare の自動 `-mg1` 等)を避け、
42
+ * `<project>.pages.dev` のプレビュー URL を推測困難にする(Issue #138)。
43
+ */
44
+ export function generateHexSuffix() {
45
+ const bytes = new Uint8Array(4);
46
+ crypto.getRandomValues(bytes);
47
+ return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
48
+ }
49
+ /**
50
+ * Cloudflare Pages プロジェクト名(content 用・admin 用)を導出する(Issue #138)。
51
+ * randomSuffix=true なら content/admin それぞれに**別々の** hex サフィックスを付ける
52
+ * (片方の名前が露出しても、もう片方を推測されないようにする)。
53
+ *
54
+ * 例: ("website", true) → { pagesProjectName: "website-1a2b3c4d",
55
+ * adminPagesProjectName: "website-admin-e5f6a7b8" }
56
+ */
57
+ export function buildPagesProjectNames(repoName, randomSuffix) {
58
+ if (!randomSuffix) {
59
+ return { pagesProjectName: repoName, adminPagesProjectName: `${repoName}-admin` };
60
+ }
61
+ return {
62
+ pagesProjectName: `${repoName}-${generateHexSuffix()}`,
63
+ adminPagesProjectName: `${repoName}-admin-${generateHexSuffix()}`,
64
+ };
65
+ }
39
66
  /**
40
67
  * productionUrl からステージング用の推測困難なカスタムサブドメインを生成する。
41
68
  * 例: https://example.com → staging-a3f9c2kp.example.com
@@ -84,6 +111,9 @@ export function generateConfigJson(config) {
84
111
  siteTitle: config.siteTitle,
85
112
  productionUrl: config.productionUrl,
86
113
  previewUrl: config.previewUrl,
114
+ // ビジュアル編集・プレビューのベース URL(Issue #140)。未指定なら previewUrl を既定。
115
+ // 未設定だと admin オリジンへフォールバックしコンテンツ資産を配信できないため明示出力する。
116
+ templatePreviewBaseUrl: config.templatePreviewBaseUrl || config.previewUrl,
87
117
  pagesProjectName: config.pagesProjectName,
88
118
  adminPagesProjectName: config.adminPagesProjectName,
89
119
  r2BucketName: config.r2BucketName,
@@ -126,6 +156,15 @@ export function buildAllowedOrigins(config) {
126
156
  * いずれのデプロイ対象ディレクトリにも本ファイルは含まれない(公開されない)。
127
157
  */
128
158
  export function generateWranglerToml(config) {
159
+ // デプロイ管理機能(Issue #27)の account_id(非シークレット)。
160
+ // 空のときは行ごと出力しない: 空文字を [vars] に置くと wrangler pages deploy が
161
+ // 実値/secret を毎デプロイで空上書きしてしまうため(Issue #137)。
162
+ const accountIdBlock = config.cloudflareAccountId
163
+ ? `# デプロイ管理機能(Issue #27): functions/api/deployments が Cloudflare Pages API を呼ぶのに使用。
164
+ # CLOUDFLARE_API_TOKEN はシークレットのため wrangler pages secret で管理画面プロジェクトに設定する(ここには置かない)。
165
+ CLOUDFLARE_ACCOUNT_ID = "${config.cloudflareAccountId}"
166
+ `
167
+ : '';
129
168
  return `# Cloudflare Pages 設定(コンテンツ配信・管理画面デプロイで共用 / Issue #23)
130
169
  # pages_build_output_dir を指定することで wrangler pages deploy が本ファイルを
131
170
  # 読み込み、R2 バインディングと環境変数をデプロイ時に自動適用する。
@@ -143,10 +182,11 @@ bucket_name = "${config.r2BucketName}"
143
182
  R2_PUBLIC_URL = "${config.r2PublicUrl}"
144
183
  ALLOWED_ORIGINS = "${buildAllowedOrigins(config)}"
145
184
  CONTENT_REPO = "${config.contentRepo}"
146
- # デプロイ管理機能(Issue #27): functions/api/deployments が Cloudflare Pages API を呼ぶのに使用。
147
- # CLOUDFLARE_API_TOKEN はシークレットのため wrangler pages secret で管理画面プロジェクトに設定する(ここには置かない)。
148
- CLOUDFLARE_ACCOUNT_ID = "${config.cloudflareAccountId ?? ''}"
149
- PAGES_PROJECT_NAME = "${config.pagesProjectName}"
185
+ # 管理画面 OAuth の公開クライアントID(admin/config.json の githubClientId と同値)。
186
+ # wrangler pages deploy は [vars] で plain env を置換するため、ここに置かないと
187
+ # 毎デプロイで admin プロジェクトから消え、管理画面ログインが 500 になる(Issue #137)。
188
+ GITHUB_CLIENT_ID = "${config.githubClientId}"
189
+ ${accountIdBlock}PAGES_PROJECT_NAME = "${config.pagesProjectName}"
150
190
  # 本番ゲート(Issue #93): コンテンツ配信の functions/_middleware.ts がエッジで参照する。
151
191
  # SITE_MODE: live | prelaunch | maintenance | closed。
152
192
  # CANONICAL_HOST / CONTENT_PAGES_DEV は派生値(productionUrl ホスト / <project>.pages.dev)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-time/frelio-cli",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "description": "Frelio CMS setup CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",