build-index.js 561 B

1234567891011121314151617
  1. const fs = require("fs");
  2. const path = require("path");
  3. const componentsPath = path.resolve(__dirname, "../src/components");
  4. const indexPath = path.resolve(__dirname, "../src");
  5. let statements = fs
  6. .readdirSync(componentsPath)
  7. .map(file => {
  8. let filePath = path.resolve(componentsPath, file);
  9. let relPath = path.relative(indexPath, filePath);
  10. let { dir, name } = path.parse(relPath);
  11. return `export { default as ${name} } from \"./${dir}/${name}\";`;
  12. })
  13. .join("\n");
  14. fs.writeFileSync(path.resolve(indexPath, "index.ts"), statements);