Skip to content

Commit

Permalink
refactor public api for shared ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Bender101 committed Nov 20, 2023
1 parent 37ab1a4 commit 0e5ce58
Show file tree
Hide file tree
Showing 41 changed files with 146 additions and 99 deletions.
49 changes: 49 additions & 0 deletions scripts/refactoring/createPublicApiForSharedUi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Project } from 'ts-morph';
import path from 'path';

const project = new Project({});

project.addSourceFilesAtPaths('src/**/*.ts');
project.addSourceFilesAtPaths('src/**/*.tsx');

const files = project.getSourceFiles();
const uiPath = path.resolve(__dirname, '..', '..', 'src', 'shared', 'ui');
const sharedUiDirectory = project.getDirectory(uiPath);
const componentsDirs = sharedUiDirectory?.getDirectories();

function isAbsolute(value: string) {
const layers = ['app', 'shared', 'entities', 'features', 'widgets', 'pages'];
return layers.some((layer) => value.startsWith(layer));
}

componentsDirs?.forEach((directory) => {
const indexFilePath = `${directory.getPath()}/index.ts`;
const indexFile = directory.getSourceFile(indexFilePath);

if (!indexFile) {
const sourceCode = `export * from './${directory.getBaseName()}'`;
const file = directory.createSourceFile(indexFilePath, sourceCode, { overwrite: true });

file.save();
}
});

files.forEach((sourceFile) => {
const importDeclarations = sourceFile.getImportDeclarations();
importDeclarations.forEach((importDeclaration) => {
const value = importDeclaration.getModuleSpecifierValue();
const valueWithoutAlias = value.replace('@/', '');

const segments = valueWithoutAlias.split('/');

const isSharedLayer = segments?.[0] === 'shared';
const isUiSlice = segments?.[1] === 'ui';

if (isAbsolute(valueWithoutAlias) && isSharedLayer && isUiSlice) {
const result = valueWithoutAlias.split('/').slice(0, 3).join('/');
importDeclaration.setModuleSpecifier(`@/${result}`);
}
});
});

project.save();
26 changes: 26 additions & 0 deletions scripts/refactoring/updateImports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Project } from 'ts-morph';

const project = new Project({});

project.addSourceFilesAtPaths('src/**/*.ts');
project.addSourceFilesAtPaths('src/**/*.tsx');

const files = project.getSourceFiles();

function isAbsolute(value: string) {
const layers = ['app', 'shared', 'entities', 'features', 'widgets', 'pages'];
return layers.some((layer) => value.startsWith(layer));
}

files.forEach((sourceFile) => {
const importDeclarations = sourceFile.getImportDeclarations();
importDeclarations.forEach((importDeclaration) => {
const value = importDeclaration.getModuleSpecifierValue();

if (isAbsolute(value)) {
importDeclaration.setModuleSpecifier(`@/${value}`);
}
});
});

project.save();
28 changes: 0 additions & 28 deletions scripts/updateImports.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Code } from "@/shared/ui/Code/Code";
import { Code } from "@/shared/ui/Code";
import cls from "./ArticleCodeBlockComponent.module.scss";
import { ArticleCodeBlock } from "../../model/types/article";

Expand Down
8 changes: 4 additions & 4 deletions src/entities/Article/ui/ArticleDetails/ArticleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useTranslation } from "react-i18next";
import { memo, useCallback, useEffect } from "react";
import { useSelector } from "react-redux";
import { useAppDispatch } from "@/shared/lib/hooks/useAppDispatch/useAppDispatch";
import { Text, TextAlign, TextSize } from "@/shared/ui/Text/Text";
import { Skeleton } from "@/shared/ui/Skeleton/Skeleton";
import { Avatar } from "@/shared/ui/Avatar/Avatar";
import { Text, TextAlign, TextSize } from "@/shared/ui/Text";
import { Skeleton } from "@/shared/ui/Skeleton";
import { Avatar } from "@/shared/ui/Avatar";
import EyeIcon from "@/shared/assets/icons/eye-20-20.svg";
import CalendarIcon from "@/shared/assets/icons/calendar-20-20.svg";
import { Icon } from "@/shared/ui/Icon/Icon";
import { Icon } from "@/shared/ui/Icon";
import { fetchArticleById } from "../../model/services/fetchArticleById/fetchArticleById";
import { articleDetailsReducer } from "../../model/slice/articleDetailsSlice";
import cls from "./ArticleDetails.module.scss";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Text, TextAlign } from "@/shared/ui/Text/Text";
import { Text, TextAlign } from "@/shared/ui/Text";
import cls from "./ArticleImageBlockComponent.module.scss";
import { ArticleImageBlock } from "../../model/types/article";

