diff --git a/README.md b/README.md
index 935e024..f56eec9 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ Write npm modules with TypeScript without hassle.
## What is NPMTS?
NPMTS is your friend when it comes to write, test, publish and document NPM modules written in TypeScript.
+By default NPMTS will **bundle declaration files**. As a result npm module **code completion in editors like Visual Studio Code** works.
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/)
@@ -29,9 +30,7 @@ Then use it in package.json's script section to trigger a build:
}
```
-### Default behaviour
-
-**Execution order of tasks**
+### Default task execution order
1. Check config in ./npmts.json
1. Clean up from any previous builds (old js files)
@@ -51,9 +50,14 @@ the npmts.json is the main config file. You can use it to customize the behaviou
```json
{
"mode":"default",
+ "codecov":true,
"ts":{
"./customdir/*.ts":"./"
},
+ "docs": {
+ "publish":true,
+ "destination":"github"
+ },
"tsOptions":{
"declaration":false,
"target":"ES6"
@@ -65,21 +69,18 @@ the npmts.json is the main config file. You can use it to customize the behaviou
"./customdir/typings.json"
],
"typingsInclude":"auto",
- "codecov":true,
- "docs": {
- "publish":true
- },
"cli":true
}
```
-| key | description |
-| --- | --- |
-| codecov | if true, coverage data will be uploaded to codecov when running on travis |
-| docs | `{"publish":true, destination:"github"}` lets you control what happens with your module documentation |
-| mode | "default" will do some defualt stuff, "custom" only does what you specify |
-| tsOptions | specify options for tsc |
-| | |
+| key | default value | description |
+| --- | --- | --- |
+| `"codecov"` | `true` | if true, coverage data will be uploaded to codecov when running on travis |
+| `"docs"` | `{"publish":"false"}` | `{"publish":true, destination:"github"}` lets you control what happens with your module documentation |
+| `"mode"` | `"default"` | "default" will do some defualt stuff, "custom" only does what you specify |
+| `"tsOptions"` | `{"target":"ES5", "declaration":"true"}` | specify options for tsc |
+| `"typings"` | `["./ts/typings.json"]` | allows you to specify multiple locations for typings.json to install. This is needed for modules that do not yet bundle typings |
+| `"cli"` | "false" | some modules are designed to be used from cli. If set to true NPMTS will create a cli.js that wires you dist files up for cli use. |
#### Typings
**npmts** looks for `./ts/typings.json` by default and installs any defined typings to `.ts/typings/`.
@@ -121,8 +122,8 @@ Any errors will be shown with reference to their originating source in TypeScrip
thanks to autogenerated source maps.
## Example Usage in modules:
-[gulp-typings](https://www.npmjs.com/package/gulp-typings)
-[gulp-browser](https://www.npmjs.com/package/gulp-typings)
+* [gulp-typings](https://www.npmjs.com/package/gulp-typings)
+* [gulp-browser](https://www.npmjs.com/package/gulp-typings)
> We will add more options over time.
diff --git a/dist/npmts.compile.js b/dist/npmts.compile.js
index e3c59a1..aa93bd2 100644
--- a/dist/npmts.compile.js
+++ b/dist/npmts.compile.js
@@ -3,6 +3,34 @@
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
var helpers = require("./npmts.compile.helpers");
+/**
+ * handles definition to make them fit for modular use
+ */
+var definitionHandler = function (configArg) {
+ plugins.beautylog.log("now making declaration files ready");
+ var done = plugins.Q.defer();
+ var configTsLenght = Object.keys(configArg.ts).length;
+ if (configTsLenght == 0) {
+ plugins.beautylog.warn("No declaration files found... Are you sure you don't want them?");
+ done.resolve(configArg); //if there are no definition files, resolve...
+ }
+ var localCounter = 0;
+ for (var key in configArg.ts) {
+ var distPath = configArg.ts[key];
+ var stream = plugins.gulp.src(plugins.path.join(distPath, "**/*.d.ts"))
+ .pipe(plugins.g.replace(plugins.smartstring.typescript.regexReferencePath, ""))
+ .pipe(plugins.gulp.dest(distPath))
+ .pipe(plugins.g.gFunction(function () {
+ localCounter++;
+ if (localCounter == configTsLenght) {
+ plugins.beautylog.ok("declaration files ready!!!");
+ done.resolve(configArg);
+ }
+ ;
+ }, "atEnd"));
+ }
+ return done.promise;
+};
exports.run = function (configArg) {
var done = plugins.Q.defer();
var config = configArg;
@@ -36,16 +64,12 @@ exports.run = function (configArg) {
}
}
moduleStream.on("queueDrain", function () {
- plugins.beautylog.ok("TypeScript has been compiled!");
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);
+ plugins.beautylog.ok("TypeScript has been compiled!");
+ definitionHandler(config)
+ .then(function () {
+ done.resolve(config);
+ });
});
moduleStream.end();
});
diff --git a/dist/npmts.plugins.js b/dist/npmts.plugins.js
index 5346c7d..25e877c 100644
--- a/dist/npmts.plugins.js
+++ b/dist/npmts.plugins.js
@@ -9,6 +9,7 @@ exports.g = {
istanbul: require("gulp-istanbul"),
jsdoc3: require("gulp-jsdoc3"),
mocha: require("gulp-mocha"),
+ replace: require("gulp-replace"),
sourcemaps: require("gulp-sourcemaps"),
typescript: require("gulp-typescript"),
typings: require("gulp-typings")
@@ -25,4 +26,5 @@ exports.smartcov = require("smartcov");
exports.smartenv = require("smartenv");
exports.smartfile = require("smartfile");
exports.smartpath = require("smartpath");
+exports.smartstring = require("smartstring");
exports.sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
diff --git a/package.json b/package.json
index 9027802..7c99b56 100644
--- a/package.json
+++ b/package.json
@@ -35,9 +35,10 @@
"gulp-istanbul": "^0.10.4",
"gulp-jsdoc3": "^0.2.1",
"gulp-mocha": "^2.2.0",
+ "gulp-replace": "^0.5.4",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-typescript": "2.13.0",
- "gulp-typings": "1.3.4",
+ "gulp-typings": "1.3.5",
"lodash": "^4.11.1",
"merge2": "1.0.2",
"projectinfo": "1.0.1",
@@ -48,7 +49,8 @@
"smartcov": "0.0.6",
"smartenv": "1.2.2",
"smartfile": "3.0.5",
- "smartpath": "3.1.5",
+ "smartpath": "3.2.0",
+ "smartstring": "^1.0.2",
"source-map-support": "^0.4.0"
},
"devDependencies": {}
diff --git a/test/assets/dist/index.d.ts b/test/assets/dist/index.d.ts
index 0792d3e..2ca7215 100644
--- a/test/assets/dist/index.d.ts
+++ b/test/assets/dist/index.d.ts
@@ -1,4 +1,3 @@
-///
declare let testplugin: {
logSomething: () => void;
};
diff --git a/test/assets/test/test.d.ts b/test/assets/test/test.d.ts
index cca223f..c408306 100644
--- a/test/assets/test/test.d.ts
+++ b/test/assets/test/test.d.ts
@@ -1,2 +1 @@
-///
declare var testplugin: any;
diff --git a/ts/npmts.compile.ts b/ts/npmts.compile.ts
index c57be38..ae111fa 100644
--- a/ts/npmts.compile.ts
+++ b/ts/npmts.compile.ts
@@ -4,6 +4,36 @@ import paths = require("./npmts.paths");
import helpers = require("./npmts.compile.helpers");
+/**
+ * handles definition to make them fit for modular use
+ */
+let definitionHandler = function(configArg){
+ plugins.beautylog.log("now making declaration files ready");
+ let done = plugins.Q.defer();
+ let configTsLenght = Object.keys(configArg.ts).length;
+ if(configTsLenght == 0) {
+ plugins.beautylog.warn("No declaration files found... Are you sure you don't want them?");
+ done.resolve(configArg); //if there are no definition files, resolve...
+ }
+ let localCounter = 0;
+ for (let key in configArg.ts){
+ let distPath = configArg.ts[key];
+ let stream = plugins.gulp.src(plugins.path.join(distPath,"**/*.d.ts"))
+ .pipe(plugins.g.replace(plugins.smartstring.typescript.regexReferencePath,""))
+ .pipe(plugins.gulp.dest(distPath))
+ .pipe(plugins.g.gFunction(function(){
+ localCounter++
+ if(localCounter == configTsLenght){
+ plugins.beautylog.ok("declaration files ready!!!");
+ done.resolve(configArg)
+ };
+ },"atEnd"));
+
+ }
+ return done.promise;
+}
+
+
export let run = function (configArg) {
let done = plugins.Q.defer();
let config = configArg;
@@ -43,18 +73,12 @@ export let run = function (configArg) {
}
moduleStream.on("queueDrain", function () {
- plugins.beautylog.ok("TypeScript has been compiled!");
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);
+ plugins.beautylog.ok("TypeScript has been compiled!");
+ definitionHandler(config)
+ .then(function(){
+ done.resolve(config);
+ });
});
moduleStream.end();
});
diff --git a/ts/npmts.plugins.ts b/ts/npmts.plugins.ts
index adc7419..6e41014 100644
--- a/ts/npmts.plugins.ts
+++ b/ts/npmts.plugins.ts
@@ -8,6 +8,7 @@ export let g = {
istanbul: require("gulp-istanbul"),
jsdoc3: require("gulp-jsdoc3"),
mocha: require("gulp-mocha"),
+ replace: require("gulp-replace"),
sourcemaps: require("gulp-sourcemaps"),
typescript: require("gulp-typescript"),
typings: require("gulp-typings")
@@ -25,4 +26,5 @@ export let smartcov = require("smartcov");
export let smartenv = require("smartenv");
export let smartfile = require("smartfile");
export let smartpath = require("smartpath");
+export let smartstring = require("smartstring");
export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
\ No newline at end of file