add prettier

This commit is contained in:
Yanis Rigaudeau 2022-10-10 17:01:31 +02:00
parent 868b46317d
commit 63478aa887
Signed by: yanis
GPG Key ID: 4DD2841DF1C94D83
21 changed files with 152 additions and 93 deletions

22
api/package-lock.json generated
View File

@ -21,6 +21,7 @@
"@types/express-session": "^1.17.5",
"@types/ip": "^1.1.0",
"@types/node": "^18.7.18",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.0.0"
@ -1124,6 +1125,21 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
@ -2508,6 +2524,12 @@
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true
},
"prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true
},
"proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",

View File

@ -7,7 +7,8 @@
"scripts": {
"build": "tsc",
"dev": "ts-node-dev --respawn --transpile-only ./src/app.ts",
"start": "npm run build && node ./dist/app.js"
"start": "npm run build && node ./dist/app.js",
"prettier": "prettier -w ./src"
},
"devDependencies": {
"@types/cors": "^2.8.12",
@ -15,6 +16,7 @@
"@types/express-session": "^1.17.5",
"@types/ip": "^1.1.0",
"@types/node": "^18.7.18",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.0.0"

View File

@ -1,16 +1,18 @@
import Server, { Services } from './framework/express/server';
import Mongo from './framework/mongo/mongo';
import ip from "ip";
import ip from 'ip';
const PORT = 8000;
const MONGOURI = "mongodb://localhost:27017";
const MONGOURI = 'mongodb://localhost:27017';
const mongo = new Mongo(MONGOURI);
const services: Services = {
db: mongo.getDb()
}
db: mongo.getDb(),
};
const server = new Server(services);
server.start(PORT, () => console.log(`Running on http://${ip.address()}:${PORT}`));
server.start(PORT, () =>
console.log(`Running on http://${ip.address()}:${PORT}`),
);

View File

@ -1,9 +1,9 @@
import { RequestHandler } from "express";
import { randomUUID } from "crypto";
import { RequestHandler } from 'express';
import { randomUUID } from 'crypto';
export function BeforeEach(): RequestHandler {
return (req, res, next) => {
req.headers["request-id"] = randomUUID();
req.headers['request-id'] = randomUUID();
next();
}
}
};
}

View File

@ -1,11 +1,11 @@
import { Router } from "express";
import { Services } from "./server";
import * as user from "./user";
import { Router } from 'express';
import { Services } from './server';
import * as user from './user';
export function getRoutes(services: Services) {
const router = Router();
router.use("/user", user.getRoutes(services));
router.use('/user', user.getRoutes(services));
return router;
}

View File

@ -1,12 +1,12 @@
import express, { Express } from "express";
import express, { Express } from 'express';
import cors from 'cors';
import * as router from './router';
import { BeforeEach } from "./middleware";
import { Db } from "mongodb";
import { BeforeEach } from './middleware';
import { Db } from 'mongodb';
export type Services = {
db: Db;
}
};
class Server {
private app: Express;

View File

@ -12,10 +12,10 @@ export function CreateHandler(services: Services): RequestHandler {
const createUser = Create(services);
return async (req, res) => {
const user = await createUser(req.get("request-id"), req.body);
const user = await createUser(req.get('request-id'), req.body);
res.send(user);
}
};
}
export function getRoutes(services: Services) {
@ -23,8 +23,6 @@ export function getRoutes(services: Services) {
router.post('/login', LoginHandler(services));
router.post('/create', CreateHandler(services));
return router;
}

View File

@ -1,4 +1,4 @@
import { MongoClient, Db } from "mongodb";
import { MongoClient, Db } from 'mongodb';
class Mongo {
private client: MongoClient;

View File

@ -1,14 +1,16 @@
import { CreateUserBody, User, UserInfo } from "@core";
import { Services } from "../express/server";
import { CreateUserBody, User, UserInfo } from '@core';
import { Services } from '../express/server';
export function Create(services: Services): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
export function Create(
services: Services,
): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
const { db } = services;
const coll = db.collection("users");
const coll = db.collection('users');
return async (tracker, user) => {
await coll.insertOne(user);
return {
name: "test"
}
}
}
name: 'test',
};
};
}

View File

@ -1,11 +1,13 @@
import { CreateUserBody, UserInfo } from "@core";
import { Services } from "../framework/express/server";
import * as mongo from "../framework/mongo/user";
import { CreateUserBody, UserInfo } from '@core';
import { Services } from '../framework/express/server';
import * as mongo from '../framework/mongo/user';
export function Create(services: Services): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
export function Create(
services: Services,
): (tracker: string, user: CreateUserBody) => Promise<UserInfo> {
const createUser = mongo.Create(services);
return async (tracker, user) => {
return createUser(tracker, user);
}
}
};
}

