Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added grunt, tests, oss conventions #12

Merged
merged 4 commits into from
Feb 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.iml
.idea
node_modules
npm-debug.log
npm-debug.log

tmp/
29 changes: 29 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"smarttabs": true,
"node": true,
"browser": true,
"quotmark": true,
"indent": 4,
"globals": {
"it": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"define": true,
"chai": true,
"assert": true
}
}
94 changes: 94 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-mocha');

grunt.initConfig({
jshint: {
options: grunt.util._.defaults(grunt.file.readJSON('.jshintrc'), {
reporter: 'node_modules/jshint-path-reporter'
}),
support: [
'Gruntfile.js',
'tasks/**/*.js'
],
code: [
'lib/**/*.js',
],
tests: [
'test/**/*.js'
]
},
clean: {
tmp: ['test/tmp/**/*']
},
mochaTest: {
options: {
reporter: 'mocha-unfunk-reporter'
},
all: {
src: [
'test/spec/*.test.js'
]
}
},
mocha: {
options: {
bail: true,
log: true,
mocha: {
ignoreLeaks: true
},
reporter: 'mocha-unfunk-reporter',
run: false
},
pass_amd: {
options: {
urls: ['http://localhost:9009/test/pass-amd.html']
}
}
},
connect: {
test: {
options: {
port: 9009,
base: './'
}
},
server: {
options: {
keepalive: true,
port: 9001,
base: './'
}
}
}
});

grunt.registerTask('default', ['test']);