Expand Down
2 changes: 1 addition & 1 deletion src/entities/Article/ui/ArticleList/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ArticleListItemSkeleton } from "../../ui/ArticleListItem/ArticleListIte
import { ArticleListItem } from "../ArticleListItem/ArticleListItem";
import cls from "./ArticleList.module.scss";
import { Article } from "../../model/types/article";
import { TextSize, Text } from "@/shared/ui/Text/Text";
import { TextSize, Text } from "@/shared/ui/Text";
import { useTranslation } from "react-i18next";
import { ArticleView } from "../../model/consts/consts";

Expand Down
12 changes: 6 additions & 6 deletions src/entities/Article/ui/ArticleListItem/ArticleListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { HTMLAttributeAnchorTarget, memo } from "react";
import { Text } from "@/shared/ui/Text/Text";
import { Icon } from "@/shared/ui/Icon/Icon";
import { Text } from "@/shared/ui/Text";
import { Icon } from "@/shared/ui/Icon";
import EyeIcon from "@/shared/assets/icons/eye-20-20.svg";
import { Card } from "@/shared/ui/Card/Card";
import { Avatar } from "@/shared/ui/Avatar/Avatar";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Card } from "@/shared/ui/Card";
import { Avatar } from "@/shared/ui/Avatar";
import { Button, ButtonTheme } from "@/shared/ui/Button";
import cls from "./ArticleListItem.module.scss";
import { Article, ArticleTextBlock } from "../../model/types/article";
import { ArticleTextBlockComponent } from "../ArticleTextBlockComponent/ArticleTextBlockComponent";
import { AppLink } from "@/shared/ui/AppLink/AppLink";
import { AppLink } from "@/shared/ui/AppLink";
import { ArticleBlockType, ArticleView } from "../../model/consts/consts";
import {RoutePath} from "@/shared/const/router";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Card } from "@/shared/ui/Card/Card";
import { Skeleton } from "@/shared/ui/Skeleton/Skeleton";
import { Card } from "@/shared/ui/Card";
import { Skeleton } from "@/shared/ui/Skeleton";
import cls from "./ArticleListItem.module.scss";

import { ArticleView } from "../../model/consts/consts";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { memo, useCallback, useMemo } from "react";
import { Select, SelectOption } from "@/shared/ui/Select/Select";
import { Select, SelectOption } from "@/shared/ui/Select";
import { SortOrder } from "@/shared/types";
import cls from "./ArticleSortSelector.module.scss";
import { ArticleSortField } from "../../model/consts/consts";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Text } from "@/shared/ui/Text/Text";
import { Text } from "@/shared/ui/Text";
import cls from "./ArticleTextBlockComponent.module.scss";
import { ArticleTextBlock } from "../../model/types/article";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { memo, useCallback, useMemo } from "react";
import { TabItem, Tabs } from "@/shared/ui/Tabs/Tabs";
import { TabItem, Tabs } from "@/shared/ui/Tabs";

import { ArticleType } from "../../model/consts/consts";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import ListIcon from "@/shared/assets/icons/list-24-24.svg";
import TiledIcon from "@/shared/assets/icons/tiled-24-24.svg";
import { Icon } from "@/shared/ui/Icon/Icon";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Icon } from "@/shared/ui/Icon";
import { Button, ButtonTheme } from "@/shared/ui/Button";
import cls from "./ArticleViewSelector.module.scss";

