Tinkered with pre-commit, jest, and tsconfig

This commit is contained in:
WatDuhHekBro 2021-01-26 07:22:23 -06:00
parent 5ed9d79715
commit 1fd8634ef1
9 changed files with 4629 additions and 553 deletions

7
jest.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
roots: ["<rootDir>/src"],
testMatch: ["**/*.test.+(ts|tsx)"],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest"
}
};

5077
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,24 +17,31 @@
"devDependencies": {
"@types/glob": "^7.1.3",
"@types/inquirer": "^6.5.0",
"@types/mocha": "^8.2.0",
"@types/jest": "^26.0.20",
"@types/ms": "^0.7.31",
"@types/node": "^14.14.20",
"@types/ws": "^7.4.0",
"mocha": "^8.2.1",
"jest": "^26.6.3",
"pre-commit": "^1.2.2",
"prettier": "2.1.2",
"ts-node": "^9.1.1",
"ts-jest": "^26.4.4",
"tsc-watch": "^4.2.9",
"typescript": "^3.9.7"
},
"scripts": {
"build": "tsc && npm prune --production",
"start": "node dist/index.js",
"build": "tsc --project tsconfig.prod.json && npm prune --production",
"start": "node .",
"once": "tsc && npm start",
"dev": "tsc-watch --onSuccess \"node dist/index.js dev\"",
"test": "mocha --require ts-node/register --extension ts --recursive",
"format": "prettier --write **/*"
"dev": "tsc-watch --onSuccess \"node . dev\"",
"test": "jest",
"format": "prettier --write **/*",
"precommit-message": "echo \"Running pre-commit formatting and testing...\""
},
"pre-commit": [
"precommit-message",
"test",
"format"
],
"keywords": [
"discord.js",
"bot"

View File

@ -148,7 +148,7 @@ export default new Command({
if (typeof evaled !== "string") evaled = require("util").inspect(evaled);
channel.send(clean(evaled), {code: "js", split: true});
} catch (err) {
channel.send(`\`ERROR\` \`\`\`js\n${clean(err)}\n\`\`\``);
channel.send(clean(err), {code: "js", split: true});
}
}
}),

View File

@ -1,6 +1,4 @@
import {MessageEmbed, version as djsversion} from "discord.js";
/// @ts-ignore
import {version} from "../../package.json";
import ms from "ms";
import os from "os";
import Command from "../core/command";
@ -53,7 +51,7 @@ export default new Command({
`** Channels:** ${$.client.channels.cache.size.toLocaleString()}`,
`** Creation Date:** ${utc($.client.user?.createdTimestamp).format("Do MMMM YYYY HH:mm:ss")}`,
`** Node.JS:** ${process.version}`,
`** Version:** v${version}`,
`** Version:** v${process.env.npm_package_version}`,
`** Discord.JS:** ${djsversion}`,
"\u200b"
])
@ -183,10 +181,10 @@ export default new Command({
`** Server Join Date:** ${moment(member.joinedAt).format("LL LTS")}`,
`** Hoist Role:** ${member.roles.hoist ? member.roles.hoist.name : "None"}`,
`** Roles:** [${roles.length}]: ${
roles.length < 10
roles.length < 10 && roles.length > 0
? roles.join(", ")
: roles.length > 10
? this.client.utils.trimArray(roles)
: roles.length >= 10
? roles.slice(0, 10)
: "None"
}`
]);

View File

@ -47,11 +47,7 @@ export interface CommonLibrary {
timeout?: number
) => void;
askYesOrNo: (message: Message, senderID: string, timeout?: number) => Promise<boolean>;
askMultipleChoice: (
message: Message,
senderID: string,
callbackStack: (() => void)[] | ((choice: number) => void)
) => void;
askMultipleChoice: (message: Message, senderID: string, callbackStack: (() => void)[], timeout?: number) => void;
// Dynamic Properties //
args: any[];

View File

@ -1,5 +1,5 @@
import {strict as assert} from "assert";
import {NumberWrapper, StringWrapper, ArrayWrapper} from "../src/core/wrappers";
import {NumberWrapper, StringWrapper, ArrayWrapper} from "./wrappers";
// I can't figure out a way to run the test suite while running the bot.
describe("Wrappers", () => {

View File

@ -1,18 +1,35 @@
// Reference: https://www.typescriptlang.org/tsconfig
{
"include": ["src/**/*"], // This makes it so that the compiler won't compile anything outside of "src".
//"exclude": ["src/**/*.test.ts"], // Exclude .test.ts files since they're for Jest only.
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"removeComments": true,
"sourceMap": true
},
"exclude": ["test"]
// Project Structure //
"rootDir": "src", // rootDir only affects the STRUCTURE of the folders, not what gets compiled. For extra measure, make sure the structure conforms to "src".
"outDir": "dist", // Likewise, outDir only chooses which folder to compile to. Prevent the compiler from creating JS files right next to source files.
"moduleResolution": "node", // Specify how the compiler resolves modules, like going for node_modules first then searching elsewhere. The official docs just say to use this instead of classic.
// Type Settings //
"strict": true, // Enables all strict checks possible.
"noImplicitReturns": true, // Makes sure you don't accidentally return something + undefined.
"noFallthroughCasesInSwitch": true, // Prevents accidentally forgetting to break every switch case. Of course, if you know what you're doing, feel free to add a @ts-ignore, which also signals that it's not a mistake.
"forceConsistentCasingInFileNames": true, // Make import paths case-sensitive. "./tEst" is no longer the same as "./test".
"esModuleInterop": true, // Enables compatibility with Node.js' module system since the entire export can be whatever you want. allowSyntheticDefaultImports doesn't address runtime issues and is made redundant by this setting.
"resolveJsonModule": true, // Allows you to import JSON files just like how you can require() them. Do note that if you're accessing any JSON files outside of src, it'll mess up dist.
"lib": ["ES2020"], // Specifies what common libraries you have access to. If you're working in Node.js, you'll want to leave out the DOM library. But do make sure to include "@types/node" because otherwise, variables like "console" won't be defined.
// Output //
"module": "CommonJS", // Compiles ES6 imports to require() syntax.
"removeComments": false,
"sourceMap": true, // Used for displaying the original source when debugging in webpack. Allows you to set breakpoints directly on TypeScript code for VSCode's debugger.
// Library Building //
"declaration": false, // Exports declaration files in addition, used for exporting a module.
"declarationMap": false, // Allows the user to go to the source file when hitting a go-to-implementation key like F12 in VSCode for example.
//"declarationDir": "typings", // declarationDir allows you to separate the compiled code from the declaration files, used in conjunction with package.json's "types" property.
// Web Compatibility //
"target": "ES2020", // ES2017 supports async/await, reducing the amount of compiled code, especially for async-heavy projects. ES2020 is from the Node 14 base (https://github.com/tsconfig/bases/blob/master/bases/node14.json)
"downlevelIteration": false, // This flag adds extra support when targeting ES3, but adds extra bloat otherwise.
"importHelpers": false // Reduce the amount of bloat that comes from downlevelIteration (when polyfills are redeclared).
}
}

8
tsconfig.prod.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"exclude": ["src/**/*.test.ts", "src/**/template.ts"],
"compilerOptions": {
"removeComments": true,
"sourceMap": false
}
}