-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,510 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# php-wasm-cli | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build php-wasm-cli` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test php-wasm-cli` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'nx-extensions', | ||
preset: '../../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': [ | ||
'ts-jest', | ||
{ tsconfig: '<rootDir>/tsconfig.spec.json' }, | ||
], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../../coverage/packages/nx-extensions', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@wp-playground/cli", | ||
"version": "0.6.16", | ||
"description": "PHP.wasm CLI for node.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/WordPress/wordpress-playground" | ||
}, | ||
"homepage": "https://developer.wordpress.org/playground", | ||
"author": "The WordPress contributors", | ||
"contributors": [ | ||
{ | ||
"name": "Adam Zielinski", | ||
"email": "adam@adamziel.com", | ||
"url": "https://github.com/adamziel" | ||
} | ||
], | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "../../../dist/packages/wp-playground/cli" | ||
}, | ||
"license": "GPL-2.0-or-later", | ||
"type": "module", | ||
"main": "main.js", | ||
"bin": "php-wasm.js", | ||
"gitHead": "2f8d8f3cea548fbd75111e8659a92f601cddc593", | ||
"devDependencies": { | ||
"@types/compressible": "2.0.2", | ||
"@types/compression": "1.7.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"name": "wp-playground-cli", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/wp-playground/cli/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@wp-playground/nx-extensions:package-json", | ||
"options": { | ||
"tsConfig": "packages/wp-playground/cli/tsconfig.lib.json", | ||
"outputPath": "dist/packages/wp-playground/cli", | ||
"buildTarget": "php-wasm-cli:build:bundle:production" | ||
} | ||
}, | ||
"build:bundle": { | ||
"executor": "@nx/vite:build", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"main": "dist/packages/wp-playground/cli/main.js", | ||
"outputPath": "dist/packages/wp-playground/cli" | ||
}, | ||
"defaultConfiguration": "production", | ||
"configurations": { | ||
"development": { | ||
"minify": false | ||
}, | ||
"production": { | ||
"minify": true | ||
} | ||
} | ||
}, | ||
"dev": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "bun --watch ./packages/playground/cli/src/index.ts" | ||
} | ||
}, | ||
"start": { | ||
"executor": "@wp-playground/nx-extensions:built-script", | ||
"options": { | ||
"scriptPath": "dist/packages/wp-playground/cli/main.js" | ||
}, | ||
"dependsOn": ["build"] | ||
}, | ||
"publish": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"command": "node tools/scripts/publish.mjs php-wasm-cli {args.ver} {args.tag}" | ||
}, | ||
"dependsOn": ["build"] | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/wp-playground/cli/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "packages/wp-playground/cli/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
}, | ||
"typecheck": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
"tsc -p packages/wp-playground/cli/tsconfig.lib.json --noEmit", | ||
"tsc -p packages/wp-playground/cli/tsconfig.spec.json --noEmit" | ||
] | ||
} | ||
} | ||
}, | ||
"tags": ["scope:php-wasm-public"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
import './main.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
echo 'Hello, World!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import path from 'path'; | ||
import yargs from 'yargs'; | ||
import { startServer } from './server'; | ||
|
||
const args = await yargs(process.argv) | ||
.option('php', { | ||
describe: 'PHP version to use.', | ||
type: 'string', | ||
default: 'latest', | ||
}) | ||
.option('port', { | ||
describe: 'Port to listen on.', | ||
type: 'number', | ||
default: 9400, | ||
}) | ||
.option('mount', { | ||
describe: 'Mount a directory to the PHP runtime.', | ||
type: 'array', | ||
string: true, | ||
}).argv; | ||
|
||
const mounts = (args.mount || []).map((mount) => { | ||
const [source, vfsPath] = mount.split(':'); | ||
return { | ||
hostPath: path.resolve(process.cwd(), source), | ||
vfsPath, | ||
}; | ||
}); | ||
|
||
console.log('Starting PHP server...'); | ||
console.log({ mounts }); | ||
|
||
startServer({ | ||
mounts, | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/playground/cli/src/middleware/add-trailing-slash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
/** | ||
* Adds redirection adding a trailing slash, when a request matches a given path. | ||
* @param path - The path to add a trailing slash to. E.g. '/wp-admin' | ||
* @returns - Returns a middleware function that may redirect adding a trailing slash to the given path. E.g. '/wp-admin/' | ||
*/ | ||
export function addTrailingSlash(path: string) { | ||
return (req: Request, res: Response, next: NextFunction) => { | ||
const urlParts = req.url.split('?'); | ||
const url = urlParts[0]; | ||
const queryString = req.url.substr(url.length); | ||
if (url === path) { | ||
res.redirect(301, `${path}/${queryString}`); | ||
} else { | ||
next(); | ||
} | ||
}; | ||
} |
Oops, something went wrong.