From 1facca1ac59af0da21e85f17ded97b39e179dafe Mon Sep 17 00:00:00 2001 From: おさむのひと <46447427+samunohito@users.noreply.github.com> Date: Wed, 3 Dec 2025 09:00:37 +0900 Subject: enhance(backend): 起動前にconfigをjson化 (#16923) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance(backend): 起動前にconfigをjson化 * fix * fix * fix * fix * fix * fix CHANGELOG.md * fix * Update CHANGELOG.md * get original --- packages/backend/scripts/convert_config.js | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 packages/backend/scripts/convert_config.js (limited to 'packages/backend/scripts') diff --git a/packages/backend/scripts/convert_config.js b/packages/backend/scripts/convert_config.js new file mode 100644 index 0000000000..32576621cb --- /dev/null +++ b/packages/backend/scripts/convert_config.js @@ -0,0 +1,56 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +/** + * YAMLファイルをJSONファイルに変換するスクリプト + * ビルド前に実行し、ランタイムにjs-yamlを含まないようにする + */ + +import fs from 'node:fs'; +import { resolve, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import yaml from 'js-yaml'; + +const _filename = fileURLToPath(import.meta.url); +const _dirname = dirname(_filename); + +const configDir = resolve(_dirname, '../../../.config'); + +/** + * YAMLファイルをJSONファイルに変換 + * @param {string} ymlPath - YAMLファイルのパス + * @param {string} jsonPath - JSONファイルの出力パス + */ +function convertYamlToJson(ymlPath, jsonPath) { + if (!fs.existsSync(ymlPath)) { + console.log(`${ymlPath} が見つからないためスキップします`); + return; + } + + const yamlContent = fs.readFileSync(ymlPath, 'utf-8'); + const jsonContent = yaml.load(yamlContent); + fs.writeFileSync(jsonPath, JSON.stringify(jsonContent, null, 2), 'utf-8'); + console.log(`✓ ${ymlPath} → ${jsonPath}`); +} + +// default.yml と test.yml を変換 +convertYamlToJson( + resolve(configDir, 'default.yml'), + resolve(configDir, 'default.json'), +); + +convertYamlToJson( + resolve(configDir, 'test.yml'), + resolve(configDir, 'test.json'), +); + +// MISSKEY_CONFIG_YML 環境変数が指定されている場合も変換 +if (process.env.MISSKEY_CONFIG_YML) { + const customYmlPath = resolve(configDir, process.env.MISSKEY_CONFIG_YML); + const customJsonPath = customYmlPath.replace(/\.ya?ml$/i, '.json'); + convertYamlToJson(customYmlPath, customJsonPath); +} + +console.log('設定ファイルの変換が完了しました'); -- cgit v1.2.3-freya