Skip to content

Commit f882b55

Browse files
committed
feat: Add CLI tool to generate WordPress themes from HTML
1 parent 4ec0094 commit f882b55

File tree

17 files changed

+1213
-1429
lines changed

17 files changed

+1213
-1429
lines changed

README.md

Lines changed: 139 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,51 @@
22

33
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md) [![Build Status](https://github.com/ioncakephper/php-theme-gen/actions/workflows/ci.yml/badge.svg)](https://github.com/ioncakephper/php-theme-gen/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/ioncakephper/php-theme-gen/branch/main/graph/badge.svg)](https://codecov.io/gh/ioncakephper/php-theme-gen) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Changelog](https://img.shields.io/badge/changelog-keep_a_changelog-blue.svg)](CHANGELOG.md)
44

5-
A command-line interface (CLI) that generates a WordPress theme structure from a single HTML file. This tool creates `header.php` and `footer.php` files by extracting content from the provided HTML file, using `<!-- wp:file ... -->` and `<!-- /wp:file -->` comment tags to identify the relevant sections.
5+
A command-line interface (CLI) that streamlines WordPress theme development. It generates a complete WordPress theme structure (including `header.php`, `footer.php`, `index.php`, `style.css`, and `functions.php`) from a single HTML file, using `<!-- wp:file ... -->` comment tags for content separation. It also provides a command to quickly scaffold new HTML templates.
66

77
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
88
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
99

1010
## 📚 Table of Contents
1111

12-
- [PHP Theme Generator CLI](#php-theme-generator-cli)
13-
- [📚 Table of Contents](#-table-of-contents)
14-
- [✨ Key Features](#-key-features)
15-
- [🚀 Getting Started](#-getting-started)
16-
- [Prerequisites](#prerequisites)
17-
- [Using this Template](#using-this-template)
18-
- [Method 1: GitHub Template (Recommended)](#method-1-github-template-recommended)
19-
- [Method 2: Using `degit` (for a local copy)](#method-2-using-degit-for-a-local-copy)
20-
- [🚀 Available Scripts](#-available-scripts)
21-
- [Automated Documentation](#automated-documentation)
22-
- [Code Quality \& Formatting](#code-quality--formatting)
23-
- [Core Development](#core-development)
24-
- [The "One-Click" Pre-Commit Workflow](#the-one-click-pre-commit-workflow)
25-
- [A Focus on Quality and Productivity](#a-focus-on-quality-and-productivity)
26-
- [The Cost of Stale Documentation](#the-cost-of-stale-documentation)
27-
- [The Power of Workflow Scripts](#the-power-of-workflow-scripts)
28-
- [📦 Release \& Versioning](#-release--versioning)
29-
- [How it Works](#how-it-works)
30-
- [Creating a New Release](#creating-a-new-release)
31-
- [Your First Release](#your-first-release)
32-
- [📁 Project Structure](#-project-structure)
33-
- [✍️ Linting for Documentation](#️-linting-for-documentation)
34-
- [How to Check for Missing Documentation](#how-to-check-for-missing-documentation)
35-
- [Example](#example)
36-
- [🤝 Contributing](#-contributing)
37-
- [🗺️ Roadmap](#️-roadmap)
38-
- [⚖️ Code of Conduct](#️-code-of-conduct)
39-
- [🙏 Acknowledgements](#-acknowledgements)
40-
- [👨‍💻 About the Author](#-about-the-author)
41-
- [📄 License](#-license)
12+
- [✨ Key Features](#-key-features)
13+
- [🚀 Getting Started](#-getting-started)
14+
- [Prerequisites](#prerequisites)
15+
- [Installation](#installation)
16+
- [🚀 Usage](#-usage)
17+
- [`build` Command](#build-command)
18+
- [`new` Command](#new-command)
19+
- [🚀 Available Scripts](#-available-scripts)
20+
- [Automated Documentation](#automated-documentation)
21+
- [Code Quality & Formatting](#code-quality--formatting)
22+
- [Core Development](#core-development)
23+
- [The "One-Click" Pre-Commit Workflow](#the-one-click-pre-commit-workflow)
24+
- [A Focus on Quality and Productivity](#a-focus-on-quality-and-productivity)
25+
- [The Cost of Stale Documentation](#the-cost-of-stale-documentation)
26+
- [The Power of Workflow Scripts](#the-power-of-workflow-scripts)
27+
- [📦 Release & Versioning](#-release--versioning)
28+
- [How it Works](#how-it-works)
29+
- [Creating a New Release](#creating-a-new-release)
30+
- [Your First Release](#your-first-release)
31+
- [📁 Project Structure](#-project-structure)
32+
- [✍️ Linting for Documentation](#-linting-for-documentation)
33+
- [How to Check for Missing Documentation](#how-to-check-for-missing-documentation)
34+
- [Example](#example)
35+
- [🤝 Contributing](#-contributing)
36+
- [🗺️ Roadmap](#-roadmap)
37+
- [⚖️ Code of Conduct](#-code-of-conduct)
38+
- [🙏 Acknowledgements](#-acknowledgements)
39+
- [👨‍💻 About the Author](#-about-the-author)
40+
- [📄 License](#-license)
4241

4342
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4443

4544
## ✨ Key Features
4645

46+
- **WordPress Theme Generation**: Quickly generate a full WordPress theme (including `header.php`, `footer.php`, `index.php`, `style.css`, and `functions.php`) from a single HTML file.
47+
- **HTML-to-PHP Conversion**: Intelligently extracts content based on `<!-- wp:file ... -->` and `<!-- /wp:file -->` HTML comment tags to create corresponding PHP template files.
48+
- **Customizable Theme Metadata**: Easily define theme name, author, description, and other details via CLI options, which are automatically included in `style.css` and PHP file headers.
49+
- **HTML Template Scaffolding**: Generate new HTML template files pre-configured with `wp:file` tags, accelerating new page development.
4750
- **Comprehensive Testing Suite**: Pre-configured with Jest for unit and integration testing. Includes coverage reporting out-of-the-box to ensure code quality.
4851
- **Automated Code Quality**: A strict, pre-configured setup using ESLint and Prettier to catch errors, enforce best practices, and maintain a consistent code style across all files (`.js`, `.md`, `.json`).
4952
- **Enforced Documentation Standards**: Integrated `eslint-plugin-jsdoc` to require JSDoc comments for all functions, improving code clarity and long-term maintainability.
@@ -59,42 +62,96 @@ A command-line interface (CLI) that generates a WordPress theme structure from a
5962

6063
- Node.js version 18.0.0 or higher
6164

62-
### Using this Template
65+
## Installation
6366

64-
There are two recommended ways to use this template to start your project.
67+
1. Install the package globally (recommended):
6568

66-
#### Method 1: GitHub Template (Recommended)
69+
```bash
70+
npm install -g php-theme-gen
71+
```
6772

68-
This is the best approach for creating a new repository on GitHub that is linked to this template.
73+
The `phpgen` app is available globally. In any folder on your computer, check it runs:
6974

70-
1. Click the green **"Use this template"** button on the [main repository page](https://github.com/ioncakephper/php-theme-gen).
71-
2. Select **"Create a new repository"**.
72-
3. Give your new repository a name and description, then create it.
73-
4. Clone your newly created repository to your local machine, replacing `YOUR_USERNAME` and `YOUR_REPOSITORY_NAME`:
74-
```bash
75-
git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git
76-
```
77-
5. Navigate into the project directory and install the dependencies:
78-
```bash
79-
cd YOUR_REPOSITORY_NAME
80-
npm install
81-
```
82-
6. You're all set! Start building your application in the `src` directory.
75+
```bash
76+
phpgen -V
77+
```
8378

84-
#### Method 2: Using `degit` (for a local copy)
79+
2. Execute the package directly, using the `npx` command:
8580

86-
If you want a clean copy of the template files on your local machine without the full Git history, you can use `degit`.
81+
```bash
82+
npx php-theme-gen [options] [command] [arguments]
83+
84+
# e.g. for help
85+
# npx php-theme-gen -h
86+
87+
# e.g. to build theme from index.html
88+
# npx php-theme-gen build demo/index.html --output demo/mytheme
89+
```
90+
91+
## 🚀 Usage
92+
93+
The `php-theme-gen` CLI tool allows you to quickly generate a WordPress theme structure from a single HTML file.
94+
95+
### `build` Command
96+
97+
The `build` command is used to process your HTML file and generate the theme files.
98+
99+
```bash
100+
node src/index.js build <sourceFile> [options]
101+
```
102+
103+
**Arguments:**
104+
105+
- `<sourceFile>`: The path to your source HTML file. This file should contain `<!-- wp:file name="header" -->` and `<!-- wp:file name="footer" -->` HTML comments to delineate the header and footer sections.
106+
107+
**Options:**
108+
109+
- `-o, --output <dir>`: The output directory for the generated theme files. Defaults to `dist`.
110+
- `--themeName <name>`: The name of your WordPress theme. This will be used in the theme's `style.css` and PHP file headers. Defaults to `MyTheme`.
111+
- `--themeURI <uri>`: The URI of your theme.
112+
- `--author <name>`: The author of the theme.
113+
- `--authorURI <uri>`: The author's URI.
114+
- `--description <text>`: A brief description of your theme.
115+
- `--tags <tags>`: Comma-separated tags for your theme (e.g., `blog, responsive`).
116+
117+
**Example:**
118+
119+
To generate a theme from `demo/index.html` into the `demo/mytheme` directory with a custom theme name:
120+
121+
```bash
122+
node src/index.js build demo/index.html --output demo/mytheme --themeName "My Elegant Theme" --author "Your Name" --description "An elegant WordPress theme."
123+
```
124+
125+
This command will create the following files in `demo/mytheme`:
126+
127+
- `header.php`
128+
- `footer.php`
129+
- `index.php` (or the basename of your source file, e.g., `demo.php`)
130+
- `style.css`
131+
132+
### `new` Command
133+
134+
The `new` command generates a new HTML template file with basic WordPress theme tags. This is useful for quickly starting a new theme development.
135+
136+
```bash
137+
node src/index.js new <templateName> [options]
138+
```
87139

88-
1. Run the following command in your terminal, replacing `my-new-project` with your desired folder name:
89-
```bash
90-
npx degit ioncakephper/php-theme-gen my-new-project
91-
```
92-
2. Navigate into your new project directory and install the dependencies:
93-
```bash
94-
cd my-new-project
95-
npm install
96-
```
97-
3. You're all set! You can now initialize a new Git repository (`git init`) and start building.
140+
**Arguments:**
141+
142+
- `<templateName>`: The name of the HTML template file to create (e.g., `my-page`). The tool will create `<templateName>.html`.
143+
144+
**Options:**
145+
146+
- `-o, --output <dir>`: The output directory for the new template file. Defaults to the current directory (`.`).
147+
148+
**Example:**
149+
150+
To create a new HTML template named `about-us.html` in the `templates` directory:
151+
152+
```bash
153+
node src/index.js new about-us --output templates
154+
```
98155

99156
## 🚀 Available Scripts
100157

@@ -191,14 +248,35 @@ For more details, refer to the [release-please documentation](https://github.com
191248

192249
```plaintext
193250
.
251+
├── -p/
252+
194253
├── .github/ # GitHub Actions workflows
195254
│ └── workflows/
196255
│ ├── ci.yml # Continuous Integration (CI) workflow
197256
│ ├── publish.yml
198257
│ └── release-please.yml
258+
├── .qodo/
259+
260+
├── demo/
261+
│ ├── mytheme/
262+
│ │ ├── footer.php
263+
│ │ ├── header.php
264+
│ │ ├── index.php
265+
│ │ └── style.css
266+
│ └── index.html
199267
├── src/ # Source code
200-
│ └── index.js # Main application entry point
268+
│ ├── commands/
269+
│ │ ├── build.js
270+
│ │ └── new.js
271+
│ ├── utils/
272+
│ │ ├── createThemeFile.js
273+
│ │ └── loadCommands.js
274+
│ ├── cli.js
275+
│ ├── index.js # Main application entry point
276+
│ └── program.js
201277
├── tests/
278+
│ ├── utils/
279+
│ │ └── createThemeFile.test.js
202280
│ └── index.test.js
203281
├── .eslintignore # Files/folders for ESLint to ignore
204282
├── .eslintrc.json # ESLint configuration

0 commit comments

Comments
 (0)