@@ -35,6 +35,7 @@ import {
3535 parseMountDirArguments ,
3636 parseMountWithDelimiterArguments ,
3737} from './mounts' ;
38+ import { expandEditMarkdownCommandArgs } from '@wp-playground/markdown-editor' ;
3839import {
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
0 commit comments