-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·39 lines (31 loc) · 1.18 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import click
from view_creator.view_creator import View
@click.command()
@click.option("--name", help="Create a component with the specified name")
@click.option("--directory", help="This creates a component from the specified directory")
@click.argument('name')
def component(name: str, directory: str):
# Base component directory
component_dir = './src/components'
if not os.path.exists(component_dir):
os.makedirs(component_dir, mode = 0o777)
if directory:
component_dir = directory
# Create a directory for the component
if not os.path.exists(name):
os.makedirs(component_dir + '/' + name)
with open(f"{component_dir}/{name}/{name}.tsx", 'w') as fh:
fh.write(View.generate_jsx_view_str(name))
with open(f"{component_dir}/{name}/{name}.scss", "w") as fh:
fh.write(f".{name}-container {'{}'}")
with open(f"{component_dir}/{name}/index.ts", "w") as fh:
fh.write(View.generate_index_file(name))
with open(f"{component_dir}/{name}/{name}.spec.ts", "w") as fh:
fh.write(View.generate_test_file(name))
@click.group()
def cli():
pass
cli.add_command(component)
if __name__ == "__main__":
cli()