@@ -0,0 +1,98 @@
|
||||
require('module-alias/register');
|
||||
import * as fs from 'fs';
|
||||
import { Plugin } from '@typings/plugin';
|
||||
import { languages } from '@libs/languages';
|
||||
import * as path from 'path';
|
||||
|
||||
const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
|
||||
const root = path.dirname(__dirname);
|
||||
const size = 96;
|
||||
|
||||
const skip: { [key: string]: boolean } = {
|
||||
//custom icons
|
||||
'ReN': true,
|
||||
'sektenovel': true,
|
||||
'FWK.US': true,
|
||||
|
||||
//low quality
|
||||
'BLN': true,
|
||||
'novelhall': true,
|
||||
'NO.net': true,
|
||||
|
||||
//broken icons
|
||||
'guavaread': true,
|
||||
'LightNovelUpdates': true,
|
||||
'turkcelightnovels': true,
|
||||
'novelki.pl': true,
|
||||
'lunarletters': true,
|
||||
|
||||
//dead plugins?
|
||||
'freenovel.me': true,
|
||||
'daonovel': true,
|
||||
'mtl-novel': true,
|
||||
'novelroom': true,
|
||||
'zinnovel': true,
|
||||
'novelr18': true,
|
||||
'novelstic': true,
|
||||
'readwebnovels': true,
|
||||
};
|
||||
|
||||
const used = new Set();
|
||||
used.add(path.join(root, '..', 'icons', 'coverNotAvailable.webp'));
|
||||
|
||||
(async () => {
|
||||
console.log('\nDownloading icons ⌛');
|
||||
for (let language in languages) {
|
||||
const langPath = path.join(root, 'plugins', language.toLowerCase());
|
||||
if (!fs.existsSync(langPath)) continue;
|
||||
const plugins = fs.readdirSync(langPath);
|
||||
for (let i = 0; i < plugins.length; i++) {
|
||||
const instance: Plugin.PluginBase = require(
|
||||
`../plugins/${language.toLowerCase()}/${plugins[i].split('.')[0]}`,
|
||||
).default;
|
||||
|
||||
const { id, name, site, icon } = instance;
|
||||
try {
|
||||
if (icon) used.add(path.join(root, '..', 'icons', icon));
|
||||
|
||||
if (!skip[id] && icon && site) {
|
||||
const image = await fetch(
|
||||
`https://www.google.com/s2/favicons?domain=${site}&sz=${size}`,
|
||||
)
|
||||
.then(res => res.arrayBuffer())
|
||||
.then(res => Buffer.from(res));
|
||||
|
||||
const fullPath = path.join(root, '..', 'icons', icon);
|
||||
const dir = fullPath.match(/^.*[\\\/]/)?.[0] || fullPath;
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(fullPath, image);
|
||||
console.log(name, '✅');
|
||||
} else {
|
||||
console.log(name, '❌');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(name, '❌', err);
|
||||
}
|
||||
await delay(2500);
|
||||
}
|
||||
}
|
||||
console.log('\nDeleting unused icons ⌛');
|
||||
|
||||
function fileList(dir: string): string[] {
|
||||
return fs.readdirSync(dir).reduce((list: string[], file: string) => {
|
||||
const name = path.join(dir, file);
|
||||
const isDir = fs.statSync(name).isDirectory();
|
||||
return list.concat(isDir ? fileList(name) : [name]);
|
||||
}, []);
|
||||
}
|
||||
|
||||
fileList(path.join(root, '..', 'icons')).forEach(path => {
|
||||
if (!used.has(path)) {
|
||||
console.log('🗑️', path);
|
||||
fs.rmSync(path, { force: true });
|
||||
}
|
||||
});
|
||||
console.log('\nDone ✅');
|
||||
})();
|
||||
@@ -30,7 +30,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: HotNovelPubMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/hotnovelpub/icons/${metadata.id}.png`;
|
||||
this.icon = `multisrc/hotnovelpub/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
this.apiSite = metadata.sourceSite.replace('://', '://api.');
|
||||
this.version = '1.0.0';
|
||||
|
||||
@@ -23,7 +23,7 @@ class IfreedomPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: IfreedomMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/ifreedom/icons/${metadata.id}.png`;
|
||||
this.icon = `multisrc/ifreedom/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
this.version = '1.0.0';
|
||||
this.filters = metadata.filters;
|
||||
|
||||
@@ -31,7 +31,7 @@ class LightNovelWPPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: LightNovelWPMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/lightnovelwp/${metadata.id}.png`;
|
||||
this.icon = `multisrc/lightnovelwp/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||
this.version = `1.0.${4 + versionIncrements}`;
|
||||
|
||||
@@ -36,7 +36,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: MadaraMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/madara/${metadata.id.toLowerCase()}.png`;
|
||||
this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||
this.version = `1.0.${1 + versionIncrements}`;
|
||||
|
||||
@@ -27,7 +27,7 @@ class ReadNovelFullPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: ReadNovelFullMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/readnovelfull/${metadata.id}.png`;
|
||||
this.icon = `multisrc/readnovelfull/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||
this.version = `1.0.${0 + versionIncrements}`;
|
||||
|
||||
@@ -24,7 +24,7 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: ReadwnMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/readwn/icons/${metadata.id}.png`;
|
||||
this.icon = `multisrc/readwn/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
this.version = '1.0.0';
|
||||
this.filters = metadata.filters;
|
||||
|
||||
@@ -23,7 +23,7 @@ class RulatePlugin implements Plugin.PluginBase {
|
||||
constructor(metadata: RulateMetadata) {
|
||||
this.id = metadata.id;
|
||||
this.name = metadata.sourceName;
|
||||
this.icon = `multisrc/rulate/icons/${metadata.id}.png`;
|
||||
this.icon = `multisrc/rulate/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
this.version = '1.0.0';
|
||||
this.filters = metadata.filters;
|
||||
|
||||
+15
-15
@@ -1,22 +1,22 @@
|
||||
const { minify_sync } = require('terser');
|
||||
import * as fs from 'fs';
|
||||
|
||||
const config = {
|
||||
compress: {
|
||||
arrows: false,
|
||||
booleans_as_integers: true,
|
||||
},
|
||||
mangle: {},
|
||||
ecma: 5, // specify one of: 5, 2015, 2016, etc.
|
||||
enclose: false, // or specify true, or "args:values"
|
||||
keep_classnames: false,
|
||||
keep_fnames: false,
|
||||
module: true,
|
||||
toplevel: true,
|
||||
};
|
||||
|
||||
export const minify = function (path: string) {
|
||||
const code = fs.readFileSync(path).toString();
|
||||
const result = minify_sync(code, {
|
||||
parse: {},
|
||||
compress: {
|
||||
booleans_as_integers: true,
|
||||
},
|
||||
mangle: {},
|
||||
ecma: 5, // specify one of: 5, 2015, 2016, etc.
|
||||
enclose: false, // or specify true, or "args:values"
|
||||
keep_classnames: false,
|
||||
keep_fnames: false,
|
||||
ie8: false,
|
||||
module: false,
|
||||
safari10: false,
|
||||
toplevel: true,
|
||||
});
|
||||
const result = minify_sync(code, config);
|
||||
fs.writeFileSync(path, result.code);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user