typescript.api
Advanced tools
Comparing version 0.3.2 to 0.3.3
33
index.js
@@ -188,3 +188,3 @@ var _vm = require("vm"); | ||
function build(inputs, callback) { | ||
function build(filenames, callback) { | ||
var get_diagnostics = function (sourceUnits) { | ||
@@ -202,5 +202,6 @@ var result = []; | ||
exports.resolve(inputs, function (sourceUnits) { | ||
exports.resolve(filenames, function (sourceUnits) { | ||
if (!exports.check(sourceUnits)) { | ||
callback(get_diagnostics(sourceUnits), null); | ||
callback(get_diagnostics(sourceUnits), null, null); | ||
return; | ||
@@ -211,16 +212,28 @@ } | ||
if (!exports.check(sourceUnits)) { | ||
callback(get_diagnostics(sourceUnits), null); | ||
callback(get_diagnostics(sourceUnits), null, null); | ||
return; | ||
} | ||
var buffer = []; | ||
var source_buffer = []; | ||
for (var n in compiledUnits) { | ||
buffer.push('////////////////////////////////////////\n'); | ||
buffer.push('// ' + _path.basename(compiledUnits[n].path) + '\n'); | ||
buffer.push('////////////////////////////////////////\n'); | ||
buffer.push(compiledUnits[n].content + '\n\n'); | ||
var pattern = /\/\/\/ <reference path="(.*?)" \/>/g; | ||
var content = compiledUnits[n].content.replace(pattern, ''); | ||
source_buffer.push(content + '\n\n'); | ||
} | ||
callback(null, buffer.join('')); | ||
var declaration_buffer = []; | ||
for (var n in compiledUnits) { | ||
var pattern = /\/\/\/ <reference path="(.*?)" \/>/g; | ||
var content = compiledUnits[n].declaration.replace(pattern, ''); | ||
declaration_buffer.push(content + '\n\n'); | ||
} | ||
callback(null, source_buffer.join(''), declaration_buffer.join('')); | ||
}); | ||
@@ -227,0 +240,0 @@ }); |
{ | ||
"name": "typescript.api", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "A compiler as a service api enabling nodejs developers to resolve, compile, reflect and run typescript 0.9 source files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -240,3 +240,4 @@ # typescript.api | ||
Builds the supplied source files. | ||
A quick means of building a typescript source file(s) and producing the compiled | ||
source code as a string. | ||
@@ -246,3 +247,3 @@ __arguments__ | ||
* sources - an array of input source filenames. | ||
* callback - a callback containing errors and the compiled source. | ||
* callback - a callback containing errors and the compiled source code and declaration. | ||
@@ -252,3 +253,3 @@ __example__ | ||
The following will build the source file 'program.ts' and write the compiled | ||
code to the console. | ||
code and declaration output to the console. | ||
@@ -258,9 +259,17 @@ ```javascript | ||
typescript.build(['program.ts'], function(errors, output) { | ||
typescript.build_source(['program.ts'], function(errors, sourcecode, declaration) { | ||
if(errors) { | ||
// iterate each error. | ||
for(var n in errors) { | ||
console.log( errors[n].toString() ); | ||
} | ||
} | ||
else { | ||
console.log(output); | ||
console.log(declaration); | ||
console.log(sourcecode); | ||
} | ||
@@ -267,0 +276,0 @@ }); |
3042590
56906
360