92 lines
4.3 KiB
JavaScript
92 lines
4.3 KiB
JavaScript
// site-335411向け全体反映(updatesite)ボディ生成スクリプト(送信はしない・プレビュー専用)。
|
||
// siteSettingJsons/site-335411_latest.json のSiteSettingsを土台に、
|
||
// - Scripts/Styles/ServerScripts/Processes は configs/site-335411_.../ 配下の現在のファイル一式で丸ごと置き換え
|
||
// - Columns は Section-6/Section-7配下の指定列のみ FieldCss に "code-readonly2" を追加(既存クラスは保持、重複追加はしない)
|
||
// を反映した送信予定ボディを modify/{ラベル}/desired_body_full.json として書き出す。
|
||
// 実行方法: node build-full-335411.js "modify/2026-07-20T2000_Status同期_readonly2追加"
|
||
const fs = require("fs");
|
||
const path = require("path");
|
||
|
||
const READONLY2_TARGET_COLUMNS = [
|
||
"Date061", "Class061", "Class062", "Date062", "Class063",
|
||
"Date063", "Class065", "Description061", "Attachments061",
|
||
];
|
||
|
||
function main() {
|
||
const baseDir = __dirname;
|
||
const modifyRel = process.argv[2];
|
||
if (!modifyRel) {
|
||
console.error("[エラー] 出力先の modify フォルダを指定してください(例: node build-full-335411.js \"modify/2026-07-20T2000_xxx\")");
|
||
process.exit(1);
|
||
}
|
||
const siteId = 335411;
|
||
const siteDir = path.join(baseDir, "configs", "site-335411_②問い合わせ内容管理 Ver0.3");
|
||
const outDir = path.isAbsolute(modifyRel) ? modifyRel : path.join(siteDir, modifyRel);
|
||
|
||
const latest = JSON.parse(
|
||
fs.readFileSync(path.join(baseDir, "siteSettingJsons", `site-${siteId}_latest.json`), "utf8")
|
||
);
|
||
const d = latest.Response.Data;
|
||
const manifest = JSON.parse(fs.readFileSync(path.join(siteDir, "manifest.json"), "utf8"));
|
||
|
||
// 変更前スナップショットを保存
|
||
fs.mkdirSync(outDir, { recursive: true });
|
||
fs.writeFileSync(path.join(outDir, `before_site-${siteId}_latest.json`), JSON.stringify(latest, null, 2), "utf-8");
|
||
|
||
const siteSettings = JSON.parse(JSON.stringify(d.SiteSettings));
|
||
|
||
function rebuildList(manifestEntries, dir) {
|
||
return (manifestEntries || []).map((entry) => {
|
||
const { File, ...meta } = entry;
|
||
const body = fs.readFileSync(path.join(siteDir, dir, File), "utf-8");
|
||
return { ...meta, Body: body };
|
||
});
|
||
}
|
||
siteSettings.Scripts = rebuildList(manifest.Scripts, "scripts");
|
||
siteSettings.Styles = rebuildList(manifest.Styles, "styles");
|
||
siteSettings.ServerScripts = rebuildList(manifest.ServerScripts, "serverscripts");
|
||
|
||
const processesPath = path.join(siteDir, manifest.ProcessesFile || "processes.json");
|
||
siteSettings.Processes = fs.existsSync(processesPath) ? JSON.parse(fs.readFileSync(processesPath, "utf8")) : [];
|
||
|
||
// Columns: 対象列のFieldCssへ code-readonly2 を追加(既存があれば変更なし)
|
||
const fieldCssChanges = [];
|
||
siteSettings.Columns = siteSettings.Columns.map((col) => {
|
||
if (!READONLY2_TARGET_COLUMNS.includes(col.ColumnName)) return col;
|
||
|
||
const before = col.FieldCss || "";
|
||
const classes = before.split(/\s+/).filter(Boolean);
|
||
if (classes.includes("code-readonly2")) {
|
||
fieldCssChanges.push({ ColumnName: col.ColumnName, before, after: before, changed: false });
|
||
return col;
|
||
}
|
||
classes.push("code-readonly2");
|
||
const after = classes.join(" ");
|
||
fieldCssChanges.push({ ColumnName: col.ColumnName, before, after, changed: true });
|
||
return { ...col, FieldCss: after };
|
||
});
|
||
|
||
const body = {
|
||
ApiVersion: "1.1",
|
||
ApiKey: "***(送信時にconfig.jsonから読み込み。プレビューJSONには含めません)***",
|
||
TenantId: d.TenantId,
|
||
SiteId: d.SiteId,
|
||
Title: d.Title,
|
||
ReferenceType: d.ReferenceType,
|
||
ParentId: d.ParentId,
|
||
InheritPermission: d.InheritPermission,
|
||
SiteSettings: siteSettings,
|
||
};
|
||
|
||
fs.writeFileSync(path.join(outDir, "desired_body_full.json"), JSON.stringify(body, null, 2), "utf-8");
|
||
|
||
console.log("[OK] 生成しました:", path.join(outDir, "desired_body_full.json"));
|
||
console.log("\n=== FieldCss変更内容(Section-6/Section-7配下) ===");
|
||
for (const c of fieldCssChanges) {
|
||
console.log(` ${c.ColumnName}: "${c.before}" → "${c.after}" ${c.changed ? "(変更)" : "(既存のため変更なし)"}`);
|
||
}
|
||
console.log("\n次のステップ: 内容を確認の上、実行が許可されたら send-335411-full.js で送信してください(config.jsonのApiKeyを使って別途送信します)。");
|
||
}
|
||
|
||
main();
|