wp-shakedown 0.1.0 → 0.2.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.
Files changed (44) hide show
  1. package/README.md +15 -3
  2. package/dist/cli.js +160 -3
  3. package/dist/diff.d.ts +2 -1
  4. package/dist/diff.js +5 -3
  5. package/dist/engines/config.js +1 -0
  6. package/dist/engines/custom.d.ts +10 -0
  7. package/dist/engines/custom.js +286 -0
  8. package/dist/engines/index.js +3 -1
  9. package/dist/engines/php-lint.js +1 -0
  10. package/dist/engines/phpstan.js +1 -0
  11. package/dist/engines/theme-check.d.ts +7 -0
  12. package/dist/engines/theme-check.js +109 -0
  13. package/dist/engines/theme-review.d.ts +24 -0
  14. package/dist/engines/theme-review.js +378 -0
  15. package/dist/engines/updates.d.ts +2 -0
  16. package/dist/engines/updates.js +6 -0
  17. package/dist/engines/wp-json.js +1 -0
  18. package/dist/hub.d.ts +32 -0
  19. package/dist/hub.js +99 -0
  20. package/dist/index.d.ts +5 -1
  21. package/dist/index.js +5 -1
  22. package/dist/mcp/tools.js +16 -2
  23. package/dist/profiles.d.ts +4 -0
  24. package/dist/profiles.js +41 -0
  25. package/dist/projects.d.ts +36 -0
  26. package/dist/projects.js +91 -0
  27. package/dist/report/html.js +1 -1
  28. package/dist/report/markdown.js +1 -1
  29. package/dist/runner.d.ts +4 -1
  30. package/dist/runner.js +16 -2
  31. package/dist/session.d.ts +4 -1
  32. package/dist/session.js +10 -2
  33. package/dist/types.d.ts +30 -0
  34. package/dist/types.js +2 -0
  35. package/dist/ui/server.js +218 -55
  36. package/package.json +2 -1
  37. package/php-tools/composer.json +29 -1
  38. package/php-tools/composer.lock +22 -1
  39. package/php-tools/theme-check.php +239 -0
  40. package/ui/dist/assets/index-DXwdz_Wu.css +2 -0
  41. package/ui/dist/assets/index-V8IOqxHa.js +54 -0
  42. package/ui/dist/index.html +2 -2
  43. package/ui/dist/assets/index-7zN46ssH.js +0 -54
  44. package/ui/dist/assets/index-B1axZya5.css +0 -2
package/dist/ui/server.js CHANGED
@@ -4,8 +4,13 @@ import http from 'node:http';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
+ import { customEngines } from '../engines/custom.js';
8
+ import { profiles } from '../profiles.js';
9
+ import { addProject, listProjects, removeProject } from '../projects.js';
10
+ import { readPreviousRun } from '../report/write.js';
7
11
  import { runSession } from '../session.js';
8
12
  import { detectTarget } from '../target.js';
13
+ import { DEPTHS } from '../types.js';
9
14
  import { VERSION } from '../version.js';
10
15
  // The page is a Vite build. Its files are index.html and the hashed files in assets/.
11
16
  const UI_DIR = fileURLToPath(new URL('../../ui/dist/', import.meta.url));
@@ -30,6 +35,9 @@ const HEADERS = {
30
35
  'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self'; img-src 'self' data:; base-uri 'none'; form-action 'none'",
31
36
  };
32
37
  const MAX_BODY = 65536;
