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");
|
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-07-01 02:50:23 +00:00
|
|
|
var promiseArray = [];
|
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();
|
2016-07-27 14:08:33 +00:00
|
|
|
var compilerOptionsDefault = {
|
2016-04-30 09:55:42 +00:00
|
|
|
declaration: true,
|
2016-07-27 14:08:33 +00:00
|
|
|
module: "CommonJS",
|
|
|
|
target: "ES6"
|
2016-04-30 09:55:42 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* merges default ts options with those found in npmts.json
|
|
|
|
*/
|
2016-07-27 14:08:33 +00:00
|
|
|
var compilerOptions = function (keyArg) {
|
|
|
|
var tsOptionsCombined = plugins.lodashObject.merge(compilerOptionsDefault, tsOptionsArg);
|
|
|
|
var compilerOptions = {
|
|
|
|
declaration: tsOptionsCombined.declaration,
|
|
|
|
module: plugins.tsn.ModuleKind[tsOptionsCombined.module],
|
|
|
|
target: plugins.tsn.ScriptTarget[tsOptionsCombined.target]
|
|
|
|
};
|
|
|
|
return compilerOptions;
|
2016-04-30 09:55:42 +00:00
|
|
|
};
|
2016-07-01 02:50:23 +00:00
|
|
|
var _loop_1 = function(keyArg) {
|
|
|
|
plugins.beautylog.info("TypeScript assignment: transpile from " + keyArg.blue + " to " + tsFileArrayArg[keyArg].blue);
|
2016-06-07 06:49:22 +00:00
|
|
|
if (helpers.checkOutputPath(tsFileArrayArg, keyArg)) {
|
2016-07-01 02:50:23 +00:00
|
|
|
var filesReadPromise = plugins.smartfile.fs.listFileTree(process.cwd(), keyArg)
|
|
|
|
.then(function (filesToConvertArg) {
|
|
|
|
var filesToConvertAbsolute = plugins.smartpath.transform.toAbsolute(filesToConvertArg, process.cwd());
|
|
|
|
var destDir = plugins.smartpath.transform.toAbsolute(tsFileArrayArg[keyArg], process.cwd());
|
2016-07-27 14:08:33 +00:00
|
|
|
var filesCompiledPromise = plugins.tsn.compile(filesToConvertAbsolute, destDir, compilerOptions(keyArg));
|
2016-07-01 02:50:23 +00:00
|
|
|
promiseArray.push(filesCompiledPromise);
|
|
|
|
});
|
|
|
|
promiseArray.push(filesReadPromise);
|
2016-04-30 09:55:42 +00:00
|
|
|
}
|
2016-07-01 02:50:23 +00:00
|
|
|
};
|
|
|
|
for (var keyArg in tsFileArrayArg) {
|
|
|
|
_loop_1(keyArg);
|
2016-03-12 09:21:16 +00:00
|
|
|
}
|
2016-07-01 02:50:23 +00:00
|
|
|
;
|
|
|
|
plugins.Q.all(promiseArray)
|
|
|
|
.then(done.resolve);
|
2016-06-07 06:49:22 +00:00
|
|
|
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-07-01 02:50:23 +00:00
|
|
|
plugins.beautylog.ok("compiled main TypeScript!");
|
|
|
|
plugins.beautylog.log("now compiling tests!");
|
|
|
|
return compileTs(config.testTs);
|
2016-06-07 06:49:22 +00:00
|
|
|
})
|
|
|
|
.then(function () {
|
2016-07-01 02:50:23 +00:00
|
|
|
plugins.beautylog.ok("compiled all TypeScript!");
|
2016-07-01 00:28:34 +00:00
|
|
|
done.resolve(config);
|
2016-02-19 23:53:23 +00:00
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|