Compare commits

...

20 Commits

Author SHA1 Message Date
6dad1c3d85 5.1.1 2016-04-30 12:25:52 +02:00
7d9b9b2d1d now makes TypeScript modules fully typed by default 2016-04-30 12:25:35 +02:00
e3e6a326b5 5.1.0 2016-04-30 11:56:45 +02:00
3d59f6d393 now reading tsOptions from tsConfig and supporting declaration file handling 2016-04-30 11:55:42 +02:00
07d752449e clean up TypeScript compilation handling 2016-04-30 05:49:53 +02:00
ea779add20 5.0.4 2016-04-09 11:35:42 +02:00
938a7bd872 some improvement in handling projects that do not follow npmts conventions 2016-04-09 11:35:29 +02:00
45f9674550 5.0.3 2016-04-05 00:54:19 +02:00
eae983b271 now everything working again 2016-04-05 00:54:01 +02:00
871990725d 5.0.2 2016-04-05 00:45:56 +02:00
d46bb18893 update deps 2016-04-05 00:45:50 +02:00
d8fb9747cd 5.0.1 2016-04-05 00:31:25 +02:00
53209b18a9 update des 2016-04-05 00:31:17 +02:00
3e3561f4bb 5.0.0 2016-04-04 23:19:50 +02:00
099b513e0a update deps 2016-04-04 23:19:34 +02:00
cf15c428c1 4.0.3 2016-04-04 22:58:08 +02:00
3bd876a201 update deps 2016-04-04 22:57:50 +02:00
af62f20614 4.0.2 2016-04-04 16:57:13 +02:00
69eba08b27 updated log message 2016-04-04 16:57:09 +02:00
6635265f4b added codecov badge 2016-04-02 19:36:46 +02:00
17 changed files with 189 additions and 116 deletions

View File

