mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-03 14:56:16 +02:00
enhance(backend): 起動前にconfigをjson化 (#16923)
* enhance(backend): 起動前にconfigをjson化 * fix * fix * fix * fix * fix * fix CHANGELOG.md * fix * Update CHANGELOG.md * get original
This commit is contained in:
56
packages/backend/scripts/convert_config.js
Normal file
56
packages/backend/scripts/convert_config.js
Normal file
@@ -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('設定ファイルの変換が完了しました');
|
||||
Reference in New Issue
Block a user