Implement import/export in CLI#2963
Implement import/export in CLI#2963fredrikekelund wants to merge 17 commits intostu-1354-site-picker-syncfrom
Conversation
f26f025 to
9ab29a1
Compare
| // We configure `trash` as an external module, since it includes a native macOS binary that Vite | ||
| // inlines as a base64 string, which produces a runtime error. Since `trash` is also an ESM-only | ||
| // module, we need to import it dynamically (since Rollup doesn't get a chance to process it) | ||
| const trash = ( await import( 'trash' ) ).default; |
There was a problem hiding this comment.
Not related to the core changes in this PR, but we output ESM now, and trash is always configured as an external module when Vite bundles, so this is no longer an issue.
| break; | ||
|
|
||
| case ExportEvents.BACKUP_CREATE_PROGRESS: { | ||
| const progressData = data as BackupCreateProgressEventData; |
There was a problem hiding this comment.
I'd love to avoid type assertions for the event payloads, but since this copies the logic we already have in the app, I decided to stick with that for now.
| logger.reportStart( | ||
| LoggerAction.INSTALL_SQLITE, | ||
| __( 'Setting up SQLite integration, if needed…' ) | ||
| ); | ||
| await keepSqliteIntegrationUpdated( siteFolder ); | ||
| logger.reportSuccess( __( 'SQLite integration configured as needed' ) ); |
There was a problem hiding this comment.
It's important to keep the SQLite integration up to date whenever we work with the site database. Exporting the site is one such example.
| const zipUrl = getWordPressVersionUrl( wp ); | ||
|
|
||
| const [ response, exitPhp ] = await runWpCliCommand( sitePath, phpVersion, [ | ||
| await using command = await runWpCliCommand( sitePath, phpVersion, [ |
There was a problem hiding this comment.
If you're not familiar with the using keyword, I recommend a quick read-up on JavaScript resource management. Playground already uses this internally.
In short, it saves us from having to call a cleanup function (exitPhp) because the JS runtime automatically calls the method identified by Symbol.dispose when exiting the scope. Very nifty.
There was a problem hiding this comment.
See my comment in apps/cli/commands/site/set.ts about JavaScript resource management to understand what's going on here.
| "@php-wasm/node": "3.1.15", | ||
| "@php-wasm/universal": "3.1.15", | ||
| "@php-wasm/util": "3.1.15", | ||
| "@php-wasm/node": "3.1.13", | ||
| "@php-wasm/universal": "3.1.13", | ||
| "@php-wasm/util": "3.1.13", | ||
| "@vscode/sudo-prompt": "^9.3.2", | ||
| "@wordpress/i18n": "^6.14.0", | ||
| "@wp-playground/blueprints": "3.1.15", | ||
| "@wp-playground/cli": "3.1.15", | ||
| "@wp-playground/common": "3.1.15", | ||
| "@wp-playground/storage": "3.1.15", | ||
| "@wp-playground/wordpress": "3.1.15", | ||
| "@wp-playground/blueprints": "3.1.13", | ||
| "@wp-playground/cli": "3.1.13", | ||
| "@wp-playground/common": "3.1.13", | ||
| "@wp-playground/storage": "3.1.13", | ||
| "@wp-playground/wordpress": "3.1.13", |
There was a problem hiding this comment.
I had to downgrade these packages because I couldn't get WP-CLI to play ball. See p1775051878031829-slack-C04GESRBWKW
Related issues
How AI was used in this PR
Primarily to review my implementation and help me preemptively fix several issues.
Proposed Changes
Tip
I'm happy to pair review this PR.
This one's a biggie. It adds
site importandsite exportCLI commands. I've copied the core import/export logic fromapps/studioand adapted it to CLI conditions (the types are slightly different, we call WP-CLI in different ways, etc).Moreover, this PR finalizes the
sync pullandsync pushcommands by wiring up the import/export logic there, too.Testing Instructions
npm run cli:buildnode apps/cli/dist/cli/main.mjs site exportcommand. Explore the flags and try different combinations.node apps/cli/dist/cli/main.mjs site importcommand. Explore the flags and try different combinations.node apps/cli/dist/cli/main.mjs sync pullcommand.node apps/cli/dist/cli/main.mjs sync pushcommand.Pre-merge Checklist