@caweb/cli 1.3.7 → 1.3.9
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/commands/env/start.js +4 -0
- package/commands/sync.js +6 -0
- package/lib/wordpress/api.js +43 -4
- package/package.json +12 -12
package/commands/env/start.js
CHANGED
|
@@ -74,6 +74,10 @@ export default async function start({
|
|
|
74
74
|
const { workDirectoryPath } = config;
|
|
75
75
|
const cacheKey = await getCache(CONFIG_CACHE_KEY, {workDirectoryPath});
|
|
76
76
|
|
|
77
|
+
// Set extra congiguration for WordPress.
|
|
78
|
+
// Increase max execution time to 300 seconds.
|
|
79
|
+
process.env.WORDPRESS_CONFIG_EXTRA = 'set_time_limit(300);';
|
|
80
|
+
|
|
77
81
|
// wp-env launch.
|
|
78
82
|
await wpEnvStart({
|
|
79
83
|
spinner,
|
package/commands/sync.js
CHANGED
|
@@ -266,9 +266,15 @@ export default async function sync({
|
|
|
266
266
|
|
|
267
267
|
// filter any duplicate media.
|
|
268
268
|
media = media.filter((m, index, self) => { return index === self.findIndex((t) => { return t.id === m.id; })} );
|
|
269
|
+
let i = 0;
|
|
269
270
|
|
|
270
271
|
// before we can upload media files we have to generate the media blob data.
|
|
271
272
|
for( let m of media ){
|
|
273
|
+
if( debug ){
|
|
274
|
+
i++;
|
|
275
|
+
spinner.info(`Media ID ${m.id} Collected: ${i}/${media.length}`)
|
|
276
|
+
}
|
|
277
|
+
|
|
272
278
|
const mediaBlob = await axios.request(
|
|
273
279
|
{
|
|
274
280
|
...fromOptions,
|
package/lib/wordpress/api.js
CHANGED
|
@@ -195,7 +195,7 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
|
|
|
195
195
|
// process object properties.
|
|
196
196
|
for( let prop in obj ){
|
|
197
197
|
// we process the rendered property and delete the rendered property.
|
|
198
|
-
if( 'object' === typeof obj[prop] && null !== obj[prop] && obj[prop]
|
|
198
|
+
if( 'object' === typeof obj[prop] && null !== obj[prop] && Object.hasOwn(obj[prop], 'rendered' ) ){
|
|
199
199
|
obj[prop] = processData(obj[prop].rendered);
|
|
200
200
|
}
|
|
201
201
|
|
|
@@ -258,9 +258,44 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
|
|
|
258
258
|
data: 'media' === tax ? createMediaItem(obj) : obj,
|
|
259
259
|
url
|
|
260
260
|
})
|
|
261
|
-
.then( async (res) => {
|
|
261
|
+
.then( async (res) => {
|
|
262
|
+
/**
|
|
263
|
+
* If the request is for media, sometimes there are warnings that are included with the object. These need to be removed.
|
|
264
|
+
*/
|
|
265
|
+
if( 'media' === tax && 'string' === typeof res.data && '}' === res.data.substring(res.data.length - 1) ){
|
|
266
|
+
// return the JSON object.
|
|
267
|
+
return JSON.parse(res.data.substring(res.data.indexOf('{')))
|
|
268
|
+
}
|
|
269
|
+
//console.log( res.data );
|
|
270
|
+
return res.data;
|
|
271
|
+
} ).catch( async (error) => {
|
|
272
|
+
let { data, status } = error.response;
|
|
273
|
+
let msg = data.message || 'An unknown error occurred.';
|
|
274
|
+
|
|
275
|
+
if( 401 === status ){
|
|
276
|
+
msg += `\nPlease check your ${terminalLink('Application Password', 'https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/')}`;
|
|
277
|
+
} else if( 403 === status ){
|
|
278
|
+
msg = 'Forbidden Request: A potentially unsafe operation has been detected in your request to this site';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
spinner.fail( msg )
|
|
282
|
+
|
|
283
|
+
// Exit with a non-zero status code if the error is 401 or 403.
|
|
284
|
+
if( 401 === status || 403 === status ){
|
|
285
|
+
process.exit( 1 );
|
|
286
|
+
}else{
|
|
287
|
+
if( existingID && 'rest_upload_unknown_error' === data.code ){
|
|
288
|
+
spinner.fail( `Media ID ${existingID} could not be synced.` );
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// if no results, continue to the next object.
|
|
295
|
+
if( null === results ){
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
262
298
|
|
|
263
|
-
|
|
264
299
|
/**
|
|
265
300
|
* if the obj had an existing ID we make a request to our plugin endpoint to update the IDs.
|
|
266
301
|
*/
|
|
@@ -274,6 +309,11 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
|
|
|
274
309
|
// get expected guid, replace source domain with the new domain.
|
|
275
310
|
let expectedGuid = obj.source_url.replace(sourceDomain, request.url);
|
|
276
311
|
|
|
312
|
+
// remove any media detail properties that may cause conflicts with the WP Rest API.
|
|
313
|
+
if( results.media_details && Object.hasOwn(results.media_details, 'audio') && Object.hasOwn(results.media_details.audio, 'lossless' ) ){
|
|
314
|
+
delete results.media_details.audio.lossless;
|
|
315
|
+
}
|
|
316
|
+
|
|
277
317
|
extraArgs = {
|
|
278
318
|
guid: results.guid.rendered,
|
|
279
319
|
newGuid: expectedGuid,
|
|
@@ -295,7 +335,6 @@ async function createTaxonomies( taxData, request, tax = 'pages', spinner ){
|
|
|
295
335
|
}
|
|
296
336
|
})
|
|
297
337
|
.then( async (res) => { return res.data; } )
|
|
298
|
-
|
|
299
338
|
// update the API results ID, back to the existing ID from earlier.
|
|
300
339
|
results.id = existingID;
|
|
301
340
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "CAWebPublishing Command Line Interface.",
|
|
5
5
|
"exports": "./lib/env.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "CAWebPublishing",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"bin": {
|
|
11
|
-
"caweb": "bin/caweb"
|
|
11
|
+
"caweb": "bin/caweb.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"assets",
|
|
@@ -57,27 +57,27 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@wordpress/env": "^9.
|
|
61
|
-
"@wordpress/scripts": "^27.
|
|
62
|
-
"accessibility-checker": "^3.1.
|
|
63
|
-
"autoprefixer": "^10.4.
|
|
64
|
-
"axios": "^1.6.
|
|
65
|
-
"axios-retry": "^4.
|
|
60
|
+
"@wordpress/env": "^9.6.0",
|
|
61
|
+
"@wordpress/scripts": "^27.5.0",
|
|
62
|
+
"accessibility-checker": "^3.1.68",
|
|
63
|
+
"autoprefixer": "^10.4.19",
|
|
64
|
+
"axios": "^1.6.8",
|
|
65
|
+
"axios-retry": "^4.1.0",
|
|
66
66
|
"chalk": "^5.3.0",
|
|
67
67
|
"commander": "^12.0.0",
|
|
68
68
|
"cross-spawn": "^7.0.3",
|
|
69
69
|
"css-loader": "^6.10.0",
|
|
70
|
-
"docker-compose": "^0.24.
|
|
70
|
+
"docker-compose": "^0.24.7",
|
|
71
71
|
"handlebars-loader": "^1.7.3",
|
|
72
72
|
"html-to-json-parser": "^2.0.1",
|
|
73
73
|
"html-webpack-plugin": "^5.6.0",
|
|
74
|
-
"mini-css-extract-plugin": "^2.8.
|
|
74
|
+
"mini-css-extract-plugin": "^2.8.1",
|
|
75
75
|
"ora": "^8.0.1",
|
|
76
|
-
"postcss-loader": "^8.1.
|
|
76
|
+
"postcss-loader": "^8.1.1",
|
|
77
77
|
"resolve-bin": "^1.0.1",
|
|
78
78
|
"sass-loader": "^14.1.1",
|
|
79
79
|
"terminal-link": "^3.0.0",
|
|
80
80
|
"url": "^0.11.3",
|
|
81
|
-
"webpack": "^5.
|
|
81
|
+
"webpack": "^5.91.0"
|
|
82
82
|
}
|
|
83
83
|
}
|