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OAAS,EACrB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAS,EAAI,OAAQ,IACxC,GAAS,IAEV,GAA6B,iBAAlB,EAAS,GACnB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAS,GAAK,OAAQ,IACrC,EAAS,GAAK,GACjB,GAAU,EAAQ,EAAS,GAAK,GAAK,KAErC,GAAU,OAAS,EAAM,UAIvB,EAAS,GACZ,GAAU,EAAQ,EAAS,GAAO,KAElC,GAAU,OAAS,EAAM,IAG5B,CAEA,OADA,GAAU,yBACH,CACR,EAID,OAAO,QAAU","file":"/npm/scriptcat-webpack-plugin@1.3.2/lib/plugin.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/scriptcat-webpack-plugin@1.3.2/lib/plugin.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\n// @ts-check\n// Import types\n/** @typedef {import(\"./types/typings\").Options} ScriptCatWebpackOptions */\n/** @typedef {import(\"./types/typings\").UserConfig} ScriptCatWebpackUserConfig */\n/** @typedef {import(\"webpack/lib/Compiler.js\")} WebpackCompiler */\n/** @typedef {import(\"webpack/lib/Compilation.js\")} WebpackCompilation */\n'use strict';\nconst YAML = require('yaml');\nconst fs = require('fs');\n\n\nclass ScriptCatWebpackPlugin {\n\n\t/**\n\t * @param {ScriptCatWebpackOptions} [options]\n\t * @param {ScriptCatWebpackUserConfig} [userConfig]\n\t */\n\tconstructor(options, userConfig) {\n\t\tthis.options = options;\n\t\tthis.userConfig = userConfig;\n\t}\n\n\t/**\n\t  * @param {WebpackCompiler} [compiler]\n\t  */\n\tapply(compiler) {\n\t\tif (!compiler) {\n\t\t\treturn;\n\t\t}\n\t\tcompiler.hooks.done.tap(\"ScriptCatWebpackPlugin\", ({compilation}) => {\n\t\t\tif (this.options?.file && compilation.assets[this.options.file]) {\n\t\t\t\t/**\n\t\t\t\t * @var {{ [key: string]: string[] | string }} metadata\n\t\t\t\t */\n\t\t\t\tlet metadata = {};\n\t\t\t\tmetadata[\"name\"] = this.options.name;\n\t\t\t\tmetadata[\"namespace\"] = this.options.namespace;\n\t\t\t\tmetadata[\"description\"] = this.options.description;\n\t\t\t\tmetadata[\"version\"] = this.options.version === undefined ? process.env.npm_package_version : this.options.version;\n\t\t\t\tmetadata[\"author\"] = this.options.author;\n\t\t\t\tObject.assign(metadata, this.options.metadata);\n\t\t\t\tlet userConfig = \"\";\n\t\t\t\tif (this.userConfig) {\n\t\t\t\t\tuserConfig = \"/* ==UserConfig==\\n\";\n\t\t\t\t\tuserConfig += YAML.stringify(this.userConfig);\n\t\t\t\t\tuserConfig += \" ==/UserConfig== */\\n\";\n\t\t\t\t}\n\t\t\t\tlet requireFile = \"\";\n\t\t\t\tif (this.options.requireFile) {\n\t\t\t\t\t// 读取文件\n\t\t\t\t\trequireFile += \"\\n\"\n\t\t\t\t\tthis.options.requireFile.forEach(file => {\n\t\t\t\t\t\trequireFile += fs.readFileSync(file, \"utf-8\") + \"\\n\";\n\t\t\t\t\t});\n\t\t\t\t\trequireFile += \"\\n\"\n\t\t\t\t}\n\t\t\t\tconst filePath = compilation.outputOptions.path + '/' + this.options.file;\n\t\t\t\tconst source = fs.readFileSync(filePath, \"utf-8\");\n\t\t\t\tconst content = this.align(metadata) + requireFile + userConfig + source;\n\t\t\t\tfs.writeFileSync(filePath, content);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * 对齐输出header\n\t */\n\talign(metadata) {\n\t\t// 先找出最长的单词\n\t\tlet maxLen = 0;\n\t\tfor (const key in metadata) {\n\t\t\tif (key.length > maxLen) {\n\t\t\t\tmaxLen = key.length;\n\t\t\t}\n\t\t}\n\t\tmaxLen++;\n\t\tlet header = \"// ==UserScript==\\n\";\n\t\tfor (const key in metadata) {\n\t\t\tif (metadata[key] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet start = \"// @\" + key;\n\t\t\tfor (let i = 0; i < maxLen - key.length; i++) {\n\t\t\t\tstart += \" \"\n\t\t\t}\n\t\t\tif (typeof metadata[key] === \"object\") {\n\t\t\t\tfor (let i = 0; i < metadata[key].length; i++) {\n\t\t\t\t\tif (metadata[key][i]) {\n\t\t\t\t\t\theader += start + metadata[key][i] + \"\\n\";\n\t\t\t\t\t} else {\n\t\t\t\t\t\theader += \"// @\" + key + \"\\n\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (metadata[key]) {\n\t\t\t\t\theader += start + metadata[key] + \"\\n\";\n\t\t\t\t} else {\n\t\t\t\t\theader += \"// @\" + key + \"\\n\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\theader += \"// ==/UserScript==\\n\\n\"\n\t\treturn header;\n\t}\n\n}\n\nmodule.exports = ScriptCatWebpackPlugin\n"]}