2016-03-12 09:21:16 +00:00
|
|
|
"use strict";
|
2016-05-25 03:23:48 +00:00
|
|
|
require("typings-global");
|
2016-02-19 23:53:23 +00:00
|
|
|
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-05-17 00:32:40 +00:00
|
|
|
var npmts_promisechain_1 = require("./npmts.promisechain");
|
2016-05-01 19:15:52 +00:00
|
|
|
/**
|
|
|
|
* handles definition to make them fit for modular use
|
|
|
|
*/
|
|
|
|
var definitionHandler = function (configArg) {
|
2016-05-17 00:32:40 +00:00
|
|
|
npmts_promisechain_1.npmtsOra.text("now making declaration files ready");
|
2016-05-01 19:15:52 +00:00
|
|
|
var done = plugins.Q.defer();
|
|
|
|
var configTsLenght = Object.keys(configArg.ts).length;
|
|
|
|
if (configTsLenght == 0) {
|
2016-06-07 06:49:22 +00:00
|
|
|
plugins.beautylog.warn("No TS file and thus no definitions found!");
|
2016-05-01 19:15:52 +00:00
|
|
|
done.resolve(configArg); //if there are no definition files, resolve...
|
|
|
|
}
|
|
|
|
var localCounter = 0;
|
|
|
|
for (var key in configArg.ts) {
|
|
|
|
var distPath = configArg.ts[key];
|
|
|
|
var stream = plugins.gulp.src(plugins.path.join(distPath, "**/*.d.ts"))
|
|
|
|
.pipe(plugins.g.replace(plugins.smartstring.typescript.regexReferencePath, ""))
|
|
|
|
.pipe(plugins.gulp.dest(distPath))
|
|
|
|
.pipe(plugins.g.gFunction(function () {
|
|
|
|
localCounter++;
|
|
|
|
if (localCounter == configTsLenght) {
|
2016-05-17 00:32:40 +00:00
|
|
|
plugins.beautylog.ok("made declaration files ready!");
|
2016-05-01 19:15:52 +00:00
|
|
|
done.resolve(configArg);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
}, "atEnd"));
|
|
|
|
}
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-06-07 06:49:22 +00:00
|
|
|
var compileTs = function (tsFileArrayArg, tsOptionsArg) {
|
|
|
|
if (tsOptionsArg === void 0) { tsOptionsArg = {}; }
|
2016-02-22 21:22:39 +00:00
|
|
|
var done = plugins.Q.defer();
|
|
|
|
var moduleStream = plugins.merge2({ end: false });
|
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) {
|
2016-06-07 06:49:22 +00:00
|
|
|
return plugins.lodashObject.assign(tsOptionsDefault, tsOptionsArg);
|
2016-04-30 09:55:42 +00:00
|
|
|
};
|
2016-06-07 06:49:22 +00:00
|
|
|
for (var keyArg in tsFileArrayArg) {
|
|
|
|
if (helpers.checkOutputPath(tsFileArrayArg, keyArg)) {
|
2016-04-30 09:55:42 +00:00
|
|
|
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
|
2016-06-07 06:49:22 +00:00
|
|
|
.pipe(plugins.gulp.dest(tsFileArrayArg[keyArg]));
|
2016-04-30 09:55:42 +00:00
|
|
|
var declarationStream = tsStream.dts
|
2016-06-07 06:49:22 +00:00
|
|
|
.pipe(plugins.gulp.dest(tsFileArrayArg[keyArg]));
|
2016-04-30 09:55:42 +00:00
|
|
|
moduleStream.add(tsStream, jsStream, declarationStream);
|
|
|
|
}
|
2016-03-12 09:21:16 +00:00
|
|
|
}
|
|
|
|
moduleStream.on("queueDrain", function () {
|
2016-06-07 06:49:22 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
|
|
|
exports.run = function (configArg) {
|
|
|
|
var done = plugins.Q.defer();
|
|
|
|
var config = configArg;
|
|
|
|
npmts_promisechain_1.npmtsOra.text("now compiling " + "TypeScript".yellow);
|
|
|
|
compileTs(config.ts, config.tsOptions)
|
|
|
|
.then(function () {
|
2016-06-07 06:53:47 +00:00
|
|
|
compileTs(config.testTs);
|
2016-06-07 06:49:22 +00:00
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
plugins.beautylog.ok("compiled TypeScript!");
|
|
|
|
definitionHandler(config)
|
|
|
|
.then(function () {
|
|
|
|
done.resolve(config);
|
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;
|
|
|
|
};
|