-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
176 lines (153 loc) · 5.05 KB
/
cli.py
File metadata and controls
176 lines (153 loc) · 5.05 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import argparse
import logging
import json
from py_node_manager import get_logger
from .utils import TailwindCommand
logger = get_logger(logging.getLogger(__name__))
class _TailwindCLI:
"""
CLI class for the Dash TailwindCSS plugin
"""
def __init__(self):
"""
Initialize the CLI tool
"""
pass
def run(self):
"""
Main entry point for the CLI tool
Returns:
None
"""
parser = argparse.ArgumentParser(description='Dash TailwindCSS Plugin CLI')
parser.add_argument(
'command',
choices=['init', 'build', 'watch', 'clean'],
help='Command to execute',
)
parser.add_argument(
'--tailwind-version',
type=str,
default='3',
help='Version of Tailwind CSS to use',
)
parser.add_argument(
'--content-path',
action='append',
help='Glob pattern for files to scan for Tailwind classes. Can be specified multiple times.',
)
parser.add_argument(
'--plugin-tmp-dir',
default='./_tailwind',
help='Path to temporary directory for plugin files',
)
parser.add_argument(
'--input-css-path',
default='./_tailwind/tailwind_input.css',
help='Path to input CSS file',
)
parser.add_argument(
'--output-css-path',
default='./_tailwind/tailwind.css',
help='Path to output CSS file',
)
parser.add_argument(
'--config-js-path',
default='./_tailwind/tailwind.config.js',
help='Path to Tailwind config file',
)
parser.add_argument(
'--tailwind-theme-config',
type=str,
help='JSON string of custom theme configuration for Tailwind CSS',
)
parser.add_argument(
'--clean-after',
action='store_true',
help='Clean up generated files after build',
)
parser.add_argument(
'--download-node',
action='store_true',
help='Download Node.js if not found in PATH',
)
parser.add_argument(
'--node-version',
default='18.17.0',
help='Node.js version to download (if --download-node is used)',
)
args = parser.parse_args()
# Parse theme config if provided
theme_config = None
if args.tailwind_theme_config:
try:
theme_config = json.loads(args.tailwind_theme_config)
except json.JSONDecodeError as e:
logger.error(f'Invalid JSON for theme config: {e}')
theme_config = None
self.tailwind_command = TailwindCommand(
tailwind_version=args.tailwind_version,
content_path=args.content_path if args.content_path else ['**/*.py'],
plugin_tmp_dir=args.plugin_tmp_dir,
input_css_path=args.input_css_path,
output_css_path=args.output_css_path,
config_js_path=args.config_js_path,
is_cli=True,
download_node=args.download_node,
node_version=args.node_version,
theme_config=theme_config,
)
if args.command == 'init':
self.init_tailwindcss(input_css_path=args.input_css_path, config_js_path=args.config_js_path)
elif args.command == 'build':
self.build_tailwindcss(clean_after=args.clean_after)
elif args.command == 'watch':
self.watch_tailwindcss()
elif args.command == 'clean':
self.clean_tailwindcss()
def init_tailwindcss(self, input_css_path: str, config_js_path: str):
"""
Initialize a new Tailwind config file
Args:
input_css_path (str): Path to input CSS file
config_js_path (str): Path to the Tailwind config file
Returns:
None
"""
self.tailwind_command.init().install()
logger.info('📝 Next steps:')
logger.info('1. Customize your config file if needed')
logger.info('2. Build CSS with:')
logger.info('dash-tailwindcss-plugin build')
def build_tailwindcss(self, clean_after: bool):
"""
Build Tailwind CSS
Args:
clean_after (bool): Whether to clean up generated files after build
Returns:
None
"""
built = self.tailwind_command.init().install().build()
# Clean up if requested
if clean_after:
built.clean()
def watch_tailwindcss(self):
"""
Watch for changes and rebuild Tailwind CSS
Returns:
None
"""
self.tailwind_command.init().install().watch()
def clean_tailwindcss(self):
"""
Clean up generated files
Returns:
None
"""
self.tailwind_command.clean()
def main():
"""
CLI tool for the Dash TailwindCSS plugin
"""
cli = _TailwindCLI()
cli.run()