Skip to content

Commit

Permalink
Merge pull request #1 from ktutnik/master
Browse files Browse the repository at this point in the history
Merging from ktutnik repo, add many updates
  • Loading branch information
ktutnik committed Jan 26, 2017
2 parents bbde9fa + 1ee630d commit 23bf51f
Show file tree
Hide file tree
Showing 52 changed files with 1,421 additions and 1,790 deletions.
20 changes: 0 additions & 20 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
// 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": [
{
Expand All @@ -19,23 +16,6 @@
"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
}
]
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js.map": true,
//"**/*.js": {"when": "$(basename).ts"},
//"**/*.d.ts": {"when": "$(basename).ts"},
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true
}
,
"vsicons.presets.angular": false
}
136 changes: 93 additions & 43 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,136 @@
"use strict";


var gulp = require("gulp"),
tsc = require("gulp-typescript"),
var gulp = require("gulp"),
tsc = require("gulp-typescript"),
del = require("del"),
runSequence = require("run-sequence"),
mocha = require("gulp-mocha"),
istanbul = require("gulp-istanbul");
mocha = require("gulp-mocha"),
istanbul = require("gulp-istanbul");
//********CLEAN ************

gulp.task("clean-source", function (cb) {
return del([
"./src/**/*.js",
"./src/**/*.d.ts",
"./src/**/*.js.map"], cb)
})

gulp.task("clean-test", function (cb) {
return del([
"./test/**/*.js",
"./test/**/*.d.ts",
"./test/**/*.js.map"], cb)
})

gulp.task("clean-lib", function (cb) {
return del([
"./lib/**/*.js",
"./lib/**/*.d.ts",
"./lib/**/*.js.map"], cb)
})


gulp.task("clean", function (cb) {
runSequence("clean-source", "clean-test", "clean-lib", cb);
});

//******** BUILD *************

var tsProject = tsc.createProject("tsconfig.json", {
declaration: true,
declaration: false,
noResolve: false,
typescript: require("typescript")
typescript: require("typescript")
});

