congajs / conga-annotations

Annotation parser library for node.js
Other
18 stars 14 forks source link

Empty metadata when loading content #4

Open m-frachet opened 9 years ago

m-frachet commented 9 years ago

Hi,

I m actually trying to use your library to create my own annotations, but I cant make what I need.

In fact, I have a simple annotation : var Annotation = require('conga-annotations').Annotation;

module.exports = Annotation.extend({

/**
 * The name of the annotation

 * @type {String}
 */
annotation: 'Inject',

/**
 * The possible targets
 *
 * (Annotation.CONSTRUCTOR, Annotation.PROPERTY, Annotation.METHOD)
 *
 * @type {Array}
 */
targets: [Annotation.PROPERTY],

/**
 * The main value
 *
 * @type {String}
 */
value: 'default value',

/**
 * An additional attribute
 *
 * @type {String}
 */
sample: 'default value for sample',

/**
 * Optional initialization method that
 * can be used to transform data
 *
 * @param  {Object} data
 * @return {void}
 */
init: function (data) {
    // do something with data
    console.log(data);
}

});

And here's my parser : var path = require('path'); var annotations = require('conga-annotations');

// create the registry var registry = new annotations.Registry();

// add annotations to the registry registry.registerAnnotation(path.join(__dirname, 'annotations', 'InjectAnnotation'));

// create the annotation reader var reader = new annotations.Reader(registry);

// parse the annotations from a file reader.parse(path.join(__dirname, 'FileToParse.js'));

// get the annotations var propertyAnnotations = reader.getPropertyAnnotations(); console.log(propertyAnnotations); // loop through and handle the annotations propertyAnnotations.forEach(function (annotation) {

// @MyConstructorAnnotation
if (annotation.annotation === 'Inject') {

    // do something with the annotation data
    console.log(annotation.target); // -> "MySample"
    console.log(annotation.value); // -> "some value"
    console.log(annotation.sample); // -> "here is an attribute value"
}

});

When I try to log the _metadata in reader.js line 103, it seems that it' fully empty and giving me this :

{ methods: [], properties: [], fileComment: '/**', path: 'F:\AnnotationLibrary\FileToParse.js' }

Is this a problem with the current version or am I doing it wrong ?

createvibe commented 9 years ago

Here is a working example. Let me know if it helps you or if you are still experiencing issues.

http://code.runnable.com/VMlxhH4h9tNkarWi/conga-annotations-hello-world-example-for-node-js-and-congajs

stanislaska commented 7 years ago

Hi,

I believe that, the online demo work fine e.g: http://code.runnable.com/VMlxhH4h9tNkarWi/conga-annotations-hello-world-example-for-node-js-and-congajs. However, when you locally pickup the same code and run it, same issue pop's up. Even though, i just clone this repo and then "npm install && npm test" but all the test failed.

Here're my configuration: node version --> 5.7.0 npm version --> 4.6.1

I just open this issue: https://github.com/jaumard/ecmas-annotations/issues/42

Is there anything wrong?

lampjunkie commented 7 years ago

Hi @stanislaska,

I believe the issue is that the latest version (v1.0.0) needs node 6 in order to work. I just realized that we need to update the minimum engine dependency in package.json as well as the README.

Otherwise, if you can't update node or don't need ES6 support you can try installing v0.1.8 of the module.

Let me know if that helps!

stanislaska commented 7 years ago

Hi @lampjunkie,

After updating to node v7.10.0, everything work fine. We're waiting for the package.json and README update.

Thanks you a lot. :D