Normalise multiSrc Source Names
This commit is contained in:
+71
-65
@@ -7,75 +7,81 @@ import { Plugin, isPlugin } from "@typings/plugin";
|
|||||||
|
|
||||||
const root = path.dirname(__dirname);
|
const root = path.dirname(__dirname);
|
||||||
const outRoot = path.join(root, "..");
|
const outRoot = path.join(root, "..");
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require("child_process");
|
||||||
const REMOTE = execSync('git remote get-url origin').toString().replace(/[\s\n]/g, '');
|
const REMOTE = execSync("git remote get-url origin")
|
||||||
const CURRENT_BRANCH = execSync('git rev-parse --abbrev-ref HEAD').toString().replace(/[\s\n]/g, '');
|
.toString()
|
||||||
const USERNAME = REMOTE.split('/')[3].trim();
|
.replace(/[\s\n]/g, "");
|
||||||
const REPO = REMOTE.split('/')[4].trim().replace(/\.git$/, '');
|
const CURRENT_BRANCH = execSync("git rev-parse --abbrev-ref HEAD")
|
||||||
|
.toString()
|
||||||
|
.replace(/[\s\n]/g, "");
|
||||||
|
const USERNAME = REMOTE.split("/")[3].trim();
|
||||||
|
const REPO = REMOTE.split("/")[4]
|
||||||
|
.trim()
|
||||||
|
.replace(/\.git$/, "");
|
||||||
const USER_CONTENT_LINK = `https://raw.githubusercontent.com/${USERNAME}/${REPO}/${CURRENT_BRANCH}`;
|
const USER_CONTENT_LINK = `https://raw.githubusercontent.com/${USERNAME}/${REPO}/${CURRENT_BRANCH}`;
|
||||||
|
|
||||||
|
|
||||||
const ICON_LINK = `${USER_CONTENT_LINK}/icons`;
|
const ICON_LINK = `${USER_CONTENT_LINK}/icons`;
|
||||||
const PLUGIN_LINK = `${USER_CONTENT_LINK}/.js/plugins`;
|
const PLUGIN_LINK = `${USER_CONTENT_LINK}/.js/plugins`;
|
||||||
|
|
||||||
const json: {
|
const json: {
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
site: string;
|
site: string;
|
||||||
lang: string;
|
lang: string;
|
||||||
version: string;
|
version: string;
|
||||||
url: string;
|
url: string;
|
||||||
iconUrl: string;
|
iconUrl: string;
|
||||||
}[];
|
}[];
|
||||||
} = {};
|
} = {};
|
||||||
if(!fs.existsSync(path.join(outRoot, '.dist'))){
|
if (!fs.existsSync(path.join(outRoot, ".dist"))) {
|
||||||
fs.mkdirSync(path.join(outRoot, '.dist'));
|
fs.mkdirSync(path.join(outRoot, ".dist"));
|
||||||
}
|
}
|
||||||
const jsonPath = path.join(outRoot, ".dist", "plugins.json");
|
const jsonPath = path.join(outRoot, ".dist", "plugins.json");
|
||||||
const jsonMinPath = path.join(outRoot, ".dist", "plugins.min.json");
|
const jsonMinPath = path.join(outRoot, ".dist", "plugins.min.json");
|
||||||
const pluginSet = new Set();
|
const pluginSet = new Set();
|
||||||
|
|
||||||
for (let language in languages) {
|
for (let language in languages) {
|
||||||
// language with English name
|
// language with English name
|
||||||
const langPath = path.join(root, "plugins", language.toLowerCase());
|
const langPath = path.join(root, "plugins", language.toLowerCase());
|
||||||
if (!fs.existsSync(langPath)) continue;
|
if (!fs.existsSync(langPath)) continue;
|
||||||
const plugins = fs.readdirSync(langPath);
|
const plugins = fs.readdirSync(langPath);
|
||||||
json[language] = [];
|
json[language] = [];
|
||||||
plugins.forEach((plugin) => {
|
plugins.forEach((plugin) => {
|
||||||
if (plugin.startsWith(".")) return;
|
if (plugin.startsWith(".")) return;
|
||||||
const instance:
|
const instance: Plugin.PluginBase | unknown =
|
||||||
| Plugin.PluginBase
|
require(`../plugins/${language.toLowerCase()}/${
|
||||||
| unknown = require(`../plugins/${language.toLowerCase()}/${
|
plugin.split(".")[0]
|
||||||
plugin.split(".")[0]
|
}`).default;
|
||||||
}`).default;
|
|
||||||
|
|
||||||
if (!isPlugin(instance)) {
|
if (!isPlugin(instance)) {
|
||||||
console.log(plugin);
|
console.log(plugin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { id, name, site, version, icon } = instance;
|
const { id, name, site, version, icon } = instance;
|
||||||
const info = {
|
const normalisedName = name.replace(/\[.*\]/, "");
|
||||||
id,
|
|
||||||
name,
|
|
||||||
site,
|
|
||||||
lang: language,
|
|
||||||
version,
|
|
||||||
url: `${PLUGIN_LINK}/${language.toLowerCase()}/${plugin}`,
|
|
||||||
iconUrl: `${ICON_LINK}/${icon}`,
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
if (pluginSet.has(id)) {
|
const info = {
|
||||||
console.log("There's already a plugin with id:", id);
|
id,
|
||||||
throw new Error("2 or more plugins have the same id");
|
name: normalisedName,
|
||||||
} else {
|
site,
|
||||||
pluginSet.add(id);
|
lang: language,
|
||||||
}
|
version,
|
||||||
|
url: `${PLUGIN_LINK}/${language.toLowerCase()}/${plugin}`,
|
||||||
|
iconUrl: `${ICON_LINK}/${icon}`,
|
||||||
|
} as const;
|
||||||
|
|
||||||
json[language].push(info);
|
if (pluginSet.has(id)) {
|
||||||
console.log(name, "✅");
|
console.log("There's already a plugin with id:", id);
|
||||||
});
|
throw new Error("2 or more plugins have the same id");
|
||||||
|
} else {
|
||||||
|
pluginSet.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
json[language].push(info);
|
||||||
|
console.log(name, "✅");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let lang in json) json[lang].sort((a, b) => a.id.localeCompare(b.id));
|
for (let lang in json) json[lang].sort((a, b) => a.id.localeCompare(b.id));
|
||||||
@@ -85,19 +91,19 @@ fs.writeFileSync(jsonPath, JSON.stringify(json, null, "\t"));
|
|||||||
|
|
||||||
// check for broken plugins
|
// check for broken plugins
|
||||||
for (let language in languages) {
|
for (let language in languages) {
|
||||||
const tsFiles = fs.readdirSync(
|
const tsFiles = fs.readdirSync(
|
||||||
path.join(root, "..", "plugins", language.toLocaleLowerCase())
|
path.join(root, "..", "plugins", language.toLocaleLowerCase())
|
||||||
);
|
);
|
||||||
tsFiles
|
tsFiles
|
||||||
.filter((f) => f.endsWith(".broken.ts"))
|
.filter((f) => f.endsWith(".broken.ts"))
|
||||||
.forEach((fn) => {
|
.forEach((fn) => {
|
||||||
console.error(
|
console.error(
|
||||||
language.toLocaleLowerCase() +
|
language.toLocaleLowerCase() +
|
||||||
"/" +
|
"/" +
|
||||||
fn.replace(".broken.ts", "") +
|
fn.replace(".broken.ts", "") +
|
||||||
" ❌"
|
" ❌"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(jsonPath);
|
console.log(jsonPath);
|
||||||
|
|||||||
Reference in New Issue
Block a user