| 39 | } |
| 40 | |
| 41 | async function seedOne(storagePath, location) { |
| 42 | const dir = path.resolve(process.cwd(), location); |
| 43 | const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')); |
| 44 | if (manifest.private) { |
| 45 | return null; |
| 46 | } |
| 47 | const {name, version} = manifest; |
| 48 | if (!name || !version) { |
| 49 | throw new Error(`Workspace at ${location} is missing name or version`); |
| 50 | } |
| 51 | |
| 52 | const files = await packlist({path: dir}); |
| 53 | const buf = await tarballBuffer(dir, files); |
| 54 | |
| 55 | const shasum = crypto.createHash('sha1').update(buf).digest('hex'); |
| 56 | const integrity = 'sha512-' + crypto.createHash('sha512').update(buf).digest('base64'); |
| 57 | const tgzName = `${unscoped(name)}-${version}.tgz`; |
| 58 | |
| 59 | const pkgDir = path.join(storagePath, name); |
| 60 | fs.mkdirSync(pkgDir, {recursive: true}); |
| 61 | fs.writeFileSync(path.join(pkgDir, tgzName), buf); |
| 62 | |
| 63 | const now = new Date().toISOString(); |
| 64 | const versionManifest = Object.assign({}, manifest, { |
| 65 | _id: `${name}@${version}`, |
| 66 | dist: {integrity, shasum, tarball: `${REGISTRY}/${name}/-/${tgzName}`} |
| 67 | }); |
| 68 | const packument = { |
| 69 | name, |
| 70 | versions: {[version]: versionManifest}, |
| 71 | time: {modified: now, created: now, [version]: now}, |
| 72 | users: {}, |
| 73 | 'dist-tags': {latest: version}, |
| 74 | _uplinks: {}, |
| 75 | _distfiles: {}, |
| 76 | _attachments: {[tgzName]: {shasum, version}}, |
| 77 | _rev: '1-' + crypto.randomBytes(8).toString('hex'), |
| 78 | _id: name, |
| 79 | readme: manifest.readme || 'ERROR: No README data found!' |
| 80 | }; |
| 81 | fs.writeFileSync(path.join(pkgDir, 'package.json'), JSON.stringify(packument)); |
| 82 | return name; |
| 83 | } |
| 84 | |
| 85 | async function readWorkspaceLocations() { |
| 86 | const chunks = []; |