Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
995161dd54 | |||
29c941044f | |||
1dc8b1aeec | |||
a0c83c8f48 | |||
b6e63664bb | |||
88b39213a6 | |||
6dad1c3d85 | |||
7d9b9b2d1d | |||
e3e6a326b5 | |||
3d59f6d393 | |||
07d752449e | |||
ea779add20 | |||
938a7bd872 | |||
45f9674550 | |||
eae983b271 | |||
871990725d | |||
d46bb18893 | |||
d8fb9747cd | |||
53209b18a9 |
85
README.md
85
README.md
@ -10,6 +10,10 @@ 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:
|
||||||
|
[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:
|
||||||
@ -26,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)
|
||||||
@ -45,9 +47,48 @@ 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",
|
||||||
|
"codecov":true,
|
||||||
|
"ts":{
|
||||||
|
"./customdir/*.ts":"./"
|
||||||
|
},
|
||||||
|
"docs": {
|
||||||
|
"publish":true,
|
||||||
|
"destination":"github"
|
||||||
|
},
|
||||||
|
"tsOptions":{
|
||||||
|
"declaration":false,
|
||||||
|
"target":"ES6"
|
||||||
|
},
|
||||||
|
"typings":[
|
||||||
|
"./ts/typings.json",
|
||||||
|
"./subts1/typings.json",
|
||||||
|
"./subts2/typings.json",
|
||||||
|
"./customdir/typings.json"
|
||||||
|
],
|
||||||
|
"typingsInclude":"auto",
|
||||||
|
"cli":true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| 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
|
#### 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">`
|
||||||
|
We are currently working on a "typingsInclude" option, that will autoload any typings during compilation.
|
||||||
|
tsconfig is NOT supported, since it would render this module useless
|
||||||
|
|
||||||
#### 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,17 +97,20 @@ 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.
|
||||||
|
|
||||||
|
> Note: If you don't want declaration files, set tsOptions.declaration to false in npmts.json
|
||||||
|
|
||||||
#### Instrumentalize Code
|
#### Instrumentalize Code
|
||||||
npmts instrumentalizes (using istanbul) the created JavaScript code to create a coverage report.
|
npmts instrumentalizes (using istanbul) the created JavaScript code to create a coverage report.
|
||||||
|
|
||||||
@ -77,30 +121,13 @@ npmts looks for `.test/test.ts` which will be transpiled to test.js and run with
|
|||||||
Any errors will be shown with reference to their originating source in TypeScript
|
Any errors will be shown with reference to their originating source in TypeScript
|
||||||
thanks to autogenerated source maps.
|
thanks to autogenerated source maps.
|
||||||
|
|
||||||
|
## Example Usage in modules:
|
||||||
### Custom behaviour
|
* [gulp-typings](https://www.npmjs.com/package/gulp-typings)
|
||||||
Custom behaviour can be achieved through the npmts.json config file at the root of your package.
|
* [gulp-browser](https://www.npmjs.com/package/gulp-typings)
|
||||||
The file must be named **npmts.json**
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"mode":"custom",
|
|
||||||
"ts":{
|
|
||||||
"./customdir/custom.ts":"./customcompiled.js"
|
|
||||||
},
|
|
||||||
"typings":[
|
|
||||||
"./customdir"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
* **mode** can be "default" or "custom"
|
|
||||||
* **ts** You can list as many TypeScript files as you like. The key represents the source TypeScript file, the value the output file.
|
|
||||||
* **typings** is an array of all direcories that have a typings.json present. Uses the new typings tool from npm.
|
|
||||||
|
|
||||||
> We will add more options over time.
|
> We will add more options over time.
|
||||||
|
|
||||||
### About the authors:
|
## About the authors:
|
||||||
[](https://lossless.com/)
|
[](https://lossless.com/)
|
||||||
|
|
||||||
[](https://paypal.me/lossless)
|
[](https://paypal.me/lossless)
|
16
dist/npmts.compile.helpers.js
vendored
Normal file
16
dist/npmts.compile.helpers.js
vendored
Normal 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;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
};
|
92
dist/npmts.compile.js
vendored
92
dist/npmts.compile.js
vendored
@ -2,6 +2,35 @@
|
|||||||
/// <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");
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
@ -10,53 +39,40 @@ exports.run = function (configArg) {
|
|||||||
/* -------------------------------------------------
|
/* -------------------------------------------------
|
||||||
* ----------- compile TypeScript --------------------------
|
* ----------- compile TypeScript --------------------------
|
||||||
* ----------------------------------------------- */
|
* ----------------------------------------------- */
|
||||||
for (var key in config.ts) {
|
var tsOptionsDefault = {
|
||||||
var outputPathIsDir;
|
declaration: true,
|
||||||
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 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",
|
target: "ES5",
|
||||||
module: "commonjs"
|
module: "commonjs"
|
||||||
}))
|
};
|
||||||
|
/**
|
||||||
|
* 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.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||||
.pipe(plugins.gulp.dest(outputDir));
|
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
||||||
moduleStream.add(stream);
|
var 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!");
|
|
||||||
moduleStream.on("finish", function () {
|
moduleStream.on("finish", function () {
|
||||||
|
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||||
|
definitionHandler(config)
|
||||||
|
.then(function () {
|
||||||
done.resolve(config);
|
done.resolve(config);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
moduleStream.end();
|
moduleStream.end();
|
||||||
});
|
});
|
||||||
/*==================== END TYPESCRIPT =====================*/
|
/*==================== END TS Compilation =====================*/
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
|
2
dist/npmts.options.js
vendored
2
dist/npmts.options.js
vendored
@ -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!");
|
||||||
|
5
dist/npmts.plugins.js
vendored
5
dist/npmts.plugins.js
vendored
@ -9,10 +9,12 @@ 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")
|
||||||
};
|
};
|
||||||
|
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 +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.sourceMapSupport = require("source-map-support").install();
|
exports.smartstring = require("smartstring");
|
||||||
|
exports.sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
||||||
|
29
package.json
29
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "npmts",
|
"name": "npmts",
|
||||||
"version": "5.0.0",
|
"version": "5.1.4",
|
||||||
"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,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/npmts#readme",
|
"homepage": "https://github.com/pushrocks/npmts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "4.0.0",
|
"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-replace": "^0.5.4",
|
||||||
"gulp-typescript": "2.12.2",
|
"gulp-sourcemaps": "^2.0.0-alpha",
|
||||||
"gulp-typings": "1.3.0",
|
"gulp-typescript": "2.13.0",
|
||||||
|
"gulp-typings": "1.3.5",
|
||||||
|
"lodash": "^4.11.1",
|
||||||
"merge2": "1.0.2",
|
"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.1",
|
"smartenv": "1.2.2",
|
||||||
"smartfile": "2.3.0",
|
"smartfile": "3.0.5",
|
||||||
"smartpath": "3.1.1",
|
"smartpath": "3.2.0",
|
||||||
|
"smartstring": "^1.0.2",
|
||||||
"source-map-support": "^0.4.0"
|
"source-map-support": "^0.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {}
|
||||||
|
3
test/assets/dist/index.d.ts
vendored
Normal file
3
test/assets/dist/index.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
declare let testplugin: {
|
||||||
|
logSomething: () => void;
|
||||||
|
};
|
2
test/assets/dist/index.js
vendored
2
test/assets/dist/index.js
vendored
@ -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=
|
||||||
|
@ -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",
|
||||||
|
1
test/assets/test/test.d.ts
vendored
Normal file
1
test/assets/test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
declare var testplugin: any;
|
@ -8,4 +8,4 @@ describe("testplugins", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzdDLFFBQVEsQ0FBQyxhQUFhLEVBQUM7SUFDbkIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzdDLFFBQVEsQ0FBQyxhQUFhLEVBQUM7SUFDbkIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXX0=
|
||||||
|
15
ts/npmts.compile.helpers.ts
Normal file
15
ts/npmts.compile.helpers.ts
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -1,67 +1,88 @@
|
|||||||
/// <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;
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
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({
|
|
||||||
out: outputName,
|
|
||||||
target: "ES5",
|
target: "ES5",
|
||||||
module: "commonjs"
|
module: "commonjs"
|
||||||
}))
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merges default ts options with those found in npmts.json
|
||||||
|
*/
|
||||||
|
let tsOptions = function (keyArg:string) {
|
||||||
|
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.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
||||||
//.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
|
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
||||||
.pipe(plugins.gulp.dest(outputDir));
|
let declarationStream = tsStream.dts
|
||||||
moduleStream.add(stream);
|
.pipe(plugins.gulp.dest(config.ts[keyArg]));
|
||||||
|
moduleStream.add(tsStream,jsStream,declarationStream);
|
||||||
}
|
}
|
||||||
moduleStream.on("queueDrain",function(){
|
}
|
||||||
|
|
||||||
|
moduleStream.on("queueDrain", function () {
|
||||||
|
moduleStream.on("finish", function () {
|
||||||
plugins.beautylog.ok("TypeScript has been compiled!");
|
plugins.beautylog.ok("TypeScript has been compiled!");
|
||||||
moduleStream.on("finish",function(){
|
definitionHandler(config)
|
||||||
|
.then(function(){
|
||||||
done.resolve(config);
|
done.resolve(config);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
moduleStream.end();
|
moduleStream.end();
|
||||||
});
|
});
|
||||||
/*==================== END TYPESCRIPT =====================*/
|
/*==================== END TS Compilation =====================*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,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
|
||||||
|
|
||||||
isRelease() ? plugins.beautylog.info("All right: This is a RELEASE build!")
|
isRelease() ? plugins.beautylog.info("All right: This is a RELEASE build!")
|
||||||
|
@ -8,11 +8,13 @@ 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")
|
||||||
|
|
||||||
};
|
};
|
||||||
|
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 +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 sourceMapSupport = require("source-map-support").install();
|
export let smartstring = require("smartstring");
|
||||||
|
export let sourceMapSupport = require("source-map-support").install(); // this is required to display errors correctly during testing
|
Reference in New Issue
Block a user