tscoverage/dist/npmts.compile.js

63 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2016-03-12 09:21:16 +00:00
"use strict";
2016-02-19 23:53:23 +00:00
/// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
exports.run = function (configArg) {
2016-02-22 21:22:39 +00:00
var done = plugins.Q.defer();
2016-02-19 23:53:23 +00:00
var config = configArg;
2016-03-12 09:21:16 +00:00
plugins.beautylog.log("now compiling " + "TypeScript".yellow);
2016-02-22 21:22:39 +00:00
var moduleStream = plugins.merge2({ end: false });
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
* ----------------------------------------------- */
2016-03-12 09:21:16 +00:00
for (var key in config.ts) {
var outputPathIsDir;
try {
if (plugins.fs.statSync(plugins.path.join(paths.cwd, config.ts[key])).isDirectory()) {
outputPathIsDir = true;
}
2016-02-19 23:53:23 +00:00
}
2016-03-12 09:21:16 +00:00
catch (err) {
outputPathIsDir = false;
2016-02-19 23:53:23 +00:00
}
2016-03-12 09:21:16 +00:00
//do some evaluation of the environment
var outputNameSpecified = (!outputPathIsDir
&& (plugins.path.extname(config.ts[key]) == ".js"));
var outputName = (function () {
if (outputNameSpecified) {
return plugins.path.basename(config.ts[key]);
2016-02-19 23:53:23 +00:00
}
2016-03-12 09:21:16 +00:00
else {
return undefined;
2016-02-19 23:53:23 +00:00
}
2016-03-12 09:21:16 +00:00
})();
var outputDir = (function () {
if (outputNameSpecified) {
return plugins.path.dirname(plugins.path.join(paths.cwd, config.ts[key]));
}
else {
return plugins.path.join(paths.cwd, config.ts[key]);
}
})();
var 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: outputName,
target: "ES5",
module: "commonjs"
}))
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(plugins.gulp.dest(outputDir));
moduleStream.add(stream);
}
moduleStream.on("queueDrain", function () {
2016-03-14 03:53:35 +00:00
plugins.beautylog.ok("TypeScript has been compiled!");
2016-03-12 09:21:16 +00:00
moduleStream.on("finish", function () {
done.resolve(config);
2016-02-19 23:53:23 +00:00
});
2016-03-12 09:21:16 +00:00
moduleStream.end();
2016-02-19 23:53:23 +00:00
});
2016-03-12 09:21:16 +00:00
/*==================== END TYPESCRIPT =====================*/
2016-02-19 23:53:23 +00:00
return done.promise;
};