Skip to content

Commit

Permalink
Manage WordPress build tasks using a gulpfile
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Oct 21, 2022
1 parent 27c127b commit 18f3c74
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 48 deletions.
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
"description": "",
"main": "index.js",
"scripts": {
"dev": "npm run dev:web",
"dev:web": "npm-run-all --parallel dev:web:*",
"dev:web:app": "npm run build:web -- --watch",
"dev:web:serve": "node liveServer.js",
"build": "npm run build:web",
"build:wpnet": "SERVICE_WORKER_ORIGIN=https://wasm.wordpress.net WASM_WORKER_ORIGIN=https://wasm-worker.wordpress.net npm run build:web",
"build:web": "node build.js ",
"dev": "npm run build -- --watch",
"build": "npm run build:js",
"build:js": "node build.js",
"build:wp": "cd packages/wordpress-wasm/wordpress && bash prepare-wordpress.sh && bash bundle-data.sh && bash web-publish.sh && bash node-publish.sh",
"build:php": "npm run build:php:web",
"build:php:web": "cd wasm-build/php && TARGET=web bash build-wasm.sh",
"build:wp": "cd wasm-build/wordpress-data && bash prepare-wordpress.sh && bash bundle-data.sh && bash web-publish.sh && bash node-publish.sh",
"build:app": "npm-run-all build:web build:node",
"build:php:node": "cd wasm-build/php && PLATFORM=node bash build-wasm.sh",
"clean": "npm-run-all --parallel clean:*",
"clean:php": "rm -rf dist-web/wasm-build/php/docker-output/*",
"clean:wp": "rm -rf dist-web/wasm-build/wordpress/docker-output/* dist-web/wasm-build/wordpress/preload/*",
"clean:php": "rm -rf packages/php-wasm/build-wasm/*",
"clean:wp": "rm -rf packages/wordpress-wasm/build-wp/*",
"format": "prettier --write src",
"lint:js": "eslint \"./src/**/*.{js,mjs,ts}\"",
"lint:js:fix": "npm run lint:js -- --fix",
Expand All @@ -29,19 +26,19 @@
"npx eslint --fix"
]
},
"engines" : {
"npm" : ">=8.0.0",
"node" : ">=16.7.0"
"engines": {
"npm": ">=8.0.0",
"node": ">=16.7.0"
},
"author": "Adam Zielinski",
"license": "ISC",
"dependencies": {
"glob": "^8.0.3",
"yargs": "^17.5.1",
"php-wasm": "file:packages/php-wasm",
"php-wasm-browser": "file:packages/php-wasm-browser",
"wordpress-wasm": "file:packages/wordpress-wasm",
"wordpress-wasm-node": "file:packages/wordpress-wasm-node"
"wordpress-wasm-node": "file:packages/wordpress-wasm-node",
"yargs": "^17.5.1"
},
"devDependencies": {
"@wordpress/eslint-plugin": "^13.0.0",
Expand All @@ -53,6 +50,7 @@
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.31.1",
"eslint-plugin-react-hooks": "^4.6.0",
"gulp": "^4.0.2",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"live-server": "^1.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/wasm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ RUN cd php-src/ && \
-c -o /root/lib/pib_eval.o

# Add nodefs when requested
RUN if [ "$WITH_NODEFS" = "yes" ]; then \
RUN if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
echo -n ' -lnodefs.js' >> /root/.emcc-php-wasm-flags; \
fi

Expand Down
4 changes: 2 additions & 2 deletions packages/php-wasm/wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
WITH_VRZNO="no"
fi

if [ "$TARGET" = "nodejs" ]; then
if [ "$PLATFORM" = "node" ]; then
WITH_NODEFS="yes"
EMSCRIPTEN_ENVIRONMENT="node"
else
Expand Down Expand Up @@ -63,7 +63,7 @@ mv $OUTDIR/php.js.tmp $OUTDIR/php.js

# Copy the build files to their relevant node.js and web directories
root_dir=../..
if [ "$TARGET" = "nodejs" ]; then
if [ "$PLATFORM" = "node" ]; then
# The default output file is already compatible with node.js
# we only need to rename it
mv $OUTDIR/php.js $OUTDIR/php-node.js
Expand Down
3 changes: 3 additions & 0 deletions packages/wordpress-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"php-wasm": "file:../php-wasm",
"php-wasm-browser": "file:../php-wasm-browser"
},
"devDependencies": {
"gulp": "^4.0.2"
},
"publishConfig": {
"access": "public"
}
Expand Down
52 changes: 52 additions & 0 deletions packages/wordpress-wasm/wordpress/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const { spawn, exec, execSync } = require('child_process');
const os = require('os');
const gulp = require('gulp');
const path = require('path');
const util = require('util');
const fs = require('fs');
const asyncExec = util.promisify(require('child_process').exec);

const sourcePath = __dirname;
const buildPath = path.join(__dirname, '..', 'build-wp');
const tmpWorkDir = fs.mkdtempSync(path.join(os.tmpdir(), 'wp-'));

async function prepareWordPress() {
await asyncPipe(
gulp.src([
`${sourcePath}/prepare-wordpress.sh`,
`${sourcePath}/request_transport_fetch.php`
]).pipe(gulp.dest(tmpWorkDir))
)

await asyncExec('bash prepare-wordpress.sh', [''], { cwd: tmpWorkDir, stdio: 'inherit' });
}

async function bundleWordPress() {
await asyncPipe(
gulp.src([
`${sourcePath}/Dockefile`,
`${sourcePath}/bundle-data.sh`
]).pipe(gulp.dest(tmpWorkDir))
)

await asyncExec('bash bundle-data.sh', [''], { cwd: tmpWorkDir, stdio: 'inherit' });

return asyncPipe(
gulp.src([
`${tmpWorkDir}/wp.js`,
`${tmpWorkDir}/wp.data`,
`${tmpWorkDir}/wp-admin`,
`${tmpWorkDir}/wp-content`,
`${tmpWorkDir}/wp-includes`,
]).pipe(gulp.dest(buildPath))
);
}

exports.build = gulp.series(prepareWordPress, bundleWordPress);

function asyncPipe(pipe) {
return new Promise(async (resolve, reject) => {
pipe.on('finish', resolve)
.on('error', reject);
});
}
14 changes: 0 additions & 14 deletions packages/wordpress-wasm/wordpress/node-publish.sh

This file was deleted.

2 changes: 0 additions & 2 deletions packages/wordpress-wasm/wordpress/prepare-wordpress.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

# set -e
mkdir -p preload
cd preload

# Remove previous WordPress installation
rm -rf wordpress
Expand Down
13 changes: 0 additions & 13 deletions packages/wordpress-wasm/wordpress/web-publish.sh

This file was deleted.

0 comments on commit 18f3c74

Please sign in to comment.