-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 35c0087
Showing
39 changed files
with
2,549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
coverage | ||
publish | ||
lib | ||
node_modules/* | ||
npm-debug.log | ||
src/*.js | ||
src/*.js.map | ||
src/*.d.ts | ||
test/*.js | ||
test/*.js.map | ||
test/*.d.ts | ||
src/**/*.js | ||
src/**/*.js.map | ||
src/**/*.d.ts | ||
test/**/*.js | ||
test/**/*.js.map | ||
test/**/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
src | ||
test | ||
coverage | ||
publish | ||
tsconfig.json | ||
tsd.json | ||
gulpfile.js | ||
.travis.yml | ||
.gitignore | ||
.vscode | ||
.publishrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- stable | ||
- 6.0.0 | ||
- 5.0.0 | ||
- 4.1.0 | ||
- '0.12' | ||
- '0.10' | ||
|
||
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
// Use IntelliSense to learn about possible Node.js debug attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Mocha", | ||
"type": "node", | ||
"request": "launch", | ||
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"--no-timeouts", | ||
"--recursive", | ||
"--colors" | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"runtimeExecutable": null, | ||
"env": { | ||
"NODE_ENV": "testing" | ||
} | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceRoot}/index.js", | ||
"cwd": "${workspaceRoot}", | ||
"outFiles": [], | ||
"sourceMaps": true | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach to Process", | ||
"port": 5858, | ||
"outFiles": [], | ||
"sourceMaps": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": "0.1.0", | ||
"command": "${cwd}/node_modules/.bin/tsc", | ||
"isShellCommand": true, | ||
"args": ["-w", "-p", "."], | ||
"showOutput": "silent", | ||
"isWatching": true, | ||
"problemMatcher": "$tsc-watch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 kambojajs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Kenanga | ||
|
||
[![Build Status](https://travis-ci.org/kambojajs/kecubung.svg?branch=master)](https://travis-ci.org/kambojajs/kecubung) | ||
[![Coverage Status](https://coveralls.io/repos/github/kambojajs/kecubung/badge.svg?branch=master)](https://coveralls.io/github/kambojajs/kecubung?branch=master) | ||
|
||
A javascript transformer to Type Metadata. | ||
|
||
###About | ||
|
||
Kenanga is javascript syntax transformer into Type information | ||
such as Class, Method, Constructor, Module etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"use strict"; | ||
|
||
|
||
var gulp = require("gulp"), | ||
tsc = require("gulp-typescript"), | ||
runSequence = require("run-sequence"), | ||
mocha = require("gulp-mocha"), | ||
istanbul = require("gulp-istanbul"); | ||
|
||
//******** BUILD ************* | ||
|
||
var tsProject = tsc.createProject("tsconfig.json", { | ||
declaration: true, | ||
noResolve: false, | ||
typescript: require("typescript") | ||
}); | ||
|
||
gulp.task("build-source", function() { | ||
return gulp.src([ | ||
"src/**/**.ts" | ||
]) | ||
.pipe(tsProject()) | ||
.on("error", function (err) { | ||
process.exit(1); | ||
}) | ||
.pipe(gulp.dest("src/")); | ||
}); | ||
|
||
var tsTestProject = tsc.createProject("tsconfig.json", { | ||
declaration: false, | ||
noResolve: false, | ||
typescript: require("typescript") | ||
}); | ||
|
||
gulp.task("build-test", function() { | ||
return gulp.src([ | ||
"test/**/**.ts" | ||
]) | ||
.pipe(tsTestProject()) | ||
.on("error", function (err) { | ||
process.exit(1); | ||
}) | ||
.pipe(gulp.dest("test")); | ||
}); | ||
|
||
|
||
gulp.task("build", function(cb) { | ||
runSequence("build-source", "build-test", cb); | ||
}); | ||
|
||
|
||
//******** TEST ************* | ||
gulp.task("mocha", function() { | ||
return gulp.src([ | ||
"test/**/**.js" | ||
]) | ||
.pipe(mocha({ui: "bdd"})) | ||
.pipe(istanbul.writeReports()); | ||
}); | ||
|
||
gulp.task("istanbul:hook", function() { | ||
return gulp.src(["src/**/**.js"]) | ||
// Covering files | ||
.pipe(istanbul()) | ||
// Force `require` to return covered files | ||
.pipe(istanbul.hookRequire()); | ||
}); | ||
|
||
gulp.task("test", function(cb) { | ||
runSequence("istanbul:hook", "mocha", cb); | ||
}); | ||
|
||
//******** DISTRIBUTION ************* | ||
gulp.task("dist", function() { | ||
return gulp.src(["src/**/*.js", "src/**/*.d.ts"]) | ||
.pipe(gulp.dest("lib/")); | ||
}); | ||
|
||
//******** DEFAULT ************* | ||
gulp.task("default", function (cb) { | ||
runSequence( | ||
"build", | ||
"test", | ||
"dist", | ||
cb); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "kecubung", | ||
"version": "0.0.1-dev001", | ||
"description": "Javascript transformer to Type Metadata", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "gulp" | ||
}, | ||
"keywords": [], | ||
"author": "Ketut Sandiarsa <ktutnik@gmail.com>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kambojajs/kenanga" | ||
}, | ||
"typings": "./lib/index.d.ts", | ||
"dependencies": { | ||
"reflect-metadata": "^0.1.9", | ||
"tslib": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/babylon": "^6.7.15", | ||
"@types/chai": "^3.4.34", | ||
"@types/express": "^4.0.34", | ||
"@types/mocha": "^2.2.33", | ||
"@types/node": "^6.0.52", | ||
"babylon": "^6.14.1", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.15", | ||
"gulp": "^3.9.1", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-typescript": "^3.1.3", | ||
"mocha": "^3.2.0", | ||
"run-sequence": "^1.2.2", | ||
"typescript": "^2.0.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { SyntaxKind } from "../core" | ||
import * as HP from "./helper" | ||
|
||
export class ClassAnalyzer { | ||
|
||
/** | ||
* expect AssignmentExpression, VariableDeclaration | ||
*/ | ||
constructor(private node) { } | ||
|
||
/** | ||
* expect AssignmentExpression | ||
*/ | ||
isExported(name, parentName) { | ||
return this.isExportedStatement() | ||
&& (this.node.left.object.name == parentName || this.node.left.object.name == "exports") | ||
&& this.node.right.name == name | ||
} | ||
|
||
/** | ||
* expect AssignmentExpression | ||
*/ | ||
private isExportedStatement() { | ||
return this.node.type == SyntaxKind.AssignmentExpression | ||
&& this.node.left.type == SyntaxKind.MemberExpression | ||
&& this.node.right.type == SyntaxKind.Identifier | ||
} | ||
|
||
getName() { | ||
if (this.isExportedStatement()) | ||
return this.node.right.name; | ||
else if (this.isCandidate()) | ||
return this.node.declarations[0].id.name | ||
else return null; | ||
} | ||
|
||
/** | ||
* expect VariableDeclaration | ||
*/ | ||
isCandidate() { | ||
return this.node.type == SyntaxKind.VariableDeclaration | ||
&& this.node.declarations[0].type == SyntaxKind.VariableDeclarator | ||
&& this.node.declarations[0].init | ||
&& this.node.declarations[0].init.type == SyntaxKind.CallExpression | ||
&& this.node.declarations[0].init.callee.type == SyntaxKind.FunctionExpression | ||
&& this.node.declarations[0].init.callee.id == null | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { SyntaxKind, MetaData } from "../core" | ||
import * as HP from "./helper" | ||
|
||
|
||
export class ClassDecoratorAnalyzer{ | ||
|
||
/** | ||
* expect AssignmentExpression | ||
*/ | ||
constructor(private node){} | ||
|
||
getClassName(){ | ||
if (this.isDecorator()){ | ||
return this.node.left.name; | ||
} | ||
else return null; | ||
} | ||
|
||
isDecorator() { | ||
return this.node.type == SyntaxKind.AssignmentExpression | ||
&& this.node.left.type == SyntaxKind.Identifier | ||
&& this.node.right.type == SyntaxKind.CallExpression | ||
&& HP.getMethodNameFromCallee(this.node.right.callee) == "__decorate" | ||
} | ||
|
||
getDecorators():MetaData[]{ | ||
if(this.isDecorator()) | ||
return HP.getDecorators(this.node.right.arguments[0]) | ||
else return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { SyntaxKind, MetaData, AnalysisType } from "../core" | ||
|
||
/** | ||
* require CallExpression.callee | ||
*/ | ||
export function getMethodNameFromCallee(callee) { | ||
if (!callee) return ""; | ||
if (callee.type == SyntaxKind.MemberExpression) return callee.property.name; | ||
else return callee.name; | ||
} | ||
|
||
/** | ||
* require ArrayExpression | ||
*/ | ||
export function getDecorators(arrayExpression) { | ||
let result = []; | ||
for (let x of arrayExpression.elements) { | ||
if (isReservedDecorator(x)) continue; | ||
result.push(<MetaData>{ | ||
type: "Decorator", | ||
name: getMethodNameFromCallee(x.callee), | ||
analysis: AnalysisType.Valid, | ||
children: x.arguments.map(arg => <MetaData>{ | ||
type: "Parameter", | ||
name: getDecoratorParameterName(arg), | ||
analysis: AnalysisType.Valid, | ||
children: [] | ||
}) | ||
}) | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* require CallExpression | ||
*/ | ||
export function isReservedDecorator(callExpression) { | ||
return getMethodNameFromCallee(callExpression.callee) == "__metadata" | ||
|| getMethodNameFromCallee(callExpression.callee) == "__param" | ||
} | ||
|
||
export function getDecoratorParameterName(param) { | ||
switch (param.type) { | ||
case SyntaxKind.StringLiteral: | ||
case SyntaxKind.NumericLiteral: | ||
case SyntaxKind.BooleanLiteral: | ||
return param.value; | ||
case SyntaxKind.Identifier: | ||
return param.name; | ||
default: | ||
return "Unknown"; | ||
} | ||
} |
Oops, something went wrong.