@ideasonpurpose/build-tools-wordpress 2.10.6 → 2.10.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.
@@ -27,8 +27,10 @@ import prettier from "prettier";
27
27
  * - wp:gallery
28
28
  */
29
29
 
30
- import { readFile, writeFile } from "fs/promises";
31
- import { resolve, basename } from "path";
30
+ import { realpathSync } from "node:fs";
31
+ import { readFile, writeFile } from "node:fs/promises";
32
+ import { basename, resolve } from "node:path";
33
+ import { fileURLToPath } from "node:url";
32
34
 
33
35
  /**
34
36
  *
@@ -146,7 +148,7 @@ export function trimInsideListElements(content) {
146
148
  .replace(/\s*<!-- wp:list /g, "<!-- wp:list ")
147
149
  .replace(/>\s*<!-- wp:list /g, ">\n\n<!-- wp:list ")
148
150
  .replace(/>\s*<!-- wp:list-item /g, ">\n\n<!-- wp:list-item ")
149
- .replace(/<!-- \/wp:list-item -->\s*</g, "<!-- \/wp:list-item -->\n\n<")
151
+ .replace(/<!-- \/wp:list-item -->\s*</g, "<!-- /wp:list-item -->\n\n<")
150
152
  .replace(/<li>\s*/g, "<li>")
151
153
  .replace(/\s*<\/li>/g, "</li>");
152
154
  }
@@ -177,12 +179,10 @@ export function formatWithPrettier(content) {
177
179
  }
178
180
 
179
181
  /**
180
- * @param {String} filepath
182
+ * @param {string} content
183
+ * @returns {Promise<string>}
181
184
  */
