wp-uikit-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WP-UIkit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
package/README.md ADDED
@@ -0,0 +1,330 @@
1
+ <div align="center">
2
+
3
+ # โšก WP-UIkit CLI
4
+
5
+ **Scaffold. Debug. Clean. Deploy.**
6
+ A blazing-fast command-line toolkit for building **SF Framework** & **SF Widget** (Elementor) plugin widgets and traits โ€” in seconds, not minutes.
7
+
8
+ [![npm version](https://img.shields.io/npm/v/wp-uikit-cli.svg?style=flat-square&color=cb3837&logo=npm)](https://www.npmjs.com/package/wp-uikit-cli)
9
+ [![npm downloads](https://img.shields.io/npm/dm/wp-uikit-cli.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/wp-uikit-cli)
10
+ [![license](https://img.shields.io/npm/l/wp-uikit-cli.svg?style=flat-square&color=green)](./LICENSE)
11
+ [![node](https://img.shields.io/node/v/wp-uikit-cli.svg?style=flat-square)](https://nodejs.org)
12
+
13
+ </div>
14
+
15
+ ---
16
+
17
+ ## ๐Ÿ“– Table of Contents
18
+
19
+ - [โœจ Features](#-features)
20
+ - [๐Ÿ“ฆ Installation](#-installation)
21
+ - [๐Ÿš€ Quick Start](#-quick-start)
22
+ - [๐Ÿงญ Commands](#-commands)
23
+ - [`sf create`](#-sf-create)
24
+ - [`sf clean`](#-sf-clean)
25
+ - [`sf debug`](#-sf-debug)
26
+ - [`sf deploy`](#-sf-deploy)
27
+ - [`sf zip`](#-sf-zip)
28
+ - [๐Ÿงฉ Traits System](#-traits-system)
29
+ - [๐Ÿ“ Generated File Structure](#-generated-file-structure)
30
+ - [โš™๏ธ How It Works](#๏ธ-how-it-works)
31
+ - [๐Ÿ› ๏ธ Requirements](#๏ธ-requirements)
32
+ - [โ“ FAQ](#-faq)
33
+ - [๐Ÿค Contributing](#-contributing)
34
+ - [๐Ÿ“„ License](#-license)
35
+
36
+ ---
37
+
38
+ ## โœจ Features
39
+
40
+ | | Feature | Description |
41
+ |---|---|---|
42
+ | ๐Ÿงฑ | **Widget Scaffolding** | Interactively generate a fully wired Elementor widget (`.php`, `.css`, `.js`, docs) from stubs. |
43
+ | ๐Ÿงฉ | **Trait Scaffolding** | Create reusable PHP traits and auto-register them so widgets can consume shared controls. |
44
+ | ๐Ÿ”— | **Smart Trait Wiring** | Automatically parses trait method signatures and injects correct `use` statements + method calls into your widget class. |
45
+ | ๐Ÿงน | **String Localization** | `sf clean` auto-wraps raw strings in `esc_html__()` with the `sf-widget` text-domain โ€” for one widget or the whole project. |
46
+ | ๐Ÿ› | **One-Line WP Debugging** | Toggle `WP_DEBUG`, `WP_DEBUG_LOG`, and `WP_DEBUG_DISPLAY` in `wp-config.php` instantly. |
47
+ | ๐Ÿš€ | **One-Command Deploy** | Minifies JS/CSS, disables dev-mode flags, strips `.gitignore`, zips the plugin, and updates `update.json` โ€” all in one go. |
48
+ | ๐Ÿ“ฆ | **Instant Zipping** | Package your current working directory into a distributable `.zip` archive. |
49
+ | โšก | **Lazy-Loaded Dependencies** | Heavy libs (`adm-zip`, `terser`, `clean-css`) load on-demand โ€” keeping every command snappy. |
50
+ | ๐ŸŽจ | **Beautiful CLI UX** | ASCII banners, spinners, colorized tables, and clear success/error states via `figlet`, `ora`, and `chalk`. |
51
+
52
+ ---
53
+
54
+ ## ๐Ÿ“ฆ Installation
55
+
56
+ Install globally to use the `sf` command anywhere:
57
+
58
+ ```bash
59
+ npm install -g wp-uikit-cli
60
+ ```
61
+
62
+ Or run it on-demand without installing:
63
+
64
+ ```bash
65
+ npx wp-uikit-cli create
66
+ ```
67
+
68
+ > ๐Ÿ’ก **Tip:** Run `sf --help` anytime to see all available commands.
69
+
70
+ ---
71
+
72
+ ## ๐Ÿš€ Quick Start
73
+
74
+ ```bash
75
+ # 1๏ธโƒฃ Navigate to your plugin root (e.g. sf-widget/)
76
+ cd sf-widget
77
+
78
+ # 2๏ธโƒฃ Scaffold a new widget or trait interactively
79
+ sf create
80
+
81
+ # 3๏ธโƒฃ Localize all visible strings for WordPress i18n
82
+ sf clean --all
83
+
84
+ # 4๏ธโƒฃ Turn on WP debugging while you build
85
+ sf debug on
86
+
87
+ # 5๏ธโƒฃ Ship it ๐Ÿšข
88
+ sf deploy --widget
89
+ ```
90
+
91
+ ---
92
+
93
+ ## ๐Ÿงญ Commands
94
+
95
+ ### ๐Ÿงฑ `sf create`
96
+
97
+ Interactively scaffold a **Widget** or a **Trait**.
98
+
99
+ ```bash
100
+ sf create
101
+ ```
102
+
103
+ You'll be walked through prompts like:
104
+
105
+ ```
106
+ ? Widget name (e.g. Heading, Icon Box): Pricing Table
107
+ ? Create CSS file? (Y/n)
108
+ ? Create JS file? (y/N)
109
+ ? Elementor icon class (e.g. eicon-star): eicon-price-table
110
+ ? Select traits to include: (Use arrow keys, <space> to select)
111
+ โ—‰ ButtonTrait
112
+ โ—‰ HeadingTrait
113
+ โ—ฏ RatingTrait
114
+ ```
115
+
116
+ The CLI then:
117
+ - โœ… Generates `widgets/<slug>.php` from `widget.php.stub`
118
+ - โœ… Optionally generates CSS/JS companions
119
+ - โœ… Auto-detects selected traits' PHP method signatures
120
+ - โœ… Injects correct `use` statements, `register_*_controls()`, and `render_*()` calls
121
+ - โœ… Warns before overwriting existing files
122
+
123
+ ---
124
+
125
+ ### ๐Ÿงน `sf clean`
126
+
127
+ Wrap raw, user-visible strings in `esc_html__()` with the `sf-widget` text domain โ€” a must for WordPress i18n and plugin review compliance.
128
+
129
+ ```bash
130
+ sf clean <widgetName> # Clean a single widget
131
+ sf clean --all # Clean every widget & print a report
132
+ ```
133
+
134
+ **Sample output:**
135
+
136
+ ```
137
+ ๐Ÿ“Š Localization Report
138
+
139
+ โ”‚ Widget โ”‚ Status โ”‚ esc_html Count โ”‚ Domain โ”‚
140
+ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
141
+ โ”‚ pricing-table โ”‚ โœ“ Done โ”‚ 12 โ”‚ sf-widget โ”‚
142
+ โ”‚ testimonial โ”‚ โœ“ Done โ”‚ 7 โ”‚ sf-widget โ”‚
143
+
144
+ โœจ Summary
145
+ โ”œโ”€ Total widgets processed: 2
146
+ โ”œโ”€ Total esc_html__() added: 19
147
+ โ””โ”€ Domain used: sf-widget
148
+ ```
149
+
150
+ It intelligently:
151
+ - Normalizes existing `esc_html__()` / `__()` calls to the correct domain
152
+ - Wraps plain `label`, `title`, `description`, `placeholder`, and `raw` strings
153
+ - Avoids double-wrapping already-escaped strings
154
+
155
+ ---
156
+
157
+ ### ๐Ÿ› `sf debug`
158
+
159
+ Toggle WordPress debug mode without ever opening `wp-config.php` yourself.
160
+
161
+ ```bash
162
+ sf debug on # Enables WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY
163
+ sf debug off # Cleanly reverts back to production settings
164
+ ```
165
+
166
+ - ๐Ÿ” Automatically walks up the directory tree to locate `wp-config.php`
167
+ - ๐Ÿ“ Appends/updates the debug block safely without breaking existing config
168
+ - ๐Ÿ“ฃ Prints exactly where to check your logs (`wp-content/debug.log`)
169
+
170
+ ---
171
+
172
+ ### ๐Ÿš€ `sf deploy`
173
+
174
+ The **release button** for `sf-framework` and `sf-widget` plugins.
175
+
176
+ ```bash
177
+ sf deploy --framework # Deploy the SF Framework plugin
178
+ sf deploy --widget # Deploy the SF Widget plugin
179
+ ```
180
+
181
+ You'll be prompted for a **destination folder** and a **new version** (`X.Y.Z`), then the CLI automatically:
182
+
183
+ 1. ๐Ÿ—œ๏ธ Minifies every `.js` file with **Terser** โ†’ `*.min.js`
184
+ 2. ๐ŸŽจ Minifies every `.css` file with **CleanCSS** โ†’ `*.min.css`
185
+ 3. ๐Ÿšฉ Flips the dev-mode constant (`SF_DEVELOPMENT_MODE` / `SF_FRAMEWORK_DEVELOPMENT_MODE`) to `false`
186
+ 4. ๐Ÿงน Removes `.gitignore` (and the `fonts` folder for widget builds)
187
+ 5. ๐Ÿ“ฆ Zips the plugin (excluding `.git`, `node_modules`)
188
+ 6. ๐Ÿ“ค Moves the zip to your destination folder
189
+ 7. ๐Ÿ“ Updates `update.json` with the new version & download URL
190
+ 8. โœ… Prints a full summary + suggested git commands
191
+
192
+ **Sample output:**
193
+
194
+ ```
195
+ โœ” Deploy complete โ€” sf-widget v1.4.0
196
+
197
+ Output
198
+ โ”œโ”€ Zip D:\Releases\sf-widget-1.4.0.zip
199
+ โ””โ”€ JSON D:\Releases\update.json
200
+
201
+ Next steps
202
+ โ”œโ”€ Open the destination folder in your file manager
203
+ โ”œโ”€ Review the changes โ€” check update.json & zip
204
+ โ”œโ”€ Stage all changes: git add .
205
+ โ”œโ”€ Commit: git commit -m "Release sf-widget v1.4.0"
206
+ โ””โ”€ Push: git push
207
+ ```
208
+
209
+ ---
210
+
211
+ ### ๐Ÿ“ฆ `sf zip`
212
+
213
+ Quickly zip the current working directory.
214
+
215
+ ```bash
216
+ sf zip # Uses the current folder name as the zip name
217
+ sf zip my-plugin # Custom output name โ†’ my-plugin.zip
218
+ ```
219
+
220
+ ---
221
+
222
+ ## ๐Ÿงฉ Traits System
223
+
224
+ Traits let you share reusable Elementor controls (buttons, ratings, badges, avatars, progress bars, etc.) across multiple widgets without duplicating code.
225
+
226
+ - Trait files live in `core/includes/traits/*-trait.php`
227
+ - Registered traits are tracked in [`traits.json`](./traits.json)
228
+ - Running `sf create` automatically **syncs** this registry by scanning your traits folder
229
+ - When you attach traits to a widget, the CLI **reads the trait's PHP source**, extracts its `register_*_controls()` / `render_*()` method signatures, and generates matching `use` + call-site code โ€” no manual wiring required
230
+
231
+ <details>
232
+ <summary>๐Ÿ“‹ Example traits already available in this project</summary>
233
+
234
+ `AvatarTrait` ยท `BadgeTrait` ยท `ButtonTrait` ยท `DescriptionTrait` ยท `FancyAnimatedTextTrait` ยท `HeaderTrait` ยท `HeadingTrait` ยท `HtmlSnippetTrait` ยท `ListTrait` ยท `ParagraphTrait` ยท `ProgressbarTrait` ยท `RatingTrait` ยท `RepeaterAvatarTrait` ยท `RepeaterBadgeTrait` ยท `RepeaterButtonTrait` ยท `RepeaterListTrait` ยท `RepeaterRadialProgressbarTrait` ยท ...and more
235
+
236
+ </details>
237
+
238
+ ---
239
+
240
+ ## ๐Ÿ“ Generated File Structure
241
+
242
+ Running `sf create` for a widget named **"Pricing Table"** produces:
243
+
244
+ ```
245
+ ๐Ÿ“ your-plugin/
246
+ โ”œโ”€โ”€ widgets/
247
+ โ”‚ โ””โ”€โ”€ pricing-table.php # Widget class with traits wired in
248
+ โ””โ”€โ”€ assets/
249
+ โ”œโ”€โ”€ css/
250
+ โ”‚ โ””โ”€โ”€ pricing-table.css
251
+ โ””โ”€โ”€ js/
252
+ โ””โ”€โ”€ pricing-table.js
253
+ ```
254
+
255
+ ---
256
+
257
+ ## โš™๏ธ How It Works
258
+
259
+ ```mermaid
260
+ flowchart LR
261
+ A[sf create] --> B{Widget or Trait?}
262
+ B -->|Widget| C[Prompt for name, assets, icon, traits]
263
+ C --> D[Parse selected trait PHP files]
264
+ D --> E[Inject use + register/render calls]
265
+ E --> F[Write from stubs/*.stub]
266
+ B -->|Trait| G[Prompt for trait name]
267
+ G --> H[Write trait.php.stub โ†’ core/includes/traits/]
268
+ ```
269
+
270
+ All generated files come from customizable templates in [`stubs/`](./stubs):
271
+
272
+ | Stub | Purpose |
273
+ |---|---|
274
+ | `widget.php.stub` | Base Elementor widget class |
275
+ | `style.css.stub` | Widget stylesheet |
276
+ | `script.js.stub` | Widget frontend script |
277
+ | `trait.php.stub` | Reusable trait skeleton |
278
+
279
+ ---
280
+
281
+ ## ๐Ÿ› ๏ธ Requirements
282
+
283
+ - **Node.js** โ‰ฅ 16
284
+ - A project following the **SF Framework** / **SF Widget** directory conventions (`widgets/`, `assets/`, `core/includes/traits/`)
285
+ - WordPress + Elementor installation for `sf debug` (looks for `wp-config.php`)
286
+
287
+ ---
288
+
289
+ ## โ“ FAQ
290
+
291
+ <details>
292
+ <summary><strong>Does <code>sf deploy</code> modify my source files permanently?</strong></summary>
293
+ <br>
294
+ Yes โ€” minification replaces original <code>.js</code>/<code>.css</code> files with <code>.min.js</code>/<code>.min.css</code> in your working directory, and the dev-mode flag is flipped to <code>false</code>. Always deploy from a clean git state so you can diff/revert if needed.
295
+ </details>
296
+
297
+ <details>
298
+ <summary><strong>Why does the first command feel slightly slower the very first time?</strong></summary>
299
+ <br>
300
+ Heavy dependencies (<code>adm-zip</code>, <code>terser</code>, <code>clean-css</code>) are <strong>lazy-loaded</strong> only when a command that needs them (<code>deploy</code>, <code>zip</code>) actually runs โ€” keeping <code>create</code>, <code>clean</code>, and <code>debug</code> fast at all times.
301
+ </details>
302
+
303
+ <details>
304
+ <summary><strong>Can I customize the generated widget/trait templates?</strong></summary>
305
+ <br>
306
+ Yes! Edit the files in the <code>stubs/</code> directory. They support <code>{{PLACEHOLDER}}</code> tokens which are replaced at generation time.
307
+ </details>
308
+
309
+ ---
310
+
311
+ ## ๐Ÿค Contributing
312
+
313
+ Contributions, issue reports, and feature ideas are welcome!
314
+
315
+ 1. Fork the repo
316
+ 2. Create a feature branch: `git checkout -b feature/amazing-thing`
317
+ 3. Commit your changes: `git commit -m "Add amazing thing"`
318
+ 4. Push and open a Pull Request
319
+
320
+ ---
321
+
322
+ ## ๐Ÿ“„ License
323
+
324
+ Released under the **[MIT License](./LICENSE)**.
325
+
326
+ <div align="center">
327
+
328
+ Made with โค๏ธ for the **SF Framework** & **SF Widget** ecosystem.
329
+
330
+ </div>