Added script for fetch api route generation
This commit is contained in:
parent
27ae590981
commit
99d2b92b03
@ -7,7 +7,9 @@
|
|||||||
"dev": "vite --host 0.0.0.0",
|
"dev": "vite --host 0.0.0.0",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"typecheck": "tsc",
|
||||||
|
"addFetchApiRoute": "bash utils/addFetchApiRoute.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/leaflet": "^1.9.3",
|
"@types/leaflet": "^1.9.3",
|
||||||
|
46
front/utils/addFetchApiRoute.sh
Normal file
46
front/utils/addFetchApiRoute.sh
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
NAME=${1:-Route}
|
||||||
|
|
||||||
|
NAME=${NAME^}
|
||||||
|
|
||||||
|
mkdir -p src/api/${NAME,}
|
||||||
|
cat > src/api/${NAME,}/index.ts << EOF
|
||||||
|
import { API_URL } from '../../config'
|
||||||
|
import { ${NAME}Response, ${NAME} } from './types'
|
||||||
|
|
||||||
|
const initial${NAME}: ${NAME} = {}
|
||||||
|
|
||||||
|
const compose${NAME}URL = () =>
|
||||||
|
API_URL + '/${NAME,}?'
|
||||||
|
|
||||||
|
const process${NAME} = (data: ${NAME}Response): ${NAME} => {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export { initial${NAME}, compose${NAME}URL, process${NAME} }
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > src/api/${NAME,}/types.ts << EOF
|
||||||
|
import { isObject } from '../../utils/types'
|
||||||
|
|
||||||
|
type ${NAME}Response = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const is${NAME}Response = (obj: unknown): obj is ${NAME}Response =>
|
||||||
|
isObject(obj, {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
type ${NAME} = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const is${NAME} = (obj: unknown): obj is ${NAME} =>
|
||||||
|
isObject(obj, {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
export type { ${NAME}Response, ${NAME} }
|
||||||
|
|
||||||
|
export { is${NAME}Response, is${NAME} }
|
||||||
|
EOF
|
Loading…
x
Reference in New Issue
Block a user