Skip to content

Commit

Permalink
✨ Move tools to "Tools" folder and remove some things.
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed Apr 7, 2021
1 parent f79ea03 commit 0462838
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 79 deletions.
4 changes: 4 additions & 0 deletions configs/tsconfig.auto.presenceUpdater.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tools/auto/tsconfig.auto.json",
"files": ["../tools/auto/presenceUpdater.ts"]
}
4 changes: 4 additions & 0 deletions configs/tsconfig.auto.schemaValidator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tools/auto/tsconfig.auto.json",
"files": ["../tools/auto/schemaValidator.ts"]
}
4 changes: 4 additions & 0 deletions configs/tsconfig.auto.syntaxEnforcer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tools/auto/tsconfig.auto.json",
"files": ["../tools/auto/syntaxEnforcer.ts"]
}
4 changes: 4 additions & 0 deletions configs/tsconfig.translator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tools/auto/tsconfig.auto.json",
"files": ["../tools/translator.ts"]
}
5 changes: 3 additions & 2 deletions massVer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import "source-map-support/register";

import { sync as glob } from "glob";
import { coerce, inc, valid } from "semver";
import {
existsSync as exists,
readFileSync as readFile,
writeFileSync as writeFile
} from "fs";
import { valid, inc, coerce } from "semver";

import { sync as glob } from "glob";

