From 02453c8cf6cf78adeb273d15329ae7c9abe54467 Mon Sep 17 00:00:00 2001 From: dm1sh Date: Thu, 15 Jul 2021 20:05:30 +0500 Subject: [PATCH] Added @type alias, separated constants.ts file --- package.json | 2 +- snowpack.config.js | 6 +++++- src/Bookshelf/BookItem/index.tsx | 2 +- src/Bookshelf/index.tsx | 6 ++---- src/api.ts | 4 ++-- src/constants.ts | 2 ++ src/{types => type}/book.ts | 0 src/{types => type}/utils.ts | 0 src/utils/localStorage.ts | 4 ++-- tsconfig.json | 6 +++++- 10 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 src/constants.ts rename src/{types => type}/book.ts (100%) rename src/{types => type}/utils.ts (100%) diff --git a/package.json b/package.json index 34242a0..ee7acca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "scripts": { - "dev": "SNOWPACK_PUBLIC_API_URL=https://publitebackend.dmitriy.icu snowpack dev", + "dev": "SNOWPACK_PUBLIC_API_URL=https://publitebackend.dmitriy.icu SNOWPACK_PUBLIC_BASE_URL=http://localhost:8080 snowpack dev", "build": "snowpack build", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/snowpack.config.js b/snowpack.config.js index 1cdead0..eaf7ffc 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -21,7 +21,11 @@ module.exports = { devOptions: { open: "none", }, - alias: { "@assets": "./src/assets", "@utils": "./src/utils" }, + alias: { + "@assets": "./src/assets", + "@utils": "./src/utils", + "@type": "./src/type", + }, exclude: ["**/node_modules/**/*", "**/*.test.*"], env: { // API_URL: "https://publitebackend.dmitriy.icu", diff --git a/src/Bookshelf/BookItem/index.tsx b/src/Bookshelf/BookItem/index.tsx index 8e8cffb..975b79c 100644 --- a/src/Bookshelf/BookItem/index.tsx +++ b/src/Bookshelf/BookItem/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import styles from "./BookItem.module.css"; -import { IBook } from "../../types/book"; +import { IBook } from "@type/book"; interface IBookItemProps extends IBook {} diff --git a/src/Bookshelf/index.tsx b/src/Bookshelf/index.tsx index 5d5c64a..5ee981b 100644 --- a/src/Bookshelf/index.tsx +++ b/src/Bookshelf/index.tsx @@ -1,9 +1,9 @@ import React, { useState } from "react"; -import { IBook } from "../types/book"; +import { IBook } from "@type/book"; import styles from "./Bookshelf.module.css"; -import list from "../assets/bookList.json"; +import list from "@assets/bookList.json"; import { BookItem } from "./BookItem"; import { AddBook } from "./AddBook"; @@ -21,5 +21,3 @@ export const Bookshelf = () => { ); }; - -export default Bookshelf; diff --git a/src/api.ts b/src/api.ts index cdd346f..7762a47 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,6 @@ -import { IBook, optionalBookProps, requiredBookProps } from "./types/book"; +import { IBook, optionalBookProps, requiredBookProps } from "@type/book"; -const API_URL = import.meta.env.SNOWPACK_PUBLIC_API_URL; +import { API_URL } from "./constants"; export const validState = (file: File | undefined): file is File => { if (!file) throw new Error("Book file is required. Please, attach one"); diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..f62fdca --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,2 @@ +export const API_URL = import.meta.env.SNOWPACK_PUBLIC_API_URL; +export const BASE_URL = import.meta.env.SNOWPACK_PUBLIC_BASE_URL; diff --git a/src/types/book.ts b/src/type/book.ts similarity index 100% rename from src/types/book.ts rename to src/type/book.ts diff --git a/src/types/utils.ts b/src/type/utils.ts similarity index 100% rename from src/types/utils.ts rename to src/type/utils.ts diff --git a/src/utils/localStorage.ts b/src/utils/localStorage.ts index e6c033d..3b3a0aa 100644 --- a/src/utils/localStorage.ts +++ b/src/utils/localStorage.ts @@ -1,5 +1,5 @@ -import { IBook } from "../types/book"; -import { isArrOfStr } from "../types/utils"; +import { IBook } from "@type/book"; +import { isArrOfStr } from "@type/utils"; export const saveBook = (bookObj: IBook, key: string): void => { const bookListStr = localStorage.getItem("list") || "[]"; diff --git a/tsconfig.json b/tsconfig.json index f1ae2a6..ea53e2b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,10 @@ "module": "ES2020", "moduleResolution": "node", "resolveJsonModule": true, - "paths": { "@assets/*": ["./src/assets/*"], "@utils/*": ["./src/utils/*"] } + "paths": { + "@assets/*": ["./src/assets/*"], + "@utils/*": ["./src/utils/*"], + "@type/*": ["./src/type/*"] + } } }