create-wordpress-theme-ts 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codefront Technologies LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # Create WP Theme TS
2
+
3
+ A CLI tool to scaffold a custom WordPress theme powered by React, TypeScript, and Vite.
4
+
5
+ Build your WordPress theme as a modern React single-page application, then deploy it as a standard WordPress theme zip file.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ npx create-wp-theme-ts my-site
11
+ cd my-site
12
+ npm run dev
13
+ ```
14
+
15
+ ## Features
16
+
17
+ - ⚔ **Vite** - Lightning-fast HMR and optimized builds
18
+ - āš›ļø **React 18** - Latest React with concurrent features
19
+ - šŸ“˜ **TypeScript** - Full type safety out of the box
20
+ - šŸ’… **styled-components** - CSS-in-JS styling
21
+ - šŸŽØ **Font Awesome** - Icon library included
22
+ - šŸ”§ **ESLint + Prettier** - Code quality tools pre-configured
23
+ - šŸ“¦ **WordPress Theme Zip** - Production build outputs a ready-to-deploy theme
24
+
25
+ ## Usage
26
+
27
+ ### Interactive Mode
28
+
29
+ Simply run without arguments to enter interactive mode:
30
+
31
+ ```bash
32
+ npx create-wp-theme-ts
33
+ ```
34
+
35
+ You'll be prompted for:
36
+
37
+ - Project name
38
+ - WordPress theme name
39
+ - Author name
40
+ - Project description
41
+
42
+ ### Command Line Arguments
43
+
44
+ ```bash
45
+ npx create-wp-theme-ts <project-name> [options]
46
+ ```
47
+
48
+ **Options:**
49
+
50
+ - `--skip-install` - Skip automatic npm install
51
+ - `--skip-git` - Skip git repository initialization
52
+
53
+ **Examples:**
54
+
55
+ ```bash
56
+ # Create with custom name
57
+ npx create-wp-theme-ts my-awesome-theme
58
+
59
+ # Skip npm install (useful if you want to use yarn/pnpm)
60
+ npx create-wp-theme-ts my-site --skip-install
61
+
62
+ # Skip both install and git init
63
+ npx create-wp-theme-ts my-site --skip-install --skip-git
64
+ ```
65
+
66
+ ## Project Structure
67
+
68
+ After scaffolding, your project will have this structure:
69
+
70
+ ```
71
+ my-site/
72
+ ā”œā”€ā”€ php/ # WordPress PHP files
73
+ │ ā”œā”€ā”€ functions.php # Theme functions
74
+ │ └── index.php # Main WordPress template
75
+ ā”œā”€ā”€ public/ # Static assets
76
+ │ ā”œā”€ā”€ images/ # Image files
77
+ │ └── style.css # WordPress theme stylesheet
78
+ ā”œā”€ā”€ src/ # React source code
79
+ │ ā”œā”€ā”€ components/ # React components
80
+ │ │ └── Layout.tsx # Main layout component
81
+ │ ā”œā”€ā”€ pages/ # Page components
82
+ │ │ ā”œā”€ā”€ Home.tsx # Home page
83
+ │ │ ā”œā”€ā”€ About.tsx # About page
84
+ │ │ └── NotFound.tsx # 404 page
85
+ │ ā”œā”€ā”€ styles/ # CSS files
86
+ │ │ └── global.css # Global styles
87
+ │ ā”œā”€ā”€ App.tsx # Main App component
88
+ │ ā”œā”€ā”€ index.tsx # Entry point
89
+ │ └── vite-env.d.ts # Vite type definitions
90
+ ā”œā”€ā”€ .eslintrc.json # ESLint configuration
91
+ ā”œā”€ā”€ .gitignore # Git ignore rules
92
+ ā”œā”€ā”€ .prettierrc # Prettier configuration
93
+ ā”œā”€ā”€ index.html # HTML template
94
+ ā”œā”€ā”€ package.json # Project dependencies
95
+ ā”œā”€ā”€ tsconfig.json # TypeScript configuration
96
+ └── vite.config.ts # Vite configuration
97
+ ```
98
+
99
+ ## Available Scripts
100
+
101
+ In your generated project, you can run:
102
+
103
+ ### `npm run dev`
104
+
105
+ Starts the development server at [http://localhost:8080](http://localhost:8080).
106
+
107
+ Features hot module replacement for instant feedback while developing.
108
+
109
+ ### `npm run build`
110
+
111
+ Creates an unminified build in the `dist/` folder.
112
+
113
+ ### `npm run build:dev`
114
+
115
+ Creates a development build with source maps.
116
+
117
+ ### `npm run build:prod`
118
+
119
+ Creates an optimized production build and generates `wordpress-custom-theme.zip` in the `dist/` folder.
120
+
121
+ ### `npm run preview`
122
+
123
+ Preview the production build locally before deploying.
124
+
125
+ ## Deploying to WordPress
126
+
127
+ 1. Run the production build:
128
+
129
+ ```bash
130
+ npm run build:prod
131
+ ```
132
+
133
+ 2. Locate the generated zip file:
134
+
135
+ ```
136
+ dist/wordpress-custom-theme.zip
137
+ ```
138
+
139
+ 3. In your WordPress admin panel:
140
+ - Go to **Appearance → Themes → Add New → Upload Theme**
141
+ - Upload `wordpress-custom-theme.zip`
142
+ - Click **Install Now**
143
+ - Click **Activate**
144
+
145
+ ## Customization
146
+
147
+ ### Adding New Pages
148
+
149
+ 1. Create a new component in `src/pages/`:
150
+
151
+ ```tsx
152
+ // src/pages/Contact.tsx
153
+ function Contact() {
154
+ return <div>Contact Page</div>;
155
+ }
156
+ export default Contact;
157
+ ```
158
+
159
+ 2. Add the route in `src/App.tsx`:
160
+
161
+ ```tsx
162
+ import Contact from './pages/Contact';
163
+
164
+ // Inside Routes:
165
+ <Route path="contact" element={<Contact />} />;
166
+ ```
167
+
168
+ 3. Add navigation link in `src/components/Layout.tsx`:
169
+ ```tsx
170
+ <NavLink to="/contact">Contact</NavLink>
171
+ ```
172
+
173
+ ### Styling
174
+
175
+ This template uses [styled-components](https://styled-components.com/) for styling:
176
+
177
+ ```tsx
178
+ import styled from 'styled-components';
179
+
180
+ const Button = styled.button`
181
+ background: #4a9eff;
182
+ color: white;
183
+ padding: 0.5rem 1rem;
184
+ border: none;
185
+ border-radius: 4px;
186
+ cursor: pointer;
187
+
188
+ &:hover {
189
+ background: #3a8eef;
190
+ }
191
+ `;
192
+ ```
193
+
194
+ ### Environment Variables
195
+
196
+ Create a `.env` file in your project root:
197
+
198
+ ```env
199
+ VITE_API_URL=https://api.example.com
200
+ VITE_APP_TITLE=My Site
201
+ ```
202
+
203
+ Access them in your code:
204
+
205
+ ```tsx
206
+ const apiUrl = import.meta.env.VITE_API_URL;
207
+ ```
208
+
209
+ **Note:** Only variables prefixed with `VITE_` are exposed to your code.
210
+
211
+ ## WordPress Theme Customization
212
+
213
+ ### Theme Header
214
+
215
+ Edit `public/style.css` to update the WordPress theme metadata:
216
+
217
+ ```css
218
+ /*
219
+ Theme Name: Your Theme Name
220
+ Author: Your Name
221
+ Author URI: https://yoursite.com
222
+ Description: Your theme description
223
+ Version: 1.0.0
224
+ License: MIT
225
+ */
226
+ ```
227
+
228
+ ### Adding WordPress Features
229
+
230
+ Edit `php/functions.php` to add WordPress functionality:
231
+
232
+ ```php
233
+ // Register a navigation menu
234
+ register_nav_menus(array(
235
+ 'primary' => __('Primary Menu'),
236
+ ));
237
+
238
+ // Add custom post type support
239
+ // Add widget areas
240
+ // etc.
241
+ ```
242
+
243
+ ## Contributing
244
+
245
+ Contributions are welcome! Please feel free to submit a Pull Request.
246
+
247
+ ## License
248
+
249
+ MIT
package/bin/index.js ADDED
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import inquirer from 'inquirer';
5
+ import chalk from 'chalk';
6
+ import ora from 'ora';
7
+ import fs from 'fs-extra';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ import { execSync } from 'child_process';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+
15
+ const TEMPLATE_DIR = path.join(__dirname, '..', 'template');
16
+
17
+ program
18
+ .name('create-wp-theme-ts')
19
+ .description('Create a new WordPress theme powered by React, TypeScript, and Vite')
20
+ .version('1.0.0')
21
+ .argument('[project-name]', 'Name of the project')
22
+ .option('--skip-install', 'Skip npm install')
23
+ .option('--skip-git', 'Skip git initialization')
24
+ .action(async (projectName, options) => {
25
+ console.log(chalk.blue.bold('\nšŸš€ Create WP React Site\n'));
26
+
27
+ // If no project name provided, prompt for it
28
+ if (!projectName) {
29
+ const answers = await inquirer.prompt([
30
+ {
31
+ type: 'input',
32
+ name: 'projectName',
33
+ message: 'What is your project name?',
34
+ default: 'my-wp-site',
35
+ validate: (input) => {
36
+ if (/^[a-zA-Z0-9-_]+$/.test(input)) return true;
37
+ return 'Project name may only include letters, numbers, dashes, and underscores.';
38
+ },
39
+ },
40
+ ]);
41
+ projectName = answers.projectName;
42
+ }
43
+
44
+ // Gather additional project info
45
+ const projectInfo = await inquirer.prompt([
46
+ {
47
+ type: 'input',
48
+ name: 'themeName',
49
+ message: 'What is your WordPress theme name?',
50
+ default: projectName
51
+ .split('-')
52
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
53
+ .join(' '),
54
+ },
55
+ {
56
+ type: 'input',
57
+ name: 'author',
58
+ message: 'Author name:',
59
+ default: '',
60
+ },
61
+ {
62
+ type: 'input',
63
+ name: 'description',
64
+ message: 'Project description:',
65
+ default: 'A custom WordPress theme built with React and Vite',
66
+ },
67
+ ]);
68
+
69
+ const targetDir = path.resolve(process.cwd(), projectName);
70
+
71
+ // Check if directory already exists
72
+ if (fs.existsSync(targetDir)) {
73
+ const { overwrite } = await inquirer.prompt([
74
+ {
75
+ type: 'confirm',
76
+ name: 'overwrite',
77
+ message: `Directory ${projectName} already exists. Overwrite?`,
78
+ default: false,
79
+ },
80
+ ]);
81
+
82
+ if (!overwrite) {
83
+ console.log(chalk.yellow('\nāš ļø Operation cancelled.\n'));
84
+ process.exit(0);
85
+ }
86
+
87
+ await fs.remove(targetDir);
88
+ }
89
+
90
+ // Copy template files
91
+ const copySpinner = ora('Creating project structure...').start();
92
+ try {
93
+ await fs.copy(TEMPLATE_DIR, targetDir);
94
+ copySpinner.succeed('Project structure created');
95
+ } catch (error) {
96
+ copySpinner.fail('Failed to create project structure');
97
+ console.error(chalk.red(error.message));
98
+ process.exit(1);
99
+ }
100
+
101
+ // Update package.json with project info
102
+ const updateSpinner = ora('Customizing project files...').start();
103
+ try {
104
+ const packageJsonPath = path.join(targetDir, 'package.json');
105
+ const packageJson = await fs.readJson(packageJsonPath);
106
+ packageJson.name = projectName;
107
+ packageJson.description = projectInfo.description;
108
+ packageJson.author = projectInfo.author;
109
+ await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
110
+
111
+ // Update style.css with theme info
112
+ const styleCssPath = path.join(targetDir, 'public', 'style.css');
113
+ if (await fs.pathExists(styleCssPath)) {
114
+ let styleContent = await fs.readFile(styleCssPath, 'utf-8');
115
+ styleContent = styleContent
116
+ .replace(/Theme Name:.*/, `Theme Name: ${projectInfo.themeName}`)
117
+ .replace(/Author:.*/, `Author: ${projectInfo.author}`)
118
+ .replace(/Description:.*/, `Description: ${projectInfo.description}`);
119
+ await fs.writeFile(styleCssPath, styleContent);
120
+ }
121
+
122
+ // Update index.html title
123
+ const indexHtmlPath = path.join(targetDir, 'index.html');
124
+ if (await fs.pathExists(indexHtmlPath)) {
125
+ let htmlContent = await fs.readFile(indexHtmlPath, 'utf-8');
126
+ htmlContent = htmlContent.replace(
127
+ /<title>.*<\/title>/,
128
+ `<title>${projectInfo.themeName}</title>`
129
+ );
130
+ htmlContent = htmlContent.replace(
131
+ /<meta property="og:title" content=".*" \/>/,
132
+ `<meta property="og:title" content="${projectInfo.themeName}" />`
133
+ );
134
+ await fs.writeFile(indexHtmlPath, htmlContent);
135
+ }
136
+
137
+ updateSpinner.succeed('Project files customized');
138
+ } catch (error) {
139
+ updateSpinner.fail('Failed to customize project files');
140
+ console.error(chalk.red(error.message));
141
+ }
142
+
143
+ // Initialize git repository
144
+ if (!options.skipGit) {
145
+ const gitSpinner = ora('Initializing git repository...').start();
146
+ try {
147
+ execSync('git init', { cwd: targetDir, stdio: 'ignore' });
148
+ gitSpinner.succeed('Git repository initialized');
149
+ } catch (error) {
150
+ gitSpinner.fail('Failed to initialize git repository');
151
+ }
152
+ }
153
+
154
+ // Install dependencies
155
+ if (!options.skipInstall) {
156
+ const installSpinner = ora('Installing dependencies (this may take a few minutes)...').start();
157
+ try {
158
+ execSync('npm install', { cwd: targetDir, stdio: 'ignore' });
159
+ installSpinner.succeed('Dependencies installed');
160
+ } catch (error) {
161
+ installSpinner.fail('Failed to install dependencies');
162
+ console.log(chalk.yellow('\nYou can install dependencies manually by running: npm install\n'));
163
+ }
164
+ }
165
+
166
+ // Success message
167
+ console.log(chalk.green.bold('\nāœ… Project created successfully!\n'));
168
+ console.log(chalk.white('Next steps:\n'));
169
+ console.log(chalk.cyan(` cd ${projectName}`));
170
+ if (options.skipInstall) {
171
+ console.log(chalk.cyan(' npm install'));
172
+ }
173
+ console.log(chalk.cyan(' npm run dev # Start development server'));
174
+ console.log(chalk.cyan(' npm run build:prod # Build for production\n'));
175
+ console.log(chalk.gray('The production build creates a WordPress theme zip file in the dist/ folder.'));
176
+ console.log(chalk.gray('Upload it via WordPress Admin > Appearance > Themes > Add New > Upload Theme\n'));
177
+ });
178
+
179
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "create-wordpress-theme-ts",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool to scaffold a WordPress theme powered by React, TypeScript, and Vite",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "create-wordpress-theme-ts": "./bin/index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [
14
+ "wordpress",
15
+ "react",
16
+ "vite",
17
+ "typescript",
18
+ "theme",
19
+ "scaffold",
20
+ "generator",
21
+ "cli"
22
+ ],
23
+ "author": "Codefront Technologies LLC",
24
+ "license": "MIT",
25
+ "files": [
26
+ "bin",
27
+ "template"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/codefront-technologies/create-wp-theme-ts"
32
+ },
33
+ "engines": {
34
+ "node": ">=16.0.0"
35
+ },
36
+ "dependencies": {
37
+ "chalk": "^5.3.0",
38
+ "commander": "^12.0.0",
39
+ "fs-extra": "^11.2.0",
40
+ "inquirer": "^9.2.12",
41
+ "ora": "^8.0.1"
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ node_modules/
2
+ dist/
@@ -0,0 +1,34 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:react/recommended",
10
+ "plugin:react-hooks/recommended",
11
+ "plugin:@typescript-eslint/recommended",
12
+ "plugin:prettier/recommended"
13
+ ],
14
+ "parser": "@typescript-eslint/parser",
15
+ "parserOptions": {
16
+ "ecmaFeatures": {
17
+ "jsx": true
18
+ },
19
+ "ecmaVersion": "latest",
20
+ "sourceType": "module"
21
+ },
22
+ "plugins": ["react", "@typescript-eslint", "prettier"],
23
+ "rules": {
24
+ "react/react-in-jsx-scope": "off",
25
+ "react/no-unescaped-entities": "off",
26
+ "prettier/prettier": "error",
27
+ "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
28
+ },
29
+ "settings": {
30
+ "react": {
31
+ "version": "detect"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "es5",
6
+ "printWidth": 100
7
+ }
@@ -0,0 +1,21 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>My WordPress Site</title>
7
+ <meta name="description" content="A custom WordPress theme built with React and Vite" />
8
+ <meta name="author" content="" />
9
+ <meta property="og:title" content="My WordPress Site" />
10
+ <meta property="og:description" content="A custom WordPress theme built with React and Vite" />
11
+ <meta property="og:type" content="website" />
12
+ <link rel="icon" href="/images/favicon.ico" />
13
+ </head>
14
+
15
+ <body>
16
+ <main>
17
+ <div id="root"></div>
18
+ </main>
19
+ <script type="module" src="/src/index.tsx"></script>
20
+ </body>
21
+ </html>