Skip to content

Commit

Permalink
add support for class components
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomKnight287 committed Apr 5, 2022
1 parent 8f6dea6 commit 1d9f544
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
61 changes: 38 additions & 23 deletions src/create_component_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod files_creater {
component_name: String,
stylesheet_name: String,
is_css_module: bool,
is_class_component: bool,
) {
let index_file_content = format!(
"export {{ default }} from \"./{}\";",
Expand All @@ -14,34 +15,48 @@ pub mod files_creater {
let component_file_content;
if is_css_module == true {
css_file_content = "".to_string();
component_file_content = format!(
"import styles from './{:}';
export default function {:}() {{
return (
<div className={{styles.h1Container}}>
<h1>Hello World</h1>
</div>
);
}}
",
stylesheet_name,
component_name.split(".").collect::<Vec<&str>>()[0]
);
if is_class_component == true {
component_file_content = format!(
"import {{ Component }} from \"react\";\nimport styles from \"./{}\";\n\nclass {} extends Component {{}}\n\nexport default {}",
stylesheet_name, component_name.split(".").collect::<Vec<&str>>()[0], component_name.split(".").collect::<Vec<&str>>()[0]
)
} else {
component_file_content = format!(
"import styles from './{:}';
export default function {:}() {{
return (
<div className={{styles.h1Container}}>
<h1>Hello World</h1>
</div>
);
}}
",
stylesheet_name,
component_name.split(".").collect::<Vec<&str>>()[0]
);
}
} else {
css_file_content = "".to_string();
component_file_content = format!(
"import './{:}';
export default function {:}() {{
return (
<div className=\"h1Container\" >
<h1>Hello, world!</h1>
if is_class_component == true {
component_file_content = format!(
"import {{ Component }} from \"react\";\nimport \"./{}\";\n\nclass {} extends Component {{}}\n\nexport default {}",
stylesheet_name, component_name.split(".").collect::<Vec<&str>>()[0], component_name.split(".").collect::<Vec<&str>>()[0]
)
} else {
component_file_content = format!(
"import './{:}';
export default function {:}() {{
return (
<div className=\"h1Container\" >
<h1>Hello, world!</h1>
</div>
);
);
}}
",
stylesheet_name,
component_name.split(".").collect::<Vec<&str>>()[0]
);
stylesheet_name,
component_name.split(".").collect::<Vec<&str>>()[0]
);
}
}
let result = fs::create_dir(format!(
"{:}",
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct Args {
/// The name of stylesheet you want to create
#[clap(short = 'S', long, default_value = "css")]
stylesheet: String,

/// Create a Class Based Component
#[clap(short='C',long)]
class: bool,
}

fn main() {
Expand All @@ -39,6 +43,7 @@ fn main() {
module: css_module,
hook,
stylesheet: stylesheet_name,
class
} = Args::parse();

if hook {
Expand Down Expand Up @@ -67,5 +72,6 @@ fn main() {
component_file_name,
stylesheet.clone(),
stylesheet.contains("module"),
class
);
}

0 comments on commit 1d9f544

Please sign in to comment.