@emeryld/manager 0.8.2 → 1.0.0

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.
Files changed (2) hide show
  1. package/dist/prompts.js +44 -63
  2. package/package.json +1 -1
package/dist/prompts.js CHANGED
@@ -2,9 +2,43 @@
2
2
  import readline from 'node:readline/promises';
3
3
  import { stdin as input, stdout as output } from 'node:process';
4
4
  import { colors } from './utils/log.js';
5
+ import { promptForScript } from './helper-cli/prompts.js';
6
+ import { normalizeScripts } from './helper-cli/scripts.js';
5
7
  export const publishCliState = {
6
8
  autoDecision: undefined,
7
9
  };
10
+ const noopHandler = () => { };
11
+ const yesNoAllChoices = [
12
+ {
13
+ name: 'Yes',
14
+ description: 'Apply once',
15
+ emoji: 'Y',
16
+ color: 'green',
17
+ handler: noopHandler,
18
+ },
19
+ {
20
+ name: 'Yes to all',
21
+ description: 'Apply to all remaining prompts',
22
+ emoji: 'YA',
23
+ color: 'brightGreen',
24
+ handler: noopHandler,
25
+ },
26
+ {
27
+ name: 'No',
28
+ description: 'Skip once',
29
+ emoji: 'N',
30
+ color: 'red',
31
+ handler: noopHandler,
32
+ },
33
+ {
34
+ name: 'No to all',
35
+ description: 'Skip all remaining prompts',
36
+ emoji: 'NA',
37
+ color: 'brightRed',
38
+ handler: noopHandler,
39
+ },
40
+ ];
41
+ const yesNoAllEntries = normalizeScripts(yesNoAllChoices);
8
42
  export function promptSingleKey(message, resolver) {
9
43
  const supportsRawMode = typeof input.setRawMode === 'function' && input.isTTY;
10
44
  if (!supportsRawMode) {
@@ -71,78 +105,25 @@ export async function promptYesNoAll(question) {
71
105
  console.log(`${question} (auto-${publishCliState.autoDecision} via "all")`);
72
106
  return publishCliState.autoDecision;
73
107
  }
74
- // Allow yes/no + "apply to all" variants: yy, ya, nn, na
75
- const promptMessage = `${question} (yy/ya/nn/na): `;
76
- const supportsRawMode = typeof input.setRawMode === 'function' && input.isTTY;
77
- const readDecisionInput = async () => {
78
- if (!supportsRawMode) {
79
- const fallback = await askLine(promptMessage);
80
- return fallback.trim().toLowerCase();
81
- }
82
- return new Promise((resolve) => {
83
- const wasRaw = input.isRaw;
84
- if (!wasRaw) {
85
- input.setRawMode(true);
86
- input.resume();
87
- }
88
- process.stdout.write(promptMessage);
89
- const cleanup = () => {
90
- input.off('data', onData);
91
- if (!wasRaw) {
92
- input.setRawMode(false);
93
- input.pause();
94
- }
95
- };
96
- let collected = '';
97
- const onData = (buffer) => {
98
- const str = buffer.toString('utf8');
99
- for (const char of str) {
100
- if (char === '\u0003') {
101
- cleanup();
102
- process.stdout.write('\n');
103
- process.exit(1);
104
- }
105
- if (char === '\u0008' || char === '\u007f') {
106
- if (collected.length > 0) {
107
- collected = collected.slice(0, -1);
108
- process.stdout.write('\b \b');
109
- }
110
- continue;
111
- }
112
- if (char === '\r' || char === '\n') {
113
- continue;
114
- }
115
- if (!/^[a-zA-Z]$/.test(char)) {
116
- continue;
117
- }
118
- process.stdout.write(char);
119
- collected += char;
120
- if (collected.length === 2) {
121
- cleanup();
122
- process.stdout.write('\n');
123
- resolve(collected.toLowerCase());
124
- return;
125
- }
126
- }
127
- };
128
- input.on('data', onData);
129
- });
130
- };
131
108
  // eslint-disable-next-line no-constant-condition
132
109
  while (true) {
133
- const answer = await readDecisionInput();
134
- if (answer === 'yy')
110
+ const selection = await promptForScript(yesNoAllEntries, question);
111
+ if (!selection) {
112
+ console.log(colors.yellow('Please select an option to continue.'));
113
+ continue;
114
+ }
115
+ if (selection.name === 'Yes')
135
116
  return 'yes';
136
- if (answer === 'ya') {
117
+ if (selection.name === 'Yes to all') {
137
118
  publishCliState.autoDecision = 'yes';
138
119
  return 'yes';
139
120
  }
140
- if (answer === 'nn')
121
+ if (selection.name === 'No')
141
122
  return 'no';
142
- if (answer === 'na') {
123
+ if (selection.name === 'No to all') {
143
124
  publishCliState.autoDecision = 'no';
144
125
  return 'no';
145
126
  }
146
- console.log(colors.red('Please enter yy, ya, nn, or na.'));
127
+ console.log(colors.red('Please select a valid option to continue.'));
147
128
  }
148
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/manager",
3
- "version": "0.8.2",
3
+ "version": "1.0.0",
4
4
  "description": "Interactive manager for pnpm monorepos (update/test/build/publish).",
5
5
  "license": "MIT",
6
6
  "type": "module",