@ideasonpurpose/build-tools-wordpress 1.1.2 → 1.1.3

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 ADDED
@@ -0,0 +1,50 @@
1
+ ### Changelog
2
+
3
+ All notable changes to this project will be documented in this file. Dates are displayed in UTC.
4
+
5
+ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
+
7
+ #### v1.1.2
8
+
9
+ > 23 January 2024
10
+
11
+ #### v1.1.1
12
+
13
+ > 23 January 2024
14
+
15
+ - versioning, github actions, bump deps, README
16
+ - update version in readme
17
+
18
+ #### v1.1.0
19
+
20
+ > 23 January 2024
21
+
22
+ - add packages
23
+ - name change, prepare for npm publish
24
+ - add port-reporter script, giving up on linking local pacakges
25
+
26
+ #### v1.0.4
27
+
28
+ > 16 January 2024
29
+
30
+ - embed default.config
31
+
32
+ #### v1.0.3
33
+
34
+ > 16 January 2024
35
+
36
+ - buildConfig
37
+
38
+ #### v1.0.2
39
+
40
+ > 16 January 2024
41
+
42
+ - add sass-embedded
43
+
44
+ #### v1.0.1
45
+
46
+ > 16 January 2024
47
+
48
+ - add modules
49
+ - add lib, temp exports
50
+ - Initial commit
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @ideasonpurpose/build-tools-wordpress
2
2
 
3
- #### Version 1.1.2
3
+ #### Version 1.1.3
4
+
5
+ ![NPM Version](https://img.shields.io/npm/v/%40ideasonpurpose%2Fbuild-tools-wordpress?logo=npm)
6
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ideasonpurpose/build-tools-wordpress/npm-publish.yml?logo=github&logoColor=white)
7
+
4
8
 
5
9
  Build scripts and dependencies for IOP's WordPress development environments.
6
10
 
@@ -8,8 +12,6 @@ Build scripts and dependencies for IOP's WordPress development environments.
8
12
 