View File

@ -7,24 +7,15 @@
"outDir": "dist",
"sourceMap": false,
"paths": {
"@core": [
"../core/src"
]
"@core": ["../core/src"]
}
},
"lib": [
"es2015"
],
"include": [
"src/**/*"
],
"exclude": [
"node_modules/*",
"dist/*"
],
"lib": ["es2015"],
"include": ["src/**/*"],
"exclude": ["node_modules/*", "dist/*"],
"references": [
{
"path": "../core"
}
]
}
}

22
core/package-lock.json generated
View File

@ -8,9 +8,25 @@
"name": "core",
"version": "1.0.0",
"devDependencies": {
"prettier": "^2.7.1",
"typescript": "^4.8.3"
}
},
"node_modules/prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/typescript": {
"version": "4.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz",
@ -26,6 +42,12 @@
}
},
"dependencies": {
"prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true
},
"typescript": {
"version": "4.8.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz",

View File

@ -5,9 +5,11 @@
"author": "Yanis Rigaudeau - Axel Barault",
"private": true,
"scripts": {
"build": "tsc"
"build": "tsc",
"prettier": "prettier -w ./src"
},
"devDependencies": {
"prettier": "^2.7.1",
"typescript": "^4.8.3"
}
}
}

View File

@ -1,2 +1,2 @@
export * from './user';
export * from './entity';
export * from "./user";
export * from "./entity";

View File

@ -2,7 +2,7 @@ import { Entity } from "./entity";
export type UserInfo = {
name: string;
}
};
export type User = UserInfo & Entity;

View File

@ -6,12 +6,7 @@
"sourceMap": false,
"outDir": "dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules/*",
"dist/*"
],
"include": ["src/**/*"],
"exclude": ["node_modules/*", "dist/*"],
"references": []
}
}

22
www/package-lock.json generated
View File

@ -18,6 +18,7 @@
"@rollup/plugin-typescript": "^8.0.0",
"@tsconfig/svelte": "^2.0.0",
"@types/three": "^0.144.0",
"prettier": "^2.7.1",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",
@ -1011,6 +1012,21 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
@ -2359,6 +2375,12 @@
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true
},
"prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true
},
"queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",

View File

@ -8,7 +8,8 @@
"build": "rollup -c",
"dev": "rollup -c -w ",
"start": "sirv public --no-clear --host",
"check": "svelte-check --tsconfig ./tsconfig.json"
"check": "svelte-check --tsconfig ./tsconfig.json",
"prettier": "prettier -w ./src"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
@ -16,6 +17,7 @@
"@rollup/plugin-typescript": "^8.0.0",
"@tsconfig/svelte": "^2.0.0",
"@types/three": "^0.144.0",
"prettier": "^2.7.1",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",

View File

@ -19,14 +19,18 @@ function serve() {
return {
writeBundle() {
if (server) return;
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
server = require('child_process').spawn(
'npm',
['run', 'start', '--', '--dev'],
{
stdio: ['ignore', 'inherit', 'inherit'],
shell: true,
},
);
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
},
};
}
@ -36,15 +40,15 @@ export default {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js'
file: 'public/build/bundle.js',
},
plugins: [
svelte({
preprocess: sveltePreprocess({ sourceMap: !production }),
compilerOptions: {
// enable run-time checks when not in production
dev: !production
}
dev: !production,
},
}),
// we'll extract any component CSS out into
// a separate file - better for performance
@ -58,12 +62,12 @@ export default {
resolve({
main: true,
browser: true,
dedupe: ['svelte']
dedupe: ['svelte'],
}),
commonjs(),
typescript({
sourceMap: !production,
inlineSources: !production
inlineSources: !production,
}),
// In dev mode, call `npm run start` once
@ -76,9 +80,9 @@ export default {
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
production && terser(),
],
watch: {
clearScreen: false
}
clearScreen: false,
},
};

View File

@ -2,7 +2,7 @@ import App from './App.svelte';
const app = new App({
target: document.body,
props: {}
props: {},
});
export default app;

View File

@ -3,21 +3,14 @@
"compilerOptions": {
"sourceMap": false,
"paths": {
"@core": [
"../core/src"
]
"@core": ["../core/src"]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules/*",
"public/*"
],
"include": ["src/**/*"],
"exclude": ["node_modules/*", "public/*"],
"references": [
{
"path": "../core"
}
]
}
}