create-wordpress-theme-ts 1.0.0 → 1.0.2

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/bin/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import { program } from 'commander';
4
4
  import inquirer from 'inquirer';
@@ -7,13 +7,43 @@ import ora from 'ora';
7
7
  import fs from 'fs-extra';
8
8
  import path from 'path';
9
9
  import { fileURLToPath } from 'url';
10
- import { execSync } from 'child_process';
10
+ import { execSync, spawn } from 'child_process';
11
11
 
12
12
  const __filename = fileURLToPath(import.meta.url);
13
13
  const __dirname = path.dirname(__filename);
14
14
 
15
15
  const TEMPLATE_DIR = path.join(__dirname, '..', 'template');
16
16
 
17
+ // Files and directories to ignore when copying the template
18
+ const IGNORED_PATTERNS = [
19
+ 'node_modules',
20
+ '.git',
21
+ 'dist',
22
+ '.DS_Store',
23
+ 'Thumbs.db',
24
+ '*.log',
25
+ '.eslintcache',
26
+ ];
27
+
28
+ // Filter function to exclude ignored files/directories
29
+ function shouldCopyFile(src) {
30
+ const basename = path.basename(src);
31
+
32
+ for (const pattern of IGNORED_PATTERNS) {
33
+ // Handle glob patterns with *
34
+ if (pattern.includes('*')) {
35
+ const regex = new RegExp('^' + pattern.replace(/\./g, '\\.').replace(/\*/g, '.*') + '$');
36
+ if (regex.test(basename)) {
37
+ return false;
38
+ }
39
+ } else if (basename === pattern) {
40
+ return false;
41
+ }
42
+ }
43
+
44
+ return true;
45
+ }
46
+
17
47
  program
18
48
  .name('create-wp-theme-ts')
19
49
  .description('Create a new WordPress theme powered by React, TypeScript, and Vite')
@@ -90,7 +120,7 @@ program
90
120
  // Copy template files
91
121
  const copySpinner = ora('Creating project structure...').start();
92
122
  try {
93
- await fs.copy(TEMPLATE_DIR, targetDir);
123
+ await fs.copy(TEMPLATE_DIR, targetDir, { filter: shouldCopyFile });
94
124
  copySpinner.succeed('Project structure created');
95
125
  } catch (error) {
96
126
  copySpinner.fail('Failed to create project structure');
@@ -153,13 +183,31 @@ program
153
183
 
154
184
  // Install dependencies
155
185
  if (!options.skipInstall) {
156
- const installSpinner = ora('Installing dependencies (this may take a few minutes)...').start();
186
+ const installSpinner = ora(
187
+ 'Installing dependencies (this may take a few minutes)...'
188
+ ).start();
157
189
  try {
158
- execSync('npm install', { cwd: targetDir, stdio: 'ignore' });
190
+ await new Promise((resolve, reject) => {
191
+ const npmInstall = spawn('npm install', {
192
+ cwd: targetDir,
193
+ stdio: 'ignore',
194
+ shell: true,
195
+ });
196
+ npmInstall.on('close', (code) => {
197
+ if (code === 0) {
198
+ resolve();
199
+ } else {
200
+ reject(new Error(`npm install exited with code ${code}`));
201
+ }
202
+ });
203
+ npmInstall.on('error', reject);
204
+ });
159
205
  installSpinner.succeed('Dependencies installed');
160
206
  } catch (error) {
161
207
  installSpinner.fail('Failed to install dependencies');
162
- console.log(chalk.yellow('\nYou can install dependencies manually by running: npm install\n'));
208
+ console.log(
209
+ chalk.yellow('\nYou can install dependencies manually by running: npm install\n')
210
+ );
163
211
  }
164
212
  }
165
213
 
@@ -172,8 +220,12 @@ program
172
220
  }
173
221
  console.log(chalk.cyan(' npm run dev # Start development server'));
174
222
  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'));
223
+ console.log(
224
+ chalk.gray('The production build creates a WordPress theme zip file in the dist/ folder.')
225
+ );
226
+ console.log(
227
+ chalk.gray('Upload it via WordPress Admin > Appearance > Themes > Add New > Upload Theme\n')
228
+ );
177
229
  });
178
230
 
179
231
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wordpress-theme-ts",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CLI tool to scaffold a WordPress theme powered by React, TypeScript, and Vite",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/template/.env ADDED
File without changes
@@ -0,0 +1,71 @@
1
+ import js from '@eslint/js';
2
+ import typescript from '@typescript-eslint/eslint-plugin';
3
+ import tsParser from '@typescript-eslint/parser';
4
+ import react from 'eslint-plugin-react';
5
+ import reactHooks from 'eslint-plugin-react-hooks';
6
+ import prettier from 'eslint-config-prettier';
7
+
8
+ export default [
9
+ {
10
+ ignores: ['node_modules/**', 'dist/**', '*.config.js', '*.config.ts'],
11
+ },
12
+ js.configs.recommended,
13
+ {
14
+ files: ['**/*.{ts,tsx}'],
15
+ languageOptions: {
16
+ parser: tsParser,
17
+ parserOptions: {
18
+ ecmaVersion: 'latest',
19
+ sourceType: 'module',
20
+ ecmaFeatures: {
21
+ jsx: true,
22
+ },
23
+ },
24
+ globals: {
25
+ // Browser globals
26
+ window: 'readonly',
27
+ document: 'readonly',
28
+ console: 'readonly',
29
+ setTimeout: 'readonly',
30
+ clearTimeout: 'readonly',
31
+ setInterval: 'readonly',
32
+ clearInterval: 'readonly',
33
+ fetch: 'readonly',
34
+ URL: 'readonly',
35
+ HTMLElement: 'readonly',
36
+ HTMLInputElement: 'readonly',
37
+ HTMLTextAreaElement: 'readonly',
38
+ Event: 'readonly',
39
+ MouseEvent: 'readonly',
40
+ KeyboardEvent: 'readonly',
41
+ FormData: 'readonly',
42
+ Response: 'readonly',
43
+ Request: 'readonly',
44
+ Headers: 'readonly',
45
+ // React global (for JSX types)
46
+ React: 'readonly',
47
+ },
48
+ },
49
+ plugins: {
50
+ '@typescript-eslint': typescript,
51
+ react,
52
+ 'react-hooks': reactHooks,
53
+ },
54
+ rules: {
55
+ ...typescript.configs.recommended.rules,
56
+ ...react.configs.recommended.rules,
57
+ ...reactHooks.configs.recommended.rules,
58
+ 'react/react-in-jsx-scope': 'off', // Not needed with React 17+ JSX transform
59
+ 'react/prop-types': 'off', // Using TypeScript for prop validation
60
+ 'no-undef': 'off', // TypeScript handles this
61
+ '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
62
+ '@typescript-eslint/no-explicit-any': 'off',
63
+ },
64
+ settings: {
65
+ react: {
66
+ version: 'detect',
67
+ },
68
+ },
69
+ },
70
+ prettier,
71
+ ];