Skip to content

Commit 31ec48f

Browse files
committed
feat: initialize book server
1 parent 66c7eaf commit 31ec48f

File tree

27 files changed

+671
-931
lines changed

27 files changed

+671
-931
lines changed

.github/workflows/velog-cron-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [18.18.2]
14+
node-version: [20.11.1]
1515
defaults:
1616
run:
1717
working-directory: './packages/velog-cron'

.github/workflows/velog-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
node-version: [18.16]
17+
node-version: [20.11.1]
1818
steps:
1919
- uses: actions/checkout@v3
2020
- uses: pnpm/action-setup@v2

.github/workflows/velog-server-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [18.18.2]
14+
node-version: [20.11.1]
1515
defaults:
1616
run:
1717
working-directory: './packages/velog-server'

.github/workflows/velog-web-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
node-version: [18.18.2]
15+
node-version: [20.11.1]
1616
defaults:
1717
run:
1818
working-directory: './packages/velog-web'

apps/book-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@graphql-tools/merge": "^9.0.0",
3333
"@packages/database": "workspace:*",
3434
"@prisma/client": "^5.11.0",
35+
"date-fns": "^2.30.0",
3536
"discord.js": "^14.14.1",
3637
"dotenv": "^16.4.5",
3738
"fastify": "^4.26.2",
@@ -52,7 +53,6 @@
5253
"@graphql-codegen/typescript": "^4.0.1",
5354
"@graphql-codegen/typescript-operations": "^4.2.0",
5455
"@graphql-codegen/typescript-resolvers": "^4.0.0",
55-
"@packages/database": "workspace:*",
5656
"@packages/scripts": "workspace:*",
5757
"@swc-node/register": "^1.9.0",
5858
"@swc/cli": "^0.3.10",

apps/book-server/scripts/copyPrisma.mts

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,9 @@
1-
import path, { dirname } from 'path'
2-
import fs from 'fs'
3-
import inquirer from 'inquirer'
1+
import { CreateServiceScript } from '@packages/scripts'
2+
import { dirname } from 'path'
43
import { fileURLToPath } from 'url'
54

65
const __filename = fileURLToPath(import.meta.url)
76
const __dirname = dirname(__filename)
87

9-
const filesData = new Map<string, string>()
10-
11-
function toPascalCase(str: string) {
12-
return str
13-
.split('')
14-
.map((s, i) => (i === 0 ? s.toUpperCase() : s))
15-
.join('')
16-
}
17-
18-
function replace(text: string, name: string) {
19-
return text.replace(/My/g, `${toPascalCase(name)}`)
20-
}
21-
22-
async function main() {
23-
const { type } = await inquirer.prompt([
24-
{
25-
type: 'list',
26-
name: 'type',
27-
message: 'Do you want to save in lib directory or services directory?',
28-
choices: ['services', 'lib'],
29-
default: 'services',
30-
},
31-
])
32-
33-
const templateDir = path.resolve(__dirname, `./templates/${type}`)
34-
const files = fs.readdirSync(templateDir)
35-
36-
files.forEach((file) => {
37-
const filePath = path.resolve(templateDir, file)
38-
const fileData = fs.readFileSync(filePath, 'utf8')
39-
filesData.set(file, fileData)
40-
})
41-
42-
const answer = await inquirer.prompt([
43-
{
44-
name: 'feature',
45-
message: 'Enter service name',
46-
},
47-
])
48-
49-
const dirPath =
50-
type === 'lib'
51-
? path.resolve(__dirname, '../src/lib')
52-
: path.resolve(__dirname, `../src/services`)
53-
54-
const filename = answer.feature.trim()
55-
56-
createService({
57-
type,
58-
dirPath,
59-
filename,
60-
files,
61-
})
62-
}
63-
64-
function createService({ type, dirPath, filename, files }: CreateServiceParams) {
65-
const newFilename = type === 'services' ? `${toPascalCase(filename)}Service` : filename
66-
67-
const serviceDir = path.resolve(dirPath, newFilename)
68-
69-
// create directory if not exist
70-
if (!fs.existsSync(serviceDir)) {
71-
fs.mkdirSync(serviceDir, { recursive: true })
72-
}
73-
74-
files.forEach((file) => {
75-
const fileData = filesData.get(file)
76-
if (fileData === undefined) return
77-
const code = replace(fileData, filename)
78-
79-
const newFilePath = path.resolve(serviceDir, replace(file, newFilename))
80-
fs.writeFileSync(newFilePath, code)
81-
})
82-
83-
console.log(`Service files are created at ${serviceDir}`)
84-
}
85-
86-
main()
87-
88-
type CreateServiceParams = {
89-
type: string
90-
dirPath: string
91-
filename: string
92-
files: string[]
93-
}
8+
const createServiceScript = new CreateServiceScript({ __dirname })
9+
createServiceScript.excute()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { FastifyPluginAsync } from 'fastify'
2+
3+
const authPlugin: FastifyPluginAsync = async (fastify) => {
4+
fastify.decorateRequest('user', null)
5+
fastify.addHook('preHandler', async (request, reply) => {
6+
if (request.url.includes('/auth/logout')) return
7+
})
8+
}
9+
10+
export default authPlugin

apps/book-server/src/types/fastify.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import 'fastify'
33
declare module 'fastify' {
44
interface FastifyRequest {
55
ipaddr: string | null
6+
user: null | { id: string }
67
}
78
}

apps/cron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"license": "MIT",
1414
"engines": {
15-
"node": ">=18.16"
15+
"node": ">=20.11.1"
1616
},
1717
"main": "/src/main.ts",
1818
"type": "module",

0 commit comments

Comments
 (0)