()
| 111 | } |
| 112 | |
| 113 | async function main() { |
| 114 | const storagePath = path.resolve( |
| 115 | process.argv[2] || process.env.VERDACCIO_STORAGE_PATH || '/tmp/verdaccio-workspace/storage' |
| 116 | ); |
| 117 | fs.mkdirSync(storagePath, {recursive: true}); |
| 118 | |
| 119 | const locations = await readWorkspaceLocations(); |
| 120 | const start = Date.now(); |
| 121 | const seeded = await pool(locations, loc => seedOne(storagePath, loc), CONCURRENCY); |
| 122 | const names = seeded.filter(Boolean); |
| 123 | |
| 124 | const dbPath = path.join(storagePath, '.verdaccio-db.json'); |
| 125 | let db = {list: [], secret: crypto.randomBytes(16).toString('hex')}; |
| 126 | if (fs.existsSync(dbPath)) { |
| 127 | try { |
| 128 | db = JSON.parse(fs.readFileSync(dbPath, 'utf8')); |
| 129 | } catch (e) { |
| 130 | // corrupt/empty db, start fresh |
| 131 | } |
| 132 | } |
| 133 | db.list = Array.from(new Set([...(db.list || []), ...names])); |
| 134 | fs.writeFileSync(dbPath, JSON.stringify(db)); |
| 135 | |
| 136 | console.log( |
| 137 | `Seeded ${names.length} packages into ${storagePath} in ${((Date.now() - start) / 1000).toFixed(1)}s` |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | main().catch(err => { |
| 142 | console.error(err); |
no test coverage detected