@rnaga/wp-node 1.1.2 → 1.1.3
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 +102 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,43 +69,128 @@ docker run -d --name wp --network wpnet -p 8080:80 \
|
|
|
69
69
|
wordpress
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
Visit http://localhost:8080 in your browser to complete the WordPress setup.
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
### Initialize WP-Node Project
|
|
75
|
+
|
|
76
|
+
WP-Node requires an initialized configuration before use. You can scaffold a new project using the CLI.
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
mkdir /tmp/test-wp-node
|
|
80
|
+
cd /tmp/test-wp-node
|
|
81
|
+
npx @rnaga/wp-node-cli -- init
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then enter prompts as follows:
|
|
75
85
|
|
|
76
86
|
```sh
|
|
77
|
-
|
|
87
|
+
✔ Enter your database hostname: · localhost
|
|
88
|
+
✔ Enter your database port: · 33306
|
|
89
|
+
✔ Enter your database username: · wp
|
|
90
|
+
✔ Enter your database password: · **
|
|
91
|
+
✔ Enter your database name: · wordpress
|
|
92
|
+
✔ Is it a multi-site? · No
|
|
93
|
+
✔ Enter your static assets path: · public
|
|
78
94
|
```
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
### Project Structure
|
|
97
|
+
|
|
98
|
+
After initialization, your project will look like this:
|
|
81
99
|
|
|
82
100
|
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
./
|
|
102
|
+
├── _wp
|
|
103
|
+
│ ├── config
|
|
104
|
+
│ │ ├── index.d.ts
|
|
105
|
+
│ │ └── wp.json
|
|
106
|
+
│ └── settings.ts
|
|
107
|
+
├── .env
|
|
108
|
+
├── index.ts
|
|
109
|
+
├── package-lock.json
|
|
110
|
+
├── package.json
|
|
111
|
+
└── tsconfig.json
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Key files**
|
|
115
|
+
|
|
116
|
+
- `_wp/config/wp.json`: Holds configuration for WP-Node such as public path and multisite info. This file is imported by settings.ts.
|
|
117
|
+
- `_wp/settings.ts`: Initializes the WP-Node Context, including config, database access and hooks.
|
|
118
|
+
- `index.ts`: The main entry point for your WP-Node app. A basic sample is provided.
|
|
119
|
+
- `.env`: Stores sensitive environment variables, including your database credentials and other configuration values required at runtime.
|
|
120
|
+
|
|
121
|
+
### Run the App
|
|
122
|
+
|
|
123
|
+
Once the config is initialized, run the app using:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
mvn use 22
|
|
127
|
+
npx ts-node ./index.ts
|
|
86
128
|
```
|
|
87
129
|
|
|
88
|
-
|
|
130
|
+
If everything is working correctly, you’ll see SQL output like:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
select * from `wp_posts` as `posts_5` where `posts_5`.`ID` = 1
|
|
134
|
+
[
|
|
135
|
+
{
|
|
136
|
+
ID: 1,
|
|
137
|
+
post_author: 1,
|
|
138
|
+
post_title: 'Hello world!',
|
|
139
|
+
...
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
```
|
|
89
143
|
|
|
90
|
-
|
|
91
|
-
- `multisite.enabled`: Enable or disable multisite support
|
|
92
|
-
- Custom post types, taxonomies, statuses
|
|
144
|
+
## CLI
|
|
93
145
|
|
|
94
|
-
|
|
146
|
+
WP-Node CLI provides a convenient way to interact with WordPress data without writing any code.
|
|
95
147
|
|
|
96
|
-
|
|
148
|
+
To query a post (e.g. ID = 1), run:
|
|
97
149
|
|
|
98
150
|
```sh
|
|
99
|
-
|
|
151
|
+
npx @rnaga/wp-node-cli -- post get 1 -Z table -F ID,post_title,post_type
|
|
152
|
+
|
|
153
|
+
┌────────────┬────────────────┐
|
|
154
|
+
│ (index) │ Values │
|
|
155
|
+
├────────────┼────────────────┤
|
|
156
|
+
│ ID │ 1 │
|
|
157
|
+
│ post_title │ 'Hello world!' │
|
|
158
|
+
│ post_type │ 'post' │
|
|
159
|
+
└────────────┴────────────────┘
|
|
100
160
|
```
|
|
101
161
|
|
|
102
|
-
|
|
162
|
+
### Listing Available Commands
|
|
163
|
+
|
|
164
|
+
To view all available CLI commands, run:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
npx @rnaga/wp-node-cli -- -h
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
output:
|
|
103
171
|
|
|
104
172
|
```sh
|
|
105
|
-
|
|
173
|
+
Usage: <command> <subcommand> [options]
|
|
174
|
+
|
|
175
|
+
Commands:
|
|
176
|
+
blog Blog commands
|
|
177
|
+
comment Comment commands
|
|
178
|
+
config Generate WP config files
|
|
179
|
+
init Initialize WP with Node. (Generate wp.json and install dependencies)
|
|
180
|
+
install Initialize a new blog and create a user
|
|
181
|
+
meta Meta commands (post, comment, blog, term, user, site)
|
|
182
|
+
option Options commands
|
|
183
|
+
post Post commands
|
|
184
|
+
repl Start a REPL
|
|
185
|
+
role Role commands
|
|
186
|
+
site Site commands
|
|
187
|
+
term Term commands
|
|
188
|
+
user User commands
|
|
106
189
|
```
|
|
107
190
|
|
|
108
|
-
Develop your
|
|
191
|
+
### Develop your CLI using decorators:
|
|
192
|
+
|
|
193
|
+
**Example**:
|
|
109
194
|
|
|
110
195
|
```ts
|
|
111
196
|
@command("page", { description: "Page commands" })
|