mardi 20 juin 2017

Parsing Ember Model file during Blueprint usage

I'm writing an Ember custom blueprint that outputs different component fields based off the Ember Data Model passed to the ember g <blueprint> <modelname> command.

However, trying to parse the model file as Javascript is hard. The reason being that we’re operating in a CommonJS Node environment trying to import an ES6 module. Even if we use an ES6 parsing library imported from npm, then we can’t resolve the Model's import path lookups from this context.

The next approach was to try and import the generated Javascript file in the dist folder (e.g. dist/my-first-blueprint.js). This is an AMD structure for modules, and none of the readily available AMD npm modules appear to allow easy consumption of this file either.

Presumably there is code added to dist/vendor.js that allows the Ember Resolver to find the correctly referenced module. However, this is where my knowledge of the Broccoli build chain and Ember internals fails me.

The final option is to parse the Javascript file as text using pattern matching. With the combinations of mixins, different root classes and other variances, this is definitely non-trivial and is something that has been deferred to a separate Blueprint.

Does anyone know of any ideas or hints on how, within the Blueprint's index.js file I can import an Ember Data model and determine it's attributes?




Aucun commentaire:

Enregistrer un commentaire