@ideasonpurpose/build-tools-wordpress 2.1.0 → 2.1.2

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/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### v2.1.1
8
+
9
+ > 9 April 2025
10
+
11
+ - Clean up outputs a little
12
+
13
+ #### v2.1.0
14
+
15
+ > 1 April 2025
16
+
17
+ - bump deps
18
+ - Standardize on sass-embedded, clean up, bump deps
19
+
7
20
  #### v2.0.6
8
21
 
9
22
  > 20 March 2025
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ideasonpurpose/build-tools-wordpress
2
2
 
3
- #### Version 2.1.0
3
+ #### Version 2.1.2
4
4
 
5
5
  [![NPM Version](https://img.shields.io/npm/v/%40ideasonpurpose%2Fbuild-tools-wordpress?logo=npm)](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
6
6
  [![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ideasonpurpose/build-tools-wordpress/npm-publish.yml?logo=github&logoColor=white)](https://github.com/ideasonpurpose/build-tools-wordpress#readme)
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * This is an experimental proof-of-concept for formatting mixed HTML & PHP
5
+ * files from a single function.
6
+ *
7
+ * TODO: Testing, naming, modularization, VS Code extension
8
+ */
9
+ import prettier from "prettier";
10
+ import prettierConfig from "@ideasonpurpose/prettier-config" with { type: "json" };
11
+
12
+ import { readFile, writeFile } from "fs/promises";
13
+ import { resolve, basename } from "path";
14
+
15
+ /**
16
+ * Prettier API doesn't recognize overrides, so we extract them
17
+ */
18
+ const htmlOptions = prettierConfig.overrides.find(
19
+ (o) => o.files === "*.html",
20
+ )?.options;
21
+
22
+ const phpOptions = prettierConfig.overrides.find(
23
+ (o) => o.files === "*.php",
24
+ )?.options;
25
+
26
+ function tokenizeHTML(htmlContent) {
27
+ const phpCodeBlocks = {};
28
+ let tokenCount = 0;
29
+
30
+ // Tokens are end-padded to the length of the span, up to 80 characters
31
+ const tokenizedHTML = htmlContent.replace(
32
+ /<\?(?:php|=)[\s\S]*?\?>/gs,
33
+ (phpCodeBlock) => {
34
+ const codeLength = Math.min(phpCodeBlock.length, 80);
35
+ const token = `__php_${tokenCount++}__`.padEnd(codeLength, "_");
36
+ phpCodeBlocks[token] = phpCodeBlock;
37
+ return token;
38
+ },
39
+ );
40
+
41
+ return { tokenizedHTML, phpCodeBlocks };
42
+ }
43
+
44
+ function unTokenizeHTML(htmlContent, tokens) {
45
+ let phpContent = htmlContent;
46
+ for (const token in tokens) {
47
+ phpContent = phpContent.replace(new RegExp(token, "g"), tokens[token]);
48
+ }
49
+ return phpContent;
50
+ }
51
+
52
+ async function formatHTMLThenPHP(filepath) {
53
+ try {
54
+ const startTime = process.hrtime.bigint();
55
+ const rawFile = await readFile(filepath, "utf8");
56
+
57
+ const { tokenizedHTML, phpCodeBlocks } = tokenizeHTML(rawFile);
58
+
59
+ const htmlFormatted = await prettier.format(tokenizedHTML, {
60
+ ...prettierConfig,
61
+ ...htmlOptions,
62
+ parser: "html",
63
+ });
64
+
65
+ const phpUnTokenized = unTokenizeHTML(htmlFormatted, phpCodeBlocks);
66
+
67
+ const phpFormatted = await prettier.format(phpUnTokenized, {
68
+ ...prettierConfig,
69
+ ...phpOptions,
70
+ parser: "php",
71
+ });
72
+
73
+ await writeFile(filepath, phpFormatted, "utf8");
74
+ const endTime = process.hrtime.bigint();
75
+ const duration = Number(endTime - startTime);
76
+
77
+ console.log(`${basename(filepath)} ${(duration / 1e6).toFixed(2)}ms`);
78
+ } catch (error) {
79
+ console.error("Error:", error);
80
+ }
81
+ }
82
+
83
+ if (process.argv[2]) {
84
+ const fullPath = resolve(process.argv[2]);
85
+ formatHTMLThenPHP(fullPath);
86
+ } else {
87
+ console.error("Error: A filepath is required.");
88
+ }
package/bin/zip.js CHANGED
@@ -56,13 +56,13 @@ const versionDirName = `${archiveName}${archiveVersion}`.replace(/[ .]/g, "_");
56
56
  const zipFileName = `${versionDirName}.zip`;
57
57
  const zipFile = new URL(`_builds/${zipFileName}`, config.configFileUrl);
58
58
 
59
- console.log({
60
- archiveName,
61
- archiveVersion,
62
- versionDirName,
63
- zipFile,
64
- zipFileName,
65
- });
59
+ // console.log({
60
+ // archiveName,
61
+ // archiveVersion,
62
+ // versionDirName,
63
+ // zipFile,
64
+ // zipFileName,
65
+ // });
66
66
 
67
67
  ensureFileSync(zipFile.pathname);
68
68
  const output = createWriteStream(zipFile);
@@ -24,7 +24,7 @@ export async function devserverProxy(config) {
24
24
  console.log(
25
25
  chalk.cyan.bold(
26
26
  `PORT FROM DEVSERVER-PROXY: TRUE ${localPort.port}`,
27
- target,
27
+ // target,
28
28
  ),
29
29
  );
30
30
  }
@@ -49,7 +49,7 @@ export async function devserverProxy(config) {
49
49
  "PORT FROM DEVSERVER-PROXY:",
50
50
  chalk.cyan(config.proxy),
51
51
  chalk.bold(localPort.port),
52
- target,
52
+ // target,
53
53
  );
54
54
  }
55
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideasonpurpose/build-tools-wordpress",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
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": {
@@ -21,7 +21,8 @@
21
21
  "bin": {
22
22
  "iop-build-port-reporter": "./bin/port-reporter.js",
23
23
  "iop-build-zip-archive": "./bin/zip.js",
24
- "iop-project-init": "./bin/project-init.js"
24
+ "iop-project-init": "./bin/project-init.js",
25
+ "iop-html-php-prettier": "./bin/format-php-prettier.js"
25
26
  },
26
27
  "directories": {
27
28
  "lib": "lib"
@@ -32,19 +33,19 @@
32
33
  },
33
34
  "prettier": "@ideasonpurpose/prettier-config",
34
35
  "dependencies": {
35
- "@ideasonpurpose/prettier-config": "^1.0.0",
36
+ "@ideasonpurpose/prettier-config": "^1.0.1",
36
37
  "@ideasonpurpose/stylelint-config": "^1.1.1",
37
38
  "@rollup/plugin-commonjs": "^28.0.3",
38
39
  "@rollup/plugin-json": "^6.1.0",
39
40
  "@rollup/plugin-node-resolve": "^16.0.1",
40
41
  "@svgr/webpack": "^8.1.0",
41
- "@wordpress/dependency-extraction-webpack-plugin": "^6.20.0",
42
+ "@wordpress/dependency-extraction-webpack-plugin": "^6.22.0",
42
43
  "ansi-html": "^0.0.9",
43
44
  "archiver": "^7.0.1",
44
45
  "auto-changelog": "^2.5.0",
45
46
  "autoprefixer": "^10.4.21",
46
47
  "babel-loader": "^10.0.0",
47
- "caniuse-lite": "^1.0.30001707",
48
+ "caniuse-lite": "^1.0.30001713",
48
49
  "chalk": "^5.4.1",
49
50
  "chalk-cli": "^5.0.1",
50
51
  "classnames": "^2.5.1",
@@ -54,9 +55,9 @@
54
55
  "cross-env": "^7.0.3",
55
56
  "css-loader": "^7.1.2",
56
57
  "cssnano": "^7.0.6",
57
- "dotenv": "^16.4.7",
58
+ "dotenv": "^16.5.0",
58
59
  "esbuild-loader": "^4.3.0",
59
- "eslint": "^9.23.0",
60
+ "eslint": "^9.24.0",
60
61
  "filesize": "^10.1.6",
61
62
  "fs-extra": "^11.3.0",
62
63
  "globby": "^14.1.0",
@@ -73,17 +74,17 @@
73
74
  "pretty-hrtime": "^1.0.3",
74
75
  "read-package-up": "^11.0.0",
75
76
  "replacestream": "^4.0.3",
76
- "sass-embedded": "^1.86.1",
77
+ "sass-embedded": "^1.86.3",
77
78
  "sass-loader": "^16.0.5",
78
79
  "semver": "^7.7.1",
79
- "sharp": "^0.33.5",
80
+ "sharp": "^0.34.1",
80
81
  "sort-package-json": "^3.0.0",
81
82
  "string-length": "^6.0.0",
82
83
  "style-loader": "^4.0.0",
83
84
  "svgo": "^3.3.2",
84
85
  "svgo-loader": "^4.0.0",
85
86
  "version-everything": "^0.11.4",
86
- "webpack": "^5.98.0",
87
+ "webpack": "^5.99.5",
87
88
  "webpack-bundle-analyzer": "^4.10.2",
88
89
  "webpack-dev-middleware": "^7.4.2",
89
90
  "webpack-dev-server": "^5.2.1"