@ -6,11 +6,14 @@ Write npm modules with TypeScript without hassle.
[![Dependency Status](https://david-dm.org/pushrocks/npmts.svg)](https://david-dm.org/pushrocks/npmts) [![Dependency Status](https://david-dm.org/pushrocks/npmts.svg)](https://david-dm.org/pushrocks/npmts)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/npmts/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/npmts/master/dependencies/npm) [![bitHound Dependencies](https://www.bithound.io/github/pushrocks/npmts/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/npmts/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/npmts/badges/code.svg)](https://www.bithound.io/github/pushrocks/npmts) [![bitHound Code](https://www.bithound.io/github/pushrocks/npmts/badges/code.svg)](https://www.bithound.io/github/pushrocks/npmts)
[![Coverage Status](https://coveralls.io/repos/github/pushrocks/npmts/badge.svg?branch=master)](https://coveralls.io/github/pushrocks/npmts?branch=master) [![codecov.io](https://codecov.io/github/pushrocks/npmts/coverage.svg?branch=master)](https://codecov.io/github/pushrocks/npmts?branch=master)
## What is NPMTS? ## What is NPMTS?
NPMTS is your friend when it comes to write, test, publish and document NPM modules written in TypeScript. NPMTS is your friend when it comes to write, test, publish and document NPM modules written in TypeScript.
There is a docker image available that includes npmts to make CI a breeze:
[hosttoday/ht-docker-npmg on Dockerhub](https://hub.docker.com/r/hosttoday/ht-docker-npmg/)
### Install ### Install
First install npmts as dev dependency: First install npmts as dev dependency:
@ -45,9 +48,41 @@ Then use it in package.json's script section to trigger a build:
#### npmts.json #### npmts.json
the npmts.json is the main config file. You can use it to customize the behaviour of NPMTS. the npmts.json is the main config file. You can use it to customize the behaviour of NPMTS.
```json
{
"mode":"default",
"ts":{
"./customdir/*.ts":"./"
},
"tsconfig":true,
"typings":[
"./ts/typings.json",
"./subts1/typings.json",
"./subts2/typings.json",
"./customdir/typings.json"
],
"codecov":true,
"docs": {
"publish":true
},
"cli":true
}
```
| key | description |
| --- | --- |
| mode | "default" will do some defualt stuff, "custom" only does what you specify |
| codecov | if true, coverage data will be uploaded to codecov when running on travis |
| docs | `{"publish":true}` lets you control what happens with your module documentation |
| | |
| | |
#### Typings #### Typings
**npmts** looks for `./ts/typings.json` by default and installs any defined typings to `.ts/typings/`. **npmts** looks for `./ts/typings.json` by default and installs any defined typings to `.ts/typings/`.
You can then reference the ./ts/typings/main.d.ts file in any of your TypeScript code.
> Note: You can reference the typings files in any of your TypeScript code with a
`/// <reference path="/some/path/main.d.ts">`
or use a tsconfig.json file.
#### TypeScript #### TypeScript
by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to
@ -56,14 +91,15 @@ by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to
Use commonjs module system for wiring up files. Use commonjs module system for wiring up files.
#### Declaration files #### Declaration files
**npmts** also creates an `index.d.ts` declaration file by default. **npmts** also creates an `./dist/index.d.ts` declaration file by default.
You can reference it in your package.json like this: You can reference it in your package.json like this.
```json ```json
"main": "index.js", "main": "dist/index.js",
"typings": "./index.d.ts", "typings": ".dist/index.d.ts",
``` ```
This is in line with the latest TypeScript best practices.
You can then import plugins via the TypeScript `import` Syntax You can then import plugins via the TypeScript `import` Syntax
and tsc will pick up the declaration file automatically. and tsc will pick up the declaration file automatically.

16
dist/npmts.compile.helpers.js vendored Normal file
View File

@ -0,0 +1,16 @@
"use strict";
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
var outputPathIsDir = function (configArg, keyArg) {
return plugins.smartpath.check.isDir(plugins.path.join(paths.cwd, configArg.ts[keyArg]));
};
exports.checkOutputPath = function (configArg, keyArg) {
if (!outputPathIsDir(configArg, keyArg)) {
plugins.beautylog.warn("Skipping " + keyArg + " because " + configArg.ts[keyArg] + " it is no directory!");
return false;
}
else {
return true;
}
;
};

70
dist/npmts.compile.js vendored
View File

@ -2,6 +2,7 @@
/// <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");
var helpers = require("./npmts.compile.helpers");
exports.run = function (configArg) { exports.run = function (configArg) {
var done = plugins.Q.defer(); var done = plugins.Q.defer();
var config = configArg; var config = configArg;
@ -10,53 +11,44 @@ exports.run = function (configArg) {
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- compile TypeScript -------------------------- * ----------- compile TypeScript --------------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
for (var key in config.ts) { var tsOptionsDefault = {
var outputPathIsDir; declaration: true,
try { target: "ES5",
if (plugins.fs.statSync(plugins.path.join(paths.cwd, config.ts[key])).isDirectory()) { module: "commonjs"
outputPathIsDir = true; };
} /**
* merges default ts options with those found in npmts.json
*/
var tsOptions = function (keyArg) {
return plugins.lodashObject.assign(tsOptionsDefault, config.tsOptions);
};
for (var keyArg in config.ts) {
if (helpers.checkOutputPath(config, keyArg)) {
var tsStream = plugins.gulp.src([plugins.path.join(paths.cwd, keyArg), "!**/typings/**"])
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
.pipe(plugins.g.typescript(tsOptions(keyArg)));
var jsStream = tsStream.js
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(plugins.gulp.dest(config.ts[keyArg]));
var declarationStream = tsStream.dts
.pipe(plugins.gulp.dest(config.ts[keyArg]));
moduleStream.add(tsStream, jsStream, declarationStream);
} }
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 stream = plugins.gulp.src([plugins.path.join(paths.cwd, key), "!**/typings/**"])
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
.pipe(plugins.g.typescript({
out: outputName,
target: "ES5",
module: "commonjs"
}))
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(plugins.gulp.dest(outputDir));
moduleStream.add(stream);
} }
moduleStream.on("queueDrain", function () { moduleStream.on("queueDrain", function () {
plugins.beautylog.ok("TypeScript has been compiled!"); plugins.beautylog.ok("TypeScript has been compiled!");
moduleStream.on("finish", function () { moduleStream.on("finish", function () {
try {
if (config.mode = "default")
plugins.fs.copySync(plugins.path.join(paths.cwd, "ts/typings"), plugins.path.join(paths.cwd, "dist/typings"));
}
catch (err) {
plugins.beautylog.warn("failed to copy external typings for full module declaration support");
}
done.resolve(config); done.resolve(config);
}); });
moduleStream.end(); moduleStream.end();
}); });
/*==================== END TYPESCRIPT =====================*/ /*==================== END TS Compilation =====================*/
return done.promise; return done.promise;
}; };

View File

@ -28,6 +28,8 @@ exports.run = function (configArg) {
); );
config.test = ["./index.js"]; config.test = ["./index.js"];
} }
//check if config.tsOptions is available
config.tsOptions ? void (0) : config.tsOptions = {};
// handle state of current build // handle state of current build
exports.isRelease() ? plugins.beautylog.info("All right: This is a RELEASE build!") exports.isRelease() ? plugins.beautylog.info("All right: This is a RELEASE build!")
: plugins.beautylog.info("NOT A RELEASE build!"); : plugins.beautylog.info("NOT A RELEASE build!");

View File

@ -13,6 +13,7 @@ exports.g = {
typescript: require("gulp-typescript"), typescript: require("gulp-typescript"),
typings: require("gulp-typings") typings: require("gulp-typings")
}; };
exports.lodashObject = require('lodash/fp/object');
exports.merge2 = require("merge2"); exports.merge2 = require("merge2");
exports.projectinfo = require("projectinfo"); exports.projectinfo = require("projectinfo");
exports.path = require("path"); exports.path = require("path");
@ -24,4 +25,4 @@ exports.smartcov = require("smartcov");
exports.smartenv = require("smartenv"); exports.smartenv = require("smartenv");
exports.smartfile = require("smartfile"); exports.smartfile = require("smartfile");
exports.smartpath = require("smartpath"); exports.smartpath = require("smartpath");
exports.sourceMapSupport = require("source-map-support").install(); exports.sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing

4
dist/npmts.tests.js vendored
View File

@ -4,11 +4,11 @@ var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths"); var paths = require("./npmts.paths");
exports.publishCoverage = function (configArg) { exports.publishCoverage = function (configArg) {
var done = plugins.Q.defer(); var done = plugins.Q.defer();
plugins.beautylog.log("now uploading coverage data to coveralls"); plugins.beautylog.log("now uploading coverage data to codecov.io");
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.codecov()) .pipe(plugins.g.codecov())
.pipe(plugins.g.gFunction(function () { .pipe(plugins.g.gFunction(function () {
plugins.beautylog.ok("Coverage data has been uploaded to Coveralls!"); plugins.beautylog.ok("Coverage data has been uploaded to codecov.io!");
done.resolve(configArg); done.resolve(configArg);
}, "atEnd")); }, "atEnd"));
return done.promise; return done.promise;

View File

@ -1,6 +1,6 @@
{ {
"name": "npmts", "name": "npmts",
"version": "4.0.1", "version": "5.1.1",
"description": "write npm modules with TypeScript", "description": "write npm modules with TypeScript",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {
@ -25,29 +25,30 @@
}, },
"homepage": "https://github.com/pushrocks/npmts#readme", "homepage": "https://github.com/pushrocks/npmts#readme",
"dependencies": { "dependencies": {
"beautylog": "3.1.2", "beautylog": "4.1.2",
"fs-extra": "^0.26.7", "fs-extra": "^0.30.0",
"gulp": "3.9.1", "gulp": "3.9.1",
"gulp-codecov": "^2.0.1", "gulp-codecov": "^2.0.1",
"gulp-concat": "^2.6.0", "gulp-concat": "^2.6.0",
"gulp-function": "^1.2.0", "gulp-function": "^1.3.1",
"gulp-if": "^2.0.0", "gulp-if": "^2.0.0",
"gulp-istanbul": "^0.10.3", "gulp-istanbul": "^0.10.4",
"gulp-jsdoc3": "^0.2.1", "gulp-jsdoc3": "^0.2.1",
"gulp-mocha": "^2.2.0", "gulp-mocha": "^2.2.0",
"gulp-sourcemaps": "^1.6.0", "gulp-sourcemaps": "^2.0.0-alpha",
"gulp-typescript": "2.12.1", "gulp-typescript": "2.13.0",
"gulp-typings": "1.3.0", "gulp-typings": "1.3.4",
"merge2": "1.0.1", "lodash": "^4.11.1",
"merge2": "1.0.2",
"projectinfo": "1.0.1", "projectinfo": "1.0.1",
"q": "^1.4.1", "q": "^1.4.1",
"shelljs": "^0.6.0", "shelljs": "^0.7.0",
"smartci": "0.0.1", "smartci": "0.0.1",
"smartcli": "0.0.11", "smartcli": "0.0.11",
"smartcov": "0.0.4", "smartcov": "0.0.6",
"smartenv": "1.2.0", "smartenv": "1.2.2",
"smartfile": "2.2.0", "smartfile": "3.0.5",
"smartpath": "3.0.3", "smartpath": "3.1.5",
"source-map-support": "^0.4.0" "source-map-support": "^0.4.0"
}, },
"devDependencies": {} "devDependencies": {}

4
test/assets/dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/// <reference path="typings/main.d.ts" />
declare let testplugin: {
logSomething: () => void;
};

View File

@ -6,4 +6,4 @@ var testplugin = {
}; };
module.exports = testplugin; module.exports = testplugin;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFJLFVBQVUsR0FBRztJQUNiLFlBQVksRUFBRTtRQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0osQ0FBQztBQUNGLE1BQU0sQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxubGV0IHRlc3RwbHVnaW4gPSB7XG4gICAgbG9nU29tZXRoaW5nOiBmdW5jdGlvbigpe1xuICAgICAgICBjb25zb2xlLmxvZyhcIm9ubHkgZnVuY3Rpb24gZXhlY3V0ZWRcIik7XG4gICAgfVxufTtcbm1vZHVsZS5leHBvcnRzID0gdGVzdHBsdWdpbjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFJLFVBQVUsR0FBRztJQUNiLFlBQVksRUFBRTtRQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0osQ0FBQztBQUNGLE1BQU0sQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxubGV0IHRlc3RwbHVnaW4gPSB7XG4gICAgbG9nU29tZXRoaW5nOiBmdW5jdGlvbigpe1xuICAgICAgICBjb25zb2xlLmxvZyhcIm9ubHkgZnVuY3Rpb24gZXhlY3V0ZWRcIik7XG4gICAgfVxufTtcbm1vZHVsZS5leHBvcnRzID0gdGVzdHBsdWdpbjsiXX0=

View File

@ -3,6 +3,9 @@
"ts":{ "ts":{
"./customdir/*.ts":"./" "./customdir/*.ts":"./"
}, },
"tsOptions":{
"target":"ES5"
},
"typings":[ "typings":[
"./ts/typings.json", "./ts/typings.json",
"./subts1/typings.json", "./subts1/typings.json",

2
test/assets/test/test.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference path="../ts/typings/main.d.ts" />
declare var testplugin: any;

View File

@ -8,4 +8,4 @@ describe("testplugins", function () {
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzdDLFFBQVEsQ0FBQyxhQUFhLEVBQUM7SUFDbkIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzdDLFFBQVEsQ0FBQyxhQUFhLEVBQUM7SUFDbkIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXX0=

View File

@ -0,0 +1,15 @@
import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths");
let outputPathIsDir = function (configArg,keyArg) {
return plugins.smartpath.check.isDir(plugins.path.join(paths.cwd, configArg.ts[keyArg]));
};
export let checkOutputPath = function(configArg,keyArg){
if(!outputPathIsDir(configArg,keyArg)) {
plugins.beautylog.warn("Skipping " + keyArg + " because " + configArg.ts[keyArg] + " it is no directory!")
return false
} else {
return true;
};
}

View File

@ -1,67 +1,64 @@
/// <reference path="./typings/main.d.ts" /> /// <reference path="./typings/main.d.ts" />
import plugins = require("./npmts.plugins"); import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths"); import paths = require("./npmts.paths");
export var run = function(configArg){
var done = plugins.Q.defer(); import helpers = require("./npmts.compile.helpers");
var config = configArg;
export let run = function (configArg) {
let done = plugins.Q.defer();
let config = configArg;
plugins.beautylog.log("now compiling " + "TypeScript".yellow); plugins.beautylog.log("now compiling " + "TypeScript".yellow);
var moduleStream = plugins.merge2({end: false}); let moduleStream = plugins.merge2({ end: false });
/* ------------------------------------------------- /* -------------------------------------------------
* ----------- compile TypeScript -------------------------- * ----------- compile TypeScript --------------------------
* ----------------------------------------------- */ * ----------------------------------------------- */
for (var key in config.ts) {
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 stream = plugins.gulp.src([plugins.path.join(paths.cwd,key),"!**/typings/**"]) let tsOptionsDefault = {
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated declaration: true,
.pipe(plugins.g.typescript({ target: "ES5",
out: outputName, module: "commonjs"
target: "ES5", };
module: "commonjs"
})) /**
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file * merges default ts options with those found in npmts.json
//.pipe(plugins.g.header('#!/usr/bin/env node\n\n')) */
.pipe(plugins.gulp.dest(outputDir)); let tsOptions = function (keyArg:string) {
moduleStream.add(stream); return plugins.lodashObject.assign(tsOptionsDefault, config.tsOptions)
};
for (let keyArg in config.ts) {
if (helpers.checkOutputPath(config,keyArg)) {
let tsStream = plugins.gulp.src([plugins.path.join(paths.cwd, keyArg), "!**/typings/**"])
.pipe(plugins.g.sourcemaps.init()) // This means sourcemaps will be generated
.pipe(plugins.g.typescript(tsOptions(keyArg)));
let jsStream = tsStream.js
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(plugins.gulp.dest(config.ts[keyArg]));
let declarationStream = tsStream.dts
.pipe(plugins.gulp.dest(config.ts[keyArg]));
moduleStream.add(tsStream,jsStream,declarationStream);
}
} }
moduleStream.on("queueDrain",function(){
moduleStream.on("queueDrain", function () {
plugins.beautylog.ok("TypeScript has been compiled!"); plugins.beautylog.ok("TypeScript has been compiled!");
moduleStream.on("finish",function(){ moduleStream.on("finish", function () {
try {
if(config.mode = "default") plugins.fs.copySync(
plugins.path.join(paths.cwd,"ts/typings"),
plugins.path.join(paths.cwd,"dist/typings")
);
}
catch (err){
plugins.beautylog.warn("failed to copy external typings for full module declaration support");
}
done.resolve(config); done.resolve(config);
}); });
moduleStream.end(); moduleStream.end();
}); });
/*==================== END TYPESCRIPT =====================*/ /*==================== END TS Compilation =====================*/

View File

@ -32,6 +32,9 @@ export var run = function(configArg){
}; };
config.test = ["./index.js"]; config.test = ["./index.js"];
} }
//check if config.tsOptions is available
config.tsOptions ? void(0) : config.tsOptions = {};
// handle state of current build // handle state of current build

View File

@ -13,6 +13,7 @@ export let g = {
typings: require("gulp-typings") typings: require("gulp-typings")
}; };
export let lodashObject = require('lodash/fp/object');
export let merge2 = require("merge2"); export let merge2 = require("merge2");
export let projectinfo = require("projectinfo"); export let projectinfo = require("projectinfo");
export let path = require("path"); export let path = require("path");
@ -24,4 +25,4 @@ export let smartcov = require("smartcov");
export let smartenv = require("smartenv"); export let smartenv = require("smartenv");
export let smartfile = require("smartfile"); export let smartfile = require("smartfile");
export let smartpath = require("smartpath"); export let smartpath = require("smartpath");
export let sourceMapSupport = require("source-map-support").install(); export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing

View File

@ -4,11 +4,11 @@ import paths = require("./npmts.paths");
export let publishCoverage = function(configArg){ export let publishCoverage = function(configArg){
let done = plugins.Q.defer(); let done = plugins.Q.defer();
plugins.beautylog.log("now uploading coverage data to coveralls"); plugins.beautylog.log("now uploading coverage data to codecov.io");
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.codecov()) .pipe(plugins.g.codecov())
.pipe(plugins.g.gFunction(function(){ .pipe(plugins.g.gFunction(function(){
plugins.beautylog.ok("Coverage data has been uploaded to Coveralls!"); plugins.beautylog.ok("Coverage data has been uploaded to codecov.io!");
done.resolve(configArg); done.resolve(configArg);
},"atEnd")); },"atEnd"));
return done.promise; return done.promise;