gulp.task("build-source", function() {
gulp.task("build-source", function () {
return gulp.src([
"src/**/**.ts"
])
.pipe(tsProject())
.on("error", function (err) {
process.exit(1);
})
.pipe(gulp.dest("src/"));
.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")
typescript: require("typescript")
});

gulp.task("build-test", function() {
gulp.task("build-test", function () {
return gulp.src([
"test/**/**.ts"
])
.pipe(tsTestProject())
.on("error", function (err) {
process.exit(1);
})
.pipe(gulp.dest("test"));
.pipe(tsTestProject())
.on("error", function (err) {
process.exit(1);
})
.pipe(gulp.dest("test"));
});


gulp.task("build", function(cb) {
runSequence("build-source", "build-test", cb);
gulp.task("build", function (cb) {
runSequence("build-source", "build-test", cb);
});


//******** TEST *************
gulp.task("mocha", function() {
return gulp.src([
"test/**/**.js"
gulp.task("mocha", function () {
return gulp.src([
"test/**/**.js"
])
.pipe(mocha({ui: "bdd"}))
.pipe(istanbul.writeReports());
.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("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);
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/"));
gulp.task("build-lib", function () {
return gulp.src(["src/**/*.js", "src/**/*.d.ts"])
.pipe(gulp.dest("lib/src/"));
});

var tsDtsProject = tsc.createProject("tsconfig.json", {
declaration: true,
noResolve: false,
typescript: require("typescript")
});

gulp.task("build-dts", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsDtsProject())
.on("error", function (err) {
process.exit(1);
})
.dts.pipe(gulp.dest("lib/dts"));
});

gulp.task("dist", function (cb) {
runSequence("build-lib", "build-dts", cb);
});

//******** DEFAULT *************
/** DEFAULT */
gulp.task("default", function (cb) {
runSequence(
"build",
"test",
"dist",
cb);
runSequence(
"clean",
"build",
"test",
"dist",
cb);
});
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
{
"name": "kecubung",
"version": "0.0.1-dev001",
"version": "0.0.2-1",
"description": "Javascript transformer to Type Metadata",
"main": "lib/index.js",
"main": "./lib/src/index.js",
"typings": "./lib/dts/index.d.ts",
"scripts": {
"test": "gulp"
"test": "gulp",
"preversion": "gulp",
"postversion": "git push && git push --tags"
},
"keywords": [],
"keywords": [
"reflection",
"metadata",
"typesystem",
"babylon",
"typescript"
],
"author": "Ketut Sandiarsa <ktutnik@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/kambojajs/kecubung"
},
"typings": "./lib/index.d.ts",
"dependencies": {
"reflect-metadata": "^0.1.9",
"tslib": "^1.4.0"
Expand All @@ -27,6 +35,7 @@
"babylon": "^6.14.1",
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
Expand Down
40 changes: 28 additions & 12 deletions src/analyzers/class-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,62 @@ import * as HP from "./helper"
export class ClassAnalyzer {

/**
* expect AssignmentExpression, VariableDeclaration
* expect VariableDeclaration, ExpressionStatement
*/
constructor(private node) { }

/**
* expect AssignmentExpression
* expect ExpressionStatement
*/
isExported(name, parentName) {
return this.isExportedStatement()
&& (this.node.left.object.name == parentName || this.node.left.object.name == "exports")
&& this.node.right.name == name
&& (this.node.expression.left.object.name == parentName || this.node.expression.left.object.name == "exports")
&& this.node.expression.right.name == name
}

/**
* expect AssignmentExpression
* expect ExpressionStatement
*/
private isExportedStatement() {
return this.node.type == SyntaxKind.AssignmentExpression
&& this.node.left.type == SyntaxKind.MemberExpression
&& this.node.right.type == SyntaxKind.Identifier
return this.node.type == SyntaxKind.ExpressionStatement
&& this.node.expression.type == SyntaxKind.AssignmentExpression
&& this.node.expression.left.type == SyntaxKind.MemberExpression
&& this.node.expression.right.type == SyntaxKind.Identifier
}

getName() {
if (this.isExportedStatement())
return this.node.right.name;
return this.node.expression.right.name;
else if (this.isCandidate())
return this.node.declarations[0].id.name
else return null;
}

/**
* expect VariableDeclaration
*/
getParentName() {
if (this.isExportedStatement())
return this.node.expression.left.object.name;
else
return null;
}

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.body.type == SyntaxKind.BlockStatement
&& this.node.declarations[0].init.callee.id == null
}

getBaseClass() {
if (this.isCandidate() && this.node.declarations[0].init.arguments.length > 0) {
if (this.node.declarations[0].init.arguments[0].type == SyntaxKind.MemberExpression)
return this.node.declarations[0].init.arguments[0].property.name;
else
return this.node.declarations[0].init.arguments[0].name
}
return null;
}
}

27 changes: 11 additions & 16 deletions src/analyzers/class-decorator-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@ import { SyntaxKind, MetaData } from "../core"
import * as HP from "./helper"


export class ClassDecoratorAnalyzer{
export class ClassDecoratorAnalyzer {

/**
* expect AssignmentExpression
* expect ExpressionStatement
*/
constructor(private node){}
constructor(private node) { }

getClassName(){
if (this.isDecorator()){
return this.node.left.name;
getClassName() {
if (this.isDecorator()) {
return this.node.expression.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;
return this.node.type == SyntaxKind.ExpressionStatement
&& this.node.expression.type == SyntaxKind.AssignmentExpression
&& this.node.expression.left.type == SyntaxKind.Identifier
&& this.node.expression.right.type == SyntaxKind.CallExpression
&& HP.getMethodNameFromCallee(this.node.expression.right.callee) == "__decorate"
}
}
Loading

0 comments on commit 23bf51f

Please sign in to comment.