import { ArticleView } from "../../model/consts/consts";
Expand Down
8 changes: 4 additions & 4 deletions src/entities/Comment/ui/CommentCard/CommentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Avatar } from "@/shared/ui/Avatar/Avatar";
import { Text } from "@/shared/ui/Text/Text";
import { Skeleton } from "@/shared/ui/Skeleton/Skeleton";
import { Avatar } from "@/shared/ui/Avatar";
import { Text } from "@/shared/ui/Text";
import { Skeleton } from "@/shared/ui/Skeleton";
import cls from "./CommentCard.module.scss";
import { Comment } from "../../model/types/comment";
import { AppLink } from "@/shared/ui/AppLink/AppLink";
import { AppLink } from "@/shared/ui/AppLink";
import { VStack } from "@/shared/ui/Stack";
import {RoutePath} from "@/shared/const/router";

Expand Down
2 changes: 1 addition & 1 deletion src/entities/Comment/ui/CommentList/CommentList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { memo } from "react";
import { Text } from "@/shared/ui/Text/Text";
import { Text } from "@/shared/ui/Text";
import { useTranslation } from "react-i18next";
import { CommentCard } from "../CommentCard/CommentCard";
import { Comment } from "../../model/types/comment";
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Counter/ui/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useDispatch, useSelector } from "react-redux";
import { counterActions } from "../model/slice/counterSlice";
import { getCounterValue } from "../model/selectors/getCounterValue/getCounterValue";
import { Button } from "@/shared/ui/Button/Button";
import { Button } from "@/shared/ui/Button";

export const Counter = () => {
const dispatch = useDispatch();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from '@/shared/lib/classNames/classNames';
import { memo } from 'react';
import { Card, CardTheme } from '@/shared/ui/Card/Card';
import { Text } from '@/shared/ui/Text/Text';
import { Card, CardTheme } from '@/shared/ui/Card';
import { Text } from '@/shared/ui/Text';
import cls from './NotificationItem.module.scss';
import { Notification } from '../../model/types/notification';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from '@/shared/lib/classNames/classNames';
import { memo } from 'react';
import { VStack } from '@/shared/ui/Stack';
import { Skeleton } from '@/shared/ui/Skeleton/Skeleton';
import { Skeleton } from '@/shared/ui/Skeleton';
import { useNotifications } from '../../api/notificationApi';
import cls from './NotificationList.module.scss';
import { NotificationItem } from '../NotificationItem/NotificationItem';
Expand Down
8 changes: 4 additions & 4 deletions src/entities/Profile/ui/ProfileCard/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { classNames, Mods } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { Text, TextAlign, TextTheme } from "@/shared/ui/Text/Text";
import { Input } from "@/shared/ui/Input/Input";
import { Text, TextAlign, TextTheme } from "@/shared/ui/Text";
import { Input } from "@/shared/ui/Input";
import cls from "./ProfileCard.module.scss";
import { Profile } from "../../model/types/profile";
import { Loader } from "@/shared/ui/Loader/Loader";
import { Loader } from "@/shared/ui/Loader";
import { Currency, CurrencySelect } from "@/entities/Currency";
import { Country, CountrySelect } from "@/entities/Country";
import { Avatar } from "@/shared/ui/Avatar/Avatar";
import { Avatar } from "@/shared/ui/Avatar";
import { HStack, VStack } from "@/shared/ui/Stack";

interface ProfileCardProps {
Expand Down
14 changes: 7 additions & 7 deletions src/entities/Rating/ui/RatingCard/RatingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useTranslation } from 'react-i18next';
import { memo, useCallback, useState } from 'react';
import { BrowserView, MobileView } from 'react-device-detect';
import { classNames } from '@/shared/lib/classNames/classNames';
import { Card } from '@/shared/ui/Card/Card';
import { Card } from '@/shared/ui/Card';
import { HStack, VStack } from '@/shared/ui/Stack';
import { Text } from '@/shared/ui/Text/Text';
import { StarRating } from '@/shared/ui/StarRating/StarRating';
import { Modal } from '@/shared/ui/Modal/Modal';
import { Input } from '@/shared/ui/Input/Input';
import { Button, ButtonSize, ButtonTheme } from '@/shared/ui/Button/Button';
import { Drawer } from '@/shared/ui/Drawer/Drawer';
import { Text } from '@/shared/ui/Text';
import { StarRating } from '@/shared/ui/StarRating';
import { Modal } from '@/shared/ui/Modal';
import { Input } from '@/shared/ui/Input';
import { Button, ButtonSize, ButtonTheme } from '@/shared/ui/Button';
import { Drawer } from '@/shared/ui/Drawer';

interface RatingCardProps {
className?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/features/AuthByUsername/ui/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Input } from "@/shared/ui/Input/Input";
import { Button, ButtonTheme } from "@/shared/ui/Button";
import { Input } from "@/shared/ui/Input";
import { useSelector } from "react-redux";
import { memo, useCallback } from "react";
import { Text, TextTheme } from "@/shared/ui/Text/Text";
import { Text, TextTheme } from "@/shared/ui/Text";
import { getLoginUsername } from "../../model/selectors/getLoginUsername/getLoginUsername";
import { getLoginPassword } from "../../model/selectors/getLoginPassword/getLoginPassword";
import { getLoginIsLoading } from "../../model/selectors/getLoginIsLoading/getLoginIsLoading";
Expand Down
4 changes: 2 additions & 2 deletions src/features/AuthByUsername/ui/LoginModal/LoginModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Modal } from "@/shared/ui/Modal/Modal";
import { Modal } from "@/shared/ui/Modal";
import { classNames } from "@/shared/lib/classNames/classNames";
import { Suspense } from "react";
import { Loader } from "@/shared/ui/Loader/Loader";
import { Loader } from "@/shared/ui/Loader";
import { LoginFormAsync } from "../LoginForm/LoginForm.async";

