1 | const logger = require('./logger');
|
2 | const Package = require('./package');
|
3 | const getPackages = require('./get-packages');
|
4 | const loadManifest = require('./load-manifest');
|
5 |
|
6 | module.exports = async (globs = []) => {
|
7 | const locations = await getPackages(globs);
|
8 | const packages = [];
|
9 |
|
10 | locations.forEach(location => {
|
11 | let manifest;
|
12 |
|
13 | try {
|
14 | manifest = loadManifest(location);
|
15 | } catch (error) {
|
16 | logger.warning(error.toString());
|
17 | }
|
18 |
|
19 | if (manifest) {
|
20 | if (packages.some(pkg => manifest.name === pkg.name)) {
|
21 | throw new Error(
|
22 | `Two or more packages have been found with the same name: "${manifest.name}"`,
|
23 | );
|
24 | } else {
|
25 | packages.push(new Package(manifest, location));
|
26 | }
|
27 | }
|
28 | });
|
29 |
|
30 | return packages;
|
31 | };
|