38
+ const MAX_RUNNING = 3;
39
+ const REPORT_CSP = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'";
40
+ const REPORT_FILES = ['report.md', 'report.json', 'report.sarif', 'report.html'];
33
41
  function toWire(e) {
34
42
  if (e.type === 'run:start') {
35
43
  const { kind, name, path: p, units } = e.target;
@@ -48,10 +56,11 @@ export function startUi(opts) {
48
56
  const token = opts.token ?? randomBytes(24).toString('base64url');
49
57
  const startDir = path.resolve(opts.startDir ?? process.cwd());
50
58
  let port = 0;
51
- let controller;
52
- let events = [];
53
- let last;
54
59
  const clients = new Set();
60
+ const active = new Map();
61
+ const queue = [];
62
+ // What a page that connects later can still show: the last run of each project in this server session.
63
+ const finished = new Map();
55
64
  const send = (res, status, body) => {
56
65
  res.writeHead(status, { ...HEADERS, 'Content-Type': 'application/json; charset=utf-8' });
57
66
  res.end(JSON.stringify(body));
@@ -59,10 +68,13 @@ export function startUi(opts) {
59
68
  const sse = (res, name, data) => {
60
69
  res.write(`event: ${name}\ndata: ${JSON.stringify(data)}\n\n`);
61
70
  };
62
- const push = (e) => {
63
- events.push(e);
71
+ const broadcast = (name, data) => {
64
72
  for (const c of clients)
65
- sse(c, 'run', e);
73
+ sse(c, name, data);
74
+ };
75
+ const push = (id, a, event) => {
76
+ a.events.push(event);
77
+ broadcast('run', { id, event });
66
78
  };
67
79
  function readBody(req) {
68
80
  return new Promise((resolve) => {
@@ -82,15 +94,18 @@ export function startUi(opts) {
82
94
  req.on('error', () => resolve(undefined));
83
95
  });
84
96
  }
85
- function start(input, type, only) {
86
- const ctl = new AbortController();
87
- controller = ctl;
88
- events = [];
97
+ function begin(id, a) {
98
+ const ctl = a.controller;
99
+ a.state = 'running';
100
+ finished.delete(id);
89
101
  let ended = false;
102
+ let session;
103
+ broadcast('projects', {});
90
104
  runSession({
91
- input,
92
- ...(type ? { type } : {}),
93
- ...(only ? { only } : {}),
105
+ input: a.path,
106
+ ...(a.profile ? { profile: a.profile } : {}),
107
+ ...(a.depth ? { depth: a.depth } : {}),
108
+ ...(a.experimental ? { experimental: true } : {}),
94
109
  engines: opts.engines,
95
110
  signal: ctl.signal,
96
111
  onEvent: (e) => {
@@ -99,24 +114,75 @@ export function startUi(opts) {
99
114
  return;
100
115
  if (e.type === 'run:end')
101
116
  ended = true;
102
- push(toWire(e));
117
+ push(id, a, toWire(e));
103
118
  },
104
119
  })
105
120
  .then((s) => {
106
121
  if (!ctl.signal.aborted)
107
- last = s;
122
+ session = s;
108
123
  })
109
124
  .catch((err) => {
110
125
  if (!ctl.signal.aborted)
111
- push({ type: 'run:error', message: err instanceof Error ? err.message : String(err) });
126
+ push(id, a, { type: 'run:error', message: err instanceof Error ? err.message : String(err) });
112
127
  })
113
128
  .finally(() => {
114
129
  if (ctl.signal.aborted && !ended)
115
- push({ type: 'run:error', message: 'The run was stopped.' });
116
- if (controller === ctl)
117
- controller = undefined;
130
+ push(id, a, { type: 'run:error', message: 'The run was stopped.' });
131
+ active.delete(id);
132
+ finished.set(id, { events: a.events, ...(session ? { session } : {}) });
133
+ pump();
134
+ broadcast('projects', {});
118
135
  });
119
136
  }
137
+ function pump() {
138
+ const running = () => [...active.values()].filter((a) => a.state === 'running').length;
139
+ while (running() < MAX_RUNNING && queue.length > 0) {
140
+ const id = queue.shift();
141
+ const a = active.get(id);
142
+ if (a)
143
+ begin(id, a);
144
+ }
145
+ }
146
+ function cancel(id) {
147
+ const a = active.get(id);
148
+ if (!a)
149
+ return;
150
+ const at = queue.indexOf(id);
151
+ if (at >= 0) {
152
+ queue.splice(at, 1);
153
+ active.delete(id);
154
+ broadcast('projects', {});
155
+ }
156
+ else
157
+ a.controller.abort();
158
+ }
159
+ async function jsonBody(req, res) {
160
+ if (!(req.headers['content-type'] ?? '').startsWith('application/json')) {
161
+ send(res, 415, { error: 'Send JSON.' });
162
+ return undefined;
163
+ }
164
+ const text = await readBody(req);
165
+ if (text === undefined) {
166
+ res.setHeader('Connection', 'close');
167
+ send(res, 413, { error: 'The request is too large.' });
168
+ return undefined;
169
+ }
170
+ try {
171
+ const data = JSON.parse(text);
172
+ return data !== null && typeof data === 'object' && !Array.isArray(data) ? data : {};
173
+ }
174
+ catch {
175
+ return {};
176
+ }
177
+ }
178
+ /** The report folder and finished session of a project, or undefined when it has no report. */
179
+ function reportOf(id) {
180
+ const session = finished.get(id)?.session;
181
+ if (session)
182
+ return { dir: session.dir, session };
183
+ const dir = listProjects().find((p) => p.id === id)?.last?.dir;
184
+ return dir ? { dir } : undefined;
185
+ }
120
186
  const handle = async (req, res) => {
121
187
  const url = new URL(req.url ?? '/', `http://127.0.0.1:${port}`);
122
188
  const route = url.pathname;
@@ -150,15 +216,18 @@ export function startUi(opts) {
150
216
  '/api/state': 'GET',
151
217
  '/api/dirs': 'GET',
152
218
  '/api/detect': 'GET',
219
+ '/api/projects': 'GET, POST',
220
+ '/api/projects/remove': 'POST',
153
221
  '/api/run': 'POST',
154
222
  '/api/cancel': 'POST',
155
223
  '/api/report': 'GET',
224
+ '/api/report.html': 'GET',
156
225
  '/api/events': 'GET',
157
226
  };
158
227
  const want = methods[route];
159
228
  if (!want)
160
229
  return send(res, 404, { error: 'Not found.' });
161
- if (method !== want)
230
+ if (!want.split(', ').includes(method))
162
231
  return send(res, 405, { error: 'Method not allowed.' });
163
232
  switch (route) {
164
233
  case '/api/state':
@@ -166,8 +235,8 @@ export function startUi(opts) {
166
235
  version: VERSION,
167
236
  home: os.homedir(),
168
237
  startDir,
169
- engines: opts.engines.map(({ id, title, kinds }) => ({ id, title, kinds })),
170
- running: controller !== undefined,
238
+ engines: [...opts.engines, ...customEngines()].map(({ id, title, kinds, depth, experimental }) => ({ id, title, kinds, depth: depth ?? 'standard', ...(experimental ? { experimental } : {}) })),
239
+ profiles: profiles.map(({ id, title, summary, kinds }) => ({ id, title, summary, kinds })),
171
240
  });
172
241
  case '/api/dirs': {
173
242
  const given = url.searchParams.get('path');
@@ -205,49 +274,137 @@ export function startUi(opts) {
205
274
  return send(res, 400, { error: err instanceof Error ? err.message : String(err) });
206
275
  }
207
276
  }
208
- case '/api/run': {
209
- if (!(req.headers['content-type'] ?? '').startsWith('application/json'))
210
- return send(res, 415, { error: 'Send JSON.' });
211
- const text = await readBody(req);
212
- if (text === undefined) {
213
- res.setHeader('Connection', 'close');
214
- return send(res, 413, { error: 'The request is too large.' });
277
+ case '/api/projects': {
278
+ if (method === 'GET') {
279
+ return send(res, 200, { projects: listProjects().map((p) => ({ ...p, ...(active.has(p.id) ? { run: active.get(p.id).state } : {}) })) });
215
280
  }
216
- const body = (() => {
217
- try {
218
- return JSON.parse(text);
219
- }
220
- catch {
221
- return null; // answered as a missing path
222
- }
223
- })();
224
- if (!body || typeof body.path !== 'string' || body.path === '')
281
+ const body = await jsonBody(req, res);
282
+ if (!body)
283
+ return;
284
+ if (typeof body.path !== 'string' || body.path === '')
225
285
  return send(res, 400, { error: 'Send a path.' });
226
- if (controller)
227
- return send(res, 409, { error: 'A run is in progress.' });
228
- const type = body.type === 'theme' || body.type === 'plugin' || body.type === 'install' ? body.type : undefined;
229
- const ids = Array.isArray(body.engines) ? body.engines.filter((x) => typeof x === 'string') : [];
230
286
  try {
231
- detectTarget(body.path, type ? { type } : {});
287
+ const added = addProject(body.path);
288
+ if (added.added)
289
+ broadcast('projects', {});
290
+ return send(res, 200, added);
232
291
  }
233
292
  catch (err) {
234
293
  return send(res, 400, { error: err instanceof Error ? err.message : String(err) });
235
294
  }
236
- for (const id of ids) {
237
- if (!opts.engines.some((e) => e.id === id))
238
- return send(res, 400, { error: `Unknown engine "${id}".` });
295
+ }
296
+ case '/api/projects/remove': {
297
+ const body = await jsonBody(req, res);
298
+ if (!body)
299
+ return;
300
+ const id = body.id;
301
+ if (typeof id !== 'string' || !listProjects().some((p) => p.id === id))
302
+ return send(res, 404, { error: 'No such project.' });
303
+ if (active.has(id))
304
+ return send(res, 409, { error: 'Stop the run first.' });
305
+ removeProject(id);
306
+ finished.delete(id);
307
+ broadcast('projects', {});
308
+ return send(res, 200, { ok: true });
309
+ }
310
+ case '/api/run': {
311
+ const body = await jsonBody(req, res);
312
+ if (!body)
313
+ return;
314
+ const ids = body.ids;
315
+ if (!Array.isArray(ids) || ids.length === 0 || !ids.every((x) => typeof x === 'string'))
316
+ return send(res, 400, { error: 'Send the projects to run.' });
317
+ const all = listProjects();
318
+ const chosen = ids.map((id) => all.find((p) => p.id === id));
319
+ if (chosen.some((p) => !p?.kind))
320
+ return send(res, 400, { error: 'No such project.' });
321
+ const depth = body.depth;
322
+ if (depth !== undefined && !DEPTHS.some((d) => d === depth))
323
+ return send(res, 400, { error: `Unknown depth "${String(depth)}".` });
324
+ const profile = body.profile;
325
+ if (profile !== undefined) {
326
+ const found = typeof profile === 'string' ? profiles.find((p) => p.id === profile) : undefined;
327
+ if (!found)
328
+ return send(res, 400, { error: `Unknown profile "${String(profile)}".` });
329
+ if (chosen.length > 1)
330
+ return send(res, 400, { error: 'A profile works with one project.' });
331
+ if (!found.kinds.includes(chosen[0].kind))
332
+ return send(res, 400, { error: `The ${found.id} profile does not fit "${chosen[0].name}".` });
333
+ }
334
+ const started = [];
335
+ for (const p of chosen) {
336
+ if (active.has(p.id))
337
+ continue;
338
+ active.set(p.id, {
339
+ path: p.path,
340
+ state: 'queued',
341
+ controller: new AbortController(),
342
+ events: [],
343
+ ...(depth ? { depth: depth } : {}),
344
+ ...(profile ? { profile: profile } : {}),
345
+ ...(body.experimental === true ? { experimental: true } : {}),
346
+ });
347
+ queue.push(p.id);
348
+ started.push(p.id);
239
349
  }
240
- start(body.path, type, ids.length > 0 ? ids : undefined);
241
- return send(res, 202, { ok: true });
350
+ pump();
351
+ if (started.length > 0)
352
+ broadcast('projects', {});
353
+ return send(res, 202, { started });
242
354
  }
243
- case '/api/cancel':
244
- controller?.abort();
355
+ case '/api/cancel': {
356
+ const text = await readBody(req);
357
+ if (text === undefined) {
358
+ res.setHeader('Connection', 'close');
359
+ return send(res, 413, { error: 'The request is too large.' });
360
+ }
361
+ let id;
362
+ try {
363
+ id = JSON.parse(text)?.id;
364
+ }
365
+ catch {
366
+ // An empty or unreadable body means every run.
367
+ }
368
+ if (typeof id === 'string')
369
+ cancel(id);
370
+ else
371
+ for (const key of [...active.keys()])
372
+ cancel(key);
245
373
  return send(res, 200, { ok: true });
374
+ }
246
375
  case '/api/report': {
247
- if (!last)
376
+ const id = url.searchParams.get('id') ?? '';
377
+ const found = reportOf(id);
378
+ if (!found)
379
+ return send(res, 404, { error: 'No report yet.' });
380
+ const result = found.session?.result ?? readPreviousRun(found.dir);
381
+ if (!result)
248
382
  return send(res, 404, { error: 'No report yet.' });
249
- const { result, diff, files, dir } = last;
250
- return send(res, 200, { result, ...(diff ? { diff } : {}), files, dir });
383
+ const diff = found.session?.diff;
384
+ return send(res, 200, {
385
+ summary: result.summary,
386
+ engines: result.engines,
387
+ finishedAt: result.finishedAt,
388
+ ...(result.profile ? { profile: result.profile } : {}),
389
+ ...(result.depth ? { depth: result.depth } : {}),
390
+ ...(result.experimental ? { experimental: true } : {}),
391
+ ...(diff ? { diff: { fixed: diff.fixed.length, added: diff.added.length, open: diff.open.length } } : {}),
392
+ files: found.session?.files ?? REPORT_FILES.map((f) => path.join(found.dir, f)),
393
+ dir: found.dir,
394
+ });
395
+ }
396
+ case '/api/report.html': {
397
+ const found = reportOf(url.searchParams.get('id') ?? '');
398
+ try {
399
+ const body = readFileSync(path.join(found?.dir ?? '', 'report.html'));
400
+ if (!found)
401
+ throw new Error('none');
402
+ res.writeHead(200, { ...HEADERS, 'Content-Security-Policy': REPORT_CSP, 'Content-Type': TYPES['.html'] });
403
+ return void res.end(body);
404
+ }
405
+ catch {
406
+ return send(res, 404, { error: 'No report yet.' });
407
+ }
251
408
  }
252
409
  default: {
253
410
  res.writeHead(200, {
@@ -255,7 +412,11 @@ export function startUi(opts) {
255
412
  'Content-Type': 'text/event-stream; charset=utf-8',
256
413
  Connection: 'keep-alive',
257
414
  });
258
- sse(res, 'snapshot', { running: controller !== undefined, events });
415
+ const runs = [
416
+ ...[...finished].map(([id, f]) => ({ id, state: 'ended', events: f.events })),
417
+ ...[...active].map(([id, a]) => ({ id, state: a.state, events: a.events })),
418
+ ];
419
+ sse(res, 'snapshot', { runs });
259
420
  clients.add(res);
260
421
  const ping = setInterval(() => res.write(': ping\n\n'), 25000);
261
422
  res.on('close', () => {
@@ -282,7 +443,9 @@ export function startUi(opts) {
282
443
  port,
283
444
  token,
284
445
  close: () => new Promise((done) => {
285
- controller?.abort();
446
+ queue.length = 0;
447
+ for (const a of active.values())
448
+ a.controller.abort();
286
449
  for (const c of clients)
287
450
  c.end();
288
451
  clients.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-shakedown",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Runs the usual WordPress checks on a theme, a plugin or a whole WordPress folder and writes one report.",
5
5
  "license": "GPL-2.0-or-later",
6
6
  "type": "module",
@@ -35,6 +35,7 @@
35
35
  "url": "git+https://github.com/alexposlushnyak/wp-shakedown.git"
36
36
  },
37
37
  "bugs": "https://github.com/alexposlushnyak/wp-shakedown/issues",
38
+ "author": "alexposlushnyak (https://github.com/alexposlushnyak)",
38
39
  "homepage": "https://github.com/alexposlushnyak/wp-shakedown#readme",
39
40
  "keywords": [
40
41
  "wordpress",
@@ -9,7 +9,9 @@
9
9
  "plugin-check/phpcs-sniffs": "2.2.0",
10
10
  "phpstan/phpstan": "^2.1",
11
11
  "szepeviktor/phpstan-wordpress": "^2.0",
12
- "php-stubs/wordpress-stubs": "^7.0"
12
+ "php-stubs/wordpress-stubs": "^7.0",
13
+ "theme-check/theme-check": "20260901",
14
+ "envato/envato-theme-check": "dev-master"
13
15
  },
14
16
  "config": {
15
17
  "allow-plugins": {
@@ -35,6 +37,32 @@
35
37
  "squizlabs/php_codesniffer": "^3.7.2"
36
38
  }
37
39
  }
40
+ },
41
+ {
42
+ "type": "package",
43
+ "package": {
44
+ "name": "theme-check/theme-check",
45
+ "version": "20260901",
46
+ "type": "library",
47
+ "dist": {
48
+ "url": "https://downloads.wordpress.org/plugin/theme-check.20260901.zip",
49
+ "type": "zip",
50
+ "shasum": "85c13a0c70078367d2d6f3dd68e435212df5881a"
51
+ }
52
+ }
53
+ },
54
+ {
55
+ "type": "package",
56
+ "package": {
57
+ "name": "envato/envato-theme-check",
58
+ "version": "dev-master",
59
+ "type": "library",
60
+ "dist": {
61
+ "url": "https://github.com/envato/envato-theme-check/archive/915562cc78065a69e65f27bc30993dcae4cacef6.zip",
62
+ "type": "zip",
63
+ "reference": "915562cc78065a69e65f27bc30993dcae4cacef6"
64
+ }
65
+ }
38
66
  }
39
67
  ]
40
68
  }
@@ -4,7 +4,7 @@
4
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
5
  "This file is @generated automatically"
6
6
  ],
7
- "content-hash": "5678bc26a89a5ba7d8a4f580892c8189",
7
+ "content-hash": "ee49e41d72b6875f16f9804e079d9a0f",
8
8
  "packages": [
9
9
  {
10
10
  "name": "dealerdirect/phpcodesniffer-composer-installer",
@@ -103,6 +103,16 @@
103
103
  "time": "2026-05-06T08:26:05+00:00",
104
104
  "published-time": "2026-05-06T12:56:03+00:00"
105
105
  },
106
+ {
107
+ "name": "envato/envato-theme-check",
108
+ "version": "dev-master",
109
+ "dist": {
110
+ "type": "zip",
111
+ "url": "https://github.com/envato/envato-theme-check/archive/915562cc78065a69e65f27bc30993dcae4cacef6.zip",
112
+ "reference": "915562cc78065a69e65f27bc30993dcae4cacef6"
113
+ },
114
+ "type": "library"
115
+ },
106
116
  {
107
117
  "name": "php-stubs/wordpress-stubs",
108
118
  "version": "v7.1.2",
@@ -786,6 +796,16 @@
786
796
  "time": "2026-05-22T16:22:09+00:00",
787
797
  "published-time": "2026-08-28T06:48:49+00:00"
788
798
  },
799
+ {
800
+ "name": "theme-check/theme-check",
801
+ "version": "20260901",
802
+ "dist": {
803
+ "type": "zip",
804
+ "url": "https://downloads.wordpress.org/plugin/theme-check.20260901.zip",
805
+ "shasum": "85c13a0c70078367d2d6f3dd68e435212df5881a"
806
+ },
807
+ "type": "library"
808
+ },
789
809
  {
790
810
  "name": "wp-coding-standards/wpcs",
791
811
  "version": "3.4.1",
@@ -858,6 +878,7 @@
858
878
  "aliases": [],
859
879
  "minimum-stability": "alpha",
860
880
  "stability-flags": {
881
+ "envato/envato-theme-check": 20,
861
882
  "phpcompatibility/phpcompatibility-wp": 15
862
883
  },
863
884
  "prefer-stable": true,