create-react-on-rails-app 17.0.0-rc.5 → 17.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,24 +1,22 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ready = void 0;
7
4
  const commander_1 = require("commander");
8
- const chalk_1 = __importDefault(require("chalk"));
9
5
  const validators_js_1 = require("./validators.js");
10
6
  const create_app_js_1 = require("./create-app.js");
7
+ const mode_js_1 = require("./mode.js");
11
8
  const utils_js_1 = require("./utils.js");
12
- const prompt_js_1 = require("./prompt.js");
13
9
  // Use require() for CJS compatibility - avoids __dirname + fs.readFileSync
14
10
  // eslint-disable-next-line @typescript-eslint/no-require-imports, global-require
15
11
  const packageJson = require('../package.json');
16
- async function run(appName, rawOpts, command) {
17
- const { template } = rawOpts;
18
- if (typeof template !== 'string' || (template !== 'javascript' && template !== 'typescript')) {
19
- (0, utils_js_1.logError)(`Invalid template "${String(template)}". Must be "javascript" or "typescript".`);
12
+ function run(appName, rawOpts, command) {
13
+ const { template: rawTemplate } = rawOpts;
14
+ if (typeof rawTemplate !== 'string' || (rawTemplate !== 'javascript' && rawTemplate !== 'typescript')) {
15
+ (0, utils_js_1.logError)(`Invalid template "${String(rawTemplate)}". Must be "javascript" or "typescript".`);
20
16
  process.exit(1);
17
+ return;
21
18
  }
19
+ const template = rawTemplate;
22
20
  let packageManager = rawOpts.packageManager;
23
21
  if (packageManager) {
24
22
  if (packageManager !== 'npm' && packageManager !== 'pnpm') {
@@ -29,9 +27,14 @@ async function run(appName, rawOpts, command) {
29
27
  else {
30
28
  packageManager = (0, utils_js_1.detectPackageManager)() ?? 'npm';
31
29
  }
32
- if (rawOpts.standard && (rawOpts.pro || rawOpts.rsc)) {
33
- (0, utils_js_1.logError)('--standard cannot be combined with --pro or --rsc.');
30
+ let setupMode;
31
+ try {
32
+ setupMode = (0, mode_js_1.resolveSetupMode)(rawOpts);
33
+ }
34
+ catch (error) {
35
+ (0, utils_js_1.logError)(error instanceof Error ? error.message : String(error));
34
36
  process.exit(1);
37
+ return;
35
38
  }
36
39
  // --webpack is a friendly alias for --no-rspack. Commander reports --no-rspack's declared
37
40
  // default as rawOpts.rspack === true, so we use the option source to distinguish an explicit
@@ -42,34 +45,14 @@ async function run(appName, rawOpts, command) {
42
45
  (0, utils_js_1.logError)('Conflicting bundler flags: pass either --rspack or --webpack (alias for --no-rspack), not both.');
43
46
  process.exit(1);
44
47
  }
45
- let pro = Boolean(rawOpts.pro);
46
- let rsc = Boolean(rawOpts.rsc);
47
- let tailwind = Boolean(rawOpts.tailwind);
48
48
  console.log('');
49
- console.log(`${chalk_1.default.bold('create-react-on-rails-app')} v${packageJson.version}`);
49
+ console.log(`${utils_js_1.pc.bold('create-react-on-rails-app')} v${packageJson.version}`);
50
50
  console.log('');
51
51
  const nameValidation = (0, create_app_js_1.validateAppName)(appName);
52
52
  if (!nameValidation.success) {
53
53
  (0, utils_js_1.logError)(nameValidation.error ?? 'Invalid app name');
54
54
  process.exit(1);
55
55
  }
56
- // When no mode flag is explicitly passed, prompt interactively (TTY only).
57
- // Non-interactive environments (CI, pipes) fall back to standard mode.
58
- const modeExplicit = rawOpts.pro !== undefined || rawOpts.rsc !== undefined || rawOpts.standard !== undefined;
59
- if (!modeExplicit) {
60
- if (process.stdin.isTTY && process.stdout.isTTY) {
61
- const choice = await (0, prompt_js_1.promptForMode)();
62
- pro = choice.pro;
63
- rsc = choice.rsc;
64
- // Explicit mode flags keep the command deterministic; no-flag interactive runs get the Tailwind prompt.
65
- if (rawOpts.tailwind === undefined) {
66
- tailwind = await (0, prompt_js_1.promptForTailwind)();
67
- }
68
- }
69
- else {
70
- (0, utils_js_1.logInfo)('No mode flag specified and not running interactively (stdin/stdout is not a TTY); using standard mode.');
71
- }
72
- }
73
56
  const options = {
74
57
  template,
75
58
  packageManager: packageManager,
@@ -82,33 +65,36 @@ async function run(appName, rawOpts, command) {
82
65
  // generator, so the generator's own fresh-install fallback (fresh_install_rspack_default,
83
66
  // which consults the Shakapacker version) is never reached via create-react-on-rails-app.
84
67
  rspack: webpackRequested ? false : (rawOpts.rspack ?? true) === true,
85
- tailwind,
86
- pro,
87
- rsc,
68
+ tailwind: Boolean(rawOpts.tailwind),
69
+ pro: setupMode.pro,
70
+ rsc: setupMode.rsc,
88
71
  // Commander's `--no-agent-files` declares a default of true on rawOpts.agentFiles,
89
72
  // so undefined (no flag) and true (default) both map to true; only --no-agent-files
90
73
  // sets it false.
91
74
  agentFiles: (rawOpts.agentFiles ?? true) === true,
92
75
  cliVersion: packageJson.version,
93
76
  };
94
- if (options.rsc && options.pro) {
95
- (0, utils_js_1.logInfo)('Note: --rsc takes precedence over --pro; --pro will be ignored.');
77
+ if (setupMode.defaulted) {
78
+ (0, utils_js_1.logInfo)('Default setup: React on Rails Pro for React 19.2 support. Use --standard only when you intentionally want an open-source-only setup.');
96
79
  }
97
- if (options.rsc || options.pro) {
80
+ if (setupMode.requiresPro) {
98
81
  const modeFlag = options.rsc ? '--rsc' : '--pro';
99
- (0, utils_js_1.logInfo)(`Note: ${modeFlag} installs react_on_rails_pro and requires that gem to be installable.`);
100
- (0, utils_js_1.logInfo)(`If installation fails, verify your Bundler/RubyGems setup for react_on_rails_pro, then rerun with ${modeFlag}.`);
82
+ const setupLabel = setupMode.defaulted ? 'The default setup' : modeFlag;
83
+ (0, utils_js_1.logInfo)(`Note: ${setupLabel} adds react_on_rails_pro and uses the Pro generator path.`);
84
+ (0, utils_js_1.logInfo)('If installation fails, verify your Bundler/RubyGems setup, then rerun the command.');
101
85
  (0, utils_js_1.logInfo)('Pro setup docs: https://reactonrails.com/docs/pro/installation/');
86
+ (0, utils_js_1.logInfo)('Pro pricing and sign up: https://pro.reactonrails.com/');
87
+ (0, utils_js_1.logInfo)('License: no token is required for development, test, CI/CD, or staging. Production Pro deployments need a paid license, with free or low-cost options for startups and small projects.');
102
88
  console.log('');
103
89
  }
104
90
  (0, utils_js_1.logInfo)('Checking prerequisites...');
105
91
  const { allValid, results } = (0, validators_js_1.validateAll)(options.packageManager);
106
92
  for (const { name, result } of results) {
107
93
  if (result.valid) {
108
- console.log(chalk_1.default.green(` ✓ ${name}: ${result.message}`));
94
+ console.log(utils_js_1.pc.green(` ✓ ${name}: ${result.message}`));
109
95
  }
110
96
  else {
111
- console.log(chalk_1.default.red(` ✗ ${name}`));
97
+ console.log(utils_js_1.pc.red(` ✗ ${name}`));
112
98
  }
113
99
  }
114
100
  if (!allValid) {
@@ -123,10 +109,13 @@ async function run(appName, rawOpts, command) {
123
109
  console.log('');
124
110
  let modeLabel = '';
125
111
  if (options.rsc) {
126
- modeLabel = ', mode: rsc';
112
+ modeLabel = ', setup: pro with RSC example';
127
113
  }
128
114
  else if (options.pro) {
129
- modeLabel = ', mode: pro';
115
+ modeLabel = ', setup: pro without RSC example';
116
+ }
117
+ else {
118
+ modeLabel = ', setup: open-source-only';
130
119
  }
131
120
  const tailwindLabel = options.tailwind ? ', Tailwind CSS v4' : '';
132
121
  (0, utils_js_1.logInfo)(`Creating "${appName}" with template: ${options.template}, package manager: ${options.packageManager}, bundler: ${options.rspack ? 'rspack' : 'webpack'}${modeLabel}${tailwindLabel}`);
@@ -146,38 +135,43 @@ program
146
135
  .option('--no-rspack', 'Use Webpack instead of Rspack')
147
136
  .option('--webpack', 'Use Webpack as the bundler (alias for --no-rspack)')
148
137
  .option('--tailwind', 'Install Tailwind CSS v4 and style the generated SSR example')
149
- .option('--standard', 'Generate open-source React on Rails setup (skip prompt)')
150
- .option('--pro', 'Generate React on Rails Pro setup (installs react_on_rails_pro)')
151
- .option('--rsc', 'Generate React Server Components setup (installs react_on_rails_pro)')
138
+ .option('--standard', 'Advanced: generate open-source React on Rails without Pro React 19.2 features')
139
+ .option('--pro', 'Generate the default React on Rails Pro setup explicitly')
140
+ .option('--rsc', 'Advanced: generate React on Rails Pro with the RSC example')
152
141
  .option('--no-agent-files', 'Skip AI-agent guidance files (AGENTS.md + editor pointers)')
153
142
  .addHelpText('after', `
154
143
  Examples:
155
- $ npx create-react-on-rails-app my-app # prompts for mode
156
- $ npx create-react-on-rails-app my-app --rsc # skip prompt, use RSC
157
- $ npx create-react-on-rails-app my-app --pro # skip prompt, use Pro
158
- $ npx create-react-on-rails-app my-app --standard # skip prompt, use Standard
144
+ $ npx create-react-on-rails-app my-app # default: Pro for React 19.2 support
159
145
  $ npx create-react-on-rails-app my-app --template javascript
160
146
  $ npx create-react-on-rails-app my-app --no-rspack # use Webpack instead of Rspack
161
147
  $ npx create-react-on-rails-app my-app --webpack # same as --no-rspack
162
148
  $ npx create-react-on-rails-app my-app --tailwind
149
+ $ npx create-react-on-rails-app my-app --pro # explicit default Pro setup
150
+ $ npx create-react-on-rails-app my-app --rsc # advanced: Pro with RSC example
151
+ $ npx create-react-on-rails-app my-app --standard # advanced: OSS-only setup
163
152
  $ npx create-react-on-rails-app my-app --no-rspack --rsc
164
153
  $ npx create-react-on-rails-app my-app --package-manager pnpm
165
154
  $ npx create-react-on-rails-app my-app --no-agent-files # skip AGENTS.md + editor pointers
166
155
 
167
- When no mode flag (--standard, --pro, or --rsc) is given, an interactive prompt
168
- lets you choose between Standard, Pro, and RSC modes (default: RSC). When stdin
169
- or stdout is not a TTY (for example in CI, piped input, or redirected output),
170
- standard mode is used automatically.
156
+ No setup questions are asked. New apps use React on Rails Pro by default because
157
+ that is where React 19.2 feature support lives. Use --standard only when you
158
+ intentionally want an open-source-only scaffold. Use --rsc when you want the
159
+ generated React Server Components example.
160
+
161
+ Pro license note: no token is required for development, test, CI/CD, or
162
+ staging. Production Pro deployments need a paid license, with free or low-cost
163
+ options for startups and small projects. See pricing and sign up:
164
+ https://pro.reactonrails.com/
171
165
 
172
166
  What it does:
173
167
  1. Creates a new Rails app with PostgreSQL
174
- 2. Adds required gem(s) (react_on_rails, plus react_on_rails_pro for Pro/RSC)
168
+ 2. Adds required gem(s) (react_on_rails, plus react_on_rails_pro unless --standard)
175
169
  3. Runs the React on Rails generator (Shakapacker, components, webpack config)
176
170
  4. Creates educational git commits for each major scaffold step
177
171
 
178
172
  After setup, run bin/dev and visit:
179
173
  - http://localhost:3000 (generated home page)
180
- - /hello_world (default and --pro example page)
174
+ - /hello_world (default, --standard, and --pro example page)
181
175
  - /hello_server (--rsc example page)
182
176
 
183
177
  Inspect the generated setup history with:
@@ -188,15 +182,11 @@ The generated app includes one git commit per logical setup step.`)
188
182
  --pro and --rsc support both JavaScript and TypeScript templates.
189
183
 
190
184
  Documentation: https://reactonrails.com/docs/`)
191
- .action(async (appName, opts, command) => {
185
+ .action((appName, opts, command) => {
192
186
  try {
193
- await run(appName, opts, command);
187
+ run(appName, opts, command);
194
188
  }
195
189
  catch (error) {
196
- if (error instanceof Error && error.message === prompt_js_1.PROMPT_CANCELLED) {
197
- console.log('');
198
- process.exit(0);
199
- }
200
190
  (0, utils_js_1.logError)(error instanceof Error ? error.message : String(error));
201
191
  process.exit(1);
202
192
  }
package/lib/mode.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export type SetupMode = 'standard' | 'pro' | 'rsc';
2
+ interface ResolvedSetupModeBase {
3
+ defaulted: boolean;
4
+ mode: SetupMode;
5
+ }
6
+ interface StandardResolvedSetupMode extends ResolvedSetupModeBase {
7
+ defaulted: false;
8
+ mode: 'standard';
9
+ requiresPro: false;
10
+ pro: false;
11
+ rsc: false;
12
+ }
13
+ interface ProResolvedSetupMode extends ResolvedSetupModeBase {
14
+ mode: 'pro';
15
+ /** True when the selected setup installs react_on_rails_pro. */
16
+ requiresPro: true;
17
+ /** True for the Pro-without-RSC generator path. RSC mode uses its own Pro path. */
18
+ pro: true;
19
+ rsc: false;
20
+ }
21
+ interface RscResolvedSetupMode extends ResolvedSetupModeBase {
22
+ defaulted: false;
23
+ mode: 'rsc';
24
+ /** True when the selected setup installs react_on_rails_pro. */
25
+ requiresPro: true;
26
+ /** RSC mode uses its own Pro generator path, so this generator flag is false. */
27
+ pro: false;
28
+ rsc: true;
29
+ }
30
+ export type ResolvedSetupMode = StandardResolvedSetupMode | ProResolvedSetupMode | RscResolvedSetupMode;
31
+ export declare function resolveSetupMode(rawOpts: Record<string, unknown>): ResolvedSetupMode;
32
+ export {};
33
+ //# sourceMappingURL=mode.d.ts.map
package/lib/mode.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSetupMode = resolveSetupMode;
4
+ function makeSetupMode(mode, defaulted) {
5
+ if (mode === 'standard') {
6
+ return {
7
+ defaulted: false,
8
+ mode,
9
+ requiresPro: false,
10
+ pro: false,
11
+ rsc: false,
12
+ };
13
+ }
14
+ if (mode === 'rsc') {
15
+ return {
16
+ defaulted: false,
17
+ mode,
18
+ requiresPro: true,
19
+ pro: false,
20
+ rsc: true,
21
+ };
22
+ }
23
+ return {
24
+ defaulted,
25
+ mode,
26
+ requiresPro: true,
27
+ pro: true,
28
+ rsc: false,
29
+ };
30
+ }
31
+ function resolveSetupMode(rawOpts) {
32
+ const standard = Boolean(rawOpts.standard);
33
+ const pro = Boolean(rawOpts.pro);
34
+ const rsc = Boolean(rawOpts.rsc);
35
+ if ([standard, pro, rsc].filter(Boolean).length > 1) {
36
+ throw new Error('Choose only one setup mode: --standard, --pro, or --rsc.');
37
+ }
38
+ if (standard) {
39
+ return makeSetupMode('standard', false);
40
+ }
41
+ if (rsc) {
42
+ return makeSetupMode('rsc', false);
43
+ }
44
+ if (pro) {
45
+ return makeSetupMode('pro', false);
46
+ }
47
+ return makeSetupMode('pro', true);
48
+ }
49
+ //# sourceMappingURL=mode.js.map
package/lib/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const pc: import("picocolors/types").Colors;
1
2
  /**
2
3
  * Execute a command and stream output to the current terminal.
3
4
  *
package/lib/utils.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pc = void 0;
6
7
  exports.execLiveArgs = execLiveArgs;
7
8
  exports.execCaptureArgs = execCaptureArgs;
8
9
  exports.getCommandVersion = getCommandVersion;
@@ -13,7 +14,70 @@ exports.logError = logError;
13
14
  exports.logSuccess = logSuccess;
14
15
  exports.logInfo = logInfo;
15
16
  const child_process_1 = require("child_process");
16
- const chalk_1 = __importDefault(require("chalk"));
17
+ const picocolors_1 = __importDefault(require("picocolors"));
18
+ const CHALK_CI_COLOR_ENV_KEYS = [
19
+ 'TRAVIS',
20
+ 'CIRCLECI',
21
+ 'APPVEYOR',
22
+ 'GITLAB_CI',
23
+ 'GITHUB_ACTIONS',
24
+ 'BUILDKITE',
25
+ ];
26
+ const CHALK_TEAMCITY_COLOR_PATTERN = /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/;
27
+ const CHALK_TERM_256_COLOR_PATTERN = /-256(color)?$/i;
28
+ const CHALK_TERM_COLOR_PATTERN = /^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i;
29
+ function hasChalkCompatibleTtyColorSignal() {
30
+ const { CI, CI_NAME, COLORTERM, TEAMCITY_VERSION, TERM, TERM_PROGRAM } = process.env;
31
+ if (TERM === 'dumb') {
32
+ return false;
33
+ }
34
+ if (process.platform === 'win32') {
35
+ return true;
36
+ }
37
+ if (CI !== undefined) {
38
+ return CHALK_CI_COLOR_ENV_KEYS.some((key) => process.env[key] !== undefined) || CI_NAME === 'codeship';
39
+ }
40
+ if (TEAMCITY_VERSION !== undefined) {
41
+ return CHALK_TEAMCITY_COLOR_PATTERN.test(TEAMCITY_VERSION);
42
+ }
43
+ if (COLORTERM === 'truecolor') {
44
+ return true;
45
+ }
46
+ if (TERM_PROGRAM === 'iTerm.app' || TERM_PROGRAM === 'Apple_Terminal') {
47
+ return true;
48
+ }
49
+ const term = TERM ?? '';
50
+ return (CHALK_TERM_256_COLOR_PATTERN.test(term) || CHALK_TERM_COLOR_PATTERN.test(term) || COLORTERM !== undefined);
51
+ }
52
+ /**
53
+ * Decide whether to colorize output, matching what `chalk@4` produced before the
54
+ * chalk→picocolors swap. The scaffolder is a user's first contact with the
55
+ * framework and its logs are often captured, so keeping the same basic
56
+ * colorize/plain decision avoids surprising behavior changes.
57
+ *
58
+ * picocolors' own `isColorSupported` bakes in a different precedence than chalk
59
+ * (it lets NO_COLOR override FORCE_COLOR, and enables color on a bare CI even for
60
+ * piped stdout), so instead of deferring to it we reproduce the relevant chalk@4
61
+ * environment precedence directly and only use picocolors for the actual escape codes:
62
+ *
63
+ * 1. FORCE_COLOR present → `0`/`false` disables; any other value (incl. empty)
64
+ * forces color ON, overriding NO_COLOR and a non-TTY stdout.
65
+ * 2. else NO_COLOR present (any value, incl. empty) → disabled.
66
+ * 3. else colorize only for an interactive TTY with one of chalk@4's positive
67
+ * environment signals. A bare TTY with unset or unrecognized TERM stays
68
+ * plain, matching supports-color@7.2.0's fallback behavior.
69
+ */
70
+ function chalkCompatibleColorEnabled() {
71
+ const { FORCE_COLOR, NO_COLOR } = process.env;
72
+ if (FORCE_COLOR !== undefined) {
73
+ return FORCE_COLOR !== '0' && FORCE_COLOR !== 'false';
74
+ }
75
+ if (NO_COLOR !== undefined) {
76
+ return false;
77
+ }
78
+ return (process.stdout?.isTTY ?? false) && hasChalkCompatibleTtyColorSignal();
79
+ }
80
+ exports.pc = picocolors_1.default.createColors(chalkCompatibleColorEnabled());
17
81
  function childEnv(env) {
18
82
  // Always inherit PATH, HOME, and the rest of process.env; callers only add/override keys.
19
83
  return env ? { ...process.env, ...env } : process.env;
@@ -85,18 +149,18 @@ function detectPackageManager() {
85
149
  return null;
86
150
  }
87
151
  function logStep(current, total, message) {
88
- console.log(chalk_1.default.cyan(`\n[${current}/${total}] ${message}`));
152
+ console.log(exports.pc.cyan(`\n[${current}/${total}] ${message}`));
89
153
  }
90
154
  function logStepDone(message) {
91
- console.log(chalk_1.default.green(` ✓ ${message}`));
155
+ console.log(exports.pc.green(` ✓ ${message}`));
92
156
  }
93
157
  function logError(message) {
94
- console.error(chalk_1.default.red(`\nError: ${message}\n`));
158
+ console.error(exports.pc.red(`\nError: ${message}\n`));
95
159
  }
96
160
  function logSuccess(message) {
97
- console.log(chalk_1.default.green(message));
161
+ console.log(exports.pc.green(message));
98
162
  }
99
163
  function logInfo(message) {
100
- console.log(chalk_1.default.cyan(message));
164
+ console.log(exports.pc.cyan(message));
101
165
  }
102
166
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-react-on-rails-app",
3
- "version": "17.0.0-rc.5",
3
+ "version": "17.0.0-rc.7",
4
4
  "description": "Create React on Rails applications with a single command",
5
5
  "bin": {
6
6
  "create-react-on-rails-app": "./bin/create-react-on-rails-app.js"
@@ -12,8 +12,8 @@
12
12
  "lib/**/*.d.ts"
13
13
  ],
14
14
  "dependencies": {
15
- "chalk": "^4.1.2",
16
- "commander": "^12.1.0"
15
+ "commander": "^12.1.0",
16
+ "picocolors": "^1.1.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/node": "^20.17.16",
package/lib/prompt.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export interface ModeChoice {
2
- pro: boolean;
3
- rsc: boolean;
4
- }
5
- export declare const PROMPT_CANCELLED = "Prompt cancelled by user";
6
- export declare function promptForMode(): Promise<ModeChoice>;
7
- export declare function promptForTailwind(): Promise<boolean>;
8
- //# sourceMappingURL=prompt.d.ts.map
package/lib/prompt.js DELETED
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PROMPT_CANCELLED = void 0;
7
- exports.promptForMode = promptForMode;
8
- exports.promptForTailwind = promptForTailwind;
9
- const readline_1 = __importDefault(require("readline"));
10
- const chalk_1 = __importDefault(require("chalk"));
11
- exports.PROMPT_CANCELLED = 'Prompt cancelled by user';
12
- const MODES = [
13
- {
14
- key: '1',
15
- label: 'Standard',
16
- desc: 'Open-source React on Rails with SSR',
17
- pro: false,
18
- rsc: false,
19
- },
20
- {
21
- key: '2',
22
- label: 'Pro',
23
- desc: 'Adds Node.js server rendering (requires react_on_rails_pro)',
24
- pro: true,
25
- rsc: false,
26
- },
27
- {
28
- key: '3',
29
- label: 'RSC',
30
- desc: 'React Server Components (requires react_on_rails_pro)',
31
- pro: false,
32
- rsc: true,
33
- },
34
- ];
35
- const DEFAULT_KEY = '3';
36
- function createPromptInterface() {
37
- return readline_1.default.createInterface({
38
- input: process.stdin,
39
- output: process.stdout,
40
- });
41
- }
42
- function rejectWhenClosed(rl, reject) {
43
- let answered = false;
44
- rl.on('SIGINT', () => {
45
- answered = true;
46
- rl.close();
47
- reject(new Error(exports.PROMPT_CANCELLED));
48
- });
49
- rl.once('close', () => {
50
- if (!answered) {
51
- reject(new Error(exports.PROMPT_CANCELLED));
52
- }
53
- });
54
- return () => {
55
- answered = true;
56
- };
57
- }
58
- function promptForMode() {
59
- return new Promise((resolve, reject) => {
60
- const rl = createPromptInterface();
61
- const markAnswered = rejectWhenClosed(rl, reject);
62
- console.log(chalk_1.default.bold('Select a setup mode:\n'));
63
- for (const mode of MODES) {
64
- const recommended = mode.key === DEFAULT_KEY ? chalk_1.default.cyan(' (recommended)') : '';
65
- console.log(` ${mode.key}. ${chalk_1.default.bold(mode.label.padEnd(10))} ${mode.desc}${recommended}`);
66
- }
67
- console.log('');
68
- rl.question(`Choice (1-3) [${DEFAULT_KEY}]: `, (answer) => {
69
- markAnswered();
70
- rl.close();
71
- const key = answer.trim() || DEFAULT_KEY;
72
- const selected = MODES.find((m) => m.key === key);
73
- if (!selected) {
74
- console.log(chalk_1.default.yellow(`Invalid choice "${key}", defaulting to RSC.`));
75
- resolve({ pro: false, rsc: true });
76
- return;
77
- }
78
- resolve({ pro: selected.pro, rsc: selected.rsc });
79
- });
80
- });
81
- }
82
- function promptForTailwind() {
83
- return new Promise((resolve, reject) => {
84
- const rl = createPromptInterface();
85
- const markAnswered = rejectWhenClosed(rl, reject);
86
- console.log(chalk_1.default.bold('Add styling:\n'));
87
- console.log(` ${chalk_1.default.bold('Y. Tailwind CSS v4')} ${chalk_1.default.cyan('(recommended)')}`);
88
- console.log(' n. No Tailwind CSS');
89
- console.log('');
90
- rl.question('Add Tailwind CSS v4? [Y/n]: ', (answer) => {
91
- markAnswered();
92
- rl.close();
93
- const normalized = answer.trim().toLowerCase();
94
- resolve(!(normalized === 'n' || normalized === 'no'));
95
- });
96
- });
97
- }
98
- //# sourceMappingURL=prompt.js.map