class-annotations
Advanced tools
Comparing version 0.3.1 to 0.4.0-beta
@@ -6,2 +6,3 @@ const pathResolver = require('path') ; | ||
const clientDir = require('./lib/client-dir')() ; | ||
const ReadDirectory = require('./lib/read-directory') ; | ||
@@ -30,4 +31,18 @@ class ClassAnnotation { | ||
// here file not exists | ||
this.success = false; | ||
this.details = 'ClassAnnotations Error: file not found from: ' + this.pathFile ; | ||
this.pathDirectory = pathFile ; | ||
if( fs.existsSync( this.pathDirectory ) ) { | ||
const directoryName = pathResolver.basename( this.pathDirectory ) ; | ||
this.directories = {} ; | ||
this.directories[ directoryName ] = new ReadDirectory( this.pathDirectory ) ; | ||
} else { | ||
this.success = false; | ||
this.details = 'ClassAnnotations Error: file not found from: ' + this.pathFile ; | ||
} | ||
} | ||
@@ -109,2 +124,18 @@ | ||
get pathDirectory() { | ||
return this._pathDirectory ; | ||
} | ||
set pathDirectory( pathDirectory ) { | ||
if( pathResolver.isAbsolute( pathDirectory ) ) { | ||
this._pathDirectory = pathDirectory ; | ||
} else { | ||
this._pathDirectory = pathResolver.join( ClassAnnotation.__DIR__ , pathDirectory ) ; | ||
} | ||
} | ||
get pathFile() { | ||
@@ -278,6 +309,4 @@ | ||
} ; | ||
static create( __DIR__ ) { | ||
function createClassAnnotation( __DIR__ ) { | ||
ClassAnnotation.__DIR__ = typeof __DIR__ === "string" ? __DIR__ : clientDir ; | ||
@@ -294,4 +323,6 @@ | ||
return ClassAnnotation ; | ||
} | ||
} | ||
module.exports = createClassAnnotation ; | ||
} ; | ||
module.exports = ClassAnnotation.create ; |
{ | ||
"name": "class-annotations", | ||
"version": "0.3.1", | ||
"version": "0.4.0-beta", | ||
"description": "A reader annotations from class write with ES6 syntax", | ||
@@ -5,0 +5,0 @@ "main": "class-annotations.js", |
@@ -11,2 +11,4 @@ # [class-annotations]( https://www.npmjs.com/package/class-annotations ) | ||
### can read all items from directories ( beta features ) | ||
A comment not starting with an: "@" character not be considered as an annotation, but may be brought up in the data provided via the table: excludes | ||
@@ -48,3 +50,2 @@ | ||
```javascript | ||
const createClassAnnotations = require('class-annotations') ; | ||
@@ -124,2 +125,91 @@ | ||
### Read an directory: | ||
structure directories *e.g*: | ||
- app.js | ||
- models/ | ||
- foo.js | ||
- foo2.js | ||
- submodels/ | ||
- foo3.js | ||
app.js | ||
```javascript | ||
const createClassAnnotations = require('class-annotations') ; | ||
const ClassAnnotations = createClassAnnotations( __dirname ) ; | ||
// read models directory | ||
const annotations = new ClassAnnotations('./models') ; | ||
console.log( annotations ) ; | ||
``` | ||
output log of `annotations` data: | ||
```javascript | ||
{ | ||
directories: { | ||
models: { | ||
'foo.js': { | ||
readers: { | ||
Foo: { | ||
data: { | ||
// your annotations data | ||
} | ||
} | ||
} , | ||
success: boolean , | ||
?details: string | ||
} , | ||
'foo2.js': { | ||
readers: { | ||
Foo2: { | ||
data: { | ||
// your annotaions data | ||
} | ||
} | ||
} , | ||
success: boolean, | ||
?details: string | ||
} , | ||
submodels: { | ||
directories: { | ||
// because recursive reader | ||
submodels: { | ||
'foo3.js': { | ||
readers: { | ||
Foo3: { | ||
data: { | ||
// your annotations data | ||
} | ||
} , | ||
success: boolean , | ||
?details: string | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
console.log( | ||
annotations // ClassAnnotations | ||
.directories // object | ||
.models // ReadDirectory | ||
.submodels // ClassAnnotations | ||
.directories // object | ||
.submodels // ReadDirectory | ||
['foo3.js'] // ClassAnnotations | ||
.readers // object | ||
.Foo3 // object | ||
.data // object | ||
) ; | ||
``` | ||
#### If you have detect an bug or anormal behavior with `ClassAnnotaions` please remote a issues on [github](https://github.com/Orivoir/class-annotations/issues) |
452
213
22184
7
2