@@ -32,6 +32,15 @@ const error = (msg) => {
3232
3333const run = ( cmd , options = { } ) => {
3434 try {
35+ // Prepare options for execSync
36+ const execOptions = { ...options } ;
37+ if ( options . input ) {
38+ execOptions . input = options . input ;
39+ delete execOptions . input ; // Remote input from options passed to execSync if it's not supported directly in the spread (though it is for some node versions, let's be safe)
40+ }
41+
42+ // If providing input, we must rely on the provided stdio or default to pipe for stdin
43+ // execSync with input handles stdin automatically if not overridden to something incompatible
3544 const result = execSync ( cmd , { stdio : 'pipe' , encoding : 'utf-8' , ...options } ) ;
3645 return result ? result . trim ( ) : null ;
3746 } catch ( e ) {
@@ -157,8 +166,13 @@ async function main() {
157166 // Check if secrets likely exist (rudimentary check, or just prompt to overwrite)
158167 const adminPassword = await ask ( 'Enter a secure Admin Password:' ) ;
159168 if ( adminPassword ) {
160- run ( `echo "${ adminPassword } " | wrangler secret put ADMIN_PASSWORD` ) ;
161- success ( 'ADMIN_PASSWORD set.' ) ;
169+ // Use input option to pass password to stdin, avoiding echo and potential shell issues
170+ try {
171+ run ( 'wrangler secret put ADMIN_PASSWORD' , { input : adminPassword , stdio : [ 'pipe' , 'pipe' , 'inherit' ] } ) ;
172+ success ( 'ADMIN_PASSWORD set.' ) ;
173+ } catch ( e ) {
174+ error ( `Failed to set ADMIN_PASSWORD: ${ e . message } ` ) ;
175+ }
162176 }
163177
164178 const jwtToken = await ask ( 'Enter a random JWT Token (or press Enter to generate one):' ) ;
@@ -167,8 +181,22 @@ async function main() {
167181 finalJwt = crypto . randomBytes ( 32 ) . toString ( 'hex' ) ;
168182 console . log ( `Generated JWT Token: ${ finalJwt } ` ) ;
169183 }
170- run ( `echo "${ finalJwt } " | wrangler secret put JWT_TOKEN` ) ;
171- success ( 'JWT_TOKEN set.' ) ;
184+ try {
185+ run ( 'wrangler secret put JWT_TOKEN' , { input : finalJwt , stdio : [ 'pipe' , 'pipe' , 'inherit' ] } ) ;
186+ success ( 'JWT_TOKEN set.' ) ;
187+ } catch ( e ) {
188+ error ( `Failed to set JWT_TOKEN: ${ e . message } ` ) ;
189+ }
190+
191+ const resendApiKey = await ask ( 'Enter your Resend API Key (optional, for sending emails):' ) ;
192+ if ( resendApiKey ) {
193+ try {
194+ run ( 'wrangler secret put RESEND_API_KEY' , { input : resendApiKey , stdio : [ 'pipe' , 'pipe' , 'inherit' ] } ) ;
195+ success ( 'RESEND_API_KEY set.' ) ;
196+ } catch ( e ) {
197+ error ( `Failed to set RESEND_API_KEY: ${ e . message } ` ) ;
198+ }
199+ }
172200
173201 const mailDomain = await ask ( 'Enter your Mail Domain (e.g., example.com):' ) ;
174202 if ( mailDomain ) {
@@ -184,6 +212,34 @@ async function main() {
184212 warn ( 'MAIL_DOMAIN not set. You may need to configure this manually in wrangler.toml.' ) ;
185213 }
186214
215+ let finalAdminName = 'admin' ;
216+ const adminName = await ask ( 'Enter a custom Admin Username (default: admin):' ) ;
217+ if ( adminName && adminName . trim ( ) !== '' && adminName . trim ( ) !== 'admin' ) {
218+ finalAdminName = adminName . trim ( ) ;
219+ wranglerConfig = fs . readFileSync ( wranglerPath , 'utf-8' ) ;
220+
221+ // Check if ADMIN_NAME already exists
222+ if ( wranglerConfig . includes ( 'ADMIN_NAME' ) ) {
223+ const updatedConfig = wranglerConfig . replace (
224+ / A D M I N _ N A M E \s * = \s * " [ ^ " ] * " / ,
225+ `ADMIN_NAME = "${ finalAdminName } "`
226+ ) ;
227+ fs . writeFileSync ( wranglerPath , updatedConfig ) ;
228+ } else {
229+ // Append to [vars] section
230+ if ( wranglerConfig . includes ( '[vars]' ) ) {
231+ const updatedConfig = wranglerConfig . replace (
232+ / \[ v a r s \] / ,
233+ `[vars]\nADMIN_NAME = "${ finalAdminName } "`
234+ ) ;
235+ fs . writeFileSync ( wranglerPath , updatedConfig ) ;
236+ } else {
237+ fs . appendFileSync ( wranglerPath , `\n[vars]\nADMIN_NAME = "${ finalAdminName } "\n` ) ;
238+ }
239+ }
240+ success ( `ADMIN_NAME set to '${ finalAdminName } ' in wrangler.toml.` ) ;
241+ }
242+
187243
188244 // 7. Deploy
189245 step ( 'Building and Deploying...' ) ;
@@ -196,7 +252,7 @@ async function main() {
196252
197253 console . log ( `\n${ colors . green } ${ colors . bright } ✅ Deployment Complete!${ colors . reset } ` ) ;
198254 console . log ( `\nYour app should be live. Check the URL above.` ) ;
199- console . log ( `Admin User: admin ` ) ;
255+ console . log ( `Admin User: ${ finalAdminName } ` ) ;
200256 console . log ( `Admin Password: (hidden)` ) ;
201257
202258 } catch ( e ) {
0 commit comments