Skip to content

Commit 3c63bb1

Browse files
committed
feat: prompt for SSH users during init, generate .shipnode/users.yml
1 parent 451f790 commit 3c63bb1

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/cli/commands/init.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ export async function cmdInit(cwd: string, options: { nonInteractive?: boolean;
123123
domain = await ask('Domain (optional)', '');
124124
}
125125

126+
// ── Users ──────────────────────────────────────────────────────
127+
const users: Array<{ username: string; publicKey: string; sudo: boolean }> = [];
128+
const addUsers = (await ask('Add SSH users to the server?', 'no')).toLowerCase().startsWith('y');
129+
if (addUsers) {
130+
let addMore = true;
131+
while (addMore) {
132+
const username = await ask('Username');
133+
if (!username) break;
134+
const publicKey = await ask(`Public key for ${username}`);
135+
const sudo = (await ask(`Grant sudo to ${username}?`, 'no')).toLowerCase().startsWith('y');
136+
users.push({ username, publicKey, sudo });
137+
addMore = (await ask('Add another user?', 'no')).toLowerCase().startsWith('y');
138+
}
139+
}
140+
126141
rl.close();
127142

128143
const config = generateConfig({
@@ -156,7 +171,7 @@ export async function cmdInit(cwd: string, options: { nonInteractive?: boolean;
156171
await writeFile(configPath, config, 'utf-8');
157172
ui.success('Created shipnode.config.ts');
158173

159-
await generateShipnodeDir(cwd, detection.orm);
174+
await generateShipnodeDir(cwd, detection.orm, users);
160175
}
161176

162177
async function getAppName(cwd: string): Promise<string> {
@@ -194,7 +209,11 @@ interface ConfigOptions {
194209
dbPassword?: string;
195210
}
196211

197-
async function generateShipnodeDir(cwd: string, detectedOrm?: string): Promise<void> {
212+
async function generateShipnodeDir(
213+
cwd: string,
214+
detectedOrm?: string,
215+
users: Array<{ username: string; publicKey: string; sudo: boolean }> = [],
216+
): Promise<void> {
198217
const dir = resolve(cwd, '.shipnode');
199218
await ensureDir(dir);
200219

@@ -216,6 +235,17 @@ async function generateShipnodeDir(cwd: string, detectedOrm?: string): Promise<v
216235
await writeFile(ignorePath, generateShipnodeIgnore(), 'utf-8');
217236
}
218237

238+
if (users.length > 0) {
239+
const usersPath = resolve(dir, 'users.yml');
240+
const yaml = users.map((u) => [
241+
`- username: ${u.username}`,
242+
` publicKey: ${u.publicKey}`,
243+
` sudo: ${u.sudo}`,
244+
].join('\n')).join('\n') + '\n';
245+
await writeFile(usersPath, yaml, 'utf-8');
246+
ui.success(`Created .shipnode/users.yml with ${users.length} user(s)`);
247+
}
248+
219249
const ormMsg = detectedOrm ? ` with ${detectedOrm} commands` : '';
220250
ui.success(`Generated .shipnode/ hooks${ormMsg} and .shipnodeignore`);
221251
}

0 commit comments

Comments
 (0)