How to use the umi-utils.findJS function in umi-utils

To help you get started, we’ve selected a few umi-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi-build-dev / src / routes / getRouteConfigFromDir.js View on Github external
export default function getRouteConfigFromDir(paths) {
  const { cwd, absPagesPath, absSrcPath, dirPath = '' } = paths;
  const absPath = join(absPagesPath, dirPath);
  const files = readdirSync(absPath);

  const absLayoutFile = findJS(absPagesPath, '_layout');
  if (absLayoutFile) {
    throw new Error('root _layout.js is not supported, use layouts/index.js instead');
  }

  const routes = sortRoutes(
    files
      .filter(file => {
        if (
          file.charAt(0) === '.' ||
          file.charAt(0) === '_' ||
          /\.(test|spec|d)\.(j|t)sx?$/.test(file)
        )
          return false;
        return true;
      })
      .reduce(handleFile.bind(null, paths, absPath), []),
github chiaweilee / umi-plugin-md / src / helpers / getRouteConfigFromDir.ts View on Github external
.filter(file => {
        if (
          file.charAt(0) === '.' ||
          file.charAt(0) === '_' ||
          /\.(test|spec)\.(j|t)sx?$/.test(file)
        ) {
          return false;
        }
        return true;
      })
      .reduce(handleFile.bind(null, paths, absPath), []),
  );

  if (dirPath === '' && absSrcPath) {
    const globalLayoutFile =
      findJS(absSrcPath, 'layouts/index') || findJS(absSrcPath, 'layout/index');
    if (globalLayoutFile) {
      const wrappedRoutes = [];
      addRoute(
        wrappedRoutes,
        {
          path: '/',
          component: `./${winPath(relative(cwd, globalLayoutFile))}`,
          routes,
        },
        {
          componentFile: globalLayoutFile,
        },
      );
      return wrappedRoutes;
    }
  }
github umijs / umi / packages / umi-build-dev / src / routes / getRouteConfigFromDir.js View on Github external
files
      .filter(file => {
        if (
          file.charAt(0) === '.' ||
          file.charAt(0) === '_' ||
          /\.(test|spec|d)\.(j|t)sx?$/.test(file)
        )
          return false;
        return true;
      })
      .reduce(handleFile.bind(null, paths, absPath), []),
  );

  if (dirPath === '' && absSrcPath) {
    const globalLayoutFile =
      findJS(absSrcPath, 'layouts/index') || findJS(absSrcPath, 'layout/index');
    if (globalLayoutFile) {
      const wrappedRoutes = [];
      addRoute(
        wrappedRoutes,
        {
          path: '/',
          component: `./${winPath(relative(cwd, globalLayoutFile))}`,
          routes,
        },
        {
          componentFile: globalLayoutFile,
        },
      );
      return wrappedRoutes;
    }
  }
github umijs / umi / packages / umi-plugin-dva / src / index.js View on Github external
function getDvaJS() {
    const dvaJS = findJS(paths.absSrcPath, 'dva');
    if (dvaJS) {
      return winPath(dvaJS);
    }
  }
github umijs / umi / packages / umi-build-dev / src / FilesGenerator.js View on Github external
})
      .map((source, index) => {
        return {
          source,
          specifier: `moduleBeforeRenderer${index}`,
        };
      });

    const plugins = this.service
      .applyPlugins('addRuntimePlugin', {
        initialValue: [],
      })
      .map(plugin => {
        return winPath(relative(paths.absTmpDirPath, plugin));
      });
    if (findJS(paths.absSrcPath, 'app')) {
      plugins.push('@/app');
    }
    const validKeys = this.service.applyPlugins('addRuntimePluginKey', {
      initialValue: [
        'patchRoutes',
        'render',
        'rootContainer',
        'modifyRouteProps',
        'onRouteChange',
        'modifyInitialProps',
        'initialProps',
      ],
    });
    assert(
      uniq(validKeys).length === validKeys.length,
      `Conflict keys found in [${validKeys.join(', ')}]`,
github umijs / umi / packages / umi-plugin-dva / src / index.js View on Github external
export function getModel(cwd, api) {
  const { config, winPath } = api;

  const modelJSPath = findJS(cwd, 'model');
  if (modelJSPath) {
    return [winPath(modelJSPath)];
  }

  return globby
    .sync(`./${config.singular ? 'model' : 'models'}/**/*.{ts,tsx,js,jsx}`, {
      cwd,
    })
    .filter(
      p =>
        !p.endsWith('.d.ts') &&
        !p.endsWith('.test.js') &&
        !p.endsWith('.test.jsx') &&
        !p.endsWith('.test.ts') &&
        !p.endsWith('.test.tsx'),
    )