From 99d2b92b03d52d2b2680cef9b4841272255a2e3c Mon Sep 17 00:00:00 2001 From: dm1sh Date: Sat, 15 Jul 2023 12:25:12 +0300 Subject: [PATCH] Added script for fetch api route generation --- front/package.json | 4 ++- front/utils/addFetchApiRoute.sh | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 front/utils/addFetchApiRoute.sh diff --git a/front/package.json b/front/package.json index 7f234f2..5420348 100644 --- a/front/package.json +++ b/front/package.json @@ -7,7 +7,9 @@ "dev": "vite --host 0.0.0.0", "build": "tsc && vite build", "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": { "@types/leaflet": "^1.9.3", diff --git a/front/utils/addFetchApiRoute.sh b/front/utils/addFetchApiRoute.sh new file mode 100644 index 0000000..57bac31 --- /dev/null +++ b/front/utils/addFetchApiRoute.sh @@ -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