@caweb/cli 1.3.6 → 1.3.8
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 +18 -5
- package/lib/cli.js +2 -2
- 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
|
@@ -173,6 +173,8 @@ export default async function sync({
|
|
|
173
173
|
settings = await getTaxonomies({
|
|
174
174
|
...fromOptions,
|
|
175
175
|
fields: [
|
|
176
|
+
'title',
|
|
177
|
+
'description',
|
|
176
178
|
'show_on_front',
|
|
177
179
|
'page_on_front',
|
|
178
180
|
'posts_per_page'
|
|
@@ -237,11 +239,16 @@ export default async function sync({
|
|
|
237
239
|
* 3) save any linked media in the content of pages and posts.
|
|
238
240
|
*/
|
|
239
241
|
for( let m of mediaLibrary ){
|
|
242
|
+
// remove any new line characters.
|
|
243
|
+
m.source_url = m.source_url.replace('\n','');
|
|
244
|
+
|
|
240
245
|
// check if the media is attached to a page.
|
|
241
246
|
// if tax is undefined, we collect all media attached to posts and pages.
|
|
242
|
-
// if tax is defined,
|
|
247
|
+
// if tax is defined, if include is undefined or media is matches post/page, we collect the media.
|
|
243
248
|
if( ( ! tax && m.post ) ||
|
|
244
|
-
|
|
249
|
+
( tax &&
|
|
250
|
+
( undefined === include || include.includes( m.id.toString() ) )
|
|
251
|
+
) ){
|
|
245
252
|
media.push( m );
|
|
246
253
|
|
|
247
254
|
// we don't have to check any further.
|
|
@@ -252,16 +259,22 @@ export default async function sync({
|
|
|
252
259
|
// if the media is featured on a post or linked in the content.
|
|
253
260
|
if( p.featured_media === m.id ||
|
|
254
261
|
p.content.rendered.match( new RegExp(`src=”(${m.source_url}.*)”`, 'g') )){
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
media.push( m );
|
|
263
|
+
}
|
|
257
264
|
}
|
|
258
265
|
}
|
|
259
|
-
|
|
266
|
+
|
|
260
267
|
// filter any duplicate media.
|
|
261
268
|
media = media.filter((m, index, self) => { return index === self.findIndex((t) => { return t.id === m.id; })} );
|
|
269
|
+
let i = 0;
|
|
262
270
|
|
|
263
271
|
// before we can upload media files we have to generate the media blob data.
|
|
264
272
|
for( let m of media ){
|
|
273
|
+
if( debug ){
|
|
274
|
+
i++;
|
|
275
|
+
spinner.info(`Media ID ${m.id} Collected: ${i}/${media.length}`)
|
|
276
|
+
}
|
|
277
|
+
|
|
265
278
|
const mediaBlob = await axios.request(
|
|
266
279
|
{
|
|
267
280
|
...fromOptions,
|
package/lib/cli.js
CHANGED
|
@@ -272,12 +272,12 @@ export default function cli() {
|
|
|
272
272
|
|
|
273
273
|
// Test Command.
|
|
274
274
|
// Ensure this is commented out.
|
|
275
|
-
program.command('test')
|
|
275
|
+
/*program.command('test')
|
|
276
276
|
.description('Test commands on a WordPress environment')
|
|
277
277
|
//.addArgument(envArg)
|
|
278
278
|
.allowUnknownOption(true)
|
|
279
279
|
.action(withSpinner(env.test))
|
|
280
|
-
|
|
280
|
+
*/
|
|
281
281
|
addWPEnvCommands();
|
|
282
282
|
|
|
283
283
|
return program;
|
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.8",
|
|
4
4
|
"description": "CAWebPublishing Command Line Interface.",
|
|
5
5
|
"exports": "./lib/env.js",
|
|
6
6
|
"type": "module",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"WP_DEBUG_DISPLAY": false,
|
|
49
49
|
"WP_MEMORY_LIMIT": "256M",
|
|
50
50
|
"WP_MAX_MEMORY_LIMIT": "512M",
|
|
51
|
-
"WP_PERMALINK": "/%postname%/",
|
|
51
|
+
"WP_PERMALINK": "/%year%/%monthnum%/%postname%/",
|
|
52
52
|
"ADMIN_COOKIE_PATH": "/",
|
|
53
53
|
"COOKIE_DOMAIN": "",
|
|
54
54
|
"COOKIEPATH": "",
|
|
@@ -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
|
}
|