Skip to content

Commit f14ed39

Browse files
authored
Merge branch 'trunk' into blueprint-editor
2 parents 4a4bf00 + 0d17a12 commit f14ed39

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

packages/playground/cli/src/blueprints-v1/blueprints-v1-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
type SpawnedWorker,
2626
type WorkerType,
2727
} from '../run-cli';
28+
import { shouldRenderProgress } from '../utils/progress';
2829

2930
/**
3031
* Boots Playground CLI workers using Blueprint version 1.
@@ -279,6 +280,9 @@ export class BlueprintsV1Handler {
279280
if (this.args.verbosity === LogVerbosity.Quiet.name) {
280281
return;
281282
}
283+
if (!shouldRenderProgress(writeStream)) {
284+
return;
285+
}
282286
if (message === this.lastProgressMessage) {
283287
// Avoid repeating the same message
284288
return;

packages/playground/cli/src/blueprints-v2/blueprints-v2-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
} from './worker-thread-v2';
77
import type { MessagePort as NodeMessagePort } from 'worker_threads';
88
import type { RunCLIArgs, SpawnedWorker, WorkerType } from '../run-cli';
9+
import { shouldRenderProgress } from '../utils/progress';
910

1011
/**
1112
* Boots Playground CLI workers using Blueprint version 2.
@@ -108,6 +109,9 @@ export class BlueprintsV2Handler {
108109
message: string,
109110
finalUpdate: boolean
110111
) {
112+
if (!shouldRenderProgress(writeStream)) {
113+
return;
114+
}
111115
if (message === this.lastProgressMessage) {
112116
// Avoid repeating the same message
113117
return;

packages/playground/cli/src/blueprints-v2/worker-thread-v2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
PhpIniOptions,
4040
PHPInstanceCreatedHook,
4141
} from '@wp-playground/wordpress';
42+
import { shouldRenderProgress } from '../utils/progress';
4243

4344
async function mountResources(php: PHP, mounts: Mount[]) {
4445
for (const mount of mounts) {
@@ -74,7 +75,8 @@ function tracePhpWasm(processId: number, format: string, ...args: any[]) {
7475
}
7576

7677
/**
77-
* Force TTY status to preserve ANSI control codes in the output.
78+
* Force TTY status to preserve ANSI control codes in the output
79+
* when the environment is interactive.
7880
*
7981
* This script is spawned as `new Worker()` and process.stdout and process.stderr are
8082
* WritableWorkerStdio objects. By default, they strip ANSI control codes from the output
@@ -90,6 +92,9 @@ Object.defineProperty(process.stderr, 'isTTY', { value: true });
9092
const output = {
9193
lastWriteWasProgress: false,
9294
progress(data: string) {
95+
if (!shouldRenderProgress(process.stdout)) {
96+
return;
97+
}
9398
if (!process.stdout.isTTY) {
9499
// eslint-disable-next-line no-console
95100
console.log(data);

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,17 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
8888
*/
8989
const yargsObject = yargs(argsToParse)
9090
.usage('Usage: wp-playground <command> [options]')
91-
.positional('command', {
92-
describe: 'Command to run',
93-
choices: ['server', 'run-blueprint', 'build-snapshot'] as const,
94-
demandOption: true,
95-
})
91+
.command('server', 'Start a local WordPress server')
92+
.command(
93+
'run-blueprint',
94+
'Execute a Blueprint without starting a server'
95+
)
96+
.command(
97+
'build-snapshot',
98+
'Build a ZIP snapshot of a WordPress site based on a Blueprint'
99+
)
100+
.demandCommand(1, 'Please specify a command')
101+
.strictCommands()
96102
.option('outfile', {
97103
describe: 'When building, write to this output file.',
98104
type: 'string',
@@ -288,6 +294,18 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
288294
hidden: true,
289295
})
290296
.showHelpOnFail(false)
297+
.fail((msg, err, yargsInstance) => {
298+
if (err) {
299+
throw err;
300+
}
301+
if (msg && msg.includes('Please specify a command')) {
302+
yargsInstance.showHelp();
303+
console.error('\n' + msg);
304+
process.exit(1);
305+
}
306+
console.error(msg);
307+
process.exit(1);
308+
})
291309
.strictOptions()
292310
.check(async (args) => {
293311
if (args['skip-wordpress-install'] === true) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function shouldRenderProgress(
2+
writeStream?: { isTTY?: boolean } | null
3+
): boolean {
4+
const termIsDumb = (process.env['TERM'] || '').toLowerCase() === 'dumb';
5+
const ciFlag = (process.env['CI'] || '').toLowerCase();
6+
const runningInCI = ciFlag === '1' || ciFlag === 'true';
7+
8+
if (termIsDumb || runningInCI) {
9+
return false;
10+
}
11+
12+
if (writeStream) {
13+
return Boolean(writeStream.isTTY);
14+
}
15+
16+
return true;
17+
}

0 commit comments

Comments
 (0)