tscoverage/ts/npmts.compile.ts

97 lines
4.3 KiB
TypeScript
Raw Normal View History

2016-02-09 04:39:31 +00:00
/// <reference path="./index.ts" />
module NpmtsCompile {
export var run = function(configArg){
var done = plugins.q.defer();
var config = configArg;
plugins.beautylog.log("now running custom tasks");
var moduleStream = plugins.mergeStream({end: false});
/* -------------------------------------------------
* ----------- first install typings ---------------
* ----------------------------------------------- */
var typingsDone = plugins.q.defer();
var typingsCounter:number = 0;
var typingsCounterAdvance = function(){
typingsCounter++;
if(typeof config.typings[typingsCounter] != "undefined"){
installTypings();
} else {
plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve();
}
};
var installTypings = function() {
plugins.beautylog.log("now installing " + "typings.json".yellow + " from " + config.typings[typingsCounter].blue);
plugins.typings.install({production: false, cwd: plugins.path.join(paths.cwd,config.typings[typingsCounter])})
.then(function(){
typingsCounterAdvance();
},function(){
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
});
};
installTypings();
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function(){
for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
var outputPathIsDir:boolean;
try {
if(plugins.fs.statSync(plugins.path.join(paths.cwd,config.ts[key])).isDirectory()){
outputPathIsDir = true;
}
}
catch(err) {
outputPathIsDir = false;
}
//do some evaluation of the environment
var outputNameSpecified:boolean = (
!outputPathIsDir
&& (plugins.path.extname(config.ts[key]) == ".js")
);
var outputName = (function(){
if(outputNameSpecified){
return plugins.path.basename(config.ts[key])
} else {
return undefined
}
})();
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])
}
})();
2016-02-17 04:45:42 +00:00
var tsStream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"])
2016-02-17 00:16:21 +00:00
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
2016-02-09 04:39:31 +00:00
.pipe(plugins.g.typescript({
out: outputName,
2016-02-16 09:29:14 +00:00
declaration: true,
2016-02-17 03:26:26 +00:00
target: "ES5",
module: "commonjs"
2016-02-09 04:39:31 +00:00
}));
var stream = plugins.mergeStream([
2016-02-18 11:55:00 +00:00
//tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
2016-02-09 04:39:31 +00:00
tsStream.js
2016-02-17 00:16:21 +00:00
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
2016-02-16 09:58:42 +00:00
.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
2016-02-09 04:39:31 +00:00
.pipe(plugins.gulp.dest(outputDir))
]);
moduleStream.add(stream);
}
moduleStream.on("queueDrain",function(){
plugins.beautylog.success("custom TypeScript installed successfully");
moduleStream.on("finish",function(){
2016-02-09 16:01:37 +00:00
done.resolve(config);
2016-02-09 04:39:31 +00:00
});
moduleStream.end();
});
});
return done.promise;
}
}