now reading tsOptions from tsConfig and supporting declaration file handling
This commit is contained in:
@ -2,33 +2,14 @@ import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
|
||||
let outputPathIsDir = function (configArg,keyArg) {
|
||||
try {
|
||||
return plugins.fs.statSync(plugins.path.join(paths.cwd, configArg.ts[keyArg])).isDirectory();
|
||||
}
|
||||
catch (err) {
|
||||
return false;
|
||||
}
|
||||
return plugins.smartpath.check.isDir(plugins.path.join(paths.cwd, configArg.ts[keyArg]));
|
||||
};
|
||||
|
||||
export let outputNameSpecified = function (configArg, keyArg) {
|
||||
return !outputPathIsDir(configArg,keyArg)
|
||||
&& (plugins.path.extname(configArg.ts[keyArg]) == ".js");
|
||||
}
|
||||
|
||||
export let outputName = function (configArg, keyArg) {
|
||||
if (outputNameSpecified(configArg,keyArg)) {
|
||||
return plugins.path.basename(configArg.ts[keyArg])
|
||||
export let checkOutputPath = function(configArg,keyArg){
|
||||
if(!outputPathIsDir(configArg,keyArg)) {
|
||||
plugins.beautylog.warn("Skipping " + keyArg + " because " + configArg.ts[keyArg] + " it is no directory!")
|
||||
return false
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
};
|
||||
|
||||
export let outputDir = function (configArg, keyArg) {
|
||||
if (outputNameSpecified(configArg,keyArg)) {
|
||||
return plugins.path.dirname(
|
||||
plugins.path.join(paths.cwd, configArg.ts[keyArg])
|
||||
)
|
||||
} else {
|
||||
return plugins.path.join(paths.cwd, configArg.ts[keyArg])
|
||||
}
|
||||
};
|
||||
return true;
|
||||
};
|
||||
}
|
@ -4,31 +4,47 @@ import paths = require("./npmts.paths");
|
||||
|
||||
import helpers = require("./npmts.compile.helpers");
|
||||
|
||||
export let run = function(configArg){
|
||||
export let run = function (configArg) {
|
||||
let done = plugins.Q.defer();
|
||||
let config = configArg;
|
||||
plugins.beautylog.log("now compiling " + "TypeScript".yellow);
|
||||
let moduleStream = plugins.merge2({end: false});
|
||||
let moduleStream = plugins.merge2({ end: false });
|
||||
|
||||
/* -------------------------------------------------
|
||||
* ----------- compile TypeScript --------------------------
|
||||
* ----------------------------------------------- */
|
||||
for (let key in config.ts) {
|
||||
let stream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"])
|
||||
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
|
||||
.pipe(plugins.g.typescript({
|
||||
out: helpers.outputName(config,key),
|
||||
target: "ES5",
|
||||
module: "commonjs"
|
||||
}))
|
||||
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
.pipe(plugins.gulp.dest(helpers.outputDir(config,key)));
|
||||
moduleStream.add(stream);
|
||||
}
|
||||
|
||||
let tsOptionsDefault = {
|
||||
declaration: true,
|
||||
target: "ES5",
|
||||
module: "commonjs"
|
||||
};
|
||||
|
||||
moduleStream.on("queueDrain",function(){
|
||||
/**
|
||||
* merges default ts options with those found in npmts.json
|
||||
*/
|
||||
let tsOptions = function (keyArg:string) {
|
||||
return plugins.lodashObject.assign(tsOptionsDefault, config.tsOptions)
|
||||
};
|
||||
|
||||
for (let keyArg in config.ts) {
|
||||
if (helpers.checkOutputPath(config,keyArg)) {
|
||||
let tsStream = plugins.gulp.src([plugins.path.join(paths.cwd, keyArg), "!**/typings/**"])
|
||||
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
|
||||
.pipe(plugins.g.typescript(tsOptions(keyArg)));
|
||||
|
||||
let jsStream = tsStream.js
|
||||
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
||||
let declarationStream = tsStream.dts
|
||||
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
||||
moduleStream.add(tsStream,jsStream,declarationStream);
|
||||
}
|
||||
}
|
||||
|
||||
moduleStream.on("queueDrain", function () {
|
||||
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||
moduleStream.on("finish",function(){
|
||||
moduleStream.on("finish", function () {
|
||||
done.resolve(config);
|
||||
});
|
||||
moduleStream.end();
|
||||
|
@ -32,6 +32,9 @@ export var run = function(configArg){
|
||||
};
|
||||
config.test = ["./index.js"];
|
||||
}
|
||||
|
||||
//check if config.tsOptions is available
|
||||
config.tsOptions ? void(0) : config.tsOptions = {};
|
||||
|
||||
// handle state of current build
|
||||
|
||||
|
@ -13,6 +13,7 @@ export let g = {
|
||||
typings: require("gulp-typings")
|
||||
|
||||
};
|
||||
export let lodashObject = require('lodash/fp/object');
|
||||
export let merge2 = require("merge2");
|
||||
export let projectinfo = require("projectinfo");
|
||||
export let path = require("path");
|
||||
@ -24,4 +25,4 @@ export let smartcov = require("smartcov");
|
||||
export let smartenv = require("smartenv");
|
||||
export let smartfile = require("smartfile");
|
||||
export let smartpath = require("smartpath");
|
||||
export let sourceMapSupport = require("source-map-support").install();
|
||||
export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
Reference in New Issue
Block a user