Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 타입 생성, eslint 및 tsconfing 예외 처리, orval 6.19.1 다운그레이드 #219

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ module.exports = {
settings: {
'import/external-module-folders': ['.yarn'],
},
ignorePatters: ['orval.config.js', '**/_generated/**/*'],
}
1,330 changes: 942 additions & 388 deletions .pnp.cjs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions apps/next-app/orval.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
feedoongApp: {
input: 'src/services/spec.json',
output: {
target: 'src/services/types/_generated',
mode: 'tags',
override: {
mutator: {
path: 'src/services/api/index.ts',
name: 'feedoongApi',
},
},
},
},
}
5 changes: 3 additions & 2 deletions apps/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"deploy": "next build && next start",
"lint": "next lint",
"prepare": "cd ../.. && husky apps/next-app/.husky"
"prepare": "cd ../.. && husky apps/next-app/.husky",
"codegen": "yarn node scripts/codeGen.mjs"
},
"dependencies": {
"@emotion/is-prop-valid": "^1.2.2",
Expand All @@ -25,6 +26,7 @@
"js-cookie": "^3.0.1",
"next": "^14.2.3",
"nookies": "^2.5.2",
"orval": "6.19.1",
"query-string": "^7.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down Expand Up @@ -52,7 +54,6 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"orval": "^6.30.2",
"prettier": "^2.8.7",
"typescript": "^5.5.2"
}
Expand Down
42 changes: 42 additions & 0 deletions apps/next-app/scripts/codeGen.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
import { spawn } from 'child_process'
import fs from 'fs'

const genPath = '../src/services/types/_generated'

const __dirname = dirname(fileURLToPath(import.meta.url))
const BASE_PATH = path.join(__dirname, genPath)
console.log(BASE_PATH)

console.log('>>> generated 폴더를 삭제합니다.')

await fs.rm(BASE_PATH, { recursive: true }, (err) => {
// 디렉토리가 없는 경우를 제외함.
if (err && err.code !== 'ENOENT') {
console.log('>>> 폴더 삭제 중 에러 발생:', err)
} else {
console.log('>>> 폴더 삭제가 성공적으로 완료되었습니다.')

const process = spawn('bash')

console.log('>>> orval을 실행합니다.')

try {
process.stdin.write('orval --config ./orval.config.js')
process.stdin.end()

process.on('close', function (code) {
if (code === 0) {
console.log('>>> orval 실행이 성공적으로 완료되었습니다.')
} else {
console.error(
`>>> orval 실행이 오류와 함께 종료되었습니다. 종료 코드: ${code}`
)
}
})
} catch (err) {
console.error('>>> orval 실행 중 오류 발생:', err)
}
}
})
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import type { UserProfile } from 'services/auth'
import { getUserInfoServerSide } from 'services/auth'
import { CACHE_KEYS } from 'services/cacheKeys'
import { setAuthorizationHeader } from 'features/auth/token'
import { createApi } from 'services/api'
import { feedoongApi } from 'services/api'
import { AccessToken } from 'constants/auth'

export type GetServerSidePropsContextWithAuthClient =
GetServerSidePropsContext & {
queryClient: QueryClient
api: ReturnType<typeof createApi>
api: ReturnType<typeof feedoongApi>
}

export const withAuthQueryServerSideProps = (
getServerSidePropsFunc?: GetServerSideProps
) => {
return async (context: GetServerSidePropsContextWithAuthClient) => {
try {
const api = createApi()
const api = feedoongApi()
context.api = api
const cookies = parseCookies(
context as (typeof parseCookies)['arguments']
Expand Down
4 changes: 2 additions & 2 deletions apps/next-app/src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

const { camelizeKeys } = humps

export const createApi = () => {
export const feedoongApi = () => {
const accessToken = getAccessTokenFromCookie()

const _api = Axios.create({
Expand Down Expand Up @@ -57,6 +57,6 @@ export const createApi = () => {
return _api
}

const api = createApi()
const api = feedoongApi()

export default api
Loading
Loading