Keystone-classic: add an option to ignore/filter files in the importer

Created on 12 Nov 2016  ยท  5Comments  ยท  Source: keystonejs/keystone-classic

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.

enhancement help wanted needs input

Most helpful comment

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?

All 5 comments

Hi @joernroeder,

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

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?

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.

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 :)

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

useralive003 picture useralive003  ยท  5Comments

molomby picture molomby  ยท  5Comments

celiao picture celiao  ยท  4Comments

kamontat picture kamontat  ยท  5Comments

sorryididntmeantto picture sorryididntmeantto  ยท  3Comments