Skip to content

Commit 37a5968

Browse files
authored
Merge pull request #165 from simpleweb/feature/remove-class-component-option
Feature: Removes the `classComponent` option from component command
2 parents 9797f80 + 8526774 commit 37a5968

5 files changed

Lines changed: 19 additions & 53 deletions

File tree

.changeset/twelve-mayflies-deny.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"romulus-cli": minor
3+
---
4+
5+
Removes the `classComponent` option from component command
6+
Updates the stateless component to use `function` instead of `const`

docs/commands.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ These commands rely on the original structure created by `romulus init`.
44

55
## Component
66

7-
Creates a new component or class based component.
7+
Creates a new component.
88

99
```
1010
romulus component MyComponent
11-
romulus component MyComponent --classComponent
1211
```
1312

1413
This will generate three files:
@@ -25,7 +24,7 @@ import { View, Text } from "./styles";
2524

2625
interface Props {}
2726

28-
const MyComponent: React.FC<Props> = () => {
27+
function MyComponent() {
2928
return (
3029
<View>
3130
<Text>MyComponent</Text>
@@ -36,28 +35,7 @@ const MyComponent: React.FC<Props> = () => {
3635
export default MyComponent;
3736
```
3837

39-
If you pass the `--classComponent` flag this stateful component will be generated.
40-
41-
```js
42-
import React from "react";
43-
import { View, Text } from "./styles";
44-
45-
interface Props {}
46-
47-
class MyComponent extends React.Component<Props, {}> {
48-
render() {
49-
return (
50-
<View>
51-
<Text>MyComponent</Text>
52-
</View>
53-
);
54-
}
55-
}
56-
57-
export default MyComponent;
58-
```
59-
60-
Both types of components get the same accompanying styles.
38+
Components get accompanying styles.
6139

6240
```js
6341
import styled from "styled-components/native";

generators/component/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var Generator = require('yeoman-generator');
2-
var path = require('path');
1+
var Generator = require("yeoman-generator");
2+
var path = require("path");
33

44
module.exports = class extends Generator {
55
constructor(args, opts) {
@@ -8,31 +8,29 @@ module.exports = class extends Generator {
88
// name of the app based on the directory name generated by React Native
99
this.name = process.cwd().split(path.sep).pop();
1010

11-
this.argument('component', { type: String, required: true });
12-
this.option('classComponent');
11+
this.argument("component", { type: String, required: true });
1312
}
1413

1514
writing() {
16-
var template = (this.options.classComponent) ? 'class.tsx' : 'stateless.tsx';
1715
var component = this.options.component;
1816

1917
// create entry points for Android and iOS
2018
this.fs.copyTpl(
21-
this.templatePath(template),
19+
this.templatePath("index.tsx"),
2220
this.destinationPath(`App/Components/${component}/index.tsx`),
23-
{ name: this.name, component: component, }
21+
{ name: this.name, component: component }
2422
);
2523

2624
this.fs.copyTpl(
27-
this.templatePath('styles.ts'),
25+
this.templatePath("styles.ts"),
2826
this.destinationPath(`App/Components/${component}/styles.ts`),
29-
{ name: this.name, component: component, }
27+
{ name: this.name, component: component }
3028
);
3129

3230
this.fs.copyTpl(
33-
this.templatePath('test.tsx'),
31+
this.templatePath("test.tsx"),
3432
this.destinationPath(`App/Components/${component}/index.test.tsx`),
35-
{ name: this.name, component: component, }
33+
{ name: this.name, component: component }
3634
);
3735
}
3836
};

generators/component/templates/class.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

generators/component/templates/stateless.tsx renamed to generators/component/templates/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View, Text } from "./styles";
33

44
interface Props {}
55

6-
const <%= component %>: React.FC<Props> = () => {
6+
function <%= component %>() {
77
return (
88
<View>
99
<Text><%= component %></Text>

0 commit comments

Comments
 (0)