now using gulp-typings

This commit is contained in:
Philipp Kunz 2016-03-12 10:21:16 +01:00
parent 8efa67a4ff
commit 9f74fab2b2
23 changed files with 199 additions and 176 deletions

8
.gitignore vendored
View File

@ -1,10 +1,10 @@
.idea/ .idea/
.c9/ .c9/
node_modules/ node_modules/
test/**/node_modules/ test/assets/**/node_modules/
test/assets/docs/ test/assets/**/docs/
test/**/typings/ test/assets/**/typings/
test/**/coverage/ test/assets/**/coverage/
ts/*.js ts/*.js
ts/*.js.map ts/*.js.map
ts/typings/ ts/typings/

1
dist/index.js vendored
View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
console.log("**** starting NPMTS ****"); console.log("**** starting NPMTS ****");
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");

37
dist/npmts.compile.js vendored
View File

@ -1,43 +1,16 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths"); var paths = require("./npmts.paths");
exports.run = function (configArg) { exports.run = function (configArg) {
var done = plugins.Q.defer(); var done = plugins.Q.defer();
var config = configArg; var config = configArg;
plugins.beautylog.log("now running custom tasks"); plugins.beautylog.log("now compiling " + "TypeScript".yellow);
var moduleStream = plugins.merge2({ end: false }); var moduleStream = plugins.merge2({ end: false });
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- first install typings --------------- * ----------- compile TypeScript --------------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
var typingsDone = plugins.Q.defer();
var typingsCounter = 0;
var typingsCounterAdvance = function () {
typingsCounter++;
if (typeof config.typings[typingsCounter] != "undefined") {
installTypings();
}
else {
plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve();
}
};
var installTypings = function () {
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[typingsCounter]) })
.then(function () {
typingsCounterAdvance();
}, function () {
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
});
};
installTypings();
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function () {
for (var key in config.ts) { for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
var outputPathIsDir; var outputPathIsDir;
try { try {
if (plugins.fs.statSync(plugins.path.join(paths.cwd, config.ts[key])).isDirectory()) { if (plugins.fs.statSync(plugins.path.join(paths.cwd, config.ts[key])).isDirectory()) {
@ -78,12 +51,12 @@ exports.run = function (configArg) {
moduleStream.add(stream); moduleStream.add(stream);
} }
moduleStream.on("queueDrain", function () { moduleStream.on("queueDrain", function () {
plugins.beautylog.success("custom TypeScript installed successfully"); plugins.beautylog.ok("TypeScript is compiled!");
moduleStream.on("finish", function () { moduleStream.on("finish", function () {
done.resolve(config); done.resolve(config);
}); });
moduleStream.end(); moduleStream.end();
}); });
}); /*==================== END TYPESCRIPT =====================*/
return done.promise; return done.promise;
}; };

View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths"); var paths = require("./npmts.paths");
@ -16,6 +17,7 @@ exports.run = function () {
break; break;
default: default:
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red); plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
process.exit(1);
} }
; ;
} }

20
dist/npmts.install.js vendored Normal file
View File

@ -0,0 +1,20 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
exports.run = function (configArg) {
var config = configArg;
var done = plugins.Q.defer();
/* -------------------------------------------------
* ----------- install typings ---------------
* ----------------------------------------------- */
plugins.beautylog.log("now installing " + "typings".yellow);
var absoluteTypingsArray = plugins.smartpath.absolute(config.typings, paths.cwd);
plugins.gulp.src(absoluteTypingsArray)
.pipe(plugins.g.typings())
.pipe(plugins.g.gFunction(function () {
plugins.beautylog.ok("typings are installed!");
done.resolve(config);
}, "atEnd"));
return done.promise;
};

