clean up TypeScript compilation handling
This commit is contained in:
34
ts/npmts.compile.helpers.ts
Normal file
34
ts/npmts.compile.helpers.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
|
||||
let outputPathIsDir = function (configArg,keyArg) {
|
||||
try {
|
||||
return plugins.fs.statSync(plugins.path.join(paths.cwd, configArg.ts[keyArg])).isDirectory();
|
||||
}
|
||||
catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export let outputNameSpecified = function (configArg, keyArg) {
|
||||
return !outputPathIsDir(configArg,keyArg)
|
||||
&& (plugins.path.extname(configArg.ts[keyArg]) == ".js");
|
||||
}
|
||||
|
||||
export let outputName = function (configArg, keyArg) {
|
||||
if (outputNameSpecified(configArg,keyArg)) {
|
||||
return plugins.path.basename(configArg.ts[keyArg])
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
};
|
||||
|
||||
export let outputDir = function (configArg, keyArg) {
|
||||
if (outputNameSpecified(configArg,keyArg)) {
|
||||
return plugins.path.dirname(
|
||||
plugins.path.join(paths.cwd, configArg.ts[keyArg])
|
||||
)
|
||||
} else {
|
||||
return plugins.path.join(paths.cwd, configArg.ts[keyArg])
|
||||
}
|
||||
};
|
@ -1,59 +1,31 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./npmts.plugins");
|
||||
import paths = require("./npmts.paths");
|
||||
export var run = function(configArg){
|
||||
var done = plugins.Q.defer();
|
||||
var config = configArg;
|
||||
|
||||
import helpers = require("./npmts.compile.helpers");
|
||||
|
||||
export let run = function(configArg){
|
||||
let done = plugins.Q.defer();
|
||||
let config = configArg;
|
||||
plugins.beautylog.log("now compiling " + "TypeScript".yellow);
|
||||
var moduleStream = plugins.merge2({end: false});
|
||||
let moduleStream = plugins.merge2({end: false});
|
||||
|
||||
/* -------------------------------------------------
|
||||
* ----------- compile TypeScript --------------------------
|
||||
* ----------------------------------------------- */
|
||||
for (var key in config.ts) {
|
||||
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])
|
||||
}
|
||||
})();
|
||||
|
||||
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"])
|
||||
for (let key in config.ts) {
|
||||
let 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,
|
||||
out: helpers.outputName(config,key),
|
||||
target: "ES5",
|
||||
module: "commonjs"
|
||||
}))
|
||||
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||
//.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
|
||||
.pipe(plugins.gulp.dest(outputDir));
|
||||
.pipe(plugins.gulp.dest(helpers.outputDir(config,key)));
|
||||
moduleStream.add(stream);
|
||||
}
|
||||
|
||||
moduleStream.on("queueDrain",function(){
|
||||
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||
moduleStream.on("finish",function(){
|
||||
@ -61,7 +33,7 @@ export var run = function(configArg){
|
||||
});
|
||||
moduleStream.end();
|
||||
});
|
||||
/*==================== END TYPESCRIPT =====================*/
|
||||
/*==================== END TS Compilation =====================*/
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user