keystonejs / keystone-classic

Node.js CMS and web app framework
http://v4.keystonejs.com
MIT License
14.63k stars 2.21k forks source link

add an option to ignore/filter files in the importer #3690

Open joernroeder opened 7 years ago

joernroeder commented 7 years ago

I'm currently trying to enhance a project, which is based on the MERN stack, with a keystone backend – something i successfully did with MERN 1.0 and Keystone 3.x. Now i ran into an issue while i tried to import my models via .import('models') caused by the importer who recursively went through the models folder and tried to add the test files as well.

models/
├── __tests__
│   └── post.spec.js
└── post.js

I now that this is a very specific use case but it could be handy to have some kind of filter mechianism in the importer if you're adding the keystone backend to an existing express based app.

bassjacob commented 7 years ago

Hi @joernroeder,

Thanks for opening this request. Is this still a feature you're interested in?

joernroeder commented 7 years ago

hi @bassjacob, i worked around that issue by manually loading the models from a predefined array and i think that the current implementation still has it's downside.

there are two thinks i'd like to point you to: First of all i was wondering why Keystone.import(dirname) exists as well as Keystone.importer (http://keystonejs.com/docs/getting-started/#routesviews-settingup) – two API points which are doing almost the same with two slightly different implementations. I think the implementation of those methods should be unified – personally i would go a step further and just expose a single API entrypoint (.import or .importer).

By providing a single method to load additional files all over a keystone app – like routes, models etc. – some kind of filter mechianism (something like minimatch) would lead to new posibilities.

// just some quick examples where filtered loading could be usefull
var sectionRoutes = keystone.import('./routes', { match: '*.myfancysection' })
var models = keystone.import('./models', { exclude: '*.spec' })
var config = keysonte.import('./config', { match: '*.' + keystone.get('env') })

what do you think?

bassjacob commented 7 years ago

Hi @joernroeder,

Sounds like a great feature. I'm looking into how we use plugins and functionality into Keystone going forward and I think this makes a good use case. I'll start taking a look at this now and keep you updated here.

joernroeder commented 7 years ago

hey @bassjaco, sounds good! Let me know if you need any help/assistance. I'm pretty busy right now but would like to help wherever i can :)

Gaurav490 commented 6 years ago

Hi everyone, I am picking the issue. Is there any other option that you expect needs to be added apart from "match" or "exclude".