31 lines
999 B
JavaScript
31 lines
999 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const { faker } = require('@faker-js/faker');
|
|
|
|
async function sortAccounts() {
|
|
const sortedDir = path.join(__dirname, '../output');
|
|
const accountsFile = path.join(__dirname, '../accounts/accounts.json');
|
|
const accounts = require(accountsFile);
|
|
|
|
if (accounts.length < 6) return console.log('Not enough accounts!');
|
|
|
|
if (!fs.existsSync(sortedDir)) fs.mkdirSync(sortedDir, { recursive: true });
|
|
|
|
while (accounts.length >= 6) {
|
|
let name = faker.name.firstName();
|
|
let outputFilePath = path.join(sortedDir, `${name}.json`);
|
|
|
|
while (fs.existsSync(outputFilePath)) {
|
|
name = faker.name.firstName();
|
|
outputFilePath = path.join(sortedDir, `${name}.json`);
|
|
}
|
|
|
|
const batch = accounts.splice(0, 6);
|
|
fs.writeFileSync(outputFilePath, JSON.stringify(batch, null, 2));
|
|
fs.writeFileSync(accountsFile, JSON.stringify(accounts, null, 2));
|
|
}
|
|
console.log('Accounts Sorted!');
|
|
return process.exit(0);
|
|
}
|
|
|
|
module.exports = { sortAccounts }; |