summaryrefslogtreecommitdiff
path: root/packages/backend/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/scripts')
-rw-r--r--packages/backend/scripts/convert_config.js56
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('設定ファイルの変換が完了しました');