@caweb/cli 1.3.2 → 1.3.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 CHANGED
@@ -2,16 +2,12 @@
2
2
  `caweb-cli` is a tool which rapidly sets up a local WordPress environment fully configured for the [CAWebPublishing Service](https://caweb.cdt.ca.gov/), allows for the creation of Gutenberg blocks with the CAWebPublishing template configurations, and much more. The cli will automatically generate the necessary [.wp-env.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-json) file, to override or add additional configuration options use the [.wp-env.override.json](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#wp-env-override-json) file.
3
3
 
4
4
  *`caweb-cli` is largely inspired by WordPress Packages major thanks to the whole WordPress team and community!*
5
- The following WordPress packages are used:
6
- [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)
7
- [create-block](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/)
8
5
 
9
6
  ## Prerequisites
10
7
  - Latest version of [Docker Desktop](https://www.docker.com/products/docker-desktop), which includes [Compose v2](https://docs.docker.com/compose/migrate/), is installed.
11
8
  - <strong>For Debian-Based Linux distributions:</strong> <code>docker-compose</code> may need to be installed with: <code>sudo apt-get install docker-compose</code>.
12
9
  - <strong>For Windows users:</strong> [WSL should be set to version 2 for Windows Docker Desktop compatibility](https://docs.docker.com/desktop/windows/wsl/).
13
10
  - git is installed.
14
- - php is installed.
15
11
 
16
12
  ## Additional Features
17
13
  - Downloads and configures the [CAWeb Theme](https://github.com/CAWebPublishing/CAWeb)
@@ -21,15 +17,13 @@ The following WordPress packages are used:
21
17
  - phpMyAdmin development site starts at http://localhost:8080
22
18
  - phpMyAdmin test site started at http://localhost:9090
23
19
  - Uses CAWebPublishing [External Project Template Configuration](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template/) when creating Gutenberg Blocks, see configurations [here](https://github.com/CAWebPublishing/cli/lib/template)
24
- - Allows for syncing of WordPress instance via Rest API and CLI, requires ssh.
20
+ - Allows for syncing of WordPress instance via Rest API, to maintain ID's please ensure [CAWebPublishing Development Toolbox](https://github.com/CAWebPublishing/caweb-dev/) plugin is installed.
25
21
  - Adds config.yml to both cli containers, alias are added for each ssh connection.
26
22
  <b>Example config.yml file</b>
27
23
  <pre>
28
24
  path: /var/www/html
29
25
  apache_modules:
30
26
  - mod_rewrite
31
- @staging:
32
- ssh: wpcli@staging.wp-cli.org
33
27
  </pre>
34
28
 
35
29
 
@@ -81,7 +75,7 @@ Options:
81
75
  </pre>
82
76
  ### `caweb run <container> [command...]`
83
77
  <pre>
84
- caweb run <container> [command...]
78
+ caweb run &lt;container&gt; [command...]
85
79
 
86
80
  Runs an arbitrary command in one of the underlying Docker containers. A double
87
81
  dash can be used to pass arguments to the container without parsing them. This
@@ -166,7 +160,7 @@ Options:
166
160
 
167
161
  ### `caweb create-block [options] <slug>`
168
162
  <pre>
169
- caweb create-block [options] <slug>
163
+ caweb create-block [options] &lt;slug&gt;
170
164
 
171
165
  Scaffold for WordPress plugin to register CA.gov Design System Block.
172
166
 
@@ -178,7 +172,7 @@ Options:
178
172
  </pre>
179
173
  ### `caweb update-block [options] <slug>`
180
174
  <pre>
181
- caweb update-block [options] <slug>
175
+ caweb update-block [options] &lt;slug&gt;
182
176
 
183
177
  Updates a CA.gov Design System Block.
184
178
 
@@ -188,3 +182,18 @@ Arguments:
188
182
  Options:
189
183
  -h, --help display help for command
190
184
  </pre>
185
+ ### `caweb sync <from> <to>`
186
+ In order for the sync process to work correctly, you must have a caweb.json file in the project root directory. For more information read [caweb.json](./docs/SYNC.MD) configuration.
187
+ <pre>
188
+ caweb sync &lt;from&gt; &lt;to&gt;
189
+
190
+ Sync changes from one destination to another.
191
+
192
+ Arguments:
193
+ from Target Site URL with current changes.
194
+ to Destination Site URL that should be synced.
195
+
196
+ Options:
197
+ -h, --help display help for command
198
+ -t,--tax [tax...] Taxonomy that should be synced. Omitting this option will sync the full site. (choices: "pages", "posts", "media", "menus")
199
+ </pre>
package/commands/sync.js CHANGED
@@ -79,13 +79,11 @@ export default async function sync({
79
79
  }
80
80
  }
81
81
 
82
- let ssh = 'local' !== to ? to : `docker:${path.basename(workDirectoryPath)}-cli-1`;
83
82
 
84
83
  to = serviceConfig.sync[to];
85
84
 
86
85
  let toOptions = {
87
86
  url: to.url,
88
- ssh,
89
87
  headers: {
90
88
  Authorization: 'Basic ' + Buffer.from(`${to.user}:${to.pwd}`).toString('base64'),
91
89
  'content-type': 'multipart/form-data',
@@ -100,14 +98,18 @@ export default async function sync({
100
98
  let menus = [];
101
99
  let menuNavItems = [];
102
100
 
103
- // get all settings
104
- // site settings are always synced
105
101
  spinner.text = `Getting Site Settings from ${from.url}`;
102
+ /**
103
+ * Site settings are always synced
104
+ *
105
+ * @see https://developer.wordpress.org/rest-api/reference/settings/
106
+ */
106
107
  let settings = await getTaxonomies({
107
108
  ...fromOptions,
108
109
  fields: [
109
110
  'show_on_front',
110
- 'page_on_front'
111
+ 'page_on_front',
112
+ 'posts_per_page'
111
113
  ],
112
114
  }, 'settings')
113
115
 
@@ -4,21 +4,29 @@
4
4
  import path from 'path';
5
5
  import axios from 'axios';
6
6
  import terminalLink from 'terminal-link';
7
-
7
+ import axiosRetry from 'axios-retry';
8
8
 
9
9
  /**
10
10
  * Internal dependencies
11
11
  */
12
- import {
13
- projectPath,
14
- runCmd
15
- } from '../index.js';
16
-
17
12
  const endpoint = '/wp-json/wp/v2';
18
- const requestDelay = 1000; // we wait 1 second between requests
19
-
20
-
21
- const sleep = (waitTimeInMs) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
13
+ const syncEndpoint = '/wp-json/caweb/v1/sync';
14
+
15
+ // Axios Configurations.
16
+ axiosRetry(axios,
17
+ {
18
+ retries: 3, // attempt requests 3 times
19
+ shouldResetTimeout: true, // reset timeout on retries
20
+ retryCondition: (error) => {
21
+ if( error.response && error.response.status === 500 ){
22
+ return true;
23
+ }
24
+ }, // retry on any network or 5xx error
25
+ retryDelay: (retryCount, error ) => {
26
+ return 5000 // retry delay
27
+ }
28
+ }
29
+ );
22
30
 
23
31
  function processData( data ){
24
32
  /**
@@ -106,12 +114,13 @@ async function getTaxonomies( request, tax = 'pages' ){
106
114
  urlParams.push( 'menus=' + processUrlParam( request.menus ) );
107
115
  }
108
116
 
109
- // if per page argument.
110
- urlParams.push( 'per_page=' + request.per_page ? request.per_page : '100' )
111
-
112
-
113
- // if posts_per_page argument.
114
- urlParams.push( 'posts_per_page=' + request.posts_per_page ? request.posts_per_page : '10' )
117
+ /**
118
+ * The per_page parameter is capped at 100.
119
+ *
120
+ * @see https://developer.wordpress.org/rest-api/using-the-rest-api/pagination/
121
+ */
122
+ request.per_page = request.per_page && request.per_page <= 100 ? request.per_page : 100;
123
+ urlParams.push( 'per_page=' + request.per_page );
115
124
 
116
125
 
117
126
  let collection = [];
@@ -201,7 +210,6 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
201
210
  .catch(error => {return false;})
202
211
 
203
212
  }
204
-
205
213
  /**
206
214
  * if the ID doesn't exist we save it so we can make a request to our plugin endpoint.
207
215
  * if it does exist update endpoint url so we update the existing item.
@@ -232,13 +240,11 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
232
240
  // make WordPress REST API request.
233
241
  let results = await axios.request({
234
242
  ...request,
235
- timeout: 7500,
236
243
  data: 'media' === tax ? createMediaItem(obj) : obj,
237
244
  url
238
245
  })
239
246
  .then( async (res) => { return res.data; } )
240
247
 
241
-
242
248
  /**
243
249
  * if the obj had an existing ID that didn't exist we make a request to our plugin endpoint to update the IDs.
244
250
  */
@@ -246,8 +252,7 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
246
252
 
247
253
  await axios.request({
248
254
  ...request,
249
- url: `${request.url}/wp-json/caweb-dev/v1/sync`,
250
- timeout: 7500,
255
+ url: `${request.url}${syncEndpoint}`,
251
256
  data: {
252
257
  id: results.id,
253
258
  newId: existingID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -62,6 +62,7 @@
62
62
  "accessibility-checker": "^3.1.67",
63
63
  "autoprefixer": "^10.4.17",
64
64
  "axios": "^1.6.7",
65
+ "axios-retry": "^4.0.0",
65
66
  "chalk": "^5.3.0",
66
67
  "commander": "^12.0.0",
67
68
  "cross-spawn": "^7.0.3",
package/bin/wp-cli.phar DELETED
Binary file