Skip to content
Merged
2 changes: 1 addition & 1 deletion apps/cli/ai/tools/stop-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const stopSiteTool = defineTool(
async ( args ) => {
try {
const site = await resolveSite( args.nameOrPath );
await runStopSiteCommand( StopMode.STOP_SINGLE_SITE, site.path, false );
await runStopSiteCommand( StopMode.STOP_SINGLE_SITE, site.path );
return textResult( `Site "${ site.name }" stopped.` );
} catch ( error ) {
throw new Error(
Expand Down
7 changes: 2 additions & 5 deletions apps/cli/commands/pull-reprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
type SiteData,
unlockCliConfig,
} from 'cli/lib/cli-config/core';
import { getSiteUrl, updateSiteAutoStart, updateSiteLatestCliPid } from 'cli/lib/cli-config/sites';
import { getSiteUrl, updateSiteLatestCliPid } from 'cli/lib/cli-config/sites';
import {
connectToDaemon,
disconnectFromDaemon,
Expand Down Expand Up @@ -529,12 +529,10 @@ export async function runCommand(
logger.reportSuccess( __( 'WordPress server already running' ) );
// Mirror the start branch (and `studio site start`'s
// already-running path): refresh latestCliPid so
// running-status checks match the live process, and keep
// autoStart enabled as every pull has.
// running-status checks match the live process.
if ( runningProcess.status === 'online' ) {
await updateSiteLatestCliPid( site.id, runningProcess.pid );
}
await updateSiteAutoStart( site.id, true );
studioMetadata.localUrl = getSiteUrl( site );
savePullMetadata( studioMetadata );
recordCompletedStage( studioMetadata, 'site-started' );
Expand All @@ -545,7 +543,6 @@ export async function runCommand(
if ( processDesc.status === 'online' ) {
await updateSiteLatestCliPid( site.id, processDesc.pid );
}
await updateSiteAutoStart( site.id, true );
studioMetadata.localUrl = getSiteUrl( site );
savePullMetadata( studioMetadata );
recordCompletedStage( studioMetadata, 'site-started' );
Expand Down
7 changes: 1 addition & 6 deletions apps/cli/commands/site/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ import {
SiteData,
unlockCliConfig,
} from 'cli/lib/cli-config/core';
import {
removeSiteFromConfig,
updateSiteAutoStart,
updateSiteLatestCliPid,
} from 'cli/lib/cli-config/sites';
import { removeSiteFromConfig, updateSiteLatestCliPid } from 'cli/lib/cli-config/sites';
import { connectToDaemon, disconnectFromDaemon, emitCliEvent } from 'cli/lib/daemon-client';
import {
getAiInstructionsPath,
Expand Down Expand Up @@ -377,7 +373,6 @@ export async function runCommand(
if ( processDesc.status === 'online' ) {
await updateSiteLatestCliPid( siteDetails.id, processDesc.pid );
}
await updateSiteAutoStart( siteDetails.id, true );

siteDetails.running = true;
siteDetails.url = siteDetails.customDomain
Expand Down
7 changes: 1 addition & 6 deletions apps/cli/commands/site/start.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { updateManagedInstructionFiles } from '@studio/common/lib/agent-skills';
import { SiteCommandLoggerAction as LoggerAction } from '@studio/common/logger-actions';
import { __ } from '@wordpress/i18n';
import {
getSiteByFolder,
updateSiteAutoStart,
updateSiteLatestCliPid,
} from 'cli/lib/cli-config/sites';
import { getSiteByFolder, updateSiteLatestCliPid } from 'cli/lib/cli-config/sites';
import { connectToDaemon, disconnectFromDaemon } from 'cli/lib/daemon-client';
import { getAiInstructionsPath } from 'cli/lib/dependency-management/paths';
import { logSiteDetails, openSiteInBrowser, setupCustomDomain } from 'cli/lib/site-utils';
Expand Down Expand Up @@ -71,7 +67,6 @@ export async function runCommand(
if ( processDesc.status === 'online' ) {
await updateSiteLatestCliPid( site.id, processDesc.pid );
}
await updateSiteAutoStart( site.id, true );

if ( ! skipLogDetails ) {
logSiteDetails( site );
Expand Down
41 changes: 11 additions & 30 deletions apps/cli/commands/site/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
unlockCliConfig,
type SiteData,
} from 'cli/lib/cli-config/core';
import {
clearSiteLatestCliPid,
getSiteByFolder,
updateSiteAutoStart,
} from 'cli/lib/cli-config/sites';
import { clearSiteLatestCliPid, getSiteByFolder } from 'cli/lib/cli-config/sites';
import {
connectToDaemon,
disconnectFromDaemon,
Expand All @@ -31,25 +27,18 @@ export enum Mode {

export async function runCommand(
target: Mode.STOP_SINGLE_SITE,
siteFolder: string,
autoStart: boolean
siteFolder: string
): Promise< void >;
export async function runCommand(
target: Mode.STOP_ALL_SITES,
siteFolder: undefined,
autoStart: boolean
siteFolder: undefined
): Promise< void >;
export async function runCommand(
target: Mode,
siteFolder: string | undefined,
autoStart: boolean
): Promise< void > {
export async function runCommand( target: Mode, siteFolder: string | undefined ): Promise< void > {
try {
await connectToDaemon();

if ( target === Mode.STOP_SINGLE_SITE && siteFolder ) {
const site = await getSiteByFolder( siteFolder );
await updateSiteAutoStart( site.id, autoStart );

const runningProcess = await isServerRunning( site.id );
if ( ! runningProcess ) {
Expand Down Expand Up @@ -89,7 +78,6 @@ export async function runCommand(
for ( const site of cliConfig.sites ) {
if ( runningSites.find( ( r ) => r.id === site.id ) ) {
delete site.latestCliPid;
site.autoStart = autoStart;
}
}
await saveCliConfig( cliConfig );
Expand Down Expand Up @@ -122,25 +110,18 @@ export const registerCommand = ( yargs: StudioArgv ) => {
command: 'stop',
describe: __( 'Stop site(s)' ),
builder: ( yargs ) => {
return yargs
.option( 'all', {
type: 'boolean',
describe: __( 'Stop all sites' ),
default: false,
} )
.option( 'auto-start', {
type: 'boolean',
describe: __( 'Set auto-start flag for the site(s)' ),
default: false,
hidden: true,
} );
return yargs.option( 'all', {
type: 'boolean',
describe: __( 'Stop all sites' ),
default: false,
} );
},
handler: async ( argv ) => {
try {
if ( argv.all ) {
await runCommand( Mode.STOP_ALL_SITES, undefined, argv.autoStart );
await runCommand( Mode.STOP_ALL_SITES, undefined );
} else {
await runCommand( Mode.STOP_SINGLE_SITE, argv.path, argv.autoStart );
await runCommand( Mode.STOP_SINGLE_SITE, argv.path );
}
} catch ( error ) {
if ( error instanceof LoggerError ) {
Expand Down
4 changes: 1 addition & 3 deletions apps/cli/commands/site/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
unlockCliConfig,
SiteData,
} from 'cli/lib/cli-config/core';
import { removeSiteFromConfig, updateSiteAutoStart } from 'cli/lib/cli-config/sites';
import { removeSiteFromConfig } from 'cli/lib/cli-config/sites';
import { connectToDaemon, disconnectFromDaemon } from 'cli/lib/daemon-client';
import { updateServerFiles } from 'cli/lib/dependency-management/setup';
import { downloadWordPress } from 'cli/lib/dependency-management/wordpress';
Expand Down Expand Up @@ -71,7 +71,6 @@ vi.mock( 'cli/lib/cli-config/sites', async () => {
return {
...actual,
updateSiteLatestCliPid: vi.fn(),
updateSiteAutoStart: vi.fn().mockResolvedValue( undefined ),
removeSiteFromConfig: vi.fn(),
getSiteUrl: vi.fn().mockImplementation( ( site ) => `http://localhost:${ site.port }` ),
};
Expand Down Expand Up @@ -301,7 +300,6 @@ describe( 'CLI: studio site create', () => {
expect( saveCliConfig ).toHaveBeenCalled();
expect( connectToDaemon ).toHaveBeenCalled();
expect( startWordPressServer ).toHaveBeenCalled();
expect( updateSiteAutoStart ).toHaveBeenCalledWith( expect.any( String ), true );
expect( logSiteDetails ).toHaveBeenCalled();
expect( openSiteInBrowser ).toHaveBeenCalled();
expect( disconnectFromDaemon ).toHaveBeenCalled();
Expand Down
8 changes: 1 addition & 7 deletions apps/cli/commands/site/tests/start.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { SITE_RUNTIME_PLAYGROUND } from '@studio/common/lib/site-runtime';
import { vi } from 'vitest';
import { SiteData } from 'cli/lib/cli-config/core';
import {
getSiteByFolder,
updateSiteAutoStart,
updateSiteLatestCliPid,
} from 'cli/lib/cli-config/sites';
import { getSiteByFolder, updateSiteLatestCliPid } from 'cli/lib/cli-config/sites';
import { connectToDaemon, disconnectFromDaemon } from 'cli/lib/daemon-client';
import { logSiteDetails, openSiteInBrowser, setupCustomDomain } from 'cli/lib/site-utils';
import { keepSqliteIntegrationUpdated } from 'cli/lib/sqlite-integration';
Expand All @@ -18,7 +14,6 @@ vi.mock( 'cli/lib/cli-config/sites', async () => ( {
...( await vi.importActual( 'cli/lib/cli-config/sites' ) ),
getSiteByFolder: vi.fn(),
updateSiteLatestCliPid: vi.fn(),
updateSiteAutoStart: vi.fn().mockResolvedValue( undefined ),
} ) );
vi.mock( 'cli/lib/daemon-client' );
vi.mock( 'cli/lib/site-utils' );
Expand Down Expand Up @@ -146,7 +141,6 @@ describe( 'CLI: studio site start', () => {
testSite.id,
testProcessDescription.pid
);
expect( updateSiteAutoStart ).toHaveBeenCalledWith( testSite.id, true );
expect( logSiteDetails ).toHaveBeenCalledWith( testSite );
expect( openSiteInBrowser ).toHaveBeenCalledWith( testSite );
expect( disconnectFromDaemon ).toHaveBeenCalled();
Expand Down
Loading