4
dist/npmts.jsdoc.js vendored
View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths"); var paths = require("./npmts.paths");
@ -13,6 +14,7 @@ var genJsdoc = function (configArg) {
destination: paths.docsDir destination: paths.docsDir
} }
}, function () { }, function () {
plugins.beautylog.ok("JsDoc has been generated!");
done.resolve(configArg); done.resolve(configArg);
})); }));
return done.promise; return done.promise;
@ -42,7 +44,7 @@ var publishDocs = function (configArg) {
plugins.beautylog.error('Error: Git failed'); plugins.beautylog.error('Error: Git failed');
plugins.shelljs.exit(1); plugins.shelljs.exit(1);
} }
plugins.beautylog.success("Docs have been deployed to GitHub"); plugins.beautylog.ok("JsDoc has been deployed to GitHub!");
done.resolve(configArg); done.resolve(configArg);
} }
else { else {

View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
exports.run = function (configArg) { exports.run = function (configArg) {
@ -8,7 +9,7 @@ exports.run = function (configArg) {
} }
if (config.mode == "default") { if (config.mode == "default") {
config.typings = [ config.typings = [
"./ts/" "./ts/typings.json"
]; ];
config.ts = (_a = {}, config.ts = (_a = {},
_a["./ts/**/*.ts"] = "./dist/", _a["./ts/**/*.ts"] = "./dist/",

1
dist/npmts.paths.js vendored
View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
var paths = {}; var paths = {};

View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = { var plugins = {
beautylog: require("beautylog"), beautylog: require("beautylog"),
@ -10,7 +11,8 @@ var plugins = {
jsdoc3: require("gulp-jsdoc3"), jsdoc3: require("gulp-jsdoc3"),
mocha: require("gulp-mocha"), mocha: require("gulp-mocha"),
sourcemaps: require("gulp-sourcemaps"), sourcemaps: require("gulp-sourcemaps"),
typescript: require("gulp-typescript") typescript: require("gulp-typescript"),
typings: require("gulp-typings")
}, },
merge2: require("merge2"), merge2: require("merge2"),
projectinfo: require("projectinfo"), projectinfo: require("projectinfo"),
@ -21,6 +23,6 @@ var plugins = {
smartcli: require("smartcli"), smartcli: require("smartcli"),
smartenv: require("smartenv"), smartenv: require("smartenv"),
smartfile: require("smartfile"), smartfile: require("smartfile"),
typings: require("typings") smartpath: require("smartpath")
}; };
module.exports = plugins; module.exports = plugins;

View File

@ -1,6 +1,8 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var NpmtsConfigFile = require("./npmts.configfile"); var NpmtsConfigFile = require("./npmts.configfile");
var NpmtsOptions = require("./npmts.options"); var NpmtsOptions = require("./npmts.options");
var NpmtsInstall = require("./npmts.install");
var NpmtsCompile = require("./npmts.compile"); var NpmtsCompile = require("./npmts.compile");
var NpmtsJsdoc = require("./npmts.jsdoc"); var NpmtsJsdoc = require("./npmts.jsdoc");
var NpmtsTests = require("./npmts.tests"); var NpmtsTests = require("./npmts.tests");
@ -8,6 +10,7 @@ exports.run = function () {
var promisechain; var promisechain;
NpmtsConfigFile.run() NpmtsConfigFile.run()
.then(NpmtsOptions.run) .then(NpmtsOptions.run)
.then(NpmtsInstall.run)
.then(NpmtsCompile.run) .then(NpmtsCompile.run)
.then(NpmtsJsdoc.run) .then(NpmtsJsdoc.run)
.then(NpmtsTests.run); .then(NpmtsTests.run);

8
dist/npmts.tests.js vendored
View File

@ -1,3 +1,4 @@
"use strict";
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins"); var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths"); var paths = require("./npmts.paths");
@ -20,9 +21,13 @@ exports.run = function (configArg) {
var coveralls = function () { var coveralls = function () {
plugins.beautylog.log("now uploading coverage data to coveralls"); plugins.beautylog.log("now uploading coverage data to coveralls");
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "./coverage/lcov.info")]) var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "./coverage/lcov.info")])
.pipe(plugins.g.coveralls()); .pipe(plugins.g.coveralls())
.pipe(plugins.g.gFunction(function () {
plugins.beautylog.ok("coverage data has beend uploaded Coveralls!");
}, "atEnd"));
return stream; return stream;
}; };
plugins.beautylog.log("now starting tests");
istanbul().on("finish", function () { istanbul().on("finish", function () {
mocha().on("finish", function () { mocha().on("finish", function () {
if (plugins.smartenv.getEnv().isTravis && config.coveralls) { if (plugins.smartenv.getEnv().isTravis && config.coveralls) {
@ -31,6 +36,7 @@ exports.run = function (configArg) {
}); });
} }
else { else {
plugins.beautylog.ok("Tests have passed!");
done.resolve(config); done.resolve(config);
} }
}); });

View File

@ -36,17 +36,17 @@
"gulp-jsdoc3": "^0.2.0", "gulp-jsdoc3": "^0.2.0",
"gulp-mocha": "^2.2.0", "gulp-mocha": "^2.2.0",
"gulp-sourcemaps": "^1.6.0", "gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "2.11.0", "gulp-typescript": "2.12.1",
"gulp-typings": "1.1.0", "gulp-typings": "1.1.0",
"merge2": "1.0.1", "merge2": "1.0.1",
"projectinfo": "1.0.1", "projectinfo": "1.0.1",
"q": "^1.4.1", "q": "^1.4.1",
"shelljs": "^0.6.0", "shelljs": "^0.6.0",
"smartcli": "0.0.11", "smartcli": "0.0.11",
"smartenv": "1.1.0", "smartenv": "1.2.0",
"smartfile": "0.0.11", "smartfile": "0.0.11",
"source-map-support": "^0.4.0", "smartpath": "2.1.0",
"typings": "^0.6.8" "source-map-support": "^0.4.0"
}, },
"devDependencies": { "devDependencies": {
"gulp-typings": "^1.1.0" "gulp-typings": "^1.1.0"

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

@ -0,0 +1,3 @@
var hello = "hello";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImN1c3RvbS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxJQUFJLEtBQUssR0FBRyxPQUFPLENBQUMiLCJmaWxlIjoiY3VzdG9tLmpzIiwic291cmNlc0NvbnRlbnQiOlsidmFyIGhlbGxvID0gXCJoZWxsb1wiOyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ==

View File

@ -1,13 +1,13 @@
{ {
"mode":"default", "mode":"custom",
"ts":{ "ts":{
"./customdir/*.ts":"./" "./customdir/*.ts":"./"
}, },
"typings":[ "typings":[
"./ts", "./ts/typings.json",
"./subts1/", "./subts1/typings.json",
"./subts2/", "./subts2/typings.json",
"./customdir" "./customdir/typings.json"
], ],
"coveralls":true, "coveralls":true,
"docs": { "docs": {

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

@ -0,0 +1,3 @@
var something = "something";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRzZmlsZTEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSSxTQUFTLEdBQUcsV0FBVyxDQUFDIiwiZmlsZSI6InRzZmlsZTEuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgc29tZXRoaW5nID0gXCJzb21ldGhpbmdcIjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

View File

@ -4,39 +4,13 @@ import paths = require("./npmts.paths");
export var run = function(configArg){ export var run = function(configArg){
var done = plugins.Q.defer(); var done = plugins.Q.defer();
var config = configArg; var config = configArg;
plugins.beautylog.log("now running custom tasks"); plugins.beautylog.log("now compiling " + "TypeScript".yellow);
var moduleStream = plugins.merge2({end: false}); var moduleStream = plugins.merge2({end: false});
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- first install typings --------------- * ----------- compile TypeScript --------------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
var typingsDone = plugins.Q.defer();
var typingsCounter:number = 0;
var typingsCounterAdvance = function(){
typingsCounter++;
if(typeof config.typings[typingsCounter] != "undefined"){
installTypings();
} else {
plugins.beautylog.success("custom typings installed successfully");
typingsDone.resolve();
}
};
var installTypings = function() {
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[typingsCounter])})
.then(function(){
typingsCounterAdvance();
},function(){
plugins.beautylog.error("something went wrong: Check if path is correct: " + config.typings[typingsCounter].blue);
typingsCounterAdvance();
});
};
installTypings();
/* -------------------------------------------------
* ----------- second compile TS -------------------
* ----------------------------------------------- */
typingsDone.promise.then(function(){
for (var key in config.ts) { for (var key in config.ts) {
plugins.beautylog.log("now compiling" + key.blue);
var outputPathIsDir:boolean; var outputPathIsDir:boolean;
try { try {
if(plugins.fs.statSync(plugins.path.join(paths.cwd,config.ts[key])).isDirectory()){ if(plugins.fs.statSync(plugins.path.join(paths.cwd,config.ts[key])).isDirectory()){
@ -81,12 +55,15 @@ export var run = function(configArg){
moduleStream.add(stream); moduleStream.add(stream);
} }
moduleStream.on("queueDrain",function(){ moduleStream.on("queueDrain",function(){
plugins.beautylog.success("custom TypeScript installed successfully"); plugins.beautylog.ok("TypeScript is compiled!");
moduleStream.on("finish",function(){ moduleStream.on("finish",function(){
done.resolve(config); done.resolve(config);
}); });
moduleStream.end(); moduleStream.end();
}); });
}); /*==================== END TYPESCRIPT =====================*/
return done.promise; return done.promise;
}; };

View File

@ -16,6 +16,7 @@ export var run = function(){
break; break;
default: default:
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red); plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
process.exit(1);
}; };
} else { } else {
plugins.beautylog.log("no config file found: so mode is " + "default".yellow); plugins.beautylog.log("no config file found: so mode is " + "default".yellow);

19
ts/npmts.install.ts Normal file
View File

@ -0,0 +1,19 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths");
export var run = function(configArg){
var config = configArg;
var done = plugins.Q.defer();
/* -------------------------------------------------
* ----------- install typings ---------------
* ----------------------------------------------- */
plugins.beautylog.log("now installing " + "typings".yellow);
let absoluteTypingsArray = plugins.smartpath.absolute(config.typings,paths.cwd);
plugins.gulp.src(absoluteTypingsArray)
.pipe(plugins.g.typings())
.pipe(plugins.g.gFunction(function(){
plugins.beautylog.ok("typings are installed!");
done.resolve(config);
},"atEnd"));
return done.promise;
};

View File

@ -14,6 +14,7 @@ var genJsdoc = function(configArg){
destination: paths.docsDir destination: paths.docsDir
} }
}, function(){ }, function(){
plugins.beautylog.ok("JsDoc has been generated!");
done.resolve(configArg) done.resolve(configArg)
})); }));
return done.promise; return done.promise;
@ -48,7 +49,7 @@ var publishDocs = function(configArg){
plugins.beautylog.error('Error: Git failed'); plugins.beautylog.error('Error: Git failed');
plugins.shelljs.exit(1); plugins.shelljs.exit(1);
} }
plugins.beautylog.success("Docs have been deployed to GitHub"); plugins.beautylog.ok("JsDoc has been deployed to GitHub!");
done.resolve(configArg); done.resolve(configArg);
} else { } else {
done.resolve(configArg); done.resolve(configArg);

View File

@ -8,7 +8,7 @@ export var run = function(configArg){
} }
if (config.mode == "default"){ if (config.mode == "default"){
config.typings = [ config.typings = [
"./ts/" "./ts/typings.json"
]; ];
config.ts = { config.ts = {
["./ts/**/*.ts"]: "./dist/", ["./ts/**/*.ts"]: "./dist/",

View File

@ -10,7 +10,8 @@ var plugins = {
jsdoc3: require("gulp-jsdoc3"), jsdoc3: require("gulp-jsdoc3"),
mocha: require("gulp-mocha"), mocha: require("gulp-mocha"),
sourcemaps: require("gulp-sourcemaps"), sourcemaps: require("gulp-sourcemaps"),
typescript: require("gulp-typescript") typescript: require("gulp-typescript"),
typings: require("gulp-typings")
}, },
merge2: require("merge2"), merge2: require("merge2"),
@ -22,6 +23,6 @@ var plugins = {
smartcli: require("smartcli"), smartcli: require("smartcli"),
smartenv: require("smartenv"), smartenv: require("smartenv"),
smartfile: require("smartfile"), smartfile: require("smartfile"),
typings: require("typings") smartpath: require("smartpath")
}; };
export = plugins; export = plugins;

View File

@ -1,6 +1,7 @@
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
import NpmtsConfigFile = require("./npmts.configfile"); import NpmtsConfigFile = require("./npmts.configfile");
import NpmtsOptions = require("./npmts.options"); import NpmtsOptions = require("./npmts.options");
import NpmtsInstall = require("./npmts.install");
import NpmtsCompile = require("./npmts.compile"); import NpmtsCompile = require("./npmts.compile");
import NpmtsJsdoc = require("./npmts.jsdoc"); import NpmtsJsdoc = require("./npmts.jsdoc");
import NpmtsTests = require("./npmts.tests"); import NpmtsTests = require("./npmts.tests");
@ -8,6 +9,7 @@ export var run = function(){
var promisechain; var promisechain;
NpmtsConfigFile.run() NpmtsConfigFile.run()
.then(NpmtsOptions.run) .then(NpmtsOptions.run)
.then(NpmtsInstall.run)
.then(NpmtsCompile.run) .then(NpmtsCompile.run)
.then(NpmtsJsdoc.run) .then(NpmtsJsdoc.run)
.then(NpmtsTests.run); .then(NpmtsTests.run);

View File

@ -26,10 +26,14 @@ export var run = function(configArg) {
var coveralls = function(){ var coveralls = function(){
plugins.beautylog.log("now uploading coverage data to coveralls"); plugins.beautylog.log("now uploading coverage data to coveralls");
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"./coverage/lcov.info")]) var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"./coverage/lcov.info")])
.pipe(plugins.g.coveralls()); .pipe(plugins.g.coveralls())
.pipe(plugins.g.gFunction(function(){
plugins.beautylog.ok("coverage data has beend uploaded Coveralls!");
},"atEnd"));
return stream; return stream;
}; };
plugins.beautylog.log("now starting tests");
istanbul().on("finish",function(){ istanbul().on("finish",function(){
mocha().on("finish",function(){ mocha().on("finish",function(){
if(plugins.smartenv.getEnv().isTravis && config.coveralls){ if(plugins.smartenv.getEnv().isTravis && config.coveralls){
@ -37,6 +41,7 @@ export var run = function(configArg) {
done.resolve(config); done.resolve(config);
}) })
} else { } else {
plugins.beautylog.ok("Tests have passed!");
done.resolve(config); done.resolve(config);
} }
}) })