function isValidJSON(text: string): boolean {
try {
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"scripts": {
"pretty": "prettier --write **/*.ts **/{metadata,tsconfig}.json",
"inc": "tsc --module CommonJS --target ES2020 --esModuleInterop --removeComments --noUnusedParameters --noUnusedLocals --noFallthroughCasesInSwitch --newLine lf --inlineSourceMap ./massVer.ts && node ./massVer.js",
"se": "node ./syntaxEnforcer.js",
"se:compile": "tsc --module CommonJS --target ES2020 --typeRoots '@types,node_modules/@types' --esModuleInterop --removeComments --noUnusedParameters --noUnusedLocals --noFallthroughCasesInSwitch --newLine lf --inlineSourceMap ./syntaxEnforcer.ts",
"sv": "node ./schemaValidator.js",
"sv:compile": "tsc --module CommonJS --target ES2020 --typeRoots '@types,node_modules/@types' --esModuleInterop --removeComments --noUnusedParameters --noUnusedLocals --noFallthroughCasesInSwitch --newLine lf --inlineSourceMap ./schemaValidator.ts",
"pu": "node ./presenceUpdater.js",
"pu:compile": "tsc --module CommonJS --target ES2020 --typeRoots @types --esModuleInterop --removeComments --noUnusedParameters --noUnusedLocals --noFallthroughCasesInSwitch --newLine lf --inlineSourceMap ./presenceUpdater.ts",
"translator": "npm run translator:compile && node ./translator.js",
"translator:compile": "tsc --module CommonJS --target ES2020 --typeRoots @types --esModuleInterop --removeComments --noUnusedParameters --noUnusedLocals --noFallthroughCasesInSwitch --newLine lf --inlineSourceMap ./translator.ts"
"se": "node ./tools/auto/syntaxEnforcer.js",
"se:compile": "tsc -p ./configs/tsconfig.auto.syntaxEnforcer.json",
"sv": "node ./tools/auto/schemaValidator.js",
"sv:compile": "tsc -p ./configs/tsconfig.auto.schemaValidator.json",
"pu": "node ./tools/auto/presenceUpdater.js",
"pu:compile": "tsc -p ./configs/tsconfig.auto.presenceUpdater.json",
"translator": "npm run translator:compile && node ./tools/translator.js",
"translator:compile": "tsc -p ./configs/tsconfig.translator.json"
},
"devDependencies": {
"@babel/core": "^7.13.10",
Expand All @@ -34,7 +34,6 @@
"debug": "^4.3.1",
"enquirer": "^2.3.6",
"eslint": "^7.22.0",
"execa": "^5.0.0",
"glob": "^7.1.6",
"jsonschema": "^1.4.0",
"mongodb": "^3.6.5",
Expand Down
21 changes: 14 additions & 7 deletions presenceUpdater.ts → tools/auto/presenceUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import "source-map-support/register";

import { existsSync, readFileSync, writeFileSync } from "fs";
import { sync as glob } from "glob";
import { DeleteWriteOpResultObject, MongoClient, UpdateWriteOpResult } from "mongodb";
import { join, normalize, resolve as rslv, sep } from "path";
import { valid } from "semver";
import { minify as terser } from "terser";
import {
CompilerOptions, createProgram, flattenDiagnosticMessageText, getPreEmitDiagnostics
CompilerOptions,
createProgram,
flattenDiagnosticMessageText,
getPreEmitDiagnostics
} from "typescript";
import {
DeleteWriteOpResultObject,
MongoClient,
UpdateWriteOpResult
} from "mongodb";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { join, normalize, resolve as rslv, sep } from "path";

import { sync as glob } from "glob";
import { minify as terser } from "terser";
import { transformFileAsync as transform } from "@babel/core";
import { valid } from "semver";

const url = `mongodb://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@${process.env.MONGO_IP}:27017`,
dbname = "PreMiD";
Expand Down
File renamed without changes.
27 changes: 22 additions & 5 deletions syntaxEnforcer.ts → tools/auto/syntaxEnforcer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import "source-map-support/register";

import { coerce, inc } from "semver";
import { green, yellow } from "chalk";
import { readFileSync, writeFileSync } from "fs";
import { sync as glob } from "glob";
import { join, normalize, relative, resolve, sep } from "path";
import { format as prettier, resolveConfig } from "prettier";
import { coerce, inc } from "semver";
import { readFileSync, writeFileSync } from "fs";

import execa = require("execa");
import { exec } from "child_process";
import { sync as glob } from "glob";

/**
* Executes a shell command and return it as a Promise.
* @param cmd {string[]}
* @return Promise<string>
*/
function execShellCommand(cmd: string[]) {
return new Promise<string>((resolve) => {
exec(cmd.join(" "), (error, stdout, stderr) => {
if (error) {
console.warn(error);
}
resolve(stdout ? stdout : stderr);
});
});
}

/**
* Helper function to read any file as string
Expand Down Expand Up @@ -129,7 +145,8 @@ const readFile = (path: string): string =>
);

// Use Git to check what files have changed after TypeScript compilation
const { stdout: listOfChangedFiles } = await execa("git", [
const listOfChangedFiles = await execShellCommand([
"git",
"--no-pager",
"diff",
"--name-only"
Expand Down
14 changes: 14 additions & 0 deletions tools/auto/tsconfig.auto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"typeRoots": ["../../@types", "../../node_modules/@types"],
"module": "CommonJS",
"target": "ES2020",
"esModuleInterop": true,
"removeComments": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"newLine": "lf",
"inlineSourceMap": true
}
}
11 changes: 6 additions & 5 deletions translator.ts → tools/translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* Translation Tool for PreMiD Presences.
* @author callumok2004 <[email protected]>
* @author Bas950 <[email protected]>
* @contributor ririxidev <[email protected]>
* @author ririxidev <[email protected]>
*/

import axios from "axios";
import { existsSync, readFileSync, readdirSync, writeFileSync } from "fs";
import { gray, green, hex, red, white, yellow } from "chalk";
import ora, { Ora } from "ora";

import axios from "axios";
import debug from "debug";
import { prompt } from "enquirer";
import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
import ora, { Ora } from "ora";

debug.enable("Translator:*");
let loadSpinner: Ora,
Expand Down Expand Up @@ -45,7 +46,7 @@ const spinnerSettings = {
loadFiles = async (lang: string): Promise<boolean> => {
language = lang;
info("Loading and caching files.");
const src = `${process.cwd()}/websites/`;
const src = `./websites/`;
if (!existsSync(src))
return (
error("Presences folder could not be found... exiting."), process.exit()
Expand Down
55 changes: 4 additions & 51 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=

cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down Expand Up @@ -1585,21 +1585,6 @@ esutils@^2.0.2:
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

execa@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-5.0.0.tgz#4029b0007998a841fbd1032e5f4de86a3c1e3376"
integrity sha512-ov6w/2LCiuyO4RLYGdpFGjkcs0wMTgGE8PrkTHikeUy5iJekXyPIKUjifk5CsE0pt7sMCrMZ3YNqoCj6idQOnQ==
dependencies:
cross-spawn "^7.0.3"
get-stream "^6.0.0"
human-signals "^2.1.0"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.1"
onetime "^5.1.2"
signal-exit "^3.0.3"
strip-final-newline "^2.0.0"

fast-deep-equal@^3.1.1:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
Expand Down Expand Up @@ -1686,11 +1671,6 @@ gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

get-stream@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.0.tgz#3e0012cb6827319da2706e601a1583e8629a6718"
integrity sha512-A1B3Bh1UmL0bidM/YX2NsCOTnGJePL9rO/M+Mw3m9f2gUpfokS0hi5Eah0WSUEWZdZhIZtMjkIYS7mDfOqNHbg==

glob-parent@^5.0.0, glob-parent@^5.1.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
Expand Down Expand Up @@ -1763,11 +1743,6 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

human-signals@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

ieee754@^1.1.13:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
Expand Down Expand Up @@ -1843,11 +1818,6 @@ is-number@^7.0.0:
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==

is-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==

is-unicode-supported@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
Expand Down Expand Up @@ -1946,11 +1916,6 @@ memory-pager@^1.0.2:
resolved "https://registry.yarnpkg.com/memory-pager/-/memory-pager-1.5.0.tgz#d8751655d22d384682741c972f2c3d6dfa3e66b5"
integrity sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
Expand Down Expand Up @@ -2014,13 +1979,6 @@ node-releases@^1.1.70:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.71.tgz#cb1334b179896b1c89ecfdd4b725fb7bbdfc7dbb"
integrity sha512-zR6HoT6LrLCRBwukmrVbHv0EpEQjksO6GmFcZQQuCAy139BEsoVKPYnf3jongYW83fAa1torLGYwxxky/p28sg==

npm-run-path@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
dependencies:
path-key "^3.0.0"

object-keys@^1.0.11, object-keys@^1.0.12:
version "1.1.1"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
Expand All @@ -2043,7 +2001,7 @@ once@^1.3.0:
dependencies:
wrappy "1"

onetime@^5.1.0, onetime@^5.1.2:
onetime@^5.1.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e"
integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==
Expand Down Expand Up @@ -2089,7 +2047,7 @@ path-is-absolute@^1.0.0:
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=

path-key@^3.0.0, path-key@^3.1.0:
path-key@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
Expand Down Expand Up @@ -2311,7 +2269,7 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

signal-exit@^3.0.2, signal-exit@^3.0.3:
signal-exit@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==
Expand Down Expand Up @@ -2395,11 +2353,6 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-final-newline@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
Expand Down

0 comments on commit 0462838

Please sign in to comment.