inital commit
This commit is contained in:
3
packages/eslint-config-custom/README.md
Normal file
3
packages/eslint-config-custom/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# `@turbo/eslint-config`
|
||||
|
||||
Collection of internal eslint configurations.
|
34
packages/eslint-config-custom/library.js
Normal file
34
packages/eslint-config-custom/library.js
Normal file
@ -0,0 +1,34 @@
|
||||
const { resolve } = require("node:path");
|
||||
|
||||
const project = resolve(process.cwd(), "tsconfig.json");
|
||||
|
||||
/*
|
||||
* This is a custom ESLint configuration for use with
|
||||
* typescript packages.
|
||||
*
|
||||
* This config extends the Vercel Engineering Style Guide.
|
||||
* For more information, see https://github.com/vercel/style-guide
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
extends: [
|
||||
"@vercel/style-guide/eslint/node",
|
||||
"@vercel/style-guide/eslint/typescript",
|
||||
].map(require.resolve),
|
||||
parserOptions: {
|
||||
project,
|
||||
},
|
||||
globals: {
|
||||
React: true,
|
||||
JSX: true,
|
||||
},
|
||||
settings: {
|
||||
"import/resolver": {
|
||||
typescript: {
|
||||
project,
|
||||
},
|
||||
},
|
||||
},
|
||||
ignorePatterns: ["node_modules/", "dist/"],
|
||||
};
|
42
packages/eslint-config-custom/next.js
Normal file
42
packages/eslint-config-custom/next.js
Normal file
@ -0,0 +1,42 @@
|
||||
const { resolve } = require("node:path");
|
||||
|
||||
const project = resolve(process.cwd(), "tsconfig.json");
|
||||
|
||||
/*
|
||||
* This is a custom ESLint configuration for use with
|
||||
* Next.js apps.
|
||||
*
|
||||
* This config extends the Vercel Engineering Style Guide.
|
||||
* For more information, see https://github.com/vercel/style-guide
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
extends: [
|
||||
"@vercel/style-guide/eslint/node",
|
||||
"@vercel/style-guide/eslint/browser",
|
||||
"@vercel/style-guide/eslint/typescript",
|
||||
"@vercel/style-guide/eslint/react",
|
||||
"@vercel/style-guide/eslint/next",
|
||||
"eslint-config-turbo",
|
||||
].map(require.resolve),
|
||||
parserOptions: {
|
||||
project,
|
||||
},
|
||||
globals: {
|
||||
React: true,
|
||||
JSX: true,
|
||||
},
|
||||
settings: {
|
||||
"import/resolver": {
|
||||
typescript: {
|
||||
project,
|
||||
},
|
||||
},
|
||||
},
|
||||
ignorePatterns: ["node_modules/", "dist/"],
|
||||
// add rules configurations here
|
||||
rules: {
|
||||
"import/no-default-export": "off",
|
||||
},
|
||||
};
|
11
packages/eslint-config-custom/package.json
Normal file
11
packages/eslint-config-custom/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "eslint-config-custom",
|
||||
"license": "MIT",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@vercel/style-guide": "^5.0.0",
|
||||
"eslint-config-turbo": "^1.10.12",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
39
packages/eslint-config-custom/react-internal.js
vendored
Normal file
39
packages/eslint-config-custom/react-internal.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
const { resolve } = require("node:path");
|
||||
|
||||
const project = resolve(process.cwd(), "tsconfig.json");
|
||||
|
||||
/*
|
||||
* This is a custom ESLint configuration for use with
|
||||
* internal (bundled by their consumer) libraries
|
||||
* that utilize React.
|
||||
*
|
||||
* This config extends the Vercel Engineering Style Guide.
|
||||
* For more information, see https://github.com/vercel/style-guide
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
extends: [
|
||||
"@vercel/style-guide/eslint/browser",
|
||||
"@vercel/style-guide/eslint/typescript",
|
||||
"@vercel/style-guide/eslint/react",
|
||||
].map(require.resolve),
|
||||
parserOptions: {
|
||||
project,
|
||||
},
|
||||
globals: {
|
||||
JSX: true,
|
||||
},
|
||||
settings: {
|
||||
"import/resolver": {
|
||||
typescript: {
|
||||
project,
|
||||
},
|
||||
},
|
||||
},
|
||||
ignorePatterns: ["node_modules/", "dist/", ".eslintrc.js"],
|
||||
|
||||
rules: {
|
||||
// add specific rules configurations here
|
||||
},
|
||||
};
|
11
packages/server/package.json
Normal file
11
packages/server/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
}
|
11
packages/server/src/index.ts
Normal file
11
packages/server/src/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { badRequest } from "./messages/badRequest";
|
||||
import { unknownRoute } from "./messages/unknownRoute";
|
||||
|
||||
export const RouteMessages = {
|
||||
unknownRoute: unknownRoute,
|
||||
badRequest: badRequest,
|
||||
};
|
||||
|
||||
export * from "./route/route";
|
||||
export * from "./route/routeManager";
|
||||
export * from "./server/server";
|
10
packages/server/src/messages/badRequest.ts
Normal file
10
packages/server/src/messages/badRequest.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { baseMessage } from "./baseMessage";
|
||||
|
||||
/**
|
||||
* Creates a response for a bad request
|
||||
*
|
||||
* @returns the bad request message
|
||||
*/
|
||||
export function badRequest(message: string) {
|
||||
return baseMessage(true, message);
|
||||
}
|
13
packages/server/src/messages/baseMessage.ts
Normal file
13
packages/server/src/messages/baseMessage.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Creates a base message for use in JSON responses
|
||||
*
|
||||
* @param error the error status
|
||||
* @param message the message to show
|
||||
* @returns the base message
|
||||
*/
|
||||
export function baseMessage(error: boolean, message: string) {
|
||||
return {
|
||||
error: error,
|
||||
message: message,
|
||||
};
|
||||
}
|
10
packages/server/src/messages/unknownRoute.ts
Normal file
10
packages/server/src/messages/unknownRoute.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { baseMessage } from "./baseMessage";
|
||||
|
||||
/**
|
||||
* Creates a response for an unknown route
|
||||
*
|
||||
* @returns the unknown route message
|
||||
*/
|
||||
export function unknownRoute() {
|
||||
return baseMessage(true, "Unknown route");
|
||||
}
|
34
packages/server/src/route/route.ts
Normal file
34
packages/server/src/route/route.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
type RouteType = {
|
||||
/**
|
||||
* The path to handle
|
||||
*/
|
||||
path: string;
|
||||
};
|
||||
|
||||
export abstract class Route {
|
||||
private path: string;
|
||||
|
||||
constructor({ path }: RouteType) {
|
||||
this.path = path;
|
||||
console.log(`Created route handler for ${path}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the incoming request
|
||||
*
|
||||
* @param req the request
|
||||
* @param res the response
|
||||
*/
|
||||
abstract handle(req: Request, res: Response): void;
|
||||
|
||||
/**
|
||||
* Get the path of the route
|
||||
*
|
||||
* @returns the path
|
||||
*/
|
||||
getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
33
packages/server/src/route/routeManager.ts
Normal file
33
packages/server/src/route/routeManager.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Route } from "./route";
|
||||
|
||||
export class RouteManager {
|
||||
private routes: Route[] = [];
|
||||
|
||||
/**
|
||||
* Add a route to the route manager
|
||||
*
|
||||
* @param route the route to add
|
||||
*/
|
||||
addRoute(route: Route) {
|
||||
this.routes.push(route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a route by path
|
||||
*
|
||||
* @param path the path to get the route for
|
||||
* @returns the route or undefined if not found
|
||||
*/
|
||||
getRoute(path: string) {
|
||||
return this.routes.find((route) => route.getPath() === path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all routes
|
||||
*
|
||||
* @returns all routes
|
||||
*/
|
||||
getRoutes() {
|
||||
return this.routes;
|
||||
}
|
||||
}
|
38
packages/server/src/server/server.ts
Normal file
38
packages/server/src/server/server.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import express from "express";
|
||||
|
||||
type ServerType = {
|
||||
/**
|
||||
* The port to listen on
|
||||
* @default 3000
|
||||
*/
|
||||
port: number | string;
|
||||
|
||||
onLoaded?: () => void;
|
||||
};
|
||||
|
||||
export function createServer({ port = 3000, onLoaded }: ServerType) {
|
||||
if (typeof port === "string") {
|
||||
port = Number(port);
|
||||
if (isNaN(port)) {
|
||||
throw new Error("Port must be a number");
|
||||
}
|
||||
}
|
||||
const server = express();
|
||||
|
||||
// Enable JSON parsing
|
||||
server.use(express.json());
|
||||
|
||||
// Remove the X-Powered-By header
|
||||
server.disable("x-powered-by");
|
||||
|
||||
// Turn on ETag support (for caching)
|
||||
server.enable("etag");
|
||||
|
||||
// Listen on the specified port
|
||||
server.listen(port, () => {
|
||||
console.log(`Server listening on http://localhost:${port}`);
|
||||
onLoaded && onLoaded(); // Call the onLoaded callback if it exists
|
||||
});
|
||||
|
||||
return server;
|
||||
}
|
7
packages/server/tsconfig.json
Normal file
7
packages/server/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
}
|
||||
}
|
18
packages/tsconfig/base.json
Normal file
18
packages/tsconfig/base.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "Default",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"target": "es2022",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"strict": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"module": "NodeNext",
|
||||
"noEmit": true,
|
||||
"lib": ["es2022", "dom", "dom.iterable"]
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
13
packages/tsconfig/package.json
Normal file
13
packages/tsconfig/package.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "tsconfig",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"files": [
|
||||
"base.json",
|
||||
"server.json"
|
||||
]
|
||||
}
|
5
packages/tsconfig/server.json
Normal file
5
packages/tsconfig/server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"display": "Server",
|
||||
"extends": "./base.json"
|
||||
}
|
11
packages/utils/package.json
Normal file
11
packages/utils/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "utils",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts"
|
||||
}
|
15
packages/utils/src/envVariables.ts
Normal file
15
packages/utils/src/envVariables.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Checks if all environment variables are set
|
||||
*
|
||||
* @param variables the environment variables to check
|
||||
* @returns true if all variables are set, false otherwise
|
||||
*/
|
||||
export function checkEnvironmentVariables(...variables: string[]): boolean {
|
||||
let allVariablesSet = true;
|
||||
variables.forEach((variable) => {
|
||||
if (!process.env[variable]) {
|
||||
throw new Error(`${variable} not set in environment variables`);
|
||||
}
|
||||
});
|
||||
return allVariablesSet;
|
||||
}
|
2
packages/utils/src/index.ts
Normal file
2
packages/utils/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./envVariables";
|
||||
export * from "./secrets";
|
16
packages/utils/src/secrets.ts
Normal file
16
packages/utils/src/secrets.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import InfisicalClient from "infisical-node";
|
||||
|
||||
/**
|
||||
* Create an infisical client
|
||||
*
|
||||
* @param token the infisical token
|
||||
* @returns the infisical client
|
||||
*/
|
||||
function createInfisicalClient(token: string) {
|
||||
return new InfisicalClient({
|
||||
token,
|
||||
siteURL: "https://secrets.fascinated.cc",
|
||||
});
|
||||
}
|
||||
|
||||
export { createInfisicalClient };
|
7
packages/utils/tsconfig.json
Normal file
7
packages/utils/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user