findPackages.js 842 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2017-2020 @polkadot/apps authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. const fs = require('fs');
  5. const path = require('path');
  6. module.exports = function findPackages () {
  7. const pkgRoot = path.join(__dirname, '..', 'packages');
  8. return fs
  9. .readdirSync(pkgRoot)
  10. .filter((entry) => {
  11. const pkgPath = path.join(pkgRoot, entry);
  12. return !['.', '..'].includes(entry) &&
  13. fs.lstatSync(pkgPath).isDirectory() &&
  14. fs.existsSync(path.join(pkgPath, 'package.json'));
  15. })
  16. .map((dir) => {
  17. const jsonPath = path.join(pkgRoot, dir, 'package.json');
  18. const { name } = JSON.parse(
  19. fs.readFileSync(jsonPath).toString('utf-8')
  20. );
  21. return { dir, name };
  22. });
  23. };