Skip to content

Commit 90ef8b9

Browse files
committed
Add sqlite markdown edit command extension
1 parent a86340b commit 90ef8b9

27 files changed

Lines changed: 17652 additions & 2 deletions

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ packages/playground/wordpress-builds/src/wordpress
88
packages/playground/wordpress-builds/public
99
packages/playground/sync/src/test/wp-*
1010
packages/php-wasm/node/src/test/__test*
11+
packages/playground/markdown-editor/src/assets/vendor/php-toolkit
1112
*.timestamp-1678999213403.mjs
1213
.local
1314
.vscode

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "isomorphic-git"]
22
path="isomorphic-git"
33
url=https://github.com/adamziel/isomorphic-git.git
4+
[submodule "packages/playground/markdown-editor/src/assets/vendor/php-toolkit"]
5+
path = packages/playground/markdown-editor/src/assets/vendor/php-toolkit
6+
url = https://github.com/WordPress/php-toolkit.git

.nxignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __pycache__
99
packages/playground/wordpress-builds/src/wordpress
1010
packages/playground/wordpress-builds/public
1111
packages/php-wasm/node/src/test/__test*
12+
packages/playground/markdown-editor/src/assets/vendor/php-toolkit
1213
*.timestamp-1678999213403.mjs
1314
.local
1415
.vscode

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/php-wasm/compile/php/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,9 +1444,11 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
14441444
"sqlite_handle_closer",\
14451445
"sqlite_handle_doer",\
14461446
"sqlite_handle_preparer",\
1447+
"sqlite3_auto_extension",\
14471448
"sqlite3_autovacuum_pages",\
14481449
"sqlite3_backup_step",\
14491450
"sqlite3_bind_pointer",\
1451+
"sqlite3_cancel_auto_extension",\
14501452
"sqlite3_exec",\
14511453
"sqlite3_finalize",\
14521454
"sqlite3_free",\

packages/php-wasm/compile/php/Dockerfile-5-2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,11 @@ RUN export ASYNCIFY_IMPORTS=$'[\n\
14611461
"sqlite_handle_closer",\
14621462
"sqlite_handle_doer",\
14631463
"sqlite_handle_preparer",\
1464+
"sqlite3_auto_extension",\
14641465
"sqlite3_autovacuum_pages",\
14651466
"sqlite3_backup_step",\
14661467
"sqlite3_bind_pointer",\
1468+
"sqlite3_cancel_auto_extension",\
14671469
"sqlite3_exec",\
14681470
"sqlite3_finalize",\
14691471
"sqlite3_free",\

packages/playground/cli/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ with `extension=` or `zend_extension=` in php.ini:
156156
}
157157
```
158158

159+
### Editing Markdown Directories
160+
161+
The `edit-markdown` command opens a directory of Markdown files in wp-admin and
162+
writes block editor saves back to disk:
163+
164+
```bash
165+
npx @wp-playground/cli@latest edit-markdown ./content
166+
```
167+
168+
It loads the bundled `sqlite_markdown` PHP.wasm extension, mounts the Markdown
169+
directory at `/markdown-root`, and installs a small mu-plugin that maps
170+
`wp_posts` and `wp_postmeta` to writable SQLite virtual tables.
171+
172+
When running from a Playground source checkout, build the extension artifacts
173+
first:
174+
175+
```bash
176+
npx nx run playground-markdown-editor:build:sqlite-markdown-extension
177+
```
178+
159179
## Need some help with the CLI?
160180

161181
With the Playground CLI, you can use the `--help` to get some support about the available commands.

packages/playground/cli/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"main": "./index.cjs",
3232
"module": "./index.js",
3333
"types": "index.d.ts",
34+
"dependencies": {
35+
"@wp-playground/markdown-editor": "3.1.30"
36+
},
3437
"bin": {
3538
"wp-playground-cli": "wp-playground.js"
3639
},

packages/playground/cli/src/run-cli.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
parseMountDirArguments,
3636
parseMountWithDelimiterArguments,
3737
} from './mounts';
38+
import { expandEditMarkdownCommandArgs } from '@wp-playground/markdown-editor';
3839
import {
3940
parseDefineStringArguments,
4041
parseDefineBoolArguments,
@@ -532,6 +533,18 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
532533
.command('php', 'Run a PHP script', (yargsInstance: Argv) =>
533534
yargsInstance.options({ ...sharedOptions })
534535
)
536+
.command(
537+
'edit-markdown <dir>',
538+
'Open a directory of Markdown files in the block editor',
539+
(yargsInstance: Argv) =>
540+
yargsInstance
541+
.positional('dir', {
542+
describe: 'Directory tree of .md files to mount.',
543+
type: 'string',
544+
demandOption: true,
545+
})
546+
.options(startCommandOptions)
547+
)
535548
.demandCommand(1, 'Please specify a command')
536549
.strictCommands()
537550
.conflicts(
@@ -689,6 +702,7 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
689702
'server',
690703
'build-snapshot',
691704
'php',
705+
'edit-markdown',
692706
].includes(command)
693707
) {
694708
yargsObject.showHelp();
@@ -727,7 +741,7 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
727741
}
728742
}
729743

730-
const cliArgs = {
744+
let cliArgs = {
731745
...args,
732746
define,
733747
command,
@@ -741,6 +755,10 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
741755
],
742756
} as RunCLIArgs;
743757

758+
if (command === 'edit-markdown') {
759+
cliArgs = expandEditMarkdownCommandArgs(cliArgs) as RunCLIArgs;
760+
}
761+
744762
const cliServer = await runCLI(cliArgs);
745763
if (cliServer === undefined) {
746764
// No server was started, so we are done with our work.
@@ -876,7 +894,13 @@ export interface RunCLIArgs {
876894
| BlueprintV1Declaration
877895
| BlueprintV2Declaration
878896
| BlueprintBundle;
879-
command: 'start' | 'server' | 'run-blueprint' | 'build-snapshot' | 'php';
897+
command:
898+
| 'start'
899+
| 'server'
900+
| 'run-blueprint'
901+
| 'build-snapshot'
902+
| 'php'
903+
| 'edit-markdown';
880904
debug?: boolean;
881905
login?: boolean;
882906
mount?: Mount[];
@@ -1800,6 +1824,14 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
18001824
if (server && args.command === 'start' && !args.skipBrowser) {
18011825
openInBrowser(server.serverUrl);
18021826
}
1827+
if (server && args.command === 'edit-markdown' && !args.skipBrowser) {
1828+
openInBrowser(
1829+
new URL(
1830+
'/wp-admin/edit.php?post_type=page',
1831+
server.serverUrl
1832+
).toString()
1833+
);
1834+
}
18031835
return server;
18041836
}
18051837

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../../.eslintrc.json",
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
}
9+
]
10+
}

0 commit comments

Comments
 (0)