✨ bundle build script
This commit is contained in:
parent
29516da90f
commit
3b74fa9299
BIN
api/package-lock.json
generated
BIN
api/package-lock.json
generated
Binary file not shown.
@ -10,7 +10,7 @@
|
||||
"test": "npm run build && npm run test:only",
|
||||
"test:watch": "jest --watch",
|
||||
"start": "npm run build && node dist/start",
|
||||
"build": "npx swc src --out-dir dist",
|
||||
"build": "npx tsc -b .",
|
||||
"build-docker": "tsc -p tsconfig-docker.json",
|
||||
"dev": "tsnd --respawn src/start.ts",
|
||||
"patch": "ts-patch install -s && npx patch-package",
|
||||
@ -69,6 +69,7 @@
|
||||
"ts-node": "^9.1.1",
|
||||
"ts-node-dev": "^1.1.6",
|
||||
"ts-patch": "^1.4.4",
|
||||
"tsup": "^5.4.0",
|
||||
"typescript": "^4.4.2",
|
||||
"typescript-json-schema": "0.50.1"
|
||||
},
|
||||
@ -86,6 +87,7 @@
|
||||
"dot-prop": "^6.0.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"env-paths": "^2.2.1",
|
||||
"esbuild": "^0.13.4",
|
||||
"express": "^4.17.1",
|
||||
"express-validator": "^6.9.2",
|
||||
"form-data": "^3.0.0",
|
||||
|
||||
BIN
bundle/package-lock.json
generated
BIN
bundle/package-lock.json
generated
Binary file not shown.
@ -6,9 +6,9 @@
|
||||
"scripts": {
|
||||
"setup": "cd ../util && npm --production=false i && cd ../api && npm --production=false i && cd ../cdn && npm --production=false i && cd ../gateway && npm --production=false i && cd ../bundle/ && npm --production=false i && npm run build",
|
||||
"build": "node scripts/build.js",
|
||||
"build:bundle": "npx swc src --out-dir dist",
|
||||
"start": "npm run build && npm run start:bundle",
|
||||
"start:bundle": "node dist/start.js",
|
||||
"build:bundle": "npx tsc -b .",
|
||||
"start": "node scripts/build.js && node -r tsconfig-paths/register dist/start.js",
|
||||
"start:bundle": "node -r tsconfig-paths/register dist/start.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
@ -41,9 +41,12 @@
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/ws": "^7.4.0",
|
||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||
"esbuild": "^0.13.4",
|
||||
"esbuild-plugin-tsc": "^0.3.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"ts-patch": "^1.4.4",
|
||||
"typescript": "^4.3.5"
|
||||
"tsconfig-paths": "^3.11.0",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fosscord/api": "file:../api",
|
||||
@ -56,7 +59,6 @@
|
||||
"missing-native-js-functions": "^1.2.17",
|
||||
"nanocolors": "^0.2.12",
|
||||
"node-os-utils": "^1.3.5",
|
||||
"swc": "^1.0.11",
|
||||
"tsconfig-paths": "^3.11.0"
|
||||
"reflect-metadata": "^0.1.13"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,37 +1,70 @@
|
||||
const { spawn } = require("child_process");
|
||||
const path = require("path");
|
||||
const { performance } = require("perf_hooks");
|
||||
const fs = require("fs");
|
||||
const esbuildPluginTsc = require("esbuild-plugin-tsc");
|
||||
|
||||
let parts = "util,api,cdn,gateway,bundle".split(",");
|
||||
let parts = "api,cdn,gateway,bundle".split(",");
|
||||
const tscBin = path.join(__dirname, "..", "..", "util", "node_modules", "typescript", "bin", "tsc");
|
||||
const swcBin = path.join(__dirname, "..", "..", "util", "node_modules", "@swc", "cli", "bin", "swc");
|
||||
|
||||
// because npm run is slow we directly get the build script of the package.json script
|
||||
|
||||
function buildPackage(dir) {
|
||||
const element = path.basename(dir);
|
||||
const swcBin = path.join(dir, "node_modules", "@swc", "cli", "lib", "swc", "index.js");
|
||||
|
||||
const child = spawn("node", `${swcBin} src --out-dir dist --sync`.split(" "), {
|
||||
cwd: dir,
|
||||
require("esbuild").build({
|
||||
entryPoints: walk(path.join(dir, "src")),
|
||||
bundle: false,
|
||||
outdir: path.join(dir, "dist"),
|
||||
target: "es2021",
|
||||
format: "cjs",
|
||||
plugins: [esbuildPluginTsc({})],
|
||||
keepNames: true,
|
||||
});
|
||||
}
|
||||
|
||||
function util() {
|
||||
// const child = spawn("node", `${swcBin} src --out-dir dist --sync`.split(" "), {
|
||||
const child = spawn("node", `${tscBin} -b .`.split(" "), {
|
||||
cwd: path.join(__dirname, "..", "..", "util"),
|
||||
env: process.env,
|
||||
shell: true,
|
||||
});
|
||||
function log(data) {
|
||||
console.log(`[${element}]`.padEnd(10, " ") + data.toString().slice(0, -1));
|
||||
console.log(`[util] ` + data.toString().slice(0, -1));
|
||||
}
|
||||
child.stdout.on("data", log);
|
||||
child.stderr.on("data", log);
|
||||
child.on("error", (err) => console.error(element, err));
|
||||
child.on("error", (err) => console.error("util", err));
|
||||
return child;
|
||||
}
|
||||
|
||||
// util needs to be compiled first as the others require it
|
||||
|
||||
const start = performance.now();
|
||||
console.log("[Build] starting ...");
|
||||
|
||||
util();
|
||||
for (const part of parts) {
|
||||
buildPackage(path.join(__dirname, "..", "..", part));
|
||||
}
|
||||
|
||||
process.on("exit", () => {
|
||||
console.log("[Build] took " + Math.round(performance.now() - start) + "ms");
|
||||
console.log("[Build] took " + Math.round(performance.now() - start) + "ms");
|
||||
});
|
||||
|
||||
function walk(dir) {
|
||||
var results = [];
|
||||
var list = fs.readdirSync(dir);
|
||||
list.forEach(function (file) {
|
||||
file = dir + "/" + file;
|
||||
var stat = fs.statSync(file);
|
||||
if (stat && stat.isDirectory()) {
|
||||
/* Recurse into a subdirectory */
|
||||
results = results.concat(walk(file));
|
||||
} else if (file.endsWith(".ts")) {
|
||||
/* Is a file */
|
||||
results.push(file);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -1,4 +1,20 @@
|
||||
// process.env.MONGOMS_DEBUG = "true";
|
||||
const tsConfigPaths = require("tsconfig-paths");
|
||||
const path = require("path");
|
||||
const baseUrl = path.join(__dirname, ".."); // Either absolute or relative path. If relative it's resolved to current working directory.
|
||||
const cleanup = tsConfigPaths.register({
|
||||
baseUrl,
|
||||
paths: {
|
||||
"@fosscord/api": ["../api/dist/index.js"],
|
||||
"@fosscord/api/*": ["../api/dist/*"],
|
||||
"@fosscord/gateway": ["../gateway/dist/index.js"],
|
||||
"@fosscord/gateway/*": ["../gateway/dist/*"],
|
||||
"@fosscord/cdn": ["../cdn/dist/index.js"],
|
||||
"@fosscord/cdn/*": ["../cdn/dist/*"],
|
||||
},
|
||||
});
|
||||
|
||||
import "reflect-metadata";
|
||||
import cluster from "cluster";
|
||||
import os from "os";
|
||||
import { red, bold, yellow, cyan } from "nanocolors";
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
"incremental": true, /* Enable incremental compilation */
|
||||
"incremental": true /* Enable incremental compilation */,
|
||||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
|
||||
@ -63,6 +63,8 @@
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true
|
||||
}
|
||||
}
|
||||
|
||||
BIN
cdn/package-lock.json
generated
BIN
cdn/package-lock.json
generated
Binary file not shown.
@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"postinstall": "ts-patch install -s",
|
||||
"test": "npm run build && jest --coverage ./tests",
|
||||
"build": "npx swc src --out-dir dist",
|
||||
"build": "npx tsc -b .",
|
||||
"start": "npm run build && node dist/start.js"
|
||||
},
|
||||
"repository": {
|
||||
@ -61,7 +61,6 @@
|
||||
"nanocolors": "^0.2.12",
|
||||
"node-fetch": "^2.6.1",
|
||||
"supertest": "^6.1.6",
|
||||
"swc": "^1.0.11",
|
||||
"typescript": "^4.1.2",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
|
||||
BIN
gateway/package-lock.json
generated
BIN
gateway/package-lock.json
generated
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
"postinstall": "npx ts-patch install -s",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "npm run build && node dist/start.js",
|
||||
"build": "npx swc src --out-dir dist",
|
||||
"build": "npx tsc -b .",
|
||||
"dev": "tsnd --respawn src/start.ts"
|
||||
},
|
||||
"keywords": [],
|
||||
@ -41,7 +41,6 @@
|
||||
"missing-native-js-functions": "^1.2.17",
|
||||
"mongoose-autopopulate": "^0.12.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"swc": "^1.0.11",
|
||||
"typeorm": "^0.2.37",
|
||||
"uuid": "^8.3.2",
|
||||
"ws": "^7.4.2"
|
||||
|
||||
BIN
util/package-lock.json
generated
BIN
util/package-lock.json
generated
Binary file not shown.
@ -8,7 +8,7 @@
|
||||
"start": "npm run build && node dist/",
|
||||
"test": "npm run build && jest",
|
||||
"postinstall": "npm run build",
|
||||
"build": "npx swc src --out-dir dist"
|
||||
"build": "npx tsc -b ."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -54,7 +54,6 @@
|
||||
"pg": "^8.7.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sqlite3": "^5.0.2",
|
||||
"swc": "^1.0.11",
|
||||
"tsconfig-paths": "^3.11.0",
|
||||
"typeorm": "^0.2.37",
|
||||
"typescript": "^4.4.2",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import cluster from "cluster";
|
||||
import * as cluster from "cluster";
|
||||
|
||||
// https://github.com/discordjs/discord.js/blob/master/src/util/Snowflake.js
|
||||
// Apache License Version 2.0 Copyright 2015 - 2021 Amish Shah
|
||||
|
||||
Reference in New Issue
Block a user