pages.js 795 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
  5. */
  6. import glob from 'glob';
  7. import { join } from 'path';
  8. export default () => new Promise((resolve, reject) => {
  9. console.log('pages');
  10. glob('**/*.js', { cwd: join(__dirname, '../src') }, (err, files) => {
  11. if (err) {
  12. reject(err);
  13. } else {
  14. files = files.filter(file => !file.startsWith('js/')).map(file => {
  15. let path = '/' + file.substr(0, file.lastIndexOf('.'));
  16. if (path === '/index') {
  17. path = '/';
  18. } else if (path.endsWith('/index')) {
  19. path = path.substr(0, path.lastIndexOf('/index'));
  20. }
  21. return { path, file };
  22. });
  23. resolve(files);
  24. }
  25. });
  26. });