forked from mirrors/misskey
* wip
* Update config.ts
* wip
* convertは元ファイルを変更するようなニュアンスを若干感じるのでcompileに改名
* wip
* Update package.json
* Revert "Update package.json"
This reverts commit e5c2802316.
* wip
* wip
* 謎
* clean up
* wip
* wip
* Revert "wip"
This reverts commit 3aa25ac7cf337d57412308e63d8f54e2536b0f7f.
* wip
* wip
* Update dummy.yml
* wip
* Update compile_config.js
* Update compile_config.js
* wip
* Revert "wip"
This reverts commit fd78e097c65f747962e7a411938a0e67538ed347.
* Update dummy.yml
* Update compile_config.js
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
/*
|
|
* 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');
|
|
const OUTPUT_PATH = resolve(_dirname, '../../../built/.config.json');
|
|
|
|
// TODO: yamlのパースに失敗したときのエラーハンドリング
|
|
|
|
/**
|
|
* YAMLファイルをJSONファイルに変換
|
|
* @param {string} ymlPath - YAMLファイルのパス
|
|
*/
|
|
function yamlToJson(ymlPath) {
|
|
if (!fs.existsSync(ymlPath)) {
|
|
console.warn(`YAML file not found: ${ymlPath}`);
|
|
return;
|
|
}
|
|
|
|
console.log(`${ymlPath} → ${OUTPUT_PATH}`);
|
|
|
|
const yamlContent = fs.readFileSync(ymlPath, 'utf-8');
|
|
const jsonContent = yaml.load(yamlContent);
|
|
if (!fs.existsSync(dirname(OUTPUT_PATH))) {
|
|
fs.mkdirSync(dirname(OUTPUT_PATH), { recursive: true });
|
|
}
|
|
fs.writeFileSync(OUTPUT_PATH, JSON.stringify({
|
|
'_NOTE_': 'This file is auto-generated from YAML file. DO NOT EDIT.',
|
|
...jsonContent,
|
|
}), 'utf-8');
|
|
}
|
|
|
|
if (process.env.MISSKEY_CONFIG_YML) {
|
|
const customYmlPath = resolve(configDir, process.env.MISSKEY_CONFIG_YML);
|
|
yamlToJson(customYmlPath);
|
|
} else {
|
|
yamlToJson(resolve(configDir, process.env.NODE_ENV === 'test' ? 'test.yml' : 'default.yml'));
|
|
}
|
|
|
|
console.log('Configuration compiled ✓');
|