@imwz/wp-pattern-sentinel 1.0.4 → 1.1.0

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
@@ -104,6 +104,9 @@ node bin/sentinel.js --no-headless --url=... path/to/patterns/
104
104
 
105
105
  # Adjust concurrency (default: 4)
106
106
  node bin/sentinel.js --concurrency=6 --url=... path/to/patterns/
107
+
108
+ # Show verbose step-by-step output
109
+ node bin/sentinel.js --verbose --url=... path/to/patterns/
107
110
  ```
108
111
 
109
112
  ## Options
@@ -118,6 +121,7 @@ node bin/sentinel.js --concurrency=6 --url=... path/to/patterns/
118
121
  | `--concurrency` | `4` | Parallel workers |
119
122
  | `--json` | `false` | Output JSON (one result per line) |
120
123
  | `--keep-page` | `false` | Don't delete draft pages after validation |
124
+ | `--verbose` | `false` | Show detailed step-by-step progress for each pattern |
121
125
  | `--width` | `1280` | Viewport width |
122
126
  | `--height` | `800` | Viewport height |
123
127
  | `--cache` | `false` | Skip patterns that previously passed with the same file content (see [Pass cache](#pass-cache)) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imwz/wp-pattern-sentinel",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Browser-based WordPress block pattern validator using Playwright",
5
5
  "type": "module",
6
6
  "engines": {
package/src/args.js CHANGED
@@ -31,6 +31,7 @@ const ARG_OPTIONS = {
31
31
  headless: { type: 'boolean', default: true },
32
32
  json: { type: 'boolean', default: false },
33
33
  'keep-page': { type: 'boolean', default: false },
34
+ verbose: { type: 'boolean', default: false },
34
35
  concurrency: { type: 'string', default: '4' },
35
36
  width: { type: 'string', default: '1280' },
36
37
  height: { type: 'string', default: '800' },
@@ -138,6 +139,7 @@ export async function parseArgs(args) {
138
139
  width: parseInt(values.width, 10),
139
140
  height: parseInt(values.height, 10),
140
141
  },
142
+ verbose: values.verbose,
141
143
  files: positionals,
142
144
  };
143
145
  }
package/src/editor.js CHANGED
@@ -66,8 +66,9 @@ export function extractBlockContent(fileContent) {
66
66
  * WordPress redirects post-new.php → post.php?post=ID&action=edit,
67
67
  * so we can read the ID directly from the final URL.
68
68
  */
69
- export async function createDraftPage(page, baseUrl) {
69
+ export async function createDraftPage(page, baseUrl, verbose = false) {
70
70
  try {
71
+ if (verbose) log(' → Creating draft page...', 'gray');
71
72
  await page.goto(`${baseUrl}/wp-admin/post-new.php?post_type=page`, {
72
73
  waitUntil: 'domcontentloaded',
73
74
  timeout: 30000,
@@ -79,12 +80,17 @@ export async function createDraftPage(page, baseUrl) {
79
80
 
80
81
  const url = page.url();
81
82
  const match = url.match(/[?&]post=(\d+)/);
82
- if (match) return parseInt(match[1], 10);
83
+ if (match) {
84
+ if (verbose) log(' → Draft page created', 'gray');
85
+ return parseInt(match[1], 10);
86
+ }
83
87
 
84
88
  // Fallback: read from wp.data (editor may not have redirected yet)
85
- return await page.evaluate(() =>
89
+ const pageId = await page.evaluate(() =>
86
90
  window.wp?.data?.select('core/editor')?.getCurrentPostId?.() ?? null
87
91
  );
92
+ if (verbose && pageId) log(' → Draft page created', 'gray');
93
+ return pageId;
88
94
  } catch (error) {
89
95
  log(`Failed to create draft page: ${error.message}`, 'red');
90
96
  return null;
@@ -94,8 +100,9 @@ export async function createDraftPage(page, baseUrl) {
94
100
  /**
95
101
  * Set the editor content via wp.data and wait for blocks to parse.
96
102
  */
97
- export async function insertPatternIntoEditor(page, blockContent) {
103
+ export async function insertPatternIntoEditor(page, blockContent, verbose = false) {
98
104
  try {
105
+ if (verbose) log(' → Inserting pattern into editor...', 'gray');
99
106
  await page.evaluate(content => {
100
107
  window.wp.data.dispatch('core/editor').editPost({ content });
101
108
  }, blockContent);
@@ -106,6 +113,7 @@ export async function insertPatternIntoEditor(page, blockContent) {
106
113
  { timeout: 15000 }
107
114
  );
108
115
 
116
+ if (verbose) log(' → Pattern inserted', 'gray');
109
117
  return true;
110
118
  } catch (error) {
111
119
  log(`Failed to insert pattern: ${error.message}`, 'red');
@@ -116,9 +124,10 @@ export async function insertPatternIntoEditor(page, blockContent) {
116
124
  /**
117
125
  * Trigger savePost() and wait for the editor to finish saving.
118
126
  */
119
- export async function savePage(page) {
127
+ export async function savePage(page, verbose = false) {
120
128
  const result = { success: false, errors: [], warnings: [] };
121
129
  try {
130
+ if (verbose) log(' → Saving page...', 'gray');
122
131
  await page.evaluate(() => window.wp.data.dispatch('core/editor').savePost());
123
132
 
124
133
  // Wait for save to start, then finish
@@ -134,6 +143,7 @@ export async function savePage(page) {
134
143
  { timeout: 30000 }
135
144
  );
136
145
 
146
+ if (verbose) log(' → Page saved', 'gray');
137
147
  result.success = true;
138
148
  } catch (error) {
139
149
  result.errors.push({ type: 'save_error', message: error.message });
@@ -145,8 +155,9 @@ export async function savePage(page) {
145
155
  * Delete the draft page via the WP REST API (uses the active browser session's nonce).
146
156
  * Non-fatal — a failure here does not affect validation results.
147
157
  */
148
- export async function deletePage(page, baseUrl, pageId) {
158
+ export async function deletePage(page, baseUrl, pageId, verbose = false) {
149
159
  try {
160
+ if (verbose) log(' → Deleting draft page...', 'gray');
150
161
  await page.evaluate(async id => {
151
162
  const nonce = window.wpApiSettings?.nonce ?? '';
152
163
  await fetch(`/wp-json/wp/v2/pages/${id}?force=true`, {
@@ -154,6 +165,7 @@ export async function deletePage(page, baseUrl, pageId) {
154
165
  headers: { 'X-WP-Nonce': nonce },
155
166
  });
156
167
  }, pageId);
168
+ if (verbose) log(' → Draft page deleted', 'gray');
157
169
  } catch {
158
170
  // Non-fatal
159
171
  }
package/src/main.js CHANGED
@@ -175,6 +175,7 @@ export async function main() {
175
175
  async function validatePatternFile(patternPath, options, context) {
176
176
  const patternName = path.basename(patternPath);
177
177
  const startTime = Date.now();
178
+ const verbose = options.verbose;
178
179
 
179
180
  log(` Validating: ${patternName}`, 'cyan');
180
181
 
@@ -194,18 +195,18 @@ async function validatePatternFile(patternPath, options, context) {
194
195
  page.setDefaultTimeout(60000);
195
196
 
196
197
  try {
197
- const pageId = await createDraftPage(page, options.adminUrl);
198
+ const pageId = await createDraftPage(page, options.adminUrl, verbose);
198
199
  if (pageId === null) {
199
200
  return fail(patternName, patternPath, startTime, 'page_creation_error', 'Failed to create test page');
200
201
  }
201
202
 
202
- if (!(await insertPatternIntoEditor(page, blockContent))) {
203
- await deletePage(page, options.adminUrl, pageId);
203
+ if (!(await insertPatternIntoEditor(page, blockContent, verbose))) {
204
+ await deletePage(page, options.adminUrl, pageId, verbose);
204
205
  return fail(patternName, patternPath, startTime, 'insertion_error', 'Failed to insert pattern into editor');
205
206
  }
206
207
 
207
- const saveResult = await savePage(page);
208
- const blockErrors = await checkBlockValidation(page);
208
+ const saveResult = await savePage(page, verbose);
209
+ const blockErrors = await checkBlockValidation(page, verbose);
209
210
 
210
211
  if (blockErrors.length > 0) {
211
212
  saveResult.errors.push(...blockErrors.map(e => ({
@@ -218,12 +219,12 @@ async function validatePatternFile(patternPath, options, context) {
218
219
  })));
219
220
  }
220
221
 
221
- const comparison = await compareContent(page, blockContent);
222
+ const comparison = await compareContent(page, blockContent, verbose);
222
223
  saveResult.errors.push(...comparison.errors);
223
224
  saveResult.warnings.push(...comparison.warnings);
224
225
 
225
226
  if (!options.keepPage) {
226
- await deletePage(page, options.adminUrl, pageId);
227
+ await deletePage(page, options.adminUrl, pageId, verbose);
227
228
  }
228
229
 
229
230
  return {
package/src/validation.js CHANGED
@@ -3,9 +3,10 @@ import { log } from './format.js';
3
3
  /**
4
4
  * Walk the block tree and collect any blocks where isValid === false.
5
5
  */
6
- export async function checkBlockValidation(page) {
6
+ export async function checkBlockValidation(page, verbose = false) {
7
+ if (verbose) log(' → Checking block validation...', 'gray');
7
8
  try {
8
- return await page.evaluate(() => {
9
+ const errors = await page.evaluate(() => {
9
10
  const walk = blocks => blocks.flatMap(block => [
10
11
  ...(block.isValid === false
11
12
  ? [{
@@ -25,6 +26,8 @@ export async function checkBlockValidation(page) {
25
26
  ]);
26
27
  return walk(window.wp.data.select('core/block-editor').getBlocks());
27
28
  });
29
+ if (verbose) log(' → Block validation complete', 'gray');
30
+ return errors;
28
31
  } catch (error) {
29
32
  log(`Block validation check error: ${error.message}`, 'yellow');
30
33
  return [];
@@ -95,17 +98,21 @@ const normalizeForComparison = str =>
95
98
  * Whitespace-normalizes both sides before diffing to avoid false positives
96
99
  * from indentation changes, then surfaces up to 5 added/removed lines.
97
100
  */
98
- export async function compareContent(page, originalContent) {
101
+ export async function compareContent(page, originalContent, verbose = false) {
99
102
  const result = { matches: true, errors: [], warnings: [], savedContent: null };
100
103
 
101
104
  try {
105
+ if (verbose) log(' → Comparing content...', 'gray');
102
106
  const savedContent = await page.evaluate(() =>
103
107
  window.wp.data.select('core/editor').getEditedPostContent()
104
108
  );
105
109
  result.savedContent = savedContent;
106
110
 
107
111
  const normalize = str => str.replace(/\s+/g, ' ').trim();
108
- if (normalize(normalizeForComparison(savedContent)) === normalize(normalizeForComparison(originalContent))) return result;
112
+ if (normalize(normalizeForComparison(savedContent)) === normalize(normalizeForComparison(originalContent))) {
113
+ if (verbose) log(' → Content matches', 'gray');
114
+ return result;
115
+ }
109
116
 
110
117
  result.matches = false;
111
118
 
@@ -127,6 +134,7 @@ export async function compareContent(page, originalContent) {
127
134
  message: `Content injected by editor:\n ${added.join('\n ')}`,
128
135
  });
129
136
  }
137
+ if (verbose) log(' → Content comparison complete', 'gray');
130
138
  } catch (error) {
131
139
  result.errors.push({ type: 'comparison_error', message: error.message });
132
140
  }