refactor(plugin-model): 优化下代码,只判定src/models下的文件为模块数据

This commit is contained in:
万纯 2021-03-25 16:04:02 +08:00
parent 77e074d03a
commit d828b16ce9
2 changed files with 9 additions and 9 deletions

View File

@ -24,12 +24,12 @@ export default (api) => {
function getAllModels() { function getAllModels() {
const srcModelsPath = getModelsPath(); const srcModelsPath = getModelsPath();
return lodash.uniq([ return lodash.uniq([
...getModels(srcModelsPath), ...getModels(srcModelsPath)
...getModels( // ...getModels(
paths.absPagesPath, // paths.absPagesPath,
`**/${getModelDir()}/**/*.{js,jsx}` // `**/${getModelDir()}/**/*.{js,jsx}`
), // ),
...getModels(paths.absPagesPath, '**/*.model.{js,jsx}') // ...getModels(paths.absPagesPath, '**/*.model.{js,jsx}')
]); ]);
} }

View File

@ -24,11 +24,11 @@ function getExtraImports(models = [], absSrcPath) {
.map((ele) => { .map((ele) => {
if (ele.exportName) { if (ele.exportName) {
return `import { ${ele.exportName} } from '${winPath( return `import { ${ele.exportName} } from '${winPath(
ele.importPath.replace(/'/g, "\\'"), ele.importPath.replace(/'/g, "\\'")
)}';`; )}';`;
} }
return `import ${ele.importName} from '${winPath( return `import ${ele.importName} from '${winPath(
ele.importPath.replace(/'/g, "\\'"), ele.importPath.replace(/'/g, "\\'")
)}';`; )}';`;
}) })
.join(EOL); .join(EOL);
@ -37,7 +37,7 @@ function getExtraImports(models = [], absSrcPath) {
export const getTmpFile = ( export const getTmpFile = (
files, files,
extra = [], extra = [],
absSrcPath, absSrcPath
) => { ) => {
const userImports = genImports(files); const userImports = genImports(files);
const userModels = getModels(files, absSrcPath); const userModels = getModels(files, absSrcPath);