UNPKG

touhou-tagger

Version:

从 THBWiki 自动填写东方 Project CD 曲目信息.

39 lines (38 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setAlbumOptions = exports.getAlbumOptions = void 0; const fs_1 = require("fs"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const AlbumOptionsFileName = 'thtag.json'; const getAlbumOptions = async (workingDir, baseOptions = {}) => { const albumOptionsPath = (0, path_1.resolve)(workingDir, AlbumOptionsFileName); if (!(0, fs_1.existsSync)(albumOptionsPath)) { return baseOptions; } try { const albumOptions = JSON.parse(await (0, promises_1.readFile)(albumOptionsPath, { encoding: 'utf-8' })); return { ...baseOptions, ...albumOptions, }; } catch (error) { return baseOptions; } }; exports.getAlbumOptions = getAlbumOptions; const setAlbumOptions = async (workingDir, options) => { const albumOptionsPath = (0, path_1.resolve)(workingDir, AlbumOptionsFileName); try { const albumOptions = JSON.parse(await (0, promises_1.readFile)(albumOptionsPath, { encoding: 'utf-8' })); await (0, promises_1.writeFile)(albumOptionsPath, JSON.stringify({ ...albumOptions, ...options, }, undefined, 2)); } catch (error) { await (0, promises_1.writeFile)(albumOptionsPath, JSON.stringify(options, undefined, 2)); } }; exports.setAlbumOptions = setAlbumOptions;