Compare commits

...

10 Commits

Author SHA1 Message Date
3f0b2b1599 2.1.5 2016-02-07 12:19:50 +01:00
d477e492eb small fix 2016-02-07 12:19:42 +01:00
f39cb03fc2 2.1.4 2016-02-07 01:00:28 +01:00
f42744b927 2.1.3 2016-02-06 19:00:20 +01:00
038994e9e5 updated log output 2016-02-06 19:00:02 +01:00
7a26721420 2.1.2 2016-02-06 18:56:51 +01:00
0dc307f082 now handles multiple typings recursivly 2016-02-06 18:56:42 +01:00
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
14 changed files with 122 additions and 28 deletions

2
index.d.ts vendored
View File

@ -9,6 +9,7 @@ declare module NpmtsPlugins {
sequence: any; sequence: any;
typescript: any; typescript: any;
}; };
mathjs: any;
mergeStream: any; mergeStream: any;
mocha: any; mocha: any;
path: any; path: any;
@ -46,6 +47,7 @@ declare var plugins: {
sequence: any; sequence: any;
typescript: any; typescript: any;
}; };
mathjs: any;
mergeStream: any; mergeStream: any;
mocha: any; mocha: any;
path: any; path: any;

View File

@ -13,6 +13,7 @@ var NpmtsPlugins;
sequence: require("gulp-sequence"), sequence: require("gulp-sequence"),
typescript: require("gulp-typescript") typescript: require("gulp-typescript")
}, },
mathjs: require("mathjs"),
mergeStream: require("merge2"), mergeStream: require("merge2"),
mocha: require("mocha"), mocha: require("mocha"),
path: require("path"), path: require("path"),
@ -84,35 +85,72 @@ var NpmtsCustom;
* ----------- first install typings --------------- * ----------- first install typings ---------------
* ----------------------------------------------- */ * ----------------------------------------------- */
var typingsDone = plugins.q.defer(); var typingsDone = plugins.q.defer();
var checkTypingsDone = function (indexArg, compareArray) { var typingsCounter = 0;
if ((indexArg + 1) == compareArray.length) { var typingsCounterAdvance = function () {
typingsCounter++;
if (typeof config.typings[typingsCounter] != "undefined") {
installTypings();
}
else {
plugins.beautylog.success("custom typings installed successfully"); plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve(); typingsDone.resolve();
} }
}; };
for (var key in config.typings) { var installTypings = function () {
plugins.beautylog.log("now installing " + "typings.json".yellow + " from " + config.typings[key].blue); 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[key]) }) plugins.typings.install({ production: false, cwd: plugins.path.join(paths.cwd, config.typings[typingsCounter]) })
.then(function () { .then(function () {
checkTypingsDone(key, config.typings); typingsCounterAdvance();
}, function () {
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
}); });
} };
installTypings();
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- second compile TS ------------------- * ----------- second compile TS -------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
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"));
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.5",
"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": {
@ -34,6 +33,7 @@
"gulp-sequence": "^0.4.4", "gulp-sequence": "^0.4.4",
"gulp-typescript": "2.10.0", "gulp-typescript": "2.10.0",
"gulp-typings": "0.0.0", "gulp-typings": "0.0.0",
"mathjs": "^2.7.0",
"merge2": "1.0.1", "merge2": "1.0.1",
"mocha": "^2.4.5", "mocha": "^2.4.5",
"q": "^1.4.1", "q": "^1.4.1",

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,9 +1,12 @@
{ {
"mode":"custom", "mode":"custom",
"ts":{ "ts":{
"./customdir/custom.ts":"./customcompiled.js" "./customdir/*.ts":"./"
}, },
"typings":[ "typings":[
"./ts",
"./subts1/",
"./subts2/",
"./customdir" "./customdir"
] ]
} }

View File

@ -0,0 +1,7 @@
{
"ambientDependencies": {
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777",
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts#09e37435ffb2c56a6f908081194a74756f24f99d",
"vinyl": "github:DefinitelyTyped/DefinitelyTyped/vinyl/vinyl.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777"
}
}

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

@ -10,39 +10,74 @@ module NpmtsCustom {
* ----------- first install typings --------------- * ----------- first install typings ---------------
* ----------------------------------------------- */ * ----------------------------------------------- */
var typingsDone = plugins.q.defer(); var typingsDone = plugins.q.defer();
var checkTypingsDone = function(indexArg:number,compareArray){ var typingsCounter:number = 0;
if((indexArg + 1) == compareArray.length){ var typingsCounterAdvance = function(){
typingsCounter++;
if(typeof config.typings[typingsCounter] != "undefined"){
installTypings();
} else {
plugins.beautylog.success("custom typings installed successfully"); plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve(); typingsDone.resolve();
} }
}; };
for (var key in config.typings) { var installTypings = function() {
plugins.beautylog.log("now installing " + "typings.json".yellow + " from " + config.typings[key].blue); 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[key])}) plugins.typings.install({production: false, cwd: plugins.path.join(paths.cwd,config.typings[typingsCounter])})
.then(function(){ .then(function(){
checkTypingsDone(key,config.typings); typingsCounterAdvance();
},function(){
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
}); });
} };
installTypings();
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- second compile TS ------------------- * ----------- second compile TS -------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
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")
);
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);
} }

View File

@ -11,6 +11,7 @@ module NpmtsPlugins {
typescript: require("gulp-typescript") typescript: require("gulp-typescript")
}, },
mathjs: require("mathjs"),
mergeStream: require("merge2"), mergeStream: require("merge2"),
mocha: require("mocha"), mocha: require("mocha"),
path: require("path"), path: require("path"),