Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from Financial-Times/matth/ignore-glob-matches…
Browse files Browse the repository at this point in the history
…-without-manifest

Ignore glob matches which are not directories containing a package.json
  • Loading branch information
i-like-robots authored Feb 14, 2019
2 parents c6b7be7 + 9c8168f commit b3b00ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cli-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = (task) => {
logger.message(`Tasks complete, took ${timer.duration}s`);
} catch (error) {
const message = error instanceof Error ? error.message : error;
const exitCode = error.code || 1;
const exitCode = Number.isInteger(error.code) ? error.code : 1;

logger.error(`Task failed: "${message}"`);
process.exit(exitCode);
Expand Down
14 changes: 12 additions & 2 deletions src/load-manifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const fs = require('fs');
const path = require('path');

module.exports = (packagePath) => {
const manifestPath = path.resolve(packagePath, 'package.json');
return require(manifestPath);
const stats = fs.statSync(packagePath);

if (stats.isDirectory()) {
const manifestPath = path.resolve(packagePath, 'package.json');

if (fs.existsSync(manifestPath)) {
return require(manifestPath);
} else {
throw Error(`Folder found without package.json file: ${packagePath}`)
}
}
};
10 changes: 8 additions & 2 deletions src/load-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ const loadManifest = require('./load-manifest');

module.exports = async (globs = []) => {
const locations = await getPackages(globs);
const packages = []

return locations.map((location) => {
locations.forEach((location) => {
const manifest = loadManifest(location);
return new Package(manifest, location);

if (manifest) {
packages.push(new Package(manifest, location));
}
});

return packages
};

0 comments on commit b3b00ae

Please sign in to comment.