@tomyddddd10102929/react-component-generator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -0
- package/dist/commands/create.d.ts +8 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +29 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/component.d.ts +2 -0
- package/dist/templates/component.d.ts.map +1 -0
- package/dist/templates/component.js +13 -0
- package/dist/templates/component.js.map +1 -0
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +5 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/stories.d.ts +2 -0
- package/dist/templates/stories.d.ts.map +1 -0
- package/dist/templates/stories.js +15 -0
- package/dist/templates/stories.js.map +1 -0
- package/dist/templates/styles.d.ts +2 -0
- package/dist/templates/styles.d.ts.map +1 -0
- package/dist/templates/styles.js +7 -0
- package/dist/templates/styles.js.map +1 -0
- package/dist/templates/test.d.ts +2 -0
- package/dist/templates/test.d.ts.map +1 -0
- package/dist/templates/test.js +12 -0
- package/dist/templates/test.js.map +1 -0
- package/dist/utils/fileGenerator.d.ts +8 -0
- package/dist/utils/fileGenerator.d.ts.map +1 -0
- package/dist/utils/fileGenerator.js +33 -0
- package/dist/utils/fileGenerator.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @tomyddddd10102929/react-component-generator
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tomyddddd10102929/react-component-generator)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
5
|
+
|
|
6
|
+
React コンポーネントのスキャフォールディング CLI ツール。
|
|
7
|
+
コマンド一つで、コンポーネントに必要なファイル一式を自動生成します。
|
|
8
|
+
|
|
9
|
+
## ✨ 特徴
|
|
10
|
+
|
|
11
|
+
- 🚀 **ワンコマンド** - `rcg create Button` だけでファイル一式を生成
|
|
12
|
+
- 📁 **必要なファイルを自動生成** - コンポーネント、CSS Modules、Storybook、テストファイル
|
|
13
|
+
- ⚙️ **柔軟なオプション** - 不要なファイルはスキップ可能
|
|
14
|
+
- 📦 **TypeScript 対応** - 型定義付きのコンポーネントを生成
|
|
15
|
+
|
|
16
|
+
## 📦 インストール
|
|
17
|
+
|
|
18
|
+
### グローバルインストール
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# npm
|
|
22
|
+
npm install -g @tomyddddd10102929/react-component-generator
|
|
23
|
+
|
|
24
|
+
# pnpm
|
|
25
|
+
pnpm add -g @tomyddddd10102929/react-component-generator
|
|
26
|
+
|
|
27
|
+
# yarn
|
|
28
|
+
yarn global add @tomyddddd10102929/react-component-generator
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### プロジェクトにインストール(推奨)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# npm
|
|
35
|
+
npm install -D @tomyddddd10102929/react-component-generator
|
|
36
|
+
|
|
37
|
+
# pnpm
|
|
38
|
+
pnpm add -D @tomyddddd10102929/react-component-generator
|
|
39
|
+
|
|
40
|
+
# yarn
|
|
41
|
+
yarn add -D @tomyddddd10102929/react-component-generator
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🚀 使い方
|
|
45
|
+
|
|
46
|
+
### グローバルインストールの場合
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# カレントディレクトリにButtonコンポーネントを作成
|
|
50
|
+
rcg create Button
|
|
51
|
+
|
|
52
|
+
# 指定したパスに作成
|
|
53
|
+
rcg create Button --path ./src/components
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### プロジェクトにインストールした場合
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# npx経由で実行
|
|
60
|
+
npx rcg create Button --path ./src/components
|
|
61
|
+
|
|
62
|
+
# pnpm
|
|
63
|
+
pnpm rcg create Button --path ./src/components
|
|
64
|
+
|
|
65
|
+
# package.jsonのscriptsに追加して使用
|
|
66
|
+
# "scripts": { "gen": "rcg create" }
|
|
67
|
+
pnpm gen Button --path ./src/components
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### オプション
|
|
71
|
+
|
|
72
|
+
| オプション | 短縮形 | 説明 | デフォルト |
|
|
73
|
+
|-----------|--------|------|-----------|
|
|
74
|
+
| `--path <path>` | `-p` | コンポーネントを作成するパス | カレントディレクトリ |
|
|
75
|
+
| `--no-stories` | - | Storybook ファイルを作成しない | `false` |
|
|
76
|
+
| `--no-test` | - | テストファイルを作成しない | `false` |
|
|
77
|
+
| `--no-styles` | - | CSS モジュールファイルを作成しない | `false` |
|
|
78
|
+
|
|
79
|
+
### 使用例
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# すべてのファイルを作成
|
|
83
|
+
rcg create Button --path ./src/components
|
|
84
|
+
|
|
85
|
+
# Storybookとテストなしで作成
|
|
86
|
+
rcg create Button --no-stories --no-test
|
|
87
|
+
|
|
88
|
+
# CSSなしで作成
|
|
89
|
+
rcg create Card --no-styles
|
|
90
|
+
|
|
91
|
+
# ヘルプを表示
|
|
92
|
+
rcg --help
|
|
93
|
+
rcg create --help
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 📂 生成されるファイル
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
Button/
|
|
100
|
+
├── index.tsx # メインコンポーネント
|
|
101
|
+
├── Button.module.css # CSS モジュール
|
|
102
|
+
├── Button.stories.tsx # Storybook ストーリー
|
|
103
|
+
└── Button.test.tsx # テストファイル
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 生成されるコード例
|
|
107
|
+
|
|
108
|
+
#### index.tsx
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import styles from './Button.module.css';
|
|
112
|
+
|
|
113
|
+
type ButtonProps = {
|
|
114
|
+
// props
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export function Button(props: ButtonProps) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Button.stories.tsx
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
126
|
+
import { Button } from './';
|
|
127
|
+
|
|
128
|
+
const meta: Meta<typeof Button> = {
|
|
129
|
+
component: Button,
|
|
130
|
+
};
|
|
131
|
+
export default meta;
|
|
132
|
+
|
|
133
|
+
type Story = StoryObj<typeof Button>;
|
|
134
|
+
|
|
135
|
+
export const Default: Story = {};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Button.test.tsx
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { render, screen } from '@testing-library/react';
|
|
142
|
+
import { Button } from './';
|
|
143
|
+
|
|
144
|
+
describe('Button', () => {
|
|
145
|
+
it('renders without crashing', () => {
|
|
146
|
+
render(<Button />);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 📄 ライセンス
|
|
152
|
+
|
|
153
|
+
ISC
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CreateCommandOptions = {
|
|
2
|
+
path?: string;
|
|
3
|
+
stories?: boolean;
|
|
4
|
+
test?: boolean;
|
|
5
|
+
styles?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function createCommand(componentName: string, options: CreateCommandOptions): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { generateComponent, } from "../utils/fileGenerator.js";
|
|
4
|
+
export async function createCommand(componentName, options) {
|
|
5
|
+
// コンポーネント名の先頭を大文字に
|
|
6
|
+
const pascalCaseName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
|
|
7
|
+
const generatorOptions = {
|
|
8
|
+
path: options.path ?? process.cwd(),
|
|
9
|
+
stories: options.stories ?? true,
|
|
10
|
+
test: options.test ?? true,
|
|
11
|
+
styles: options.styles ?? true,
|
|
12
|
+
};
|
|
13
|
+
console.log(chalk.blue(`\n📦 Creating component: ${pascalCaseName}\n`));
|
|
14
|
+
try {
|
|
15
|
+
const createdFiles = await generateComponent(pascalCaseName, generatorOptions);
|
|
16
|
+
console.log(chalk.green("✅ Component created successfully!\n"));
|
|
17
|
+
console.log(chalk.white("Created files:"));
|
|
18
|
+
const componentDir = path.join(generatorOptions.path, pascalCaseName);
|
|
19
|
+
createdFiles.forEach((file) => {
|
|
20
|
+
console.log(chalk.gray(` ${componentDir}/${file}`));
|
|
21
|
+
});
|
|
22
|
+
console.log("");
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error(chalk.red("❌ Failed to create component:"), error);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AASnC,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,aAAqB,EACrB,OAA6B;IAE7B,mBAAmB;IACnB,MAAM,cAAc,GAClB,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,gBAAgB,GAAqB;QACzC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE;QACnC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI;QAChC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;KAC/B,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,4BAA4B,cAAc,IAAI,CAAC,CAAC,CAAC;IAExE,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAC1C,cAAc,EACd,gBAAgB,CACjB,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAE3C,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QACtE,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,YAAY,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,CAAC,EAAE,KAAK,CAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { createCommand } from "./commands/create.js";
|
|
4
|
+
const program = new Command();
|
|
5
|
+
program
|
|
6
|
+
.name("rcg")
|
|
7
|
+
.description("React component scaffolding CLI")
|
|
8
|
+
.version("1.0.0");
|
|
9
|
+
program
|
|
10
|
+
.command("create <componentName>")
|
|
11
|
+
.description("Create a new React component with all necessary files")
|
|
12
|
+
.option("-p, --path <path>", "Path where the component will be created", process.cwd())
|
|
13
|
+
.option("--no-stories", "Skip creating Storybook file")
|
|
14
|
+
.option("--no-test", "Skip creating test file")
|
|
15
|
+
.option("--no-styles", "Skip creating CSS module file")
|
|
16
|
+
.action(createCommand);
|
|
17
|
+
program.parse();
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,KAAK,CAAC;KACX,WAAW,CAAC,iCAAiC,CAAC;KAC9C,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,wBAAwB,CAAC;KACjC,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CACL,mBAAmB,EACnB,0CAA0C,EAC1C,OAAO,CAAC,GAAG,EAAE,CACd;KACA,MAAM,CAAC,cAAc,EAAE,8BAA8B,CAAC;KACtD,MAAM,CAAC,WAAW,EAAE,yBAAyB,CAAC;KAC9C,MAAM,CAAC,aAAa,EAAE,+BAA+B,CAAC;KACtD,MAAM,CAAC,aAAa,CAAC,CAAC;AAEzB,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../src/templates/component.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAW/D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function componentTemplate(componentName) {
|
|
2
|
+
return `import styles from './${componentName}.module.css';
|
|
3
|
+
|
|
4
|
+
type ${componentName}Props = {
|
|
5
|
+
// props
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function ${componentName}(props: ${componentName}Props) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/templates/component.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAAC,aAAqB;IACrD,OAAO,yBAAyB,aAAa;;OAExC,aAAa;;;;kBAIF,aAAa,WAAW,aAAa;;;CAGtD,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stories.d.ts","sourceRoot":"","sources":["../../src/templates/stories.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAa7D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function storiesTemplate(componentName) {
|
|
2
|
+
return `import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { ${componentName} } from './';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof ${componentName}> = {
|
|
6
|
+
component: ${componentName},
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
|
|
10
|
+
type Story = StoryObj<typeof ${componentName}>;
|
|
11
|
+
|
|
12
|
+
export const Default: Story = {};
|
|
13
|
+
`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stories.js","sourceRoot":"","sources":["../../src/templates/stories.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,aAAqB;IACnD,OAAO;WACE,aAAa;;0BAEE,aAAa;eACxB,aAAa;;;;+BAIG,aAAa;;;CAG3C,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/templates/styles.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAK5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/templates/styles.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,aAAqB;IAClD,OAAO;OACF,aAAa;;CAEnB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/templates/test.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAU1D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function testTemplate(componentName) {
|
|
2
|
+
return `import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ${componentName} } from './';
|
|
4
|
+
|
|
5
|
+
describe('${componentName}', () => {
|
|
6
|
+
it('renders without crashing', () => {
|
|
7
|
+
render(<${componentName} />);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/templates/test.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,aAAqB;IAChD,OAAO;WACE,aAAa;;YAEZ,aAAa;;cAEX,aAAa;;;CAG1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type GeneratorOptions = {
|
|
2
|
+
path: string;
|
|
3
|
+
stories: boolean;
|
|
4
|
+
test: boolean;
|
|
5
|
+
styles: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function generateComponent(componentName: string, options: GeneratorOptions): Promise<string[]>;
|
|
8
|
+
//# sourceMappingURL=fileGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileGenerator.d.ts","sourceRoot":"","sources":["../../src/utils/fileGenerator.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,EAAE,CAAC,CAkCnB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { componentTemplate, storiesTemplate, stylesTemplate, testTemplate, } from "../templates/index.js";
|
|
4
|
+
export async function generateComponent(componentName, options) {
|
|
5
|
+
const componentDir = path.join(options.path, componentName);
|
|
6
|
+
const createdFiles = [];
|
|
7
|
+
// コンポーネントディレクトリを作成
|
|
8
|
+
await fs.ensureDir(componentDir);
|
|
9
|
+
// index.tsx(メインコンポーネント)
|
|
10
|
+
const componentPath = path.join(componentDir, "index.tsx");
|
|
11
|
+
await fs.writeFile(componentPath, componentTemplate(componentName));
|
|
12
|
+
createdFiles.push("index.tsx");
|
|
13
|
+
// スタイルファイル
|
|
14
|
+
if (options.styles) {
|
|
15
|
+
const stylesPath = path.join(componentDir, `${componentName}.module.css`);
|
|
16
|
+
await fs.writeFile(stylesPath, stylesTemplate(componentName));
|
|
17
|
+
createdFiles.push(`${componentName}.module.css`);
|
|
18
|
+
}
|
|
19
|
+
// Storybookファイル
|
|
20
|
+
if (options.stories) {
|
|
21
|
+
const storiesPath = path.join(componentDir, `${componentName}.stories.tsx`);
|
|
22
|
+
await fs.writeFile(storiesPath, storiesTemplate(componentName));
|
|
23
|
+
createdFiles.push(`${componentName}.stories.tsx`);
|
|
24
|
+
}
|
|
25
|
+
// テストファイル
|
|
26
|
+
if (options.test) {
|
|
27
|
+
const testPath = path.join(componentDir, `${componentName}.test.tsx`);
|
|
28
|
+
await fs.writeFile(testPath, testTemplate(componentName));
|
|
29
|
+
createdFiles.push(`${componentName}.test.tsx`);
|
|
30
|
+
}
|
|
31
|
+
return createdFiles;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=fileGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileGenerator.js","sourceRoot":"","sources":["../../src/utils/fileGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAC;AAS/B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,aAAqB,EACrB,OAAyB;IAEzB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,mBAAmB;IACnB,MAAM,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAEjC,wBAAwB;IACxB,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC3D,MAAM,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC;IACpE,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE/B,WAAW;IACX,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,aAAa,aAAa,CAAC,CAAC;QAC1E,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC;QAC9D,YAAY,CAAC,IAAI,CAAC,GAAG,aAAa,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,gBAAgB;IAChB,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,aAAa,cAAc,CAAC,CAAC;QAC5E,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC;QAChE,YAAY,CAAC,IAAI,CAAC,GAAG,aAAa,cAAc,CAAC,CAAC;IACpD,CAAC;IAED,UAAU;IACV,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,aAAa,WAAW,CAAC,CAAC;QACtE,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC;QAC1D,YAAY,CAAC,IAAI,CAAC,GAAG,aAAa,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tomyddddd10102929/react-component-generator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React component scaffolding CLI - Generate component files with one command",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"rcg": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc --watch",
|
|
19
|
+
"start": "node dist/index.js",
|
|
20
|
+
"lint": "biome check src",
|
|
21
|
+
"lint:fix": "biome check --write src",
|
|
22
|
+
"format": "biome format --write src"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=24.13.0"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"react",
|
|
29
|
+
"component",
|
|
30
|
+
"generator",
|
|
31
|
+
"scaffold",
|
|
32
|
+
"cli"
|
|
33
|
+
],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "ISC",
|
|
36
|
+
"packageManager": "pnpm@10.28.1",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@biomejs/biome": "^2.3.12",
|
|
39
|
+
"@types/fs-extra": "^11.0.4",
|
|
40
|
+
"@types/node": "^25.0.10",
|
|
41
|
+
"chalk": "^5.6.2",
|
|
42
|
+
"commander": "^14.0.2",
|
|
43
|
+
"fs-extra": "^11.3.3",
|
|
44
|
+
"typescript": "^5.9.3"
|
|
45
|
+
}
|
|
46
|
+
}
|