mirror of
https://github.com/koloml/furbooru-tagging-assistant.git
synced 2026-03-24 23:02:58 +00:00
Separate icons for extensions, support replacing icons on build
This commit is contained in:
@@ -3,6 +3,7 @@ import path from "path";
|
||||
import { buildScriptsAndStyles } from "./lib/content-scripts.js";
|
||||
import { extractInlineScriptsFromIndex } from "./lib/index-file.js";
|
||||
import { normalizePath } from "vite";
|
||||
import fs from "fs";
|
||||
|
||||
/**
|
||||
* Build addition assets required for the extension and pack it into the directory.
|
||||
@@ -92,6 +93,47 @@ export async function packExtension(settings) {
|
||||
manifest.passVersionFromPackage(path.resolve(settings.rootDir, 'package.json'));
|
||||
manifest.saveTo(path.resolve(settings.exportDir, 'manifest.json'));
|
||||
|
||||
const iconsDirectory = path.resolve(settings.exportDir, 'icons');
|
||||
|
||||
switch (process.env.SITE) {
|
||||
case "derpibooru":
|
||||
case "tantabus":
|
||||
const siteIconsDirectory = path.resolve(iconsDirectory, process.env.SITE);
|
||||
|
||||
if (!fs.existsSync(siteIconsDirectory)) {
|
||||
console.warn(`Can't find replacement icons for site ${process.env.SITE}`);
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(`Found replacement icons for ${process.env.SITE}, swapping them...`);
|
||||
|
||||
fs.readdirSync(siteIconsDirectory).forEach(fileName => {
|
||||
const originalIconPath = path.resolve(settings.exportDir, fileName);
|
||||
const replacementIconPath = path.resolve(siteIconsDirectory, fileName);
|
||||
|
||||
if (!fs.existsSync(originalIconPath)) {
|
||||
console.warn(`Original icon not found: ${originalIconPath}`)
|
||||
return;
|
||||
}
|
||||
|
||||
fs.rmSync(originalIconPath);
|
||||
fs.cpSync(replacementIconPath, originalIconPath);
|
||||
|
||||
console.log(`Replaced: ${path.relative(settings.rootDir, replacementIconPath)} → ${path.relative(settings.rootDir, originalIconPath)}`);
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (fs.existsSync(iconsDirectory)) {
|
||||
console.log('Cleaning up icon replacements directory');
|
||||
|
||||
fs.rmSync(iconsDirectory, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
|
||||
extractInlineScriptsFromIndex(path.resolve(settings.exportDir, 'index.html'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user