Skip to content

Commit

Permalink
Build: Add temporary user to verdaccio registry
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jun 10, 2024
1 parent 7dc80d6 commit ba6c56c
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions scripts/run-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,47 @@ const publish = async (packages: { name: string; location: string }[], url: stri

const addUser = (url: string) =>
new Promise<void>(async (res, rej) => {
const username = 'username';
const password = 'password';
const email = '[email protected]';

logger.log(`👤 add temp user to verdaccio`);

try {
await execaCommand(
`npx npm-cli-adduser -r ${url} -a -u user -p password -e [email protected]`
);
res();
const npmExec = execa(`npm add user --registry ${url}`, { shell: true });

function checkStep(step: number, count: number) {
if (count > step) {
process.exit(1);
}
}

let count = 0;

npmExec.stdout.on('data', (data) => {
const str = data.toString();
process.stdout.write(str);
if (str.match(/username/i)) {
checkStep(0, count);
process.stdout.write(`${username}\n`);
npmExec.stdin.write(username + '\n');
} else if (str.match(/password/i)) {
checkStep(1, count);
process.stdout.write('\n');
npmExec.stdin.write(password + '\n');
} else if (str.match(/email/i)) {
checkStep(2, count);
process.stdout.write(`${email}\n`);
npmExec.stdin.write(email + '\n');
npmExec.stdin.end();
} else if (str.match(/.*err.*/i)) {
npmExec.stdin.end();
}
count++;
});
npmExec.on('exit', () => {
res();
});
} catch (e) {
rej(e);
}
Expand Down

0 comments on commit ba6c56c

Please sign in to comment.