๐ŸŒˆ VSCode์—์„œ ํด๋ฆญ ํ•œ ๋ฒˆ์œผ๋กœ ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ, stories.tsx, test.tsx ์ž๋™ ์ƒ์„ฑํ•˜๊ธฐ

ํ—ˆ์ง€์˜ˆยท2024๋…„ 8์›” 11์ผ
0

VSCode์—์„œ Next.js + Typescript๋กœ ๊ฐœ์ธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋‹ค.

์ƒ์‚ฐ์„ฑ์„ ๋Œ์–ด์˜ฌ๋ฆฌ๊ธฐ ์œ„ํ•ด์„œ ํด๋ฆญ ํ•œ ๋ฒˆ์œผ๋กœ ์ •ํ•ด์ง„ ํ…œ๋ธ”๋ฆฟ์œผ๋กœ ์•„๋ž˜ 3๊ฐ€์ง€ ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ธฐ๋ฅผ ๊ตฌํ˜„ํ•ด๋ดค๋‹ค.

  • Component.tsx
  • Component.stories.tsx
  • Component.test.tsx

Folder Templates ์‚ฌ์šฉํ•˜๊ธฐ

https://marketplace.visualstudio.com/items?itemName=Huuums.vscode-fast-folder-structure#template-format

vscode extension์ธ Folder Templates๋ฅผ ํ™œ์šฉํ–ˆ๋‹ค.

1. ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ํด๋”์— .fttemplates ํด๋”๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

2. component template ํด๋”๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

3. component template ํด๋” ์•„๋ž˜ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŒŒ์ผ๋“ค์„ ์ƒ์„ฑํ•œ๋‹ค.

.fttemplates/
โ”œโ”€โ”€ component template/
โ”‚   โ”œโ”€โ”€ [FTName].tsx
โ”‚   โ”œโ”€โ”€ [FTName].stories.tsx
โ”‚   โ”œโ”€โ”€ [FTName].test.tsx
โ”‚   โ”œโ”€โ”€ index.ts
โ”‚   โ”œโ”€โ”€ .ftsettings.json
  • [FTName].tsx
    export type [FTName]Props = {}
    
    // eslint-disable-next-line no-empty-pattern
    function [FTName]({}: [FTName]Props) {
      return <div data-testid="[FTName]-component"/>
    }
    
    export default [FTName];
  • [FTName].stories.tsx
    import type { Meta, StoryObj } from '@storybook/react';
    
    import [FTName] from './[FTName]';
    
    const meta = {
      title: 'Component/[FTName]',
      component: [FTName],
      parameters: {
        layout: 'centered',
      },
      tags: ['autodocs'],
      argTypes: { },
      args: { },
    } satisfies Meta<typeof [FTName]>;
    
    export default meta;
    type Story = StoryObj<typeof meta>;
    
    export const Default: Story = {
      args: {},
    };
  • [FTName].test.tsx
    import { describe, expect, it } from '@jest/globals';
    import { render, screen } from '@testing-library/react';
    
    import [FTName] from './[FTName]';
    
    describe('๐ŸŽจ [FTName] ์ปดํฌ๋„ŒํŠธ ํ…Œ์ŠคํŠธ', () => {
      it('๊ธฐ๋ณธ ๋ Œ๋”๋ง ํ…Œ์ŠคํŠธ', () => {
        render(<[FTName] />);
        const element = screen.getByTestId('[FTName]-component');
        expect(element).toBeInTheDocument();
      });
    });
  • index.tsx
    [__existingcontent__]
    ์€ ํŒŒ์ผ์„ ๋ฎ์–ด์“ฐ๊ธฐํ•  ๊ฒฝ์šฐ ์ด์ „ ๋‚ด์šฉ์ด ์—ฌ๊ธฐ ๋‹ด๊ธด๋‹ค.
    ๊ทธ ํด๋” ๋‚ด์—์„œ ์ฒ˜์Œ ์ƒ์„ฑํ•  ๊ฒฝ์šฐ์—๋Š” ์ € ๋ฌธ์ž๊ฐ€ ๊ทธ๋Œ€๋กœ ๋“ค์–ด๊ฐ€์ง€๋งŒ, (์ด๊ฑด ์ˆ˜๋™์œผ๋กœ ์ œ๊ฑฐ)
    ๊ทธ ์ดํ›„ ์ƒ์„ฑํ•  ๋•Œ๋Š” ๋ˆ„์ ๋˜์„œ ๋“ค์–ด๊ฐ„๋‹ค.
    ```tsx
    [__existingcontent__]
    export * from './[FTName]';
    export { default as [FTName] } from './[FTName]';
    ```
  • .ftsettings.json
    "overwriteExistingFiles": "always": ์ด๋ฏธ ์žˆ๋Š” ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๋ฎ์–ด์”Œ์šด๋‹ค.
    "omitParentDirectory": true : ํด๋”๋ฅผ ์ƒˆ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ , ๋ถ€๋ชจ ํด๋”์— ํŒŒ์ผ๋“ค์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
    ```tsx
    {
      "name": "๐ŸŽจ component template",
      "overwriteExistingFiles": "always",
      "omitParentDirectory": true
    }
    ```

๋๐Ÿ‘


+) vscode extension ์ถ”์ฒœ

์ด ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๋Š” ๋ฒ• ์•Œ์•„๋ณด๋ฉด์„œ ์–ด์ฉŒ๋‹ค ์•Œ๊ฒŒ ๋œ extension

https://marketplace.visualstudio.com/items?itemName=antfu.file-nesting

์•„๋ž˜์ฒ˜๋Ÿผ ๊ด€๋ จ ํŒŒ์ผ๋“ค์„ ๋ฌถ์–ด์ค€๋‹ค.

๋ฃจํŠธ ํด๋”์— config ํŒŒ์ผ๋“ค๋„ ๋ฌถ์–ด์ค˜์„œ ๋˜๊ฒŒ ํŽธํ•˜๋‹ค. settings.json์—์„œ ์ปค์Šคํ…€๋„ ๊ฐ€๋Šฅ ๐Ÿ‘

profile
๋Œ€ํ•™์ƒ์—์„œ ์ทจ์ค€์ƒ์œผ๋กœ ์ง„ํ™”ํ–ˆ๋‹ค๊ฐ€ ์ง€๊ธˆ์€ ํ’€์Šคํƒ ๊ฐœ๋ฐœ์ž๋กœ 2์ฐจ ์ง„ํ™”ํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด