UNPKG

@animepaste/bangumi

Version:
40 lines (34 loc) 1.71 kB
'use strict'; const fs = require('node:fs'); const path = require('node:path'); const node_url = require('node:url'); const breadc = require('breadc'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); const path__default = /*#__PURE__*/_interopDefaultCompat(path); const version = "0.0.12"; const bangumi = breadc.breadc("bangumi", { version }); bangumi.command("<output>").option("--begin <begin>", "Begin date").option("--end <end>", "End date").option("--type <type>", "Filter bangumi types", { default: "tv" }).option("--fields <fileds>", "Enable extension fields", { default: "" }).option("--compress", "Enable compress").action(async (name, option) => { const { transform } = await import('./transform.cjs'); const data = await transform({ begin: option.begin, end: option.end, type: option.type.split(",").filter(Boolean), fields: option.fields.split(",").filter(Boolean), compress: option.compress }); const dataPath = path__default.join(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('cli.cjs', document.baseURI).href))), "../../data"); if (!fs__default.existsSync(dataPath)) { fs__default.mkdirSync(dataPath); } const filename = name ?? "data.json"; fs__default.writeFileSync( path__default.join( dataPath, filename.endsWith(".json") ? filename : filename + ".json" ), JSON.stringify(data), "utf8" ); }); bangumi.run(process.argv.slice(2)).catch((err) => console.error(err));