fixed declaration file issue
This commit is contained in:
parent
1dc8b1aeec
commit
29c941044f
33
README.md
33
README.md
@ -10,6 +10,7 @@ Write npm modules with TypeScript without hassle.
|
|||||||
|
|
||||||
## 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.
|
||||||
|
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:
|
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/)
|
[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
|
### Default task execution order
|
||||||
|
|
||||||
**Execution order of tasks**
|
|
||||||
|
|
||||||
1. Check config in ./npmts.json
|
1. Check config in ./npmts.json
|
||||||
1. Clean up from any previous builds (old js files)
|
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
|
```json
|
||||||
{
|
{
|
||||||
"mode":"default",
|
"mode":"default",
|
||||||
|
"codecov":true,
|
||||||
"ts":{
|
"ts":{
|
||||||
"./customdir/*.ts":"./"
|
"./customdir/*.ts":"./"
|
||||||
},
|
},
|
||||||
|
"docs": {
|
||||||
|
"publish":true,
|
||||||
|
"destination":"github"
|
||||||
|
},
|
||||||
"tsOptions":{
|
"tsOptions":{
|
||||||
"declaration":false,
|
"declaration":false,
|
||||||
"target":"ES6"
|
"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"
|
"./customdir/typings.json"
|
||||||
],
|
],
|
||||||
"typingsInclude":"auto",
|
"typingsInclude":"auto",
|
||||||
"codecov":true,
|
|
||||||
"docs": {
|
|
||||||
"publish":true
|
|
||||||
},
|
|
||||||
"cli":true
|
"cli":true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
| key | description |
|
| key | default value | description |
|
||||||
| --- | --- |
|
| --- | --- | --- |
|
||||||
| codecov | if true, coverage data will be uploaded to codecov when running on travis |
|
| `"codecov"` | `true` | 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 |
|
| `"docs"` | `{"publish":"false"}` | `{"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 |
|
| `"mode"` | `"default"` | "default" will do some defualt stuff, "custom" only does what you specify |
|
||||||
| tsOptions | specify options for tsc |
|
| `"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
|
#### 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/`.
|
||||||
@ -121,8 +122,8 @@ Any errors will be shown with reference to their originating source in TypeScrip
|
|||||||
thanks to autogenerated source maps.
|
thanks to autogenerated source maps.
|
||||||
|
|
||||||
## Example Usage in modules:
|
## Example Usage in modules:
|
||||||
[gulp-typings](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)
|
* [gulp-browser](https://www.npmjs.com/package/gulp-typings)
|
||||||
|
|
||||||
> We will add more options over time.
|
> We will add more options over time.
|
||||||
|
|
||||||
|
42
dist/npmts.compile.js
vendored
42
dist/npmts.compile.js
vendored
@ -3,6 +3,34 @@
|
|||||||
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");
|
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) {
|
exports.run = function (configArg) {
|
||||||
var done = plugins.Q.defer();
|
var done = plugins.Q.defer();
|
||||||
var config = configArg;
|
var config = configArg;
|
||||||
@ -36,16 +64,12 @@ exports.run = function (configArg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
moduleStream.on("queueDrain", function () {
|
moduleStream.on("queueDrain", function () {
|
||||||
plugins.beautylog.ok("TypeScript has been compiled!");
|
|
||||||
moduleStream.on("finish", function () {
|
moduleStream.on("finish", function () {
|
||||||
try {
|
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||||
if (config.mode = "default")
|
definitionHandler(config)
|
||||||
plugins.fs.copySync(plugins.path.join(paths.cwd, "ts/typings"), plugins.path.join(paths.cwd, "dist/typings"));
|
.then(function () {
|
||||||
}
|
done.resolve(config);
|
||||||
catch (err) {
|
});
|
||||||
plugins.beautylog.warn("failed to copy external typings for full module declaration support");
|
|
||||||
}
|
|
||||||
done.resolve(config);
|
|
||||||
});
|
});
|
||||||
moduleStream.end();
|
moduleStream.end();
|
||||||
});
|
});
|
||||||
|
2
dist/npmts.plugins.js
vendored
2
dist/npmts.plugins.js
vendored
@ -9,6 +9,7 @@ exports.g = {
|
|||||||
istanbul: require("gulp-istanbul"),
|
istanbul: require("gulp-istanbul"),
|
||||||
jsdoc3: require("gulp-jsdoc3"),
|
jsdoc3: require("gulp-jsdoc3"),
|
||||||
mocha: require("gulp-mocha"),
|
mocha: require("gulp-mocha"),
|
||||||
|
replace: require("gulp-replace"),
|
||||||
sourcemaps: require("gulp-sourcemaps"),
|
sourcemaps: require("gulp-sourcemaps"),
|
||||||
typescript: require("gulp-typescript"),
|
typescript: require("gulp-typescript"),
|
||||||
typings: require("gulp-typings")
|
typings: require("gulp-typings")
|
||||||
@ -25,4 +26,5 @@ 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.smartstring = require("smartstring");
|
||||||
exports.sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
exports.sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
||||||
|
@ -35,9 +35,10 @@
|
|||||||
"gulp-istanbul": "^0.10.4",
|
"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-replace": "^0.5.4",
|
||||||
"gulp-sourcemaps": "^2.0.0-alpha",
|
"gulp-sourcemaps": "^2.0.0-alpha",
|
||||||
"gulp-typescript": "2.13.0",
|
"gulp-typescript": "2.13.0",
|
||||||
"gulp-typings": "1.3.4",
|
"gulp-typings": "1.3.5",
|
||||||
"lodash": "^4.11.1",
|
"lodash": "^4.11.1",
|
||||||
"merge2": "1.0.2",
|
"merge2": "1.0.2",
|
||||||
"projectinfo": "1.0.1",
|
"projectinfo": "1.0.1",
|
||||||
@ -48,7 +49,8 @@
|
|||||||
"smartcov": "0.0.6",
|
"smartcov": "0.0.6",
|
||||||
"smartenv": "1.2.2",
|
"smartenv": "1.2.2",
|
||||||
"smartfile": "3.0.5",
|
"smartfile": "3.0.5",
|
||||||
"smartpath": "3.1.5",
|
"smartpath": "3.2.0",
|
||||||
|
"smartstring": "^1.0.2",
|
||||||
"source-map-support": "^0.4.0"
|
"source-map-support": "^0.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {}
|
||||||
|
1
test/assets/dist/index.d.ts
vendored
1
test/assets/dist/index.d.ts
vendored
@ -1,4 +1,3 @@
|
|||||||
/// <reference path="typings/main.d.ts" />
|
|
||||||
declare let testplugin: {
|
declare let testplugin: {
|
||||||
logSomething: () => void;
|
logSomething: () => void;
|
||||||
};
|
};
|
||||||
|
1
test/assets/test/test.d.ts
vendored
1
test/assets/test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
/// <reference path="../ts/typings/main.d.ts" />
|
|
||||||
declare var testplugin: any;
|
declare var testplugin: any;
|
||||||
|
@ -4,6 +4,36 @@ import paths = require("./npmts.paths");
|
|||||||
|
|
||||||
import helpers = require("./npmts.compile.helpers");
|
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) {
|
export let run = function (configArg) {
|
||||||
let done = plugins.Q.defer();
|
let done = plugins.Q.defer();
|
||||||
let config = configArg;
|
let config = configArg;
|
||||||
@ -43,18 +73,12 @@ export let run = function (configArg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moduleStream.on("queueDrain", function () {
|
moduleStream.on("queueDrain", function () {
|
||||||
plugins.beautylog.ok("TypeScript has been compiled!");
|
|
||||||
moduleStream.on("finish", function () {
|
moduleStream.on("finish", function () {
|
||||||
try {
|
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||||
if(config.mode = "default") plugins.fs.copySync(
|
definitionHandler(config)
|
||||||
plugins.path.join(paths.cwd,"ts/typings"),
|
.then(function(){
|
||||||
plugins.path.join(paths.cwd,"dist/typings")
|
done.resolve(config);
|
||||||
);
|
});
|
||||||
}
|
|
||||||
catch (err){
|
|
||||||
plugins.beautylog.warn("failed to copy external typings for full module declaration support");
|
|
||||||
}
|
|
||||||
done.resolve(config);
|
|
||||||
});
|
});
|
||||||
moduleStream.end();
|
moduleStream.end();
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ export let g = {
|
|||||||
istanbul: require("gulp-istanbul"),
|
istanbul: require("gulp-istanbul"),
|
||||||
jsdoc3: require("gulp-jsdoc3"),
|
jsdoc3: require("gulp-jsdoc3"),
|
||||||
mocha: require("gulp-mocha"),
|
mocha: require("gulp-mocha"),
|
||||||
|
replace: require("gulp-replace"),
|
||||||
sourcemaps: require("gulp-sourcemaps"),
|
sourcemaps: require("gulp-sourcemaps"),
|
||||||
typescript: require("gulp-typescript"),
|
typescript: require("gulp-typescript"),
|
||||||
typings: require("gulp-typings")
|
typings: require("gulp-typings")
|
||||||
@ -25,4 +26,5 @@ 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 smartstring = require("smartstring");
|
||||||
export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
Loading…
Reference in New Issue
Block a user