mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
[Scripts > PCCompatCheck] Initial Add (WIP)
This commit is contained in:
parent
21f501ed56
commit
51407b9720
1 changed files with 82 additions and 0 deletions
82
scripts/pccompatCheck.js
Normal file
82
scripts/pccompatCheck.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
import { exec } from 'child_process';
|
||||
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
|
||||
import glob from 'glob';
|
||||
|
||||
function underline(text) {
|
||||
return `\x1b[4m${text}\x1b[0m`;
|
||||
}
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const { alias } = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'));
|
||||
|
||||
|
||||
const clonesDir = join(__dirname, '..', 'clones');
|
||||
|
||||
const [ repo ] = process.argv.slice(2);
|
||||
|
||||
const cloneDir = join(clonesDir, repo);
|
||||
const url = `https://github.com/${repo}.git`;
|
||||
|
||||
console.log(cloneDir, url);
|
||||
|
||||
if (!existsSync(cloneDir)) {
|
||||
await new Promise((res) => exec(`git clone ${url} ${cloneDir}`, res));
|
||||
}
|
||||
|
||||
console.log();
|
||||
|
||||
for (const jsFile of glob.sync(`${cloneDir}/**/*.js`).concat(glob.sync(`${cloneDir}/**/*.jsx`))) {
|
||||
console.log(underline(jsFile.replace(cloneDir, '')));
|
||||
|
||||
const js = readFileSync(jsFile, 'utf8');
|
||||
|
||||
let match;
|
||||
const importRegex = /{ *(.*,*) *} *= *require\(('|"|`)(.*)('|"|`)\)/g;
|
||||
|
||||
while ((match = importRegex.exec(js)) !== null) {
|
||||
let [ _1, imports, _2, requirePath, _3 ] = match;
|
||||
imports = imports.trim();
|
||||
|
||||
if (requirePath.includes('.')) continue;
|
||||
|
||||
const aliasPath = alias[requirePath];
|
||||
|
||||
if (!aliasPath) {
|
||||
console.log('No alias', requirePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
const aliasJS = readFileSync(join(__dirname, '..', aliasPath), 'utf8');
|
||||
|
||||
for (let imp of imports.split(',')) {
|
||||
imp = imp.trim().split(':')[0];
|
||||
|
||||
const searchRegex = new RegExp(`^export.*${imp}.*$`, 'gm');
|
||||
|
||||
const searchMatch = aliasJS.match(searchRegex);
|
||||
|
||||
if (!searchMatch) {
|
||||
if (requirePath === 'powercord/webpack') {
|
||||
const webpackJS = readFileSync(join(__dirname, '..', '..', 'GooseMod', 'src', 'util', 'discord', 'webpackModules.js'), 'utf8');
|
||||
|
||||
if (imp.startsWith('getModule') || webpackJS.includes(`obj.common.${imp}`)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (requirePath === 'powercord/injector') {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log('No export', requirePath, imp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
}
|
Loading…
Reference in a new issue