interface LoginModalProps {
Expand Down
2 changes: 1 addition & 1 deletion src/features/LangSwitcher/ui/LangSwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from "react";
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Button, ButtonTheme } from "@/shared/ui/Button";

enum Locale {
RU = "ru",
Expand Down
2 changes: 1 addition & 1 deletion src/features/ThemeSwitcher/ui/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { memo } from "react";
import DarkIcon from "@/shared/assets/icons/theme-dark.svg";
import LightIcon from "@/shared/assets/icons/theme-light.svg";
import { classNames } from "@/shared/lib/classNames/classNames";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Button, ButtonTheme } from "@/shared/ui/Button";
import { useTheme } from "@/shared/lib/hooks/useTheme/useTheme";
import { Theme } from "@/shared/const/theme";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { memo, useCallback } from "react";
import { Input } from "@/shared/ui/Input/Input";
import { Button, ButtonTheme } from "@/shared/ui/Button/Button";
import { Input } from "@/shared/ui/Input";
import { Button, ButtonTheme } from "@/shared/ui/Button";
import { useSelector } from "react-redux";
import { useAppDispatch } from "@/shared/lib/hooks/useAppDispatch/useAppDispatch";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { lazy, Suspense } from "react";
import { Skeleton } from "@/shared/ui/Skeleton/Skeleton";
import { Skeleton } from "@/shared/ui/Skeleton";
import { ArticleRatingProps } from "./ArticleRating";

const ArticleRatingLazy = lazy(() => import("./ArticleRating"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useRateArticle,
} from "../../api/articleRatingApi";
import { getUserAuthData } from "@/entities/User";
import { Skeleton } from "@/shared/ui/Skeleton/Skeleton";
import { Skeleton } from "@/shared/ui/Skeleton";

export interface ArticleRatingProps {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import { memo } from "react";
import { Text, TextSize } from "@/shared/ui/Text/Text";
import { Text, TextSize } from "@/shared/ui/Text";
import { ArticleList } from "@/entities/Article";
import { VStack } from "@/shared/ui/Stack";
import { useArticleRecommendationsList } from "../../api/aritcleRecommendationsApi";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { classNames } from "@/shared/lib/classNames/classNames";
import { useTranslation } from "react-i18next";
import React, { memo, useCallback } from "react";
import { Avatar } from "@/shared/ui/Avatar/Avatar";
import { Avatar } from "@/shared/ui/Avatar";
import { Dropdown } from "@/shared/ui/Popups";
import { useDispatch, useSelector } from "react-redux";
import {
Expand Down
Loading

0 comments on commit 0e5ce58

Please sign in to comment.