diff options
| author | おさむのひと <46447427+samunohito@users.noreply.github.com> | 2025-12-03 09:00:37 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-03 09:00:37 +0900 |
| commit | 1facca1ac59af0da21e85f17ded97b39e179dafe (patch) | |
| tree | 8898b1938d2c7394d83cdd4ae6bdd6331bc45551 /packages/backend/scripts | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-1facca1ac59af0da21e85f17ded97b39e179dafe.tar.gz misskey-1facca1ac59af0da21e85f17ded97b39e179dafe.tar.bz2 misskey-1facca1ac59af0da21e85f17ded97b39e179dafe.zip | |
enhance(backend): 起動前にconfigをjson化 (#16923)
* enhance(backend): 起動前にconfigをjson化
* fix
* fix
* fix
* fix
* fix
* fix CHANGELOG.md
* fix
* Update CHANGELOG.md
* get original
Diffstat (limited to 'packages/backend/scripts')
| -rw-r--r-- | packages/backend/scripts/convert_config.js | 56 |
1 files changed, 56 insertions, 0 deletions
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('設定ファイルの変換が完了しました'); |