Skip to content

Conversation

@katinthehatsite
Copy link
Contributor

@katinthehatsite katinthehatsite commented May 22, 2025

Related issues

Fixes STU-302

Proposed Changes

This PR removes the old implementation of the WP-CLI execution from the terminal (related PR) in favour of the studio CLI commands available right now.

Testing Instructions

Test Studio CLI to make sure everything works as expected:

I modified a couple of different things so let's test various aspects to make sure everything works as expected.

  • Pull the changes from this branch
  • Run npm install
  • Run npm run cli:build
  • Run node dist/cli/main.js preview list FOLDER where FOLDER is a path to a Studio site with preview sites (example: node dist/cli/main.js preview list --path="/Users/katerynakodonenko/Studio/my-bright-website")
  • Ensure that the command either prints a table containing information about the preview sites or prints No snapshots found

Check opening different terminal apps

  • Pull the changes from this branch
  • Run npm install and npm start
  • Once the app is started, navigate to the Overview tab
  • Click on your preferred terminal app to open your site in that app
  • Confirm that it open the site in a preferred terminal app
  • Try out a couple of different terminal apps
  • Confirm that it works correctly for different terminal apps

Check assistant code block running CLI inline

  • Pull the changes from this branch
  • Run npm install and npm start
  • Once the app is started, navigate to the Assistant tab
  • Ask Assistant for the CLI command for listing plugins on your site
  • Run the command inline
  • Confirm everything works:
Screenshot 2025-05-22 at 1 13 39 PM

TBD

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@katinthehatsite katinthehatsite self-assigned this May 22, 2025
@katinthehatsite katinthehatsite marked this pull request as draft May 22, 2025 08:24

store.replaceReducer( testReducer );

( useFeatureFlags as jest.Mock ).mockReturnValue( {} );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR but this code is not used so I removed it.

@katinthehatsite katinthehatsite requested a review from a team May 22, 2025 12:01
@katinthehatsite katinthehatsite marked this pull request as ready for review May 22, 2025 12:02
Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! 👍 I haven't looked very closely, but wanted to leave an initial comment about the openTerminalAtPath function

Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kat, this PR looks very promising. Great work.
The assistant is still working and I confirm the feature flag STUDIO_TERMINAL_WP_CLI has been removed.
For now I just added a small suggestion.

Copy link
Contributor

@nightnei nightnei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have this erorr on running Terminal or iTerm? I have it even in trunk, hm...
Screenshot 2025-05-22 at 18 13 48
Screenshot 2025-05-22 at 18 15 26

But everything else works well:
Screenshot 2025-05-22 at 18 08 09

Screenshot 2025-05-22 at 18 12 09

@katinthehatsite
Copy link
Contributor Author

Do you have this erorr on running Terminal or iTerm? I have it even in trunk, hm...

I am not getting it on my end either or trunk on this PR? @sejas did this work for you when you were testing the PR?

@nightnei I am also going to explore this suggestion from Fredrik: #1426 (comment)
Perhaps you could retest once I make that change.

@katinthehatsite
Copy link
Contributor Author

@nightnei I only looked briefly, but I am wondering if you have iTerm added in these settings:

Screenshot 2025-05-22 at 8 25 45 PM

Comment on lines 1002 to 1017
const platform = process.platform;
const cliPath = nodePath.join( getResourcesPath(), 'bin' );
const exePath = app.getPath( 'exe' );
const appDirectory = app.getAppPath();
const appPath = ! app.isPackaged ? `${ exePath } ${ appDirectory }` : exePath;

