MCPcopy Create free account
hub / github.com/ShipSecAI/studio / main

Function main

e2e-tests/scripts/setup-e2e-env.ts:81–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79}
80
81async function main() {
82 const rl = createInterface({ input, output });
83 const existing = existsSync(ENV_PATH) ? readFileSync(ENV_PATH, 'utf8') : '';
84 const existingMap = new Map<string, string>();
85 for (const line of existing.split(/\r?\n/)) {
86 const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
87 if (match) {
88 existingMap.set(match[1], match[2]);
89 }
90 }
91
92 const lines: string[] = [];
93 if (existing.trim().length === 0) {
94 const template = loadTemplate();
95 if (template.trim().length > 0) {
96 lines.push(...template.split(/\r?\n/).filter((l) => !l.startsWith('RUN_E2E=')));
97 }
98 }
99
100 lines.push('RUN_E2E=true');
101
102 for (const field of FIELDS) {
103 const current = existingMap.get(field.key) ?? '';
104 const hint = field.hint ? ` (${field.hint})` : '';
105 const prompt = `${field.prompt}${hint}${field.defaultValue ? ` [${field.defaultValue}]` : ''}: `;
106 const answer = (await rl.question(prompt)).trim();
107 const value = answer || current || field.defaultValue || '';
108
109 if (!value && !field.optional) {
110 console.error(`Missing required value for ${field.key}.`);
111 await rl.close();
112 process.exit(1);
113 }
114
115 if (!value && field.optional) {
116 lines.push(`${field.key}=`);
117 } else {
118 lines.push(`${field.key}=${value}`);
119 }
120 }
121
122 await rl.close();
123 ensureDir(ENV_PATH);
124 writeFileSync(ENV_PATH, `${lines.join('\n')}\n`, 'utf8');
125 console.log(`\nWrote ${ENV_PATH}`);
126}
127
128main().catch((err) => {
129 console.error(err);

Callers 1

setup-e2e-env.tsFile · 0.70

Calls 7

loadTemplateFunction · 0.85
ensureDirFunction · 0.85
errorMethod · 0.80
pushMethod · 0.65
getMethod · 0.65
setMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected