Added script for fetch api route generation

This commit is contained in:
Dmitriy Shishkov 2023-07-15 12:25:12 +03:00
parent 27ae590981
commit 99d2b92b03
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 49 additions and 1 deletions

View File

@ -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",

View 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