tscoverage/ts/npmts.compile.ts

58 lines
2.0 KiB
TypeScript
Raw Normal View History

2016-02-19 23:53:23 +00:00
/// <reference path="./typings/main.d.ts" />
import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths");
import helpers = require("./npmts.compile.helpers");
export let run = function (configArg) {
let done = plugins.Q.defer();
let config = configArg;
2016-03-12 09:21:16 +00:00
plugins.beautylog.log("now compiling " + "TypeScript".yellow);
let moduleStream = plugins.merge2({ end: false });
2016-03-12 09:21:16 +00:00
2016-02-19 23:53:23 +00:00
/* -------------------------------------------------
2016-03-12 09:21:16 +00:00
* ----------- compile TypeScript --------------------------
2016-02-19 23:53:23 +00:00
* ----------------------------------------------- */
let tsOptionsDefault = {
declaration: true,
target: "ES5",
module: "commonjs"
};
/**
* 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 () {
2016-03-14 03:53:35 +00:00
plugins.beautylog.ok("TypeScript has been compiled!");
moduleStream.on("finish", function () {
2016-03-12 09:21:16 +00:00
done.resolve(config);
2016-02-09 04:39:31 +00:00
});
2016-03-12 09:21:16 +00:00
moduleStream.end();
2016-02-19 23:53:23 +00:00
});
/*==================== END TS Compilation =====================*/
2016-03-12 09:21:16 +00:00
2016-02-19 23:53:23 +00:00
return done.promise;
};