mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
ESLint has a whole new config format, so I figure it's a good time to make the config system saner. - First, we no longer have separate eslint-no-types configs. Lint performance shouldn't be enough of a problem to justify the relevant maintenance complexity. - Second, our base config should work out-of-the-box now. `npx eslint` will work as expected, without any CLI flags. You should still use `npm run lint` which adds the `--cached` flag for performance. - Third, whatever updates I did fixed style linting, which apparently has been bugged for quite some time, considering all the obvious mixed-tabs-and-spaces issues I found in the upgrade. Also here are some changes to our style rules. In particular: - Curly brackets (for objects etc) now have spaces inside them. Sorry for the huge change. ESLint doesn't support our old style, and most projects use Prettier style, so we might as well match them in this way. See https://github.com/eslint-stylistic/eslint-stylistic/issues/415 - String + number concatenation is no longer allowed. We now consistently use template strings for this.
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const child_process = require("child_process");
|
|
const esbuild = require('esbuild');
|
|
|
|
const copyOverDataJSON = (file = 'data') => {
|
|
const files = fs.readdirSync(file);
|
|
for (const f of files) {
|
|
if (fs.statSync(`${file}/${f}`).isDirectory()) {
|
|
copyOverDataJSON(`${file}/${f}`);
|
|
} else if (f.endsWith('.json')) {
|
|
fs.copyFileSync(`${file}/${f}`, require('path').resolve('dist', `${file}/${f}`));
|
|
}
|
|
}
|
|
};
|
|
|
|
const shouldBeCompiled = file => {
|
|
if (file.includes('node_modules/')) return false;
|
|
if (file.endsWith('.tsx')) return true;
|
|
if (file.endsWith('.ts')) return !(file.endsWith('.d.ts') || file.includes('global'));
|
|
return false;
|
|
};
|
|
|
|
const findFilesForPath = path => {
|
|
const out = [];
|
|
const files = fs.readdirSync(path);
|
|
for (const file of files) {
|
|
const cur = `${path}/${file}`;
|
|
// HACK: Logs and databases exclusions are a hack. Logs is too big to
|
|
// traverse, databases adds/removes files which can lead to a filesystem
|
|
// race between readdirSync and statSync. Please, at some point someone
|
|
// fix this function to be more robust.
|
|
if (cur.includes('node_modules') || cur.includes("/logs") || cur.includes("/databases")) continue;
|
|
if (fs.statSync(cur).isDirectory()) {
|
|
out.push(...findFilesForPath(cur));
|
|
} else if (shouldBeCompiled(cur)) {
|
|
out.push(cur);
|
|
}
|
|
}
|
|
return out;
|
|
};
|
|
|
|
exports.transpile = decl => {
|
|
esbuild.buildSync({
|
|
entryPoints: findFilesForPath('./'),
|
|
outdir: './dist',
|
|
outbase: '.',
|
|
format: 'cjs',
|
|
tsconfig: './tsconfig.json',
|
|
sourcemap: true,
|
|
});
|
|
fs.copyFileSync('./config/config-example.js', './dist/config/config-example.js');
|
|
copyOverDataJSON();
|
|
|
|
// NOTE: replace is asynchronous - add additional replacements for the same path in one call instead of making multiple calls.
|
|
if (decl) {
|
|
exports.buildDecls();
|
|
}
|
|
};
|
|
|
|
exports.buildDecls = () => {
|
|
try {
|
|
child_process.execSync(`node ./node_modules/typescript/bin/tsc -p sim`, { stdio: 'inherit' });
|
|
} catch {}
|
|
};
|