grunt.registerTask('prep', [
'clean',
// 'jshint:code', // hurts but should be active!
'jshint:support',
'jshint:tests'
]);
grunt.registerTask('test', [
'prep',
'node',
'phantom'
]);
grunt.registerTask('node', [
'clean',
'mochaTest:all'
]);
grunt.registerTask('phantom', [
'connect:test',
'mocha'
]);
grunt.registerTask('server', ['connect:server']);
};
2 changes: 1 addition & 1 deletion typson → bin/typson
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
if(process.argv[2] == "schema" && process.argv[3] !== undefined) {
var app = require('./typson-schema.js');
var app = require('./../lib/typson-schema.js');
app.exec(process.argv[3], process.argv[4]);
} else {
require('sys').print('Usage: typson schema <url-or-path-to-type-script-file> [type]\n');
Expand Down
6 changes: 3 additions & 3 deletions example/invoice/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ interface Invoice {
* Who will pay?
* Not me! éàè
*/
customer: string;
customer: string;

/**
* Invoice content
* @minItems 1
* @maxItems 50
*/
lines: InvoiceLine[];
lines: InvoiceLine[];

dimension: Dimension; // Total dimension of the order

Expand All @@ -34,5 +34,5 @@ interface InvoiceLine {
* @exclusiveMaximum false
* @multipleOf 2
*/
quantity: number;
quantity: number;
}
12 changes: 6 additions & 6 deletions example/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ interface Product {
* Uniquely defines the product
* @pattern [A-Z][a-z][0-9]_
*/
name: string;
name: string;

/** How big it is */
dimension?: Dimension;
dimension?: Dimension;

/** Classification */
category: Category;
category: Category;

/** Where is it from? */
origin: Origin;
origin: Origin;
}

interface WeightedProduct extends Product {
Expand All @@ -28,11 +28,11 @@ interface WeightedProduct extends Product {

interface Category {
/** Uniquely identifies the category */
name: string;
name: string;

/** Classification level from 1 to 5 (highest)
* @type integer */
level: number;
level: number;
}

interface CategoryIndex {
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<script src="lib/require.js"></script>
<script src="vendor/require.js"></script>
<title>Typson playground</title>
</head>
<body>
<pre id="types"></pre>
<script>
require.config({ urlArgs: "bust=" + (new Date()).getTime() });
require(["typson-schema"], function(typson) {
require(["lib/typson-schema"], function(typson) {
// Show types as json-schema definitions
typson.definitions("example/invoice/line.ts").done(function(tree) {
document.getElementById("types").innerHTML = JSON.stringify(tree, undefined, 2);
Expand Down
4 changes: 2 additions & 2 deletions interactive.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="lib/require.js"></script>
<script src="vendor/require.js"></script>
<title>Typson playground</title>
<style>
body, body * {
Expand Down Expand Up @@ -59,7 +59,7 @@

<script>
require.config({ urlArgs: "bust=" + (new Date()).getTime() });
require(["typson-schema"], function(typson) {
require(["lib/typson-schema"], function(typson) {

var srcElement = document.getElementById("source");
var tgtElement = document.getElementById("schema");
Expand Down
2 changes: 1 addition & 1 deletion typson-schema.js → lib/typson-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module.exports = definition(require('underscore'), require('q'), require('./typson.js'));
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(["lib/underscore", "lib/q", "typson"], definition);
define(["vendor/underscore", "vendor/q", "./typson"], definition);
}
})
(function (underscore, Q, typson) {
Expand Down
2 changes: 1 addition & 1 deletion typson-swagger.js → lib/typson-swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(function() {
var oldRequire = require;
window.require = requirejs;
require(["typson-schema"], function(typson) {
require(["./typson-schema"], function(typson) {
SwaggerApi.modelLoader = function(api, done) {
if(api.tsModels) {
window.require = requirejs;
Expand Down
19 changes: 10 additions & 9 deletions typson.js → lib/typson.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
module.exports = definition(require('underscore'), require('q'));
// RequireJS
} else if (typeof define === "function" && define.amd) {
return define(["lib/underscore", "lib/q", "lib/superagent", "lib/typescriptServices"], definition);
return define(["vendor/underscore", "vendor/q", "vendor/superagent", "vendor/typescriptServices"], definition);
}
})(function (underscore, Q, request) {
})(function (underscore, Q, request, TypeScript) {
if (underscore) {
_ = underscore;
}
var api = {}
var api = {};

var tsLoaded = Q.defer();
api.ready = tsLoaded.promise;
Expand All @@ -36,16 +36,17 @@
requirejs.config({
baseUrl: __dirname
});
requirejs(["../vendor/typescriptServices"], function (ts) {
TypeScript = ts;
api.TypeScript = ts;
tsLoaded.resolve();
});
} else {
var requirejs = require;
api.TypeScript = TypeScript;
tsLoaded.resolve();
}

var TypeScript;
requirejs(["lib/typescriptServices"], function (ts) {
TypeScript = ts;
api.TypeScript = ts;
tsLoaded.resolve();
});


/**
Expand Down
89 changes: 59 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
{
"name": "typson",
"version": "0.2.0",
"author": "Laurent Bovet <laurent.bovet@windmaster.ch>",
"description": "generates json-schema from TypeScript declarations",
"contributors": [
{
"name": "Olivier von Dach"
}
],
"bin": {
"typson": "./typson"
"name": "typson",
"version": "0.2.0",
"description": "generates json-schema from TypeScript declarations",
"homepage": "https://github.com/lbovet/typson",
"author": {
"name": "Laurent Bovet",
"email": "laurent.bovet@windmaster.ch",
"url": "https://github.com/lbovet"
},
"contributors": [
{
"name": "Olivier von Dach"
},
"main": "./typson-schema.js",
"repository": {
"type": "git",
"url": "https://github.com/lbovet/typson.git"
},
"keywords": [
"typescript",
"json",
"schema"
],
"dependencies" : {
"underscore": "1.5.x",
"q" : "0.9.x",
"superagent": "0.15.x",
"requirejs" : "2.1.x"
},
"license": "Apache 2.0",
"engines": {
"node": ">=0.9.7"
{
"name": "Bart van der Schoor",
"url": "https://github.com/Bartvds"
}
],
"repository": {
"type": "git",
"url": "https://github.com/lbovet/typson.git"
},
"license": {
"type": "Apache 2.0",
"url": "https://raw.github.com/lbovet/typson/master/LICENSE.txt"
},
"keywords": [
"typescript",
"json",
"schema"
],
"engines": {
"node": ">= 0.10.0"
},
"preferGlobal": true,
"main": "./lib/typson-schema.js",
"bin": {
"typson": "./bin/typson"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"underscore": "1.5.x",
"q": "0.9.x",
"superagent": "0.15.x",
"requirejs": "2.1.x"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-cli": "~0.1.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-jshint": "~0.8.0",
"jshint-path-reporter": "~0.1.3",
"mocha-unfunk-reporter": "~0.4.0",
"grunt-contrib-connect": "~0.6.0",
"grunt-mocha": "~0.4.10",
"grunt-mocha-test": "~0.9.0",
"mkdirp": "~0.3.5",
"chai": "~1.9.0"
}
}
Loading