9
13
  These tools were migrated from our [Docker-based WordPress build tools](https://github.com/ideasonpurpose/docker-build) to speed up development and began the process of moving our build tools away from webpack. Gathering dependencies also simplifies the package.json files in host projects, making those slightly more manageable.
10
14
 
11
- This may end up being the container for all tools required for building a project. That would allow us to clean out most of the cruft from our project directories and only have a single dependency which packages everything we need.
12
-
13
15
  The included webpack.config.js file works best when paired with a PHP environment like our [Docker WordPress environments](https://github.com/ideasonpurpose/docker-wordpress-dev). It's capable of proxying to other servers, but that's sort of crazy.
14
16
 
15
17
  ### Additional Notes
@@ -18,33 +20,12 @@ This project expects an entirely ES Module based environment and specifies all d
18
20
 
19
21
  #### Publishing to [npm](https://www.npmjs.com/package/@ideasonpurpose/build-tools-wordpress)
20
22
 
21
- A GitHub action will auto-publish version-tagged releases to npm. In order to publish, the repository must have an `NPM_TOKEN` secret set with the token from npm. Log into npmjs.org with a publish-authorized account, then find the token linked from the Profile page sidebar.
23
+ A GitHub action will auto-publish version-tagged releases to npm. In order to publish, the repository must have an `NPM_TOKEN` secret set with the token from npm. [Log into npmjs.org](https://www.npmjs.com/login) with a publish-authorized account, then find the token page linked from the Profile page sidebar. Generate a new token and update the repository secret.
22
24
 
23
25
  ##  
24
26
 
25
- #### Brought to you by IOP
26
-
27
- <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-mint-on-black-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
28
27
 
29
28
  #### Brought to you by IOP
30
29
 
31
30
  <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-white-on-black-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
32
31
 
33
- #### Brought to you by IOP
34
-
35
- <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-clay-on-black-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
36
-
37
- #### Brought to you by IOP
38
-
39
- <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-white-on-mint-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
40
-
41
- #### Brought to you by IOP
42
-
43
- <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-black-on-mint-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
44
-
45
- #### Brought to you by IOP
46
-
47
- <a href="https://www.ideasonpurpose.com"><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/iop-logo-white-on-darkmint-88px.png" height="44" align="top" alt="IOP Logo"></a><img src="https://raw.githubusercontent.com/ideasonpurpose/ideasonpurpose/master/spacer.png" align="middle" width="4" height="54"> This project is actively developed and used in production at <a href="https://www.ideasonpurpose.com">Ideas On Purpose</a>.
48
-
49
- > _logo test..._
50
- > 😂
@@ -1,22 +1,40 @@
1
1
  #! /usr/bin/env node
2
- import { exec } from "node:child_process";
3
2
 
4
3
  import chalk from "chalk";
5
4
 
6
- exec("docker compose port wordpress 80", (error, stdout, stderr) => {
7
- if (error) {
8
- console.error(`exec error: ${error}`);
9
- return;
10
- }
11
- if (stdout) {
12
- const [addr, port] = stdout.split(":");
5
+ import { findLocalPort } from "../index.js";
6
+
7
+ /**
8
+ * This is a reporting/display wrapper for the local port discovery module
9
+ */
10
+ const main = async () => {
11
+ const info = await findLocalPort().catch((error) => ({ error }));
13
12
 
14
- console.log("\n",
13
+ if (info && info.port && info.hostname) {
14
+ console.log(
15
+ "\n",
15
16
  " 🚀 ",
16
- chalk.bold( "Local WP site:"),
17
- chalk.magenta(`http://localhost:${chalk.bold(port)}`),
17
+ chalk.bold("Local WP site:"),
18
+ chalk.magenta(`http://${info.hostname}:${chalk.bold(info.port)}`),
19
+ "\n",
18
20
  );
21
+ } else {
22
+ let errString, showDebug;
23
+
24
+ if (info.error) {
25
+ errString = info.error.toString();
26
+ } else {
27
+ errString = "Unknown error occurred. Unable to discover local port";
28
+ showDebug = true;
29
+ }
30
+
31
+ errString = errString.split("\n").join("\n ");
32
+
33
+ console.log("\n", " 🤖 ", chalk.red.bold(errString));
34
+ if (showDebug) {
35
+ console.log(chalk.green(" 🐛 Debug:"), info);
36
+ }
19
37
  }
20
- // console.log(`stdout: ${stdout}`);
21
- // console.error(`stderr: ${stderr}`);
22
- });
38
+ };
39
+
40
+ main();
package/index.js CHANGED
@@ -1,16 +1,20 @@
1
- import AfterDoneReporterPlugin from "./lib/AfterDoneReporterPlugin.js";
2
- import buildConfig from "./lib/buildConfig.js";
3
- import DependencyManifestPlugin from "./lib/DependencyManifestPlugin.js";
4
- import devserverProxy from "./lib/devserver-proxy.js";
5
- import WatchRunReporterPlugin from "./lib/WatchRunReporterPlugin.js";
1
+ export { AfterDoneReporterPlugin } from "./lib/AfterDoneReporterPlugin.js";
2
+ export { buildConfig } from "./lib/buildConfig.js";
3
+ export { DependencyManifestPlugin } from "./lib/DependencyManifestPlugin.js";
4
+ // export * from "./lib/DependencyManifestPlugin.js";
5
+ export { devserverProxy } from "./lib/devserver-proxy.js";
6
+ export { WatchRunReporterPlugin } from "./lib/WatchRunReporterPlugin.js";
7
+ export { findLocalPort } from "./lib/find-local-docker-port.js";
8
+ // export * from "./lib/find-local-docker-port.js";
9
+ // import findLocalPort from "./lib/find-local-docker-port.js";
6
10
 
7
-
8
-
9
- // export { };
10
- export {
11
- AfterDoneReporterPlugin,
12
- buildConfig,
13
- DependencyManifestPlugin,
14
- devserverProxy,
15
- WatchRunReporterPlugin,
16
- };
11
+ // export default {
12
+ // // AfterDoneReporterPlugin,
13
+ // // buildConfig,
14
+ // // DependencyManifestPlugin,
15
+ // // devserverProxy,
16
+ // // WatchRunReporterPlugin,
17
+ // // findLocalPort,
18
+ // // // moo: () => console.log("COW SAYS"),
19
+ // };
20
+ // export const moo = () => console.log("COW SAYS");
@@ -8,7 +8,7 @@ import humanizeDuration from "humanize-duration";
8
8
  *
9
9
  * new AfterDoneReporterPlugin({message: "Your Message Here"})
10
10
  */
11
- export default class AfterDoneReporterPlugin {
11
+ export class AfterDoneReporterPlugin {
12
12
  constructor(options = {}) {
13
13
  const defaults = {
14
14
  echo: true,
@@ -23,6 +23,7 @@ export default class AfterDoneReporterPlugin {
23
23
  apply(compiler) {
24
24
  compiler.hooks.done.tapPromise(this.name, async (stats) => {
25
25
  if (this.config.echo) {
26
+ // console.log(compiler);
26
27
  const { host, port } = compiler.options.devServer;
27
28
  const { startTime, endTime, modules, assetsInfo } = stats.compilation;
28
29
  const hostname = host === "0.0.0.0" ? "localhost" : host;
@@ -39,7 +40,7 @@ export default class AfterDoneReporterPlugin {
39
40
  this.config.message,
40
41
  ]
41
42
  .filter((m) => m.length)
42
- .join("\n" + this.config.prefix);
43
+ .join("\n" + this.config.prefix + " ");
43
44
 
44
45
  setTimeout(() =>
45
46
  console.log("\n" + this.config.prefix + " " + messages)
@@ -1,7 +1,7 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
3
 
4
- class DependencyManifestPlugin {
4
+ export class DependencyManifestPlugin {
5
5
  constructor(options) {
6
6
  const defaults = {
7
7
  writeManifestFile: false,
@@ -74,4 +74,4 @@ class DependencyManifestPlugin {
74
74
  }
75
75
  }
76
76
 
77
- export default DependencyManifestPlugin;
77
+ // export default DependencyManifestPlugin;
@@ -7,7 +7,7 @@ import chalk from "chalk";
7
7
  *
8
8
  * new WatchRunReporterPlugin({message: "Your Message Here"})
9
9
  */
10
- class WatchRunReporterPlugin {
10
+ export class WatchRunReporterPlugin {
11
11
  constructor(options = {}) {
12
12
  const defaults = {
13
13
  echo: true,
@@ -50,5 +50,3 @@ class WatchRunReporterPlugin {
50
50
  });
51
51
  }
52
52
  }
53
-
54
- export default WatchRunReporterPlugin;
@@ -2,6 +2,8 @@ import fs from "fs-extra";
2
2
  import { posix as path } from "path";
3
3
  import chalk from "chalk";
4
4
 
5
+ import { findLocalPort } from "../index.js";
6
+
5
7
  // import defaultConfig from "../default.config.js";
6
8
 
7
9
  const defaultConfig = {
@@ -12,15 +14,11 @@ const defaultConfig = {
12
14
  contentBase: "/dist/", // TODO: Should this be false?
13
15
  manifestFile: "./dependency-manifest.json",
14
16
  sass: "sass-embedded",
15
- port: 8080,
17
+ // port: 8080,
16
18
  transpileDependencies: ["ansi-regex", "normalize-url"],
17
- proxy: 'wordpress',
19
+ proxy: "wordpress",
18
20
  };
19
21
 
20
-
21
-
22
-
23
-
24
22
  /**
25
23
  * This file encapsulates all the config file massaging and allows
26
24
  * for asynchronous values.
@@ -29,7 +27,7 @@ const defaultConfig = {
29
27
  * -
30
28
  */
31
29
 
32
- export default (configFile = { config: {} }) => {
30
+ export async function buildConfig(configFile = { config: {} }) {
33
31
  /**
34
32
  * This is a temporary workaround for a problem with using `process.env.NAME` in
35
33
  * base ideasonpurpose.config.js files. `NAME` is often set in the environment
@@ -42,7 +40,7 @@ export default (configFile = { config: {} }) => {
42
40
  if (configFile.filepath) {
43
41
  const rawConfigFile = fs.readFileSync(configFile.filepath);
44
42
  const packageJson = fs.readJsonSync(
45
- path.resolve(configFile.filepath, "../package.json")
43
+ path.resolve(configFile.filepath, "../package.json"),
46
44
  );
47
45
  // console.log({ p: process.env.NAME });
48
46
  if (
@@ -154,11 +152,11 @@ export default (configFile = { config: {} }) => {
154
152
  console.log(
155
153
  "⚠️ ",
156
154
  chalk.bold.yellow("NOTICE"),
157
- chalk.yellow("NOTICE node-sass is no longer supported. The js-compiled")
155
+ chalk.yellow("NOTICE node-sass is no longer supported. The js-compiled"),
158
156
  );
159
157
  console.log(chalk.yellow(" dart-sass package will be used instead."));
160
158
  console.log(
161
- chalk.cyan(" https://sass-lang.com/blog/libsass-is-deprecated/")
159
+ chalk.cyan(" https://sass-lang.com/blog/libsass-is-deprecated/"),
162
160
  );
163
161
  console.log(chalk.cyan(" https://www.npmjs.com/package/sass"));
164
162
  }
@@ -169,9 +167,20 @@ export default (configFile = { config: {} }) => {
169
167
  if (config.proxy === true) {
170
168
  config.proxy = defaultConfig.proxy;
171
169
  }
170
+ const localPort = await findLocalPort();
171
+
172
+ config.proxy = `http://${localPort.hostname}:${localPort.port}`;
173
+ console.log(
174
+ chalk.cyan.bold(
175
+ `FOUND THE PORT IN BUILDCONFIG ${localPort.port}`,
176
+ config.proxy,
177
+ ),
178
+ );
179
+
180
+ /// TODO: Move the port-finding stuff in here?
172
181
 
173
182
  return config;
174
- };
183
+ }
175
184
 
176
185
  /**
177
186
  * Warnings are broken out below
@@ -180,8 +189,8 @@ const noSrcExists = (src) => {
180
189
  console.log(
181
190
  "🛑 ",
182
191
  chalk.bold.red(
183
- `ERROR: The src directory ${chalk.white(src)} does not exist.`
184
- )
192
+ `ERROR: The src directory ${chalk.white(src)} does not exist.`,
193
+ ),
185
194
  );
186
195
  };
187
196
 
@@ -189,23 +198,23 @@ const nameEnvVarWarning = () => {
189
198
  console.log(
190
199
  "⚠️ ",
191
200
  chalk.yellow.bold(
192
- "WARNING: $NAME is set in the environment and the project's config file."
193
- )
201
+ "WARNING: $NAME is set in the environment and the project's config file.",
202
+ ),
194
203
  );
195
204
  console.log(
196
205
  chalk.yellow(
197
- " The value of $NAME will likely conflict with the name property from"
198
- )
206
+ " The value of $NAME will likely conflict with the name property from",
207
+ ),
199
208
  );
200
209
  console.log(
201
210
  chalk.yellow(
202
- " package.json. Please update the project's config.js file. To silence "
203
- )
211
+ " package.json. Please update the project's config.js file. To silence ",
212
+ ),
204
213
  );
205
214
  console.log(
206
215
  chalk.yellow(
207
- " this message, set $NAME in the environment to match the project's"
208
- )
216
+ " this message, set $NAME in the environment to match the project's",
217
+ ),
209
218
  );
210
219
  console.log(chalk.yellow(" package.json `name` property."));
211
220
  };
@@ -10,10 +10,10 @@ import { isIP } from "net";
10
10
  * If config.proxy is explicitly not false, return a {proxy} object
11
11
  * otherwise return an empty object.
12
12
  */
13
- export default async (config) => {
13
+ export async function devserverProxy(config) {
14
14
  let target;
15
15
 
16
- console.log({config});
16
+ // console.log({config});
17
17
 
18
18
  // if (
19
19
  // config.proxy ===
@@ -130,7 +130,7 @@ export default async (config) => {
130
130
  if (typeof header == "string") {
131
131
  header = header.replace(
132
132
  new RegExp(config.proxyUrl.host, "gi"),
133
- req.headers.host
133
+ req.headers.host,
134
134
  );
135
135
  }
136
136
  res.setHeader(String(key).trim(), header);
@@ -140,11 +140,11 @@ export default async (config) => {
140
140
  let newBody;
141
141
  const type = (proxyRes.headers["content-type"] || "").split(";")[0];
142
142
  const wpRegexp = new RegExp(
143
- "^/wp-(?:admin|includes|content/plugins).*(?:css|js|map)$"
143
+ "^/wp-(?:admin|includes|content/plugins).*(?:css|js|map)$",
144
144
  );
145
145
  const originRegExp = new RegExp(
146
146
  `(http:\\\\/\\\\/|http://)${config.proxyUrl.host}`,
147
- "gi"
147
+ "gi",
148
148
  );
149
149
 
150
150
  if (contentTypes.includes(type) && !wpRegexp.test(req.path)) {
@@ -163,4 +163,4 @@ export default async (config) => {
163
163
  };
164
164
 
165
165
  return { proxy };
166
- };
166
+ }
@@ -0,0 +1,19 @@
1
+ import { exec } from "node:child_process";
2
+
3
+ export function findLocalPort() {
4
+ // export default () => {
5
+ return new Promise((resolve, reject) => {
6
+ exec("docker compose port wordpress 80", (error, stdout, stderr) => {
7
+ if (error) {
8
+ reject(error);
9
+ return;
10
+ }
11
+
12
+ if (stdout) {
13
+ const [addr, port] = stdout.trim().split(":");
14
+ const hostname = addr === "0.0.0.0" ? "localhost" : addr;
15
+ resolve({ hostname, port, stdout: stdout.trim() });
16
+ }
17
+ });
18
+ });
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ideasonpurpose/build-tools-wordpress",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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": {
@@ -19,12 +19,18 @@
19
19
  "type": "module",
20
20
  "main": "index.js",
21
21
  "bin": {
22
- "iop-build-port-reporter": "port-reporter.js"
22
+ "iop-build-port-reporter": "./bin/port-reporter.js"
23
+ },
24
+ "directories": {
25
+ "lib": "lib"
23
26
  },
24
27
  "scripts": {
25
28
  "version": "version-everything && auto-changelog && git add -u"
26
29
  },
30
+ "prettier": "@ideasonpurpose/prettier-config",
27
31
  "dependencies": {
32
+ "@ideasonpurpose/prettier-config": "^0.0.4",
33
+ "@prettier/plugin-php": "^0.22.1",
28
34
  "@rollup/plugin-commonjs": "^25.0.7",
29
35
  "@rollup/plugin-json": "^6.1.0",
30
36
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -44,8 +50,10 @@
44
50
  "css-loader": "^6.9.1",
45
51
  "cssnano": "^6.0.1",
46
52
  "del": "^7.1.0",
47
- "dotenv": "^16.3.2",
53
+ "dotenv": "^16.4.0",
54
+ "esbuild": "^0.19.12",
48
55
  "esbuild-loader": "^4.0.3",
56
+ "eslint": "^8.56.0",
49
57
  "filesize": "^10.0.12",
50
58
  "fs-extra": "^11.1.1",
51
59
  "globby": "^14.0.0",
@@ -58,19 +66,23 @@
58
66
  "node-sass": "^9.0.0",
59
67
  "postcss": "^8.4.29",
60
68
  "postcss-loader": "^8.0.0",
69
+ "prettier": "^3.2.4",
70
+ "prettier-eslint": "^16.3.0",
61
71
  "pretty-hrtime": "^1.0.3",
62
72
  "replacestream": "^4.0.3",
63
73
  "sass": "^1.70.0",
64
74
  "sass-embedded": "^1.70.0",
65
75
  "sass-loader": "^14.0.0",
76
+ "semver": "^7.5.4",
66
77
  "sharp": "^0.33.2",
78
+ "sort-package-json": "^2.6.0",
67
79
  "source-map-explorer": "^2.5.3",
68
80
  "string-length": "^6.0.0",
69
81
  "style-loader": "^3.3.3",
70
82
  "svgo": "^3.0.2",
71
83
  "svgo-loader": "^4.0.0",
72
84
  "version-everything": "^0.11.0",
73
- "webpack": "^5.88.2",
85
+ "webpack": "^5.90.0",
74
86
  "webpack-bundle-analyzer": "^4.9.1",
75
87
  "webpack-cli": "^5.1.4",
76
88
  "webpack-dev-middleware": "^7.0.0",
@@ -80,9 +92,5 @@
80
92
  "files": [
81
93
  "README.md"
82
94
  ]
83
- },
84
- "directories": {
85
- "lib": "lib"
86
- },
87
- "devDependencies": {}
95
+ }
88
96
  }