findPackages.js 898 B

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