switch compiler to swc, add eslint

This commit is contained in:
sam 2023-07-21 01:27:24 +02:00
parent 9f74db9857
commit 42f48fb046
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
13 changed files with 1422 additions and 144 deletions

1
.eslintignore Normal file
View file

@ -0,0 +1 @@
build/

20
.eslintrc.json Normal file
View file

@ -0,0 +1,20 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
node_modules/ node_modules/
build/ dist/
.env .env

1
.prettierignore Normal file
View file

@ -0,0 +1 @@
build/

19
.swcrc Normal file
View file

@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"target": "es2020",
"paths": {
"~/*": ["./src/*"],
"~entities/*": ["./src/db/entities/*"]
},
"baseUrl": "."
},
"module": {
"type": "es6"
}
}

View file

@ -1 +1,21 @@
# Mercury # Mercury
ActivityPub server implementation (hopefully, eventually),
currently mostly a way for me to play around with writing an API server in TypeScript.
## Configuration
For now, check out `src/config.ts`, the names should be mostly self explanatory.
Consider all environment variables required.
## Development commands
- Building the server: `pnpm build`
- Migrating the database: `pnpm migrate`
- Watching for changes and reloading the server automatically: `pnpm dev`
- Formatting: `pnpm format`
- Linting (if you don't have an ESLint plugin): `pnpm format`
## License
Mercury is licensed under the GNU Affero General Public License, version 3 **only**.

View file

@ -8,8 +8,12 @@
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"dev": "nodemon ./src/index.ts", "dev": "concurrently \"pnpm watch:build\" \"pnpm watch:dev\"",
"build": "tsc", "build": "swc src -d dist",
"watch:build": "swc src -w --out-dir dist",
"watch:dev": "nodemon --watch \"dist/**/*\" -e js ./dist/index.js",
"format": "prettier -w",
"lint": "eslint src/",
"typeorm": "typeorm-ts-node-esm", "typeorm": "typeorm-ts-node-esm",
"migrate": "typeorm-ts-node-esm migration:run -d ./src/db/index.ts" "migrate": "typeorm-ts-node-esm migration:run -d ./src/db/index.ts"
}, },
@ -26,10 +30,16 @@
"ulid": "^2.3.0" "ulid": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.70",
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"chokidar": "^3.5.3",
"concurrently": "^8.2.0",
"eslint": "^8.45.0",
"nodemon": "^3.0.1", "nodemon": "^3.0.1",
"prettier": "^3.0.0", "prettier": "^3.0.0",
"ts-node": "^10.9.1",
"typescript": "5.1.6" "typescript": "5.1.6"
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
import { ulid } from "ulid"; import { ulid } from "ulid";
import { hash } from "argon2"; import { hash } from "argon2";
import { Account } from "./entities/account.js"; import { Account } from "~entities/account.js";
import MercuryDataSource from "./index.js"; import MercuryDataSource from "./index.js";
const missingAuthData = new Error("missing auth data for local user"); const missingAuthData = new Error("missing auth data for local user");

View file

@ -1,7 +1,7 @@
import { ulid } from "ulid"; import { ulid } from "ulid";
import { Account } from "./entities/account.js"; import { Account } from "~entities/account.js";
import { Blog } from "./entities/blog.js"; import { Blog } from "~entities/blog.js";
import { generateKeyPair } from "./util/rsa.js"; import { generateKeyPair } from "./util/rsa.js";
import MercuryDataSource from "./index.js"; import MercuryDataSource from "./index.js";

View file

@ -1,10 +1,10 @@
import { DataSource } from "typeorm"; import { DataSource } from "typeorm";
import * as config from "../config.js"; import * as config from "~/config.js";
// Entity types // Entity types
import { Account } from "./entities/account.js"; import { Account } from "~entities/account.js";
import { Blog } from "./entities/blog.js"; import { Blog } from "~entities/blog.js";
import { Post } from "./entities/post.js"; import { Post } from "~entities/post.js";
const MercuryDataSource = new DataSource({ const MercuryDataSource = new DataSource({
type: "postgres", type: "postgres",

View file

@ -1,10 +1,10 @@
import type { FastifyReply, FastifyRequest, RouteOptions } from "fastify"; import type { FastifyReply, FastifyRequest, RouteOptions } from "fastify";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
import log from "../../log.js"; import log from "~/log.js";
import MercuryDataSource from "../../db/index.js"; import MercuryDataSource from "~/db/index.js";
import { Blog } from "../../db/entities/blog.js"; import { Blog } from "~entities/blog.js";
import { BASE_URL } from "../../config.js"; import { BASE_URL } from "~/config.js";
const route: RouteOptions = { const route: RouteOptions = {
method: "GET", method: "GET",

View file

@ -16,5 +16,10 @@
"strict": true, "strict": true,
"skipLibCheck": true, "skipLibCheck": true,
"noImplicitAny": false, "noImplicitAny": false,
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"],
"~entities/*": ["./src/db/entities/*"]
}
} }
} }