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");
|
2016-04-30 03:49:53 +00:00
|
|
|
var helpers = require("./npmts.compile.helpers");
|
2016-02-19 23:53:23 +00:00
|
|
|
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-04-30 09:55:42 +00:00
|
|
|
var tsOptionsDefault = {
|
|
|
|
declaration: true,
|
|
|
|
target: "ES5",
|
|
|
|
module: "commonjs"
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* merges default ts options with those found in npmts.json
|
|
|
|
*/
|
|
|
|
var tsOptions = function (keyArg) {
|
|
|
|
return plugins.lodashObject.assign(tsOptionsDefault, config.tsOptions);
|
|
|
|
};
|
|
|
|
for (var keyArg in config.ts) {
|
|
|
|
if (helpers.checkOutputPath(config, keyArg)) {
|
|
|
|
var 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)));
|
|
|
|
var jsStream = tsStream.js
|
|
|
|
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
|
|
|
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
|
|
|
var declarationStream = tsStream.dts
|
|
|
|
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
|
|
|
moduleStream.add(tsStream, jsStream, declarationStream);
|
|
|
|
}
|
2016-03-12 09:21:16 +00:00
|
|
|
}
|
|
|
|
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 () {
|
2016-04-30 10:25:35 +00:00
|
|
|
try {
|
|
|
|
if (config.mode = "default")
|
|
|
|
plugins.fs.copySync(plugins.path.join(paths.cwd, "ts/typings"), plugins.path.join(paths.cwd, "dist/typings"));
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
plugins.beautylog.warn("failed to copy external typings for full module declaration support");
|
|
|
|
}
|
2016-03-12 09:21:16 +00:00
|
|
|
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-04-30 03:49:53 +00:00
|
|
|
/*==================== END TS Compilation =====================*/
|
2016-02-19 23:53:23 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|