182
- export async function formatWPBlockPattern(filepath) {
183
- const startTime = process.hrtime.bigint();
184
- const rawFile = await readFile(filepath, "utf8");
185
-
185
+ export async function formatWPBlockPatternContent(content) {
186
186
  const formatters = [
187
187
  formatWithPrettier,
188
188
  normalizeCommentTagSpacing,
@@ -192,10 +192,19 @@ export async function formatWPBlockPattern(filepath) {
192
192
  normalizeNewlines,
193
193
  ];
194
194
 
195
- const outputHtml = await formatters.reduce(
195
+ return formatters.reduce(
196
196
  async (acc, fn) => fn(await acc),
197
- Promise.resolve(rawFile),
197
+ Promise.resolve(content),
198
198
  );
199
+ }
200
+
201
+ /**
202
+ * @param {string} filepath
203
+ */
204
+ export async function formatWPBlockPattern(filepath) {
205
+ const startTime = process.hrtime.bigint();
206
+ const rawFile = await readFile(filepath, "utf8");
207
+ const outputHtml = await formatWPBlockPatternContent(rawFile);
199
208
 
200
209
  await writeFile(filepath, outputHtml, "utf8");
201
210
  const endTime = process.hrtime.bigint();
@@ -204,11 +213,49 @@ export async function formatWPBlockPattern(filepath) {
204
213
  console.log(`${basename(filepath)} ${(duration / 1e6).toFixed(2)}ms`);
205
214
  }
206
215
 
216
+ /**
217
+ * @returns {Promise<string>}
218
+ */
219
+ async function readStdin() {
220
+ const chunks = [];
221
+ for await (const chunk of process.stdin) {
222
+ chunks.push(chunk);
223
+ }
224
+ return Buffer.concat(chunks).toString("utf8");
225
+ }
226
+
207
227
  export async function main(filepath = process.argv[2]) {
208
- if (!filepath) {
209
- console.error("Error: A filepath is required.");
210
- return;
228
+ try {
229
+ if (filepath) {
230
+ await formatWPBlockPattern(resolve(filepath));
231
+ return;
232
+ }
233
+
234
+ if (process.stdin.isTTY) {
235
+ console.error(
236
+ "Usage: iop-format-wp-block-pattern <filepath>\n iop-format-wp-block-pattern < input.php",
237
+ );
238
+ process.exitCode = 1;
239
+ return;
240
+ }
241
+
242
+ const formatted = await formatWPBlockPatternContent(await readStdin());
243
+ process.stdout.write(formatted);
244
+ } catch (error) {
245
+ console.error("Error:", error);
246
+ process.exitCode = 1;
211
247
  }
212
- await formatWPBlockPattern(resolve(filepath));
213
248
  }
214
- if (process.argv[2]) main();
249
+
250
+ const isMain = (() => {
251
+ if (process.argv[1] == null) return false;
252
+ try {
253
+ return (
254
+ fileURLToPath(import.meta.url) === realpathSync(resolve(process.argv[1]))
255
+ );
256
+ } catch {
257
+ return false;
258
+ }
259
+ })();
260
+
261
+ if (isMain) main();
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ //@ts-check
4
+
5
+ import { execFileSync } from "node:child_process";
6
+ import { realpathSync } from "node:fs";
7
+ import { resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const blockPatternPath = /(?:^|\/)wp-content\/themes\/[^/]+\/patterns\/.*\.php$/;
11
+
12
+ /**
13
+ * @param {string} filepath
14
+ * @returns {string}
15
+ */
16
+ export function getFormatter(filepath) {
17
+ const normalizedPath = filepath.replaceAll("\\", "/");
18
+ return blockPatternPath.test(normalizedPath)
19
+ ? "iop-format-wp-block-pattern"
20
+ : "format-mixed-php-html";
21
+ }
22
+
23
+ /**
24
+ * @param {string[]} args
25
+ */
26
+ export async function main(args = process.argv.slice(2)) {
27
+ const fileFlagIndex = args.indexOf("--file");
28
+ const filepath = args[fileFlagIndex + 1];
29
+
30
+ if (fileFlagIndex === -1 || !filepath) {
31
+ console.error(
32
+ "Usage: iop-format-wp-php --file <filepath> < input.php",
33
+ );
34
+ process.exitCode = 1;
35
+ return;
36
+ }
37
+
38
+ if (process.stdin.isTTY) {
39
+ console.error(
40
+ "Usage: iop-format-wp-php --file <filepath> < input.php",
41
+ );
42
+ process.exitCode = 1;
43
+ return;
44
+ }
45
+
46
+ const formatter = getFormatter(filepath);
47
+
48
+ try {
49
+ const formatted = execFileSync(formatter, [], {
50
+ input: await readStdin(),
51
+ encoding: "utf8",
52
+ stdio: ["pipe", "pipe", "inherit"],
53
+ });
54
+ process.stdout.write(formatted);
55
+ } catch (error) {
56
+ console.error(`Error running ${formatter}:`, error);
57
+ process.exitCode = 1;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @returns {Promise<string>}
63
+ */
64
+ async function readStdin() {
65
+ const chunks = [];
66
+ for await (const chunk of process.stdin) {
67
+ chunks.push(chunk);
68
+ }
69
+ return Buffer.concat(chunks).toString("utf8");
70
+ }
71
+
72
+ const isMain = (() => {
73
+ if (process.argv[1] == null) return false;
74
+ try {
75
+ return (
76
+ fileURLToPath(import.meta.url) === realpathSync(resolve(process.argv[1]))
77
+ );
78
+ } catch {
79
+ return false;
80
+ }
81
+ })();
82
+
83
+ if (isMain) main();
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+
3
+ // @ts-check
4
+
5
+ import { readFileSync } from "node:fs";
6
+ import { loadConfig, optimize } from "svgo";
7
+ import fallbackConfig from "../config/svgo.config.mjs";
8
+
9
+ console.error("starting iop-vscode-svgo");
10
+
11
+ if (process.stdin.isTTY) {
12
+ process.stderr.write("Error: No SVG data received on stdin\n");
13
+ process.exit(1);
14
+ }
15
+
16
+ const svg = readFileSync(0, "utf8").trim();
17
+ if (!svg) {
18
+ process.stderr.write("Error: No SVG data received on stdin\n");
19
+ process.exit(1);
20
+ }
21
+
22
+ try {
23
+ const svgoConfig = /** @type {import("svgo").Config} */ (
24
+ (await loadConfig()) ?? fallbackConfig
25
+ );
26
+ const result = optimize(svg, svgoConfig);
27
+ process.stdout.write(result.data);
28
+ } catch (err) {
29
+ process.stderr.write(`Error: ${err instanceof Error ? err.message : err}\n`);
30
+ process.exit(1);
31
+ }
32
+ console.error("Done!");
package/biome.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.6/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false
10
+ },
11
+ "formatter": {
12
+ "enabled": true,
13
+ "indentStyle": "space"
14
+ },
15
+ "linter": {
16
+ "enabled": true,
17
+ "rules": {
18
+ "preset": "recommended",
19
+ "a11y": {
20
+ "noSvgWithoutTitle": "off"
21
+ },
22
+ "style": {
23
+ "useNodejsImportProtocol": {
24
+ "level": "error",
25
+ "fix": "safe"
26
+ }
27
+ }
28
+ }
29
+ },
30
+ "javascript": {
31
+ "formatter": {
32
+ "quoteStyle": "double"
33
+ }
34
+ },
35
+ "assist": {
36
+ "enabled": true,
37
+ "actions": {
38
+ "source": {
39
+ "organizeImports": "on"
40
+ }
41
+ }
42
+ }
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideasonpurpose/build-tools-wordpress",
3
- "version": "2.10.6",
3
+ "version": "2.10.8",
4
4
  "description": "Build scripts and dependencies for IOP's WordPress development environments.",
5
5
  "homepage": "https://github.com/ideasonpurpose/build-tools-wordpress#readme",
6
6
  "bugs": {
@@ -23,14 +23,16 @@
23
23
  "iop-build-zip-archive": "./bin/zip.js",
24
24
  "iop-html-php-prettier": "./bin/format-php-prettier.js",
25
25
  "iop-format-wp-block-pattern": "./bin/format-wp-block-pattern.js",
26
- "iop-project-refresh": "./bin/refresh.js"
26
+ "iop-format-wp-php": "./bin/format-wp-php.js",
27
+ "iop-project-refresh": "./bin/refresh.js",
28
+ "iop-vscode-svgo": "./bin/vscode-svgo.js"
27
29
  },
28
30
  "directories": {
29
31
  "lib": "lib"
30
32
  },
31
33
  "scripts": {
32
34
  "test": "vitest",
33
- "version": "version-everything && auto-changelog && git add -u"
35
+ "version": "version-everything && git add -u"
34
36
  },
35
37
  "prettier": "@ideasonpurpose/prettier-config",
36
38
  "dependencies": {
@@ -89,12 +91,10 @@
89
91
  "version-everything": "^0.12.2",
90
92
  "webpack": "^5.108.4",
91
93
  "webpack-bundle-analyzer": "^5.3.1",
94
+ "webpack-cli": "^6.0.1",
92
95
  "webpack-dev-server": "^6.0.0",
93
96
  "webpack-manifest-plugin": "^6.0.1"
94
97
  },
95
- "peerDependencies": {
96
- "webpack-cli": "^6.0.1"
97
- },
98
98
  "engines": {
99
99
  "node": ">=22.15.0"
100
100
  },