improve path handling
This commit is contained in:
parent
3e55a666b2
commit
50fd5e83ad
35
index.js
35
index.js
@ -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);
|
||||||
}
|
}
|
||||||
|
2
test/assets/customdir/tsfile1.js
Normal file
2
test/assets/customdir/tsfile1.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
var something = "something";
|
||||||
|
//# sourceMappingURL=tsfile1.js.map
|
1
test/assets/customdir/tsfile1.js.map
Normal file
1
test/assets/customdir/tsfile1.js.map
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"tsfile1.js","sourceRoot":"","sources":["tsfile1.ts"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,WAAW,CAAC"}
|
1
test/assets/customdir/tsfile1.ts
Normal file
1
test/assets/customdir/tsfile1.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
var something = "something";
|
@ -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
1
test/assets/tsfile1.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare var something: string;
|
3
test/assets/tsfile1.js
Normal file
3
test/assets/tsfile1.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var something = "something";
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user