Skip to content

Commit c682b07

Browse files
Enhance non-interactive project creation in create-plugma by allowing immediate project creation while still using ask() for runtime context, ensuring compatibility with TTY requirements.
1 parent 4d4d387 commit c682b07

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

packages/create-plugma/src/create.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as fs from 'node:fs';
99
import * as path from 'node:path';
1010
import { dirname } from 'node:path';
1111
import { fileURLToPath } from 'node:url';
12+
import { PassThrough } from 'node:stream';
1213
import chalk from 'chalk';
1314
import stripTS from '@combino/plugin-strip-ts';
1415
import ejsMate from '@combino/plugin-ejs-mate';
@@ -549,7 +550,8 @@ async function browseAndSelectTemplate(
549550
// Check if we're in a non-interactive environment (CI, no TTY stdin)
550551
const isNonInteractive = !process.stdin.isTTY || process.env.CI === 'true';
551552

552-
// If non-interactive and quick creation is enabled, skip the askeroo/Ink layer
553+
// If non-interactive and quick creation is enabled, we still need to use ask() for runtime context
554+
// but we'll skip all the prompts
553555
if (isNonInteractive && shouldUseQuickCreation) {
554556
const type = preSelectedType || 'plugin';
555557
const framework = preSelectedFramework || 'React';
@@ -573,23 +575,46 @@ async function browseAndSelectTemplate(
573575
// We'll use the pre-selected integrations without the askeroo layer
574576
}
575577

576-
await createProjectFromOptions({
577-
type,
578-
framework,
579-
typescript,
580-
projectInfo,
581-
debug: options.debug || false,
582-
installAddOns: preSelectedAddOns === false ? [] : Array.isArray(preSelectedAddOns) ? preSelectedAddOns : [],
583-
addOnResults,
584-
addOnDeps,
585-
installDependencies: installBehavior.installDependencies,
586-
selectedPackageManager: installBehavior.selectedPackageManager,
587-
addOnAnswers,
588-
preferredPM: defaultPM,
589-
skipInstallPrompt: installBehavior.skipInstallPrompt,
590-
verbose: options.verbose,
578+
// Temporarily override stdin to appear as a TTY (for askeroo/Ink compatibility)
579+
const originalIsTTY = process.stdin.isTTY;
580+
Object.defineProperty(process.stdin, 'isTTY', {
581+
get() {
582+
return true;
583+
},
591584
});
592585

586+
try {
587+
// Still need ask() for runtime context, but we'll immediately run the creation
588+
await ask(async () => {
589+
// Skip the Plugma prompt in non-interactive mode
590+
// Just run the creation immediately
591+
await createProjectFromOptions({
592+
type,
593+
framework,
594+
typescript,
595+
projectInfo,
596+
debug: options.debug || false,
597+
installAddOns:
598+
preSelectedAddOns === false ? [] : Array.isArray(preSelectedAddOns) ? preSelectedAddOns : [],
599+
addOnResults,
600+
addOnDeps,
601+
installDependencies: installBehavior.installDependencies,
602+
selectedPackageManager: installBehavior.selectedPackageManager,
603+
addOnAnswers,
604+
preferredPM: defaultPM,
605+
skipInstallPrompt: installBehavior.skipInstallPrompt,
606+
verbose: options.verbose,
607+
});
608+
});
609+
} finally {
610+
// Restore original isTTY
611+
Object.defineProperty(process.stdin, 'isTTY', {
612+
get() {
613+
return originalIsTTY;
614+
},
615+
});
616+
}
617+
593618
return;
594619
}
595620

0 commit comments

Comments
 (0)