improve path handling

This commit is contained in:
Philipp Kunz 2016-02-06 18:06:55 +01:00
parent 3e55a666b2
commit 50fd5e83ad
10 changed files with 76 additions and 11 deletions

View File

@ -103,16 +103,45 @@ var NpmtsCustom;
typingsDone.promise.then(function () { typingsDone.promise.then(function () {
for (var key in config.ts) { for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue); plugins.beautylog.log("now compiling" + key.blue);
var outputPathIsDir;
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 = (!outputPathIsDir
&& (plugins.path.extname(config.ts[key]) == ".js"));
console.log("outputNameSpecified");
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 tsStream = plugins.gulp.src(plugins.path.join(paths.cwd, key)) var tsStream = plugins.gulp.src(plugins.path.join(paths.cwd, key))
.pipe(plugins.g.typescript({ .pipe(plugins.g.typescript({
out: plugins.path.basename(config.ts[key]), out: outputName,
declaration: true declaration: true
})); }));
var stream = plugins.mergeStream([ var stream = plugins.mergeStream([
tsStream.dts.pipe(plugins.gulp.dest(paths.cwd)), tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
tsStream.js tsStream.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n')) .pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
.pipe(plugins.gulp.dest(plugins.path.dirname(plugins.path.join(paths.cwd, config.ts[key])))) .pipe(plugins.gulp.dest(outputDir))
]); ]);
moduleStream.add(stream); moduleStream.add(stream);
} }

View File

@ -0,0 +1,2 @@
var something = "something";
//# sourceMappingURL=tsfile1.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"tsfile1.js","sourceRoot":"","sources":["tsfile1.ts"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,WAAW,CAAC"}

View File

@ -0,0 +1 @@
var something = "something";

View File

@ -1,7 +1,7 @@
{ {
"mode":"custom", "mode":"custom",
"ts":{ "ts":{
"./customdir/custom.ts":"./customcompiled.js" "./customdir/*.ts":"./"
}, },
"typings":[ "typings":[
"./customdir" "./customdir"

1
test/assets/tsfile1.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare var something: string;

3
test/assets/tsfile1.js Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env node
var something = "something";

View File

@ -29,20 +29,48 @@ module NpmtsCustom {
typingsDone.promise.then(function(){ typingsDone.promise.then(function(){
for (var key in config.ts) { for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue); 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")
);
console.log("outputNameSpecified");
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 tsStream = plugins.gulp.src(plugins.path.join(paths.cwd,key)) var tsStream = plugins.gulp.src(plugins.path.join(paths.cwd,key))
.pipe(plugins.g.typescript({ .pipe(plugins.g.typescript({
out: plugins.path.basename(config.ts[key]), out: outputName,
declaration: true declaration: true
})); }));
var stream = plugins.mergeStream([ var stream = plugins.mergeStream([
tsStream.dts.pipe(plugins.gulp.dest(paths.cwd)), tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
tsStream.js tsStream.js
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n')) .pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
.pipe(plugins.gulp.dest( .pipe(plugins.gulp.dest(outputDir))
plugins.path.dirname(
plugins.path.join(paths.cwd,config.ts[key])
)
))
]); ]);
moduleStream.add(stream); moduleStream.add(stream);
} }