if ( platform === 'darwin' ) {
const initScriptSteps = [];

if ( wpCliEnabled ) {
initScriptSteps.push(
`export PATH=\\"${ cliPath }\\":$PATH`,
`export STUDIO_APP_PATH=\\"${ appPath }\\"`
);
}

const escapedPath = targetPath.replace( /"/g, '\\"' );
initScriptSteps.push( `cd \\"${ escapedPath }\\"`, 'clear' );

const userData = await loadUserData();
const preferredTerminal = userData.preferredTerminal || DEFAULT_TERMINAL;

if ( preferredTerminal === 'warp' ) {
return promiseExec( `open -a Warp "${ targetPath }"` );
} else if ( preferredTerminal === 'ghostty' ) {
return promiseExec( `open -a Ghostty "${ targetPath }"` );
} else if ( preferredTerminal === 'iterm' ) {
return promiseExec( `osascript << END
tell application "iTerm"
activate
create window with default profile
tell current session of current window
write text "${ initScriptSteps.join( ';' ) }"
end tell
end tell
END` );
} else {
return promiseExec( `osascript << END
activate application "Terminal"
tell application "Terminal"
do script "${ initScriptSteps.join( ';' ) }"
end tell
END` );
}
const terminalApps = {
warp: 'Warp',
ghostty: 'Ghostty',
iterm: 'iTerm',
terminal: 'Terminal',
};
const appName = terminalApps[ preferredTerminal ] || 'Terminal';
return promiseExec( `open -a ${ appName } "${ escapedPath }"` );
} else if ( platform === 'win32' ) {
const userData = await loadUserData();
const preferredTerminal = userData.preferredTerminal;
const defaultShell = process.env.ComSpec || 'cmd.exe';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	const preferredTerminal = await getUserTerminal();

	if ( platform === 'darwin' ) {
		const escapedPath = targetPath.replace( /"/g, '\\"' );
		const bundleIds = {
			warp: 'dev.warp.Warp-Stable',
			ghostty: 'com.mitchellh.ghostty',
			iterm: 'com.googlecode.iterm2',
			terminal: 'com.apple.Terminal',
		};
		return promiseExec( `open -b ${ bundleIds[ preferredTerminal ] } "${ escapedPath }"` );
	} else if ( platform === 'win32' ) {
		const defaultShell = process.env.ComSpec || 'cmd.exe';

A couple of comments:

  • initScriptSteps can be removed completely. It's no longer used.
  • Applications can be renamed by the user on macOS, so open -a is not a safe option. The bundle ID, however, cannot be changed, so it's better to use open -b for opening the application.
  • We can use getUserTerminal to get the preferred terminal. I recommend removing the _event parameter from that function, as it's not used.
  • terminalApps already map all SupportedTerminal keys to a value, so there's no need to have another fallback value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestions, I made adjustments based on this. Feel free to give it another review 👍

@nightnei
Copy link
Contributor

nightnei commented May 26, 2025

@katinthehatsite I don't have iTerm/Terminal there, but today I tested it again and I don't know what changed, but I don't see that error anymore:
Screenshot 2025-05-26 at 18 34 09

Copy link
Contributor

@nightnei nightnei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works well - assistant, terminals, and CLI 👍
Screenshot 2025-05-26 at 18 39 57
Screenshot 2025-05-26 at 18 42 08

Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the additional changes, @katinthehatsite 👍 This looks good and works as expected (I've confirmed that all four terminal apps still open as expected on macOS)

@katinthehatsite katinthehatsite merged commit d31733b into trunk May 27, 2025
10 checks passed
@katinthehatsite katinthehatsite deleted the fix/remove-old-cli-implementation-code branch May 27, 2025 07:12
bcotrim pushed a commit that referenced this pull request May 27, 2025
* Remove old scripts

* Remove old cli.ts

* Cleanup tests

* Clean up terminal opening and feature flag

* Cleanup assistant code

* Clean shortcuts code

* Cleanup feature flags

* Cleanup feature flags

* Cleanup shortcuts sessions

* Removed unused feature flag for assistant

* Assistant code block test fix

* Adjust preload

* Cleanup index file and tests

* Refactor terminal usage

* Add back the lock

* Remove unintended change

* Remove unnecesary type for warp

* Use bundled Ids

* Cleanup event parameter

---------

Co-authored-by: Kateryna Kodonenko <[email protected]>
bcotrim added a commit that referenced this pull request May 27, 2025
commit d31733b
Author: katinthehatsite <[email protected]>
Date:   Tue May 27 09:12:55 2025 +0200

    Studio: Delete old proof-of-concept WP-CLI implementation (#1426)

    * Remove old scripts

    * Remove old cli.ts

    * Cleanup tests

    * Clean up terminal opening and feature flag

    * Cleanup assistant code

    * Clean shortcuts code

    * Cleanup feature flags

    * Cleanup feature flags

    * Cleanup shortcuts sessions

    * Removed unused feature flag for assistant

    * Assistant code block test fix

    * Adjust preload

    * Cleanup index file and tests

    * Refactor terminal usage

    * Add back the lock

    * Remove unintended change

    * Remove unnecesary type for warp

    * Use bundled Ids

    * Cleanup event parameter

    ---------

    Co-authored-by: Kateryna Kodonenko <[email protected]>

commit 4fac446
Author: Volodymyr Makukha <[email protected]>
Date:   Mon May 26 20:19:35 2025 +0100

    Update Ukrainian translations - May 26 (#1439)

commit c7536ef
Author: Antonio Sejas <[email protected]>
Date:   Mon May 26 18:34:28 2025 +0100

    Load LTR and RTL stylesheets conditionally (#1429)

    * Add a new component
    * Load @wordpress/components css conditionally based on RTL and LTR.
    * Load index.css a.k.a main_window.css after loading the WordPress stylesheet

commit c80b70e
Author: Bero <[email protected]>
Date:   Mon May 26 19:20:42 2025 +0200

    Update Playground packages to 1.0.38 and remove the Symlink manager (#1425)

    * Update Playground packages to 1.0.38
    * Remove SymlinkManager
    * Activate Playground's followSymlinks feature
    * Remove @php-wasm/universal patch

commit 5bfe676
Author: Wojtek Naruniec <[email protected]>
Date:   Mon May 26 15:40:18 2025 +0200

    Sanitize regex in Win editor path (#1411)

    * Sanitize regex

    * Import only escapeRegExp function

commit 2cd3e44
Author: Ivan Ottinger <[email protected]>
Date:   Mon May 26 13:18:02 2025 +0200

    Bump version from 1.5.2-beta4 to 1.5.2 (#1436)

commit f16865e
Author: Ivan Ottinger <[email protected]>
Date:   Mon May 26 12:38:24 2025 +0200

    Add release notes for 1.5.2 (#1434)

    * Add release notes for 1.5.2

    * Reorder release notes

    * Update release notes order and formatting

    * Added latest UI fix to the release notes

    * Consolidate Studio CLI fixes into a single bullet point

commit f6e48d5
Author: Ivan Ottinger <[email protected]>
Date:   Mon May 26 12:21:30 2025 +0200

    Add translations for 1.5.2 (#1433)

    * Add translations for 1.5.2

    * Add latest Polish and Spanish translations

    * Update spanish translations

    ---------

    Co-authored-by: Antonio Sejas <[email protected]>

commit ae1d163
Author: Antonio Sejas <[email protected]>
Date:   Mon May 26 10:58:22 2025 +0100

    Share same styles between preview and sync tabs (#1435)

commit d6a7905
Author: Roberto Aranda <[email protected]>
Date:   Fri May 23 15:23:14 2025 +0200

    Return original URL param when it cannot be parsed (#1420)

    * Return the passed URL parameter when it cannot be parsed instead of an empty string

commit 91d04be
Author: Antonio Sejas <[email protected]>
Date:   Fri May 23 14:22:34 2025 +0100

    Update localized docs links for Studio Sync  and Studio CLI (#1431)

    * Add translation link to new Spanish studio docs CLI
    * Add hash to Studio sync supported sites

commit 6213094
Author: katinthehatsite <[email protected]>
Date:   Fri May 23 14:27:53 2025 +0200

    Add patch to fix the accessibility with modals (#1423)

    Co-authored-by: Kateryna Kodonenko <[email protected]>

commit b2724c0
Author: Rahul Gavande <[email protected]>
Date:   Fri May 23 14:45:11 2025 +0530

    Use uri scheme to open Warp terminal app (#1428)

commit 43c831b
Author: Fredrik Rombach Ekelund <[email protected]>
Date:   Wed May 21 16:10:40 2025 +0200

    CLI: Set UTF8 encoding for output on Windows (#1424)

commit b1c0eeb
Author: Volodymyr Makukha <[email protected]>
Date:   Wed May 21 10:34:47 2025 +0100

    Fix hiding plugins spinner (#1419)

commit 48988ed
Author: Fredrik Rombach Ekelund <[email protected]>
Date:   Wed May 21 10:31:33 2025 +0200

    Add migration to rename launch uniques stat (#1415)

    * Add migration to rename launch uniques stat

    * Fix CLI zod schema

commit f363144
Author: Ivan Ottinger <[email protected]>
Date:   Tue May 20 18:24:00 2025 +0200

    Bump version to 1.5.2-beta4 (#1421)

commit 9768e67
Author: Ivan Ottinger <[email protected]>
Date:   Tue May 20 15:29:33 2025 +0200

    Pressable Sync: Fix remaining Sync modal issues (#1416)

    * Use absolute path for `WordPressLogoCircle` import

    * Use separate `isDisabled` to makde WP logo gray

    * Remove trailing space in site selector helper text

    * Decrease font size of sync sites modal learn more link

commit 9fab398
Author: Ian G. Maia <[email protected]>
Date:   Tue May 20 13:15:23 2025 +0200

    [Tooling] Update code to DRY the Windows build PS1 (#1408)

    * Update code to DRY the Windows build PS1

    * Update case of `Exit` command

    * Use `windows` instead of just `win` to prefix windows-related scripts

    * Add $LastExitCode check after `npm run make`

commit e5d4006
Author: Ivan Ottinger <[email protected]>
Date:   Tue May 20 12:01:21 2025 +0200

    Improve version comparison logic to handle prerelease transitions correctly (#1403)

commit f0a282b
Author: Rahul Gavande <[email protected]>
Date:   Tue May 20 15:15:25 2025 +0530

    HTTPS: Convert domain name Unicode characters to ASCII characters (#1400)

    * Convert domain name unicode chars to ASCII

    * Do not use punnycode domain name for paths

    * Remove unncessary punnycode domain name

commit 6cdc351
Author: Roberto Aranda <[email protected]>
Date:   Tue May 20 11:35:52 2025 +0200

    Sync: Update notification to include Hostname (#1412)

    * Push: Update notification to include Hostname

    * Pull: Update notification to include hostname

    * Add hints for translators

commit 69419a6
Author: Gergely Csécsey <[email protected]>
Date:   Tue May 20 10:30:57 2025 +0100

    Increase HTTP request timeout to 60 seconds (#1407)

    * Increase HTTP request timeout to 60 seconds

    * Increase curl timeout to 60 seconds

    * update comments

commit 6bcbbff
Author: Antonio Sejas <[email protected]>
Date:   Tue May 20 09:36:18 2025 +0100

    Update connect site text button when connecting another site (#1413)

    * Adapt the "Connect Site" button when connecting multiple sites on Sync.

commit 60a9cab
Author: Antonio Sejas <[email protected]>
Date:   Tue May 20 09:10:37 2025 +0100

    Avoid orphan in sync title (#1414)

commit 3b103cc
Author: Antonio Sejas <[email protected]>
Date:   Mon May 19 10:39:12 2025 +0100

    Release 1.5.2-beta3 (#1410)

commit a109671
Author: Ivan Ottinger <[email protected]>
Date:   Mon May 19 09:45:17 2025 +0200

    Sync: Update sync tab text and remove WordPress logo from title (#1405)

    * Update sync tab text and remove WordPress logo from title

    * Fix related test

    * Use comma

    * Update copy of the bullet points

    * Replace `WP.com` with `WordPress.com`.

    Co-authored-by: Antonio Sejas <[email protected]>

    * Replace WP.com with WordPress.com

    Co-authored-by: Antonio Sejas <[email protected]>

    * Delete unused WordPress short logo component

    ---------

    Co-authored-by: Antonio Sejas <[email protected]>

commit 716bc7a
Author: Ivan Ottinger <[email protected]>
Date:   Fri May 16 16:15:16 2025 +0200

    Sync: Update Sync modal content (#1406)

    * Update WordPress logo component `viewBox`

    * Update Sync modal heading

    * Update text below Sync search field

    * Update Sync modal site logos

    * Replace hardcoded arrows with `ArrowIcon` component in sync sites modal links

    * Localize sync modal Read more link using `getLocalizedLink` utility

commit 11b4302
Author: Roberto Aranda <[email protected]>
Date:   Fri May 16 15:14:40 2025 +0200

    Push: Read and update the progress from the sync endpoint (#1389)

    * Calls the GET /sync/import using the importId to obtain the progress
    * Use the progress from the /sync/import endpoint to update the progress in the importing state
    * Splits the progress of the importing state between backup and import

commit 7423bdf
Author: katinthehatsite <[email protected]>
Date:   Fri May 16 11:40:18 2025 +0200

    Studio: Fix no directory or file error on Windows (#1391)

    * Fix no directory or file error on Windows

    * Cleanup directories

    ---------

    Co-authored-by: Kateryna Kodonenko <[email protected]>

commit 1661ac4
Author: Antonio Sejas <[email protected]>
Date:   Fri May 16 10:04:32 2025 +0100

    Force display of what's new for minor version (#1404)

    * Force what's new display for minor version
    * Skip test that compares the patch version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants