diff --git a/util/scripts/benchmark.js b/scripts/benchmark.js
index e7435191..e7435191 100644
--- a/util/scripts/benchmark.js
+++ b/scripts/benchmark.js
diff --git a/bundle/scripts/benchmark/connections.js b/scripts/benchmark/connections.js
index 661548c3..661548c3 100644
--- a/bundle/scripts/benchmark/connections.js
+++ b/scripts/benchmark/connections.js
diff --git a/bundle/scripts/benchmark/index.js b/scripts/benchmark/index.js
index 37ac5633..37ac5633 100644
--- a/bundle/scripts/benchmark/index.js
+++ b/scripts/benchmark/index.js
diff --git a/bundle/scripts/benchmark/users.js b/scripts/benchmark/users.js
index bce67bf4..bce67bf4 100644
--- a/bundle/scripts/benchmark/users.js
+++ b/scripts/benchmark/users.js
diff --git a/scripts/build.js b/scripts/build.js
new file mode 100644
index 00000000..2c0d7328
--- /dev/null
+++ b/scripts/build.js
@@ -0,0 +1,72 @@
+const { execSync } = require("child_process");
+const path = require("path");
+const fs = require("fs");
+const { argv, stdout, exit } = require("process");
+const { execIn, parts } = require('./utils');
+
+if(argv.includes("help")) {
+ console.log(`Fosscord build script help:
+Arguments:
+ clean Cleans up previous builds
+ verbose Enable verbose logging
+ logerrors Log build errors to console
+ pretty-errors Pretty-print build errors
+ silent No output to console or files.`);
+ exit(0);
+}
+
+let steps = 1, i = 0;
+if (argv.includes("clean")) steps++;
+
+const verbose = argv.includes("verbose") || argv.includes("v");
+const logerr = argv.includes("logerrors");
+const pretty = argv.includes("pretty-errors");
+const silent = argv.includes("silent");
+
+if(silent) console.error = console.log = function(){}
+
+if (argv.includes("clean")) {
+ console.log(`[${++i}/${steps}] Cleaning...`);
+ let d = "dist";
+ if (fs.existsSync(d)) {
+ fs.rmSync(d, { recursive: true });
+ if (verbose) console.log(`Deleted ${d}!`);
+ }
+}
+
+console.log(`[${++i}/${steps}] Compiling src files ...`);
+
+let buildFlags = ''
+if(pretty) buildFlags += '--pretty '
+
+try {
+ execSync(
+ 'node "' +
+ path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") +
+ '" -p "' +
+ path.join(__dirname, "..") +
+ '" ' + buildFlags,
+ {
+ cwd: path.join(__dirname, ".."),
+ shell: true,
+ env: process.env,
+ encoding: "utf8"
+ }
+ )
+} catch (error) {
+ if(verbose || logerr) {
+ error.stdout.split(/\r?\n/).forEach((line) => {
+ let _line = line.replace('dist/','',1);
+ if(!pretty && _line.includes('.ts(')) {
+ //reformat file path for easy jumping
+ _line = _line.replace('(',':',1).replace(',',':',1).replace(')','',1)
+ }
+ console.error(_line);
+ })
+ }
+ console.error(`Build failed! Please check build.log for info!`);
+ if(!silent){
+ if(pretty) fs.writeFileSync("build.log.ansi", error.stdout);
+ fs.writeFileSync("build.log", error.stdout.replaceAll(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''));
+ }
+}
\ No newline at end of file
diff --git a/scripts/db_migrations.sh b/scripts/db_migrations.sh
new file mode 100755
index 00000000..9ec8230a
--- /dev/null
+++ b/scripts/db_migrations.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+if [ ! -z "$1" ]
+then
+ FILENAME="$1"
+ echo "Using filename: $FILENAME"
+else
+ read -p "Enter migration filename: " FILENAME
+fi
+
+[ -f ".env" ] && (
+ mv .env .env.tmp 2>/dev/null
+ source .env.tmp 2>/dev/null
+)
+npm run build clean logerrors pretty-errors
+
+make_migration() {
+ echo "Creating migrations for $2"
+ mkdir "src/util/migrations/$2" 2>/dev/null
+# npm run build clean logerrors pretty-errors
+ THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
+ THREADS=1 DATABASE="$1" DB_MIGRATE=a npx typeorm-ts-node-commonjs migration:generate "src/util/migrations/$2/$FILENAME" -d src/util/util/Database.ts -p
+ #npm run build clean logerrors pretty-errors
+ #THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
+}
+
+npm i sqlite3
+make_migration "database.db" "sqlite"
+
+[ -z "$FC_DB_POSTGRES" ] || (
+ npm i pg
+ make_migration "$FC_DB_POSTGRES" "postgres"
+)
+
+[ -z "$FC_DB_MARIADB" ] || (
+ npm i mysql2
+ make_migration "$FC_DB_MARIADB" "mariadb"
+)
+
+[ -f ".env.tmp" ] && mv .env.tmp .env 2>/dev/null
+
diff --git a/bundle/scripts/depcheck.js b/scripts/depcheck.js
index 1957f794..08df156c 100644
--- a/bundle/scripts/depcheck.js
+++ b/scripts/depcheck.js
@@ -4,7 +4,7 @@ const { env } = require("process");
const { execSync } = require("child_process");
const { argv, stdout, exit } = require("process");
-const { execIn, getLines, parts } = require("./utils");
+const { execIn, getLines } = require("./utils");
let npmi_extra_flags = "";
diff --git a/scripts/depclean.js b/scripts/depclean.js
new file mode 100644
index 00000000..333f5aa0
--- /dev/null
+++ b/scripts/depclean.js
@@ -0,0 +1,62 @@
+const path = require("path");
+const fs = require("fs");
+const { env } = require("process");
+const { execSync } = require("child_process");
+const { argv, stdout, exit } = require("process");
+
+const { execIn, getLines } = require('./utils');
+
+const bundleRequired = ["@ovos-media/ts-transform-paths"];
+const removeModules = argv.includes("cleanup");
+
+console.log(`Installing all packages...`);
+execIn("npm i", path.join(__dirname, ".."));
+
+let partDir = path.join(__dirname, "..");
+let distDir = path.join(partDir, "dist");
+let start = 0;
+start = getLines(
+ execIn("npm ls --parseable --package-lock-only -a", partDir)
+);
+if (fs.existsSync(distDir))
+ fs.rmSync(distDir, {
+ recursive: true,
+ force: true,
+ });
+let x = {
+ dependencies: [],
+ devDependencies: [],
+ invalidDirs: [],
+ invalidFiles: [],
+ missing: [],
+ using: [],
+};
+let dcproc = execIn("npx depcheck --json", partDir);
+if(dcproc.stdout) x = JSON.parse(dcproc.stdout);
+else x = JSON.parse(dcproc);
+
+fs.writeFileSync(
+ path.join(__dirname, "..", `depclean.out.json`),
+ JSON.stringify(x, null, "\t"),
+ { encoding: "utf8" }
+);
+
+let depsToRemove = x.dependencies.join(" ");
+if (depsToRemove) execIn(`npm r --save ${depsToRemove}`, partDir);
+
+depsToRemove = x.devDependencies.join(" ");
+if (depsToRemove) execIn(`npm r --save --dev ${depsToRemove}`, partDir);
+
+if (removeModules && fs.existsSync(path.join(partDir, "node_modules")))
+ fs.rmSync(path.join(partDir, "node_modules"), {
+ recursive: true,
+ force: true,
+ });
+let end = getLines(
+ execIn("npm ls --parseable --package-lock-only -a", partDir)
+);
+console.log(`${part}: ${start} -> ${end} (diff: ${start - end})`);
+
+console.log("Installing required packages for bundle...");
+
+execIn(`npm i --save ${bundleRequired.join(" ")}`, path.join(__dirname, ".."));
diff --git a/api/scripts/droptables.sql b/scripts/droptables.sql
index 8a852048..8a852048 100644
--- a/api/scripts/droptables.sql
+++ b/scripts/droptables.sql
diff --git a/scripts/gen_index.js b/scripts/gen_index.js
new file mode 100644
index 00000000..71c64a9f
--- /dev/null
+++ b/scripts/gen_index.js
@@ -0,0 +1,34 @@
+const path = require("path");
+const fs = require("fs");
+const { execIn, getLines, parts } = require('./utils');
+
+if (!process.argv[2] || !fs.existsSync(process.argv[2])) {
+ console.log("Please pass a directory that exists!");
+ process.exit(1);
+}
+console.log(`// ${process.argv[2]}/index.ts`)
+const recurse = process.argv.includes("--recursive")
+
+const files = fs.readdirSync(process.argv[2]).filter(x => x.endsWith('.ts') && x != 'index.ts');
+
+let output = '';
+
+files.forEach(x => output += `export * from "./${x.replaceAll('.ts','')}";\n`)
+
+const dirs = fs.readdirSync(process.argv[2]).filter(x => {
+ try {
+ fs.readdirSync(path.join(process.argv[2], x));
+ return true;
+ } catch (e) {
+ return false;
+ }
+});
+dirs.forEach(x => {
+ output += `export * from "./${x}/index";\n`
+})
+console.log(output);
+fs.writeFileSync(path.join(process.argv[2], "index.ts"), output)
+
+dirs.forEach(x => {
+ if(recurse) console.log(execIn([process.argv[0], process.argv[1], `"${path.join(process.argv[2], x)}"`, "--recursive"].join(' '), process.cwd()))
+})
\ No newline at end of file
diff --git a/api/scripts/generate_openapi.js b/scripts/generate_openapi.js
index 9624a5b9..9624a5b9 100644
--- a/api/scripts/generate_openapi.js
+++ b/scripts/generate_openapi.js
diff --git a/api/scripts/generate_schema.js b/scripts/generate_schema.js
index 7a498ad6..6925df5d 100644
--- a/api/scripts/generate_schema.js
+++ b/scripts/generate_schema.js
@@ -48,9 +48,8 @@ function modify(obj) {
}
function main() {
- const files = [
- ...walk(path.join(__dirname, "..", "src", "routes")),
- ...walk(path.join(__dirname, "..", "..", "util", "src")),
+ const files = [
+ ...walk(path.join(__dirname, "..", "src", "util", "schemas")),
];
const program = TJS.getProgramFromFiles(
files,
diff --git a/util/scripts/migrate_db_engine.js b/scripts/migrate_db_engine.js
index 79e9d86f..79e9d86f 100644
--- a/util/scripts/migrate_db_engine.js
+++ b/scripts/migrate_db_engine.js
diff --git a/bundle/scripts/rights.js b/scripts/rights.js
index c363b0c5..20fd139c 100644
--- a/bundle/scripts/rights.js
+++ b/scripts/rights.js
@@ -6,7 +6,7 @@ const { argv, stdout, exit } = require("process");
const { execIn, getLines, parts } = require("./utils");
-let lines = fs.readFileSync(path.join(__dirname, "..", "..", "util", "src","util","Rights.ts")).toString()
+let lines = fs.readFileSync(path.join(__dirname, "..", "src", "util", "util","Rights.ts")).toString()
let lines2 = lines.split("\n");
let lines3 = lines2.filter(y=>y.includes(": BitFlag("));
let lines4 = lines3.map(x=>x.split("//")[0].trim())
diff --git a/api/scripts/stresstest/.gitignore b/scripts/stresstest/.gitignore
index bde26fd4..bde26fd4 100644
--- a/api/scripts/stresstest/.gitignore
+++ b/scripts/stresstest/.gitignore
diff --git a/api/scripts/stresstest/accounts.json.example b/scripts/stresstest/accounts.json.example
index 61904c5e..61904c5e 100644
--- a/api/scripts/stresstest/accounts.json.example
+++ b/scripts/stresstest/accounts.json.example
diff --git a/api/scripts/stresstest/config.json.example b/scripts/stresstest/config.json.example
index 73f52f05..73f52f05 100644
--- a/api/scripts/stresstest/config.json.example
+++ b/scripts/stresstest/config.json.example
diff --git a/api/scripts/stresstest/index.js b/scripts/stresstest/index.js
index 740a9011..740a9011 100644
--- a/api/scripts/stresstest/index.js
+++ b/scripts/stresstest/index.js
diff --git a/api/scripts/stresstest/package-lock.json b/scripts/stresstest/package-lock.json
index 81c9b817..81c9b817 100644
--- a/api/scripts/stresstest/package-lock.json
+++ b/scripts/stresstest/package-lock.json
diff --git a/api/scripts/stresstest/package.json b/scripts/stresstest/package.json
index 8d94d05b..8d94d05b 100644
--- a/api/scripts/stresstest/package.json
+++ b/scripts/stresstest/package.json
diff --git a/api/scripts/stresstest/src/login/index.js b/scripts/stresstest/src/login/index.js
index ab6c9719..b153550e 100644
--- a/api/scripts/stresstest/src/login/index.js
+++ b/scripts/stresstest/src/login/index.js
@@ -1,6 +1,6 @@
const fetch = require("node-fetch");
const fs = require("fs");
-let config = require("./../../config.json");
+let config = require("../../config.json");
module.exports = login;
async function login(account) {
let body = {
diff --git a/api/scripts/stresstest/src/message/send.js b/scripts/stresstest/src/message/send.js
index d1b86914..d1b86914 100644
--- a/api/scripts/stresstest/src/message/send.js
+++ b/scripts/stresstest/src/message/send.js
diff --git a/api/scripts/stresstest/src/register/index.js b/scripts/stresstest/src/register/index.js
index 578b9022..578b9022 100644
--- a/api/scripts/stresstest/src/register/index.js
+++ b/scripts/stresstest/src/register/index.js
diff --git a/scripts/update_schemas.js b/scripts/update_schemas.js
new file mode 100644
index 00000000..361bedc1
--- /dev/null
+++ b/scripts/update_schemas.js
@@ -0,0 +1,9 @@
+const path = require("path");
+const fs = require("fs");
+const { env } = require("process");
+const { execSync } = require("child_process");
+const { argv, stdout, exit } = require("process");
+
+const { execIn, getLines, parts } = require("./utils");
+
+execIn("node scripts/generate_schema.js", path.join('.'));
\ No newline at end of file
diff --git a/bundle/scripts/utils.js b/scripts/utils.js
index bf960532..84aaeed6 100644
--- a/bundle/scripts/utils.js
+++ b/scripts/utils.js
@@ -4,8 +4,6 @@ const { env } = require("process");
const { execSync } = require("child_process");
const { argv, stdout, exit } = require("process");
-const parts = ["api", "util", "cdn", "gateway", "bundle"];
-
function copyRecursiveSync(src, dest) {
//if (verbose) console.log(`cpsync: ${src} -> ${dest}`);
let exists = fs.existsSync(src);
@@ -28,13 +26,14 @@ function copyRecursiveSync(src, dest) {
}
}
-function execIn(cmd, workdir) {
+function execIn(cmd, workdir, opts) {
try {
return execSync(cmd, {
cwd: workdir,
shell: true,
env: process.env,
encoding: "utf-8",
+ ...opts
});
} catch (error) {
return error.stdout;
@@ -47,7 +46,6 @@ function getLines(output) {
module.exports = {
//consts
- parts,
//functions
copyRecursiveSync, execIn, getLines
};
|