From 63478aa887a9fc7e9f63988932aaa66979a29e0e Mon Sep 17 00:00:00 2001 From: Yanis Rigaudeau Date: Mon, 10 Oct 2022 17:01:31 +0200 Subject: [PATCH] add prettier --- api/package-lock.json | 22 ++++++++++++++++++ api/package.json | 4 +++- api/src/app.ts | 12 +++++----- api/src/framework/express/middleware.ts | 10 ++++----- api/src/framework/express/router.ts | 8 +++---- api/src/framework/express/server.ts | 8 +++---- api/src/framework/express/user.ts | 10 ++++----- api/src/framework/mongo/mongo.ts | 2 +- api/src/framework/mongo/user.ts | 18 ++++++++------- api/src/functions/user.ts | 14 +++++++----- api/tsconfig.json | 19 +++++----------- core/package-lock.json | 22 ++++++++++++++++++ core/package.json | 6 +++-- core/src/index.ts | 4 ++-- core/src/user.ts | 2 +- core/tsconfig.json | 11 +++------ www/package-lock.json | 22 ++++++++++++++++++ www/package.json | 4 +++- www/rollup.config.js | 30 ++++++++++++++----------- www/src/main.ts | 2 +- www/tsconfig.json | 15 ++++--------- 21 files changed, 152 insertions(+), 93 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 0372f23..77167d8 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -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", diff --git a/api/package.json b/api/package.json index f853b72..08a8dcc 100644 --- a/api/package.json +++ b/api/package.json @@ -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" diff --git a/api/src/app.ts b/api/src/app.ts index abb2f8a..b857f14 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -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}`), +); diff --git a/api/src/framework/express/middleware.ts b/api/src/framework/express/middleware.ts index 4296a06..e15f87c 100644 --- a/api/src/framework/express/middleware.ts +++ b/api/src/framework/express/middleware.ts @@ -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(); - } -} \ No newline at end of file + }; +} diff --git a/api/src/framework/express/router.ts b/api/src/framework/express/router.ts index 2aa0a38..98e4fe1 100644 --- a/api/src/framework/express/router.ts +++ b/api/src/framework/express/router.ts @@ -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; } diff --git a/api/src/framework/express/server.ts b/api/src/framework/express/server.ts index 42436a8..fad67c2 100644 --- a/api/src/framework/express/server.ts +++ b/api/src/framework/express/server.ts @@ -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; diff --git a/api/src/framework/express/user.ts b/api/src/framework/express/user.ts index ca8e48f..6d120a4 100644 --- a/api/src/framework/express/user.ts +++ b/api/src/framework/express/user.ts @@ -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; } - - diff --git a/api/src/framework/mongo/mongo.ts b/api/src/framework/mongo/mongo.ts index df3fae4..753c780 100644 --- a/api/src/framework/mongo/mongo.ts +++ b/api/src/framework/mongo/mongo.ts @@ -1,4 +1,4 @@ -import { MongoClient, Db } from "mongodb"; +import { MongoClient, Db } from 'mongodb'; class Mongo { private client: MongoClient; diff --git a/api/src/framework/mongo/user.ts b/api/src/framework/mongo/user.ts index 0668917..423d102 100644 --- a/api/src/framework/mongo/user.ts +++ b/api/src/framework/mongo/user.ts @@ -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 { +export function Create( + services: Services, +): (tracker: string, user: CreateUserBody) => Promise { const { db } = services; - const coll = db.collection("users"); + const coll = db.collection('users'); return async (tracker, user) => { await coll.insertOne(user); return { - name: "test" - } - } -} \ No newline at end of file + name: 'test', + }; + }; +} diff --git a/api/src/functions/user.ts b/api/src/functions/user.ts index 06e0539..b993da2 100644 --- a/api/src/functions/user.ts +++ b/api/src/functions/user.ts @@ -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 { +export function Create( + services: Services, +): (tracker: string, user: CreateUserBody) => Promise { const createUser = mongo.Create(services); return async (tracker, user) => { return createUser(tracker, user); - } -} \ No newline at end of file + }; +} diff --git a/api/tsconfig.json b/api/tsconfig.json index 06080cc..a4626de 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -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" } ] -} \ No newline at end of file +} diff --git a/core/package-lock.json b/core/package-lock.json index 5166ea9..400b0e3 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -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", diff --git a/core/package.json b/core/package.json index 636dc47..ec61e1c 100644 --- a/core/package.json +++ b/core/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/core/src/index.ts b/core/src/index.ts index 260ce72..21bc12d 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -1,2 +1,2 @@ -export * from './user'; -export * from './entity'; +export * from "./user"; +export * from "./entity"; diff --git a/core/src/user.ts b/core/src/user.ts index 05f34f9..c430226 100644 --- a/core/src/user.ts +++ b/core/src/user.ts @@ -2,7 +2,7 @@ import { Entity } from "./entity"; export type UserInfo = { name: string; -} +}; export type User = UserInfo & Entity; diff --git a/core/tsconfig.json b/core/tsconfig.json index 3c824f6..0d8fc9f 100644 --- a/core/tsconfig.json +++ b/core/tsconfig.json @@ -6,12 +6,7 @@ "sourceMap": false, "outDir": "dist" }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules/*", - "dist/*" - ], + "include": ["src/**/*"], + "exclude": ["node_modules/*", "dist/*"], "references": [] -} \ No newline at end of file +} diff --git a/www/package-lock.json b/www/package-lock.json index 1f77682..670aa05 100644 --- a/www/package-lock.json +++ b/www/package-lock.json @@ -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", diff --git a/www/package.json b/www/package.json index 4409747..68d7480 100644 --- a/www/package.json +++ b/www/package.json @@ -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", diff --git a/www/rollup.config.js b/www/rollup.config.js index 85cb81c..106812d 100644 --- a/www/rollup.config.js +++ b/www/rollup.config.js @@ -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, + }, }; diff --git a/www/src/main.ts b/www/src/main.ts index 96112c9..b849f93 100644 --- a/www/src/main.ts +++ b/www/src/main.ts @@ -2,7 +2,7 @@ import App from './App.svelte'; const app = new App({ target: document.body, - props: {} + props: {}, }); export default app; diff --git a/www/tsconfig.json b/www/tsconfig.json index 25f190f..b6fa30d 100644 --- a/www/tsconfig.json +++ b/www/tsconfig.json @@ -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" } ] -} \ No newline at end of file +}