Skip to content

Commit

Permalink
chore: update README.md and index.js option name
Browse files Browse the repository at this point in the history
  • Loading branch information
snowden-fu committed May 10, 2024
1 parent f674139 commit 249dda9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A command-line interface (CLI) tool to quickly generate React components with op
## Installation

```bash
npm install -g create-new-react-component
npm install create-new-react-component --save-dev
```

## Usage
Expand All @@ -16,7 +16,7 @@ create-new-react-component <componentName> [options]
## Options

- --withStyles: Create a CSS file for the component
- --style <style>: Choose the file style (js or ts), default is js
- --lang <style>: Choose the file style (js or ts), default is js

## Examples
```bash
Expand All @@ -27,10 +27,10 @@ create-new-react-component MyComponent
create-new-react-component MyComponent --withStyles

# Create a TypeScript component without styles
create-new-react-component MyComponent --style ts
create-new-react-component MyComponent --lang ts

# Create a TypeScript component with styles
create-new-react-component MyComponent --withStyles --style ts
create-new-react-component MyComponent --withStyles --lang ts
```


Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ program
)
.arguments('<componentName>', 'Name of the component to create')
.option('--withStyles', 'Create a CSS file for the component')
.option('--style <style>', 'Choose the file style (js or ts)', 'js')
.option('--lang <lang>', 'Choose the file style (js or ts)', 'js')
.action(createComponent);

function createComponent(componentName, options) {
const componentDir = path.join(process.cwd(), componentName);
const indexFilePath = path.join(componentDir, `index.${options.style}`);
const componentFilePath = path.join(componentDir, `${componentName}.${options.style}x`);
const indexFilePath = path.join(componentDir, `index.${options.lang}`);
const componentFilePath = path.join(componentDir, `${componentName}.${options.lang}x`);
const stylesFilePath = path.join(componentDir, `${componentName}.css`);

const indexFileContent = `export { default } from './${componentName}';`;

const ComponentFileContent = require('./ComponentFileContent');
const componentFileContent = new ComponentFileContent(componentName, options.withStyles, options.style);
const componentFileContent = new ComponentFileContent(componentName, options.withStyles, options.lang);
const componentFileContentContent = componentFileContent.generateComponentContent();

const stylesFileContent = `/* Add your component styles here */
Expand All @@ -46,7 +46,7 @@ function createComponent(componentName, options) {
if (options.withStyles) {
fs.writeFileSync(stylesFilePath, stylesFileContent);
}
console.log(`Component ${componentName} created successfully${options.withStyles ? ' with styles' : ''} (${options.style})`);
console.log(`Component ${componentName} created successfully${options.withStyles ? ' with language' : ''} (${options.lang})`);
} catch (err) {
console.error(`Error creating component ${componentName}:`, err);
}
Expand Down

0 comments on commit 249dda9

Please sign in to comment.