@artemsemkin/wp-headers 1.1.0 → 1.2.1
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/README.md +119 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,123 @@ Generate and patch WordPress file headers from `package.json` data.
|
|
|
8
8
|
npm install @artemsemkin/wp-headers
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
Reads `wp.theme` or `wp.plugin` fields from a `package.json` and generates or updates WordPress header comments in target files (`style.css`, plugin PHP, `readme.txt`). If a file already contains a header comment, it replaces it in place. If not, it writes a new one. Also patches version strings in TGM-style PHP plugin arrays.
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
### Theme: `package.json` → `style.css`
|
|
18
|
+
|
|
19
|
+
Given this in your theme's `package.json`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"name": "@starter/flavor-theme",
|
|
24
|
+
"version": "1.0.0",
|
|
25
|
+
"description": "A starter theme for WordPress",
|
|
26
|
+
"wp": {
|
|
27
|
+
"theme": {
|
|
28
|
+
"uri": "https://example.com/flavor",
|
|
29
|
+
"author": "Dev Studio",
|
|
30
|
+
"authorUri": "https://example.com",
|
|
31
|
+
"requires": "6.0",
|
|
32
|
+
"testedUpTo": "6.7",
|
|
33
|
+
"requiresPHP": "7.4",
|
|
34
|
+
"license": "GPL-2.0-or-later",
|
|
35
|
+
"licenseUri": "https://www.gnu.org/licenses/gpl-2.0.html",
|
|
36
|
+
"textDomain": "flavor",
|
|
37
|
+
"tags": ["blog", "one-column"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Running `processMapping({ type: 'theme', slug: 'flavor', entityDir: '/path/to/theme' })` generates this `style.css`:
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
/*
|
|
47
|
+
* Theme Name: Flavor
|
|
48
|
+
* Theme URI: https://example.com/flavor
|
|
49
|
+
* Author: Dev Studio
|
|
50
|
+
* Author URI: https://example.com
|
|
51
|
+
* Description: A starter theme for WordPress
|
|
52
|
+
* Version: 1.0.0
|
|
53
|
+
* Requires at least: 6.0
|
|
54
|
+
* Tested up to: 6.7
|
|
55
|
+
* Requires PHP: 7.4
|
|
56
|
+
* License: GPL-2.0-or-later
|
|
57
|
+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
58
|
+
* Text Domain: flavor
|
|
59
|
+
* Tags: blog, one-column
|
|
60
|
+
*/
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Plugin: `package.json` → PHP header
|
|
64
|
+
|
|
65
|
+
Given this in your plugin's `package.json`:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"name": "@starter/flavor-core",
|
|
70
|
+
"version": "1.0.0",
|
|
71
|
+
"description": "Core functionality for Flavor theme",
|
|
72
|
+
"wp": {
|
|
73
|
+
"plugin": {
|
|
74
|
+
"name": "Flavor Core",
|
|
75
|
+
"uri": "https://example.com/flavor-core",
|
|
76
|
+
"author": "Dev Studio",
|
|
77
|
+
"authorUri": "https://example.com",
|
|
78
|
+
"requires": "6.0",
|
|
79
|
+
"testedUpTo": "6.7",
|
|
80
|
+
"requiresPHP": "7.4",
|
|
81
|
+
"license": "GPL-2.0-or-later",
|
|
82
|
+
"textDomain": "flavor-core"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Running `processMapping({ type: 'plugin', slug: 'flavor-core', entityDir: '/path/to/plugin' })` generates or updates the header at the top of `flavor-core.php`:
|
|
89
|
+
|
|
90
|
+
```php
|
|
91
|
+
/**
|
|
92
|
+
* Plugin Name: Flavor Core
|
|
93
|
+
* Plugin URI: https://example.com/flavor-core
|
|
94
|
+
* Description: Core functionality for Flavor theme
|
|
95
|
+
* Version: 1.0.0
|
|
96
|
+
* Requires at least: 6.0
|
|
97
|
+
* Tested up to: 6.7
|
|
98
|
+
* Requires PHP: 7.4
|
|
99
|
+
* Author: Dev Studio
|
|
100
|
+
* Author URI: https://example.com
|
|
101
|
+
* License: GPL-2.0-or-later
|
|
102
|
+
* Text Domain: flavor-core
|
|
103
|
+
*/
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### TGM version patching
|
|
107
|
+
|
|
108
|
+
When a plugin's `package.json` includes `wp.plugin.loadPluginsFile`, the tool also patches version strings inside TGM-style PHP arrays. Given this PHP file registered via `tgmBasePath`:
|
|
109
|
+
|
|
110
|
+
```php
|
|
111
|
+
$plugins = array(
|
|
112
|
+
array(
|
|
113
|
+
'name' => 'Flavor Core',
|
|
114
|
+
'slug' => 'flavor-core',
|
|
115
|
+
'version' => '1.0.0',
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
After processing with `version: "2.0.0"` in `package.json`, the version field is updated in place:
|
|
121
|
+
|
|
122
|
+
```php
|
|
123
|
+
'version' => '2.0.0',
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Whitespace alignment, quote styles, and other entries are preserved.
|
|
127
|
+
|
|
11
128
|
## Usage
|
|
12
129
|
|
|
13
130
|
```ts
|
|
@@ -21,6 +138,6 @@ processMapping({
|
|
|
21
138
|
})
|
|
22
139
|
```
|
|
23
140
|
|
|
24
|
-
|
|
141
|
+
## Vite integration
|
|
25
142
|
|
|
26
|
-
|
|
143
|
+
Use [`@artemsemkin/vite-plugin-wp-headers`](https://www.npmjs.com/package/@artemsemkin/vite-plugin-wp-headers) to automate header generation during Vite's build lifecycle and watch for changes during dev.
|