Compare commits

...

3 Commits

Author SHA1 Message Date
4b2c0fe461 2.1.1 2016-02-06 18:07:20 +01:00
50fd5e83ad improve path handling 2016-02-06 18:06:55 +01:00
3e55a666b2 update npm test 2016-02-04 20:43:52 +01:00
11 changed files with 78 additions and 14 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

@ -1,6 +1,6 @@
{ {
"name": "npmts", "name": "npmts",
"version": "2.1.0", "version": "2.1.1",
"description": "write npm modules with TypeScript", "description": "write npm modules with TypeScript",
"main": "index.js", "main": "index.js",
"typings": "./index.d.ts", "typings": "./index.d.ts",
@ -8,8 +8,7 @@
"npmts": "./index.js" "npmts": "./index.js"
}, },
"scripts": { "scripts": {
"test": "(cd compile && node compile.js)", "test": "(cd compile && node compile.js) && (cd test/assets && node ../../index.js)",
"testm": "(npm test) && (cd test/assets && node ../../index.js)",
"release": "(git add -A && git commit -m 'update' && git push origin master && npm version patch && npm publish)" "release": "(git add -A && git commit -m 'update' && git push origin master && npm version patch && npm publish)"
}, },
"repository": { "repository": {

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);
} }