Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
6f33b1f5ef | |||
45418d6049 | |||
4261ee3687 | |||
9fc3606163 | |||
2436b30605 | |||
9ad59704be | |||
29f3832d63 | |||
2d82a3a037 | |||
4806f5ceff | |||
f2ef982189 | |||
5d6ead017b | |||
1c2b4e421d | |||
6cf7d2ca0b | |||
676c072631 | |||
f29c04e09c | |||
77a06a0fc4 | |||
c9792b1955 | |||
b87de178c0 | |||
0580f29d30 | |||
2c17273671 | |||
669ed2e6ab | |||
8bc73b2bf4 | |||
78e5defd7c | |||
7e540bda87 | |||
b293dfe92d | |||
a753a5db2c | |||
27f79b4425 | |||
1ada5dd5a9 | |||
a41bfd442c | |||
2917b10ffb | |||
bfc5bbbbb7 | |||
cf507a4a17 | |||
73a57ed264 | |||
39b79b679c | |||
cc053ee396 | |||
df5371187b | |||
cbda76c380 | |||
e20bcec133 | |||
3e673e04b2 | |||
2090dad540 | |||
ebe7a02ef0 | |||
3f9194f344 | |||
13c9c96cc6 | |||
3f0b2b1599 | |||
d477e492eb | |||
f39cb03fc2 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -3,5 +3,8 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
test/**/node_modules/
|
test/**/node_modules/
|
||||||
test/**/typings/
|
test/**/typings/
|
||||||
|
test/**/coverage/
|
||||||
ts/*.js
|
ts/*.js
|
||||||
ts/*.js.map
|
ts/*.js.map
|
||||||
|
|
||||||
|
.DS_Store
|
43
README.md
43
README.md
@ -1,6 +1,13 @@
|
|||||||
# npmts
|
# npmts
|
||||||
Write npm modules with TypeScript without hassle.
|
Write npm modules with TypeScript without hassle.
|
||||||
|
|
||||||
|
## Status
|
||||||
|
[](https://travis-ci.org/pushrocks/npmts)
|
||||||
|
[](https://david-dm.org/pushrocks/npmts)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/npmts/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/npmts)
|
||||||
|
[](https://coveralls.io/github/pushrocks/npmts?branch=master)
|
||||||
|
|
||||||
## How to use npmts
|
## How to use npmts
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
@ -19,8 +26,27 @@ Then use it in package.json's script section to trigger a build:
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Default behaviour
|
### Default behaviour
|
||||||
by default npmts looks for `./ts/index.ts` and `./ts/test.ts` that will compile to
|
|
||||||
`./index.js` and `./test.js`
|
**Execution order of tasks**
|
||||||
|
|
||||||
|
1. Install typings
|
||||||
|
2. Transpile TypeScript with inline sourcemaps
|
||||||
|
3. Create Declaration Files
|
||||||
|
4. Instrumentalize created JavaScript files with istanbul
|
||||||
|
5. Run Tests
|
||||||
|
6. Create Coverage report
|
||||||
|
7. Upload Coverage reports to travis (must be activated, only triggers on travis)
|
||||||
|
|
||||||
|
|
||||||
|
#### 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 your TypeScript code.
|
||||||
|
|
||||||
|
#### TypeScript
|
||||||
|
by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to
|
||||||
|
`./dist/*.js` and `./test/test.js`
|
||||||
|
|
||||||
|
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 `index.d.ts` declaration file by default.
|
||||||
@ -31,13 +57,23 @@ You can reference it in your package.json like this:
|
|||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Instrumentalize Code
|
||||||
|
npmts instrumentalizes the created JavaScript code to create a coverage report.
|
||||||
|
|
||||||
|
#### Tests
|
||||||
|
When Typings have been installed, TypeScript + Declaration files have been transpiled and the resulting JS has been instrumentalized,
|
||||||
|
npmts runs `.test/test.js` with mocha.
|
||||||
|
|
||||||
|
Any errors will be shown with reference to their originating source in TypeScript.
|
||||||
|
|
||||||
When requiring the module from other TypeScript files,
|
When requiring the module from other TypeScript files,
|
||||||
the TypeScript Compiler will use the declaration file to resolve typings.
|
the TypeScript Compiler will use the declaration file to resolve typings.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Custom behaviour
|
### Custom behaviour
|
||||||
NPMTS looks for an npmts.json at the root of your package.
|
Custom behaviour can be achieved through a config file at the root of your package.
|
||||||
|
The file must be named **npmts.json**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -55,6 +91,7 @@ NPMTS looks for an npmts.json at the root of your package.
|
|||||||
* **ts** You can list as many TypeScript files as you like. The key represents the source TypeScript file, the value the output file.
|
* **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.
|
* **typings** is an array of all direcories that have a typings.json present. Uses the new typings tool from npm.
|
||||||
|
|
||||||
|
|
||||||
## Readme for Devs
|
## Readme for Devs
|
||||||
There is a [README-dev.md](README-dev.md) in the repo.
|
There is a [README-dev.md](README-dev.md) in the repo.
|
||||||
This is only of interest for you when looking to contribute to, improve or build upon this package.
|
This is only of interest for you when looking to contribute to, improve or build upon this package.
|
@ -4,7 +4,7 @@ var plugins = {
|
|||||||
gulp: require("gulp"),
|
gulp: require("gulp"),
|
||||||
g:{
|
g:{
|
||||||
typescript: require("gulp-typescript"),
|
typescript: require("gulp-typescript"),
|
||||||
insert: require("gulp-insert")
|
header: require("gulp-header")
|
||||||
},
|
},
|
||||||
mergeStream: require("merge2")
|
mergeStream: require("merge2")
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ plugins.gulp.task('indexTS', function() {
|
|||||||
return plugins.mergeStream([
|
return plugins.mergeStream([
|
||||||
tsResult.dts.pipe(plugins.gulp.dest('../')),
|
tsResult.dts.pipe(plugins.gulp.dest('../')),
|
||||||
tsResult.js
|
tsResult.js
|
||||||
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
|
.pipe(plugins.g.header('#!/usr/bin/env node\n\n'))
|
||||||
.pipe(plugins.gulp.dest('../'))
|
.pipe(plugins.gulp.dest('../'))
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
35
index.d.ts
vendored
35
index.d.ts
vendored
@ -5,13 +5,15 @@ declare module NpmtsPlugins {
|
|||||||
fs: any;
|
fs: any;
|
||||||
gulp: any;
|
gulp: any;
|
||||||
g: {
|
g: {
|
||||||
insert: any;
|
coveralls: any;
|
||||||
sequence: any;
|
header: any;
|
||||||
|
istanbul: any;
|
||||||
|
mocha: any;
|
||||||
|
sourcemaps: any;
|
||||||
typescript: any;
|
typescript: any;
|
||||||
};
|
};
|
||||||
mathjs: any;
|
|
||||||
mergeStream: any;
|
mergeStream: any;
|
||||||
mocha: any;
|
sourceMapSupport: any;
|
||||||
path: any;
|
path: any;
|
||||||
q: any;
|
q: any;
|
||||||
smartcli: any;
|
smartcli: any;
|
||||||
@ -22,18 +24,17 @@ declare module NpmtsPlugins {
|
|||||||
declare module NpmtsPaths {
|
declare module NpmtsPaths {
|
||||||
var init: () => any;
|
var init: () => any;
|
||||||
}
|
}
|
||||||
|
declare module NpmtsConfigFile {
|
||||||
|
var run: () => any;
|
||||||
|
}
|
||||||
declare module NpmtsOptions {
|
declare module NpmtsOptions {
|
||||||
var config: any;
|
var run: (configArg: any) => any;
|
||||||
var run: () => any;
|
|
||||||
}
|
}
|
||||||
declare module NpmtsCustom {
|
declare module NpmtsCompile {
|
||||||
var run: () => any;
|
var run: (configArg: any) => any;
|
||||||
}
|
|
||||||
declare module NpmtsDefault {
|
|
||||||
var run: () => any;
|
|
||||||
}
|
}
|
||||||
declare module NpmtsTests {
|
declare module NpmtsTests {
|
||||||
var run: () => any;
|
var run: (configArg: any) => any;
|
||||||
}
|
}
|
||||||
declare module NpmtsPromisechain {
|
declare module NpmtsPromisechain {
|
||||||
var init: () => any;
|
var init: () => any;
|
||||||
@ -43,13 +44,15 @@ declare var plugins: {
|
|||||||
fs: any;
|
fs: any;
|
||||||
gulp: any;
|
gulp: any;
|
||||||
g: {
|
g: {
|
||||||
insert: any;
|
coveralls: any;
|
||||||
sequence: any;
|
header: any;
|
||||||
|
istanbul: any;
|
||||||
|
mocha: any;
|
||||||
|
sourcemaps: any;
|
||||||
typescript: any;
|
typescript: any;
|
||||||
};
|
};
|
||||||
mathjs: any;
|
|
||||||
mergeStream: any;
|
mergeStream: any;
|
||||||
mocha: any;
|
sourceMapSupport: any;
|
||||||
path: any;
|
path: any;
|
||||||
q: any;
|
q: any;
|
||||||
smartcli: any;
|
smartcli: any;
|
||||||
|
332
index.js
332
index.js
@ -9,13 +9,15 @@ var NpmtsPlugins;
|
|||||||
fs: require("fs-extra"),
|
fs: require("fs-extra"),
|
||||||
gulp: require("gulp"),
|
gulp: require("gulp"),
|
||||||
g: {
|
g: {
|
||||||
insert: require("gulp-insert"),
|
coveralls: require("gulp-coveralls"),
|
||||||
sequence: require("gulp-sequence"),
|
header: require("gulp-header"),
|
||||||
|
istanbul: require("gulp-istanbul"),
|
||||||
|
mocha: require("gulp-mocha"),
|
||||||
|
sourcemaps: require("gulp-sourcemaps"),
|
||||||
typescript: require("gulp-typescript")
|
typescript: require("gulp-typescript")
|
||||||
},
|
},
|
||||||
mathjs: require("mathjs"),
|
|
||||||
mergeStream: require("merge2"),
|
mergeStream: require("merge2"),
|
||||||
mocha: require("mocha"),
|
sourceMapSupport: require("source-map-support").install(),
|
||||||
path: require("path"),
|
path: require("path"),
|
||||||
q: require("q"),
|
q: require("q"),
|
||||||
smartcli: require("smartcli"),
|
smartcli: require("smartcli"),
|
||||||
@ -40,198 +42,193 @@ var NpmtsPaths;
|
|||||||
};
|
};
|
||||||
})(NpmtsPaths || (NpmtsPaths = {}));
|
})(NpmtsPaths || (NpmtsPaths = {}));
|
||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
var NpmtsOptions;
|
var NpmtsConfigFile;
|
||||||
(function (NpmtsOptions) {
|
(function (NpmtsConfigFile) {
|
||||||
NpmtsOptions.config = {};
|
NpmtsConfigFile.run = function () {
|
||||||
NpmtsOptions.run = function () {
|
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
|
var config = {};
|
||||||
var configPath = plugins.path.join(paths.cwd, "npmts.json");
|
var configPath = plugins.path.join(paths.cwd, "npmts.json");
|
||||||
if (plugins.smartfile.checks.fileExistsSync(configPath)) {
|
if (plugins.smartfile.checks.fileExistsSync(configPath)) {
|
||||||
plugins.beautylog.info("npmts.json".blue + " config file found!");
|
plugins.beautylog.info("npmts.json".blue + " config file found!");
|
||||||
NpmtsOptions.config = plugins.smartfile.readFileToObject(configPath);
|
config = plugins.smartfile.readFileToObject(configPath);
|
||||||
switch (NpmtsOptions.config.mode) {
|
switch (config.mode) {
|
||||||
case "default":
|
case "default":
|
||||||
plugins.beautylog.log("mode is " + NpmtsOptions.config.mode.yellow);
|
|
||||||
done.resolve();
|
|
||||||
break;
|
|
||||||
case "custom":
|
case "custom":
|
||||||
plugins.beautylog.log("mode is " + NpmtsOptions.config.mode.yellow);
|
plugins.beautylog.log("mode is " + config.mode.yellow);
|
||||||
done.resolve();
|
done.resolve(config);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plugins.beautylog.error("mode " + NpmtsOptions.config.mode.yellow + " not recognised!".red);
|
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
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);
|
||||||
NpmtsOptions.config.mode = "default";
|
config.mode = "default";
|
||||||
done.resolve();
|
done.resolve(config);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
})(NpmtsOptions || (NpmtsOptions = {}));
|
})(NpmtsConfigFile || (NpmtsConfigFile = {}));
|
||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
var NpmtsCustom;
|
var NpmtsOptions;
|
||||||
(function (NpmtsCustom) {
|
(function (NpmtsOptions) {
|
||||||
NpmtsCustom.run = function () {
|
NpmtsOptions.run = function (configArg) {
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
var config = NpmtsOptions.config;
|
var config = configArg;
|
||||||
if (config.mode === "custom") {
|
if (typeof config.coveralls === "undefined") {
|
||||||
plugins.beautylog.log("now running custom tasks");
|
config.coveralls = false;
|
||||||
var moduleStream = plugins.mergeStream({ end: false });
|
}
|
||||||
/* -------------------------------------------------
|
if (config.mode == "default") {
|
||||||
* ----------- first install typings ---------------
|
config.typings = [
|
||||||
* ----------------------------------------------- */
|
"./ts/"
|
||||||
var typingsDone = plugins.q.defer();
|
];
|
||||||
var typingsCounter = 0;
|
config.ts = (_a = {},
|
||||||
var typingsCounterAdvance = function () {
|
_a["./ts/**/*.ts"] = "./dist/",
|
||||||
typingsCounter++;
|
_a["./test/test.ts"] = "./test/",
|
||||||
if (typeof config.typings[typingsCounter] != "undefined") {
|
_a
|
||||||
installTypings();
|
);
|
||||||
}
|
config.test = ["./index.js"];
|
||||||
else {
|
done.resolve(config);
|
||||||
plugins.beautylog.success("custom typings installed successfully");
|
}
|
||||||
typingsDone.resolve();
|
else {
|
||||||
}
|
done.resolve(config);
|
||||||
};
|
|
||||||
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) {
|
|
||||||
plugins.beautylog.log("now compiling" + key.blue);
|
|
||||||
var outputPathIsDir;
|
|
||||||
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"));
|
|
||||||
console.log("outputNameSpecified");
|
|
||||||
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 tsStream = plugins.gulp.src(plugins.path.join(paths.cwd, key))
|
|
||||||
.pipe(plugins.g.typescript({
|
|
||||||
out: outputName,
|
|
||||||
declaration: true
|
|
||||||
}));
|
|
||||||
var stream = plugins.mergeStream([
|
|
||||||
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
|
|
||||||
tsStream.js
|
|
||||||
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
|
|
||||||
.pipe(plugins.gulp.dest(outputDir))
|
|
||||||
]);
|
|
||||||
moduleStream.add(stream);
|
|
||||||
}
|
|
||||||
moduleStream.on("queueDrain", function () {
|
|
||||||
plugins.beautylog.success("custom TypeScript installed successfully");
|
|
||||||
moduleStream.on("finish", function () {
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
moduleStream.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return done.promise;
|
return done.promise;
|
||||||
|
var _a;
|
||||||
};
|
};
|
||||||
})(NpmtsCustom || (NpmtsCustom = {}));
|
})(NpmtsOptions || (NpmtsOptions = {}));
|
||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
var NpmtsDefault;
|
var NpmtsCompile;
|
||||||
(function (NpmtsDefault) {
|
(function (NpmtsCompile) {
|
||||||
NpmtsDefault.run = function () {
|
NpmtsCompile.run = function (configArg) {
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
plugins.gulp.task("defaultTypings", function (cb) {
|
var config = configArg;
|
||||||
plugins.beautylog.log("now installing default typings");
|
plugins.beautylog.log("now running custom tasks");
|
||||||
plugins.typings.install({ production: false, cwd: paths.tsDir })
|
var moduleStream = plugins.mergeStream({ end: false });
|
||||||
.then(function () {
|
/* -------------------------------------------------
|
||||||
cb();
|
* ----------- first install typings ---------------
|
||||||
});
|
* ----------------------------------------------- */
|
||||||
});
|
var typingsDone = plugins.q.defer();
|
||||||
plugins.gulp.task("defaultIndexTS", function () {
|
var typingsCounter = 0;
|
||||||
plugins.beautylog.log("now compiling" + " ts/index.ts".blue);
|
var typingsCounterAdvance = function () {
|
||||||
var tsResult = plugins.gulp.src(paths.indexTS)
|
typingsCounter++;
|
||||||
.pipe(plugins.g.typescript({
|
if (typeof config.typings[typingsCounter] != "undefined") {
|
||||||
out: "./index.js",
|
installTypings();
|
||||||
declaration: true
|
|
||||||
}));
|
|
||||||
return plugins.mergeStream([
|
|
||||||
tsResult.dts.pipe(plugins.gulp.dest(paths.cwd)),
|
|
||||||
tsResult.js
|
|
||||||
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
|
|
||||||
.pipe(plugins.gulp.dest(paths.cwd))
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
plugins.gulp.task("defaultTestTS", function () {
|
|
||||||
plugins.beautylog.log("now compiling" + " ts/test.ts".blue);
|
|
||||||
var stream = plugins.gulp.src(paths.testTS)
|
|
||||||
.pipe(plugins.g.typescript({
|
|
||||||
out: "test.js"
|
|
||||||
}))
|
|
||||||
.pipe(plugins.gulp.dest(paths.testDir));
|
|
||||||
return stream;
|
|
||||||
});
|
|
||||||
plugins.gulp.task("defaultCleanup", function (cb) {
|
|
||||||
plugins.beautylog.success("default TypeScript for this module compiled successfully.");
|
|
||||||
done.resolve();
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
plugins.gulp.task("default", function (cb) {
|
|
||||||
if (NpmtsOptions.config.mode == "default") {
|
|
||||||
plugins.g.sequence("defaultTypings", "defaultIndexTS", "defaultTestTS", "defaultCleanup", cb);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cb();
|
plugins.beautylog.success("custom typings installed successfully");
|
||||||
done.resolve();
|
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) {
|
||||||
|
plugins.beautylog.log("now compiling" + key.blue);
|
||||||
|
var outputPathIsDir;
|
||||||
|
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 tsStream = 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,
|
||||||
|
declaration: true,
|
||||||
|
target: "ES5",
|
||||||
|
module: "commonjs"
|
||||||
|
}));
|
||||||
|
var stream = plugins.mergeStream([
|
||||||
|
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
|
||||||
|
tsStream.js
|
||||||
|
.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(outputDir))
|
||||||
|
]);
|
||||||
|
moduleStream.add(stream);
|
||||||
|
}
|
||||||
|
moduleStream.on("queueDrain", function () {
|
||||||
|
plugins.beautylog.success("custom TypeScript installed successfully");
|
||||||
|
moduleStream.on("finish", function () {
|
||||||
|
done.resolve(config);
|
||||||
|
});
|
||||||
|
moduleStream.end();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
plugins.gulp.start.apply(plugins.gulp, ['default']);
|
|
||||||
return done.promise;
|
return done.promise;
|
||||||
};
|
};
|
||||||
})(NpmtsDefault || (NpmtsDefault = {}));
|
})(NpmtsCompile || (NpmtsCompile = {}));
|
||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
var NpmtsTests;
|
var NpmtsTests;
|
||||||
(function (NpmtsTests) {
|
(function (NpmtsTests) {
|
||||||
NpmtsTests.run = function () {
|
NpmtsTests.run = function (configArg) {
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
plugins.fs.ensureDirSync(paths.testDir); //make sure that mocha has a directory to look for tests
|
var config = configArg;
|
||||||
plugins.beautylog.info("Now running mocha tests");
|
var istanbul = function () {
|
||||||
var mocha = new plugins.mocha(); // Instantiate a Mocha instance.
|
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "index.js")])
|
||||||
mocha.addFile(plugins.path.join(paths.testDir, "test.js"));
|
.pipe(plugins.g.istanbul())
|
||||||
mocha.run(function (failures) {
|
.pipe(plugins.g.istanbul.hookRequire());
|
||||||
process.on('exit', function () {
|
return stream;
|
||||||
process.exit(failures);
|
};
|
||||||
|
var mocha = function () {
|
||||||
|
var stream = plugins.gulp.src(["./test/test.js"])
|
||||||
|
.pipe(plugins.g.mocha())
|
||||||
|
.pipe(plugins.g.istanbul.writeReports())
|
||||||
|
.pipe(plugins.g.istanbul.enforceThresholds({ thresholds: { global: 30 } }));
|
||||||
|
return stream;
|
||||||
|
};
|
||||||
|
var coveralls = function () {
|
||||||
|
var stream = plugins.gulp.src([plugins.path.join(paths.cwd, "./coverage/lcov.info")])
|
||||||
|
.pipe(plugins.g.coveralls());
|
||||||
|
return stream;
|
||||||
|
};
|
||||||
|
istanbul().on("finish", function () {
|
||||||
|
mocha().on("finish", function () {
|
||||||
|
if (process.env.TRAVIS && config.coveralls) {
|
||||||
|
coveralls().on("finish", function () {
|
||||||
|
done.resolve(config);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
done.resolve(config);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
@ -242,9 +239,9 @@ var NpmtsPromisechain;
|
|||||||
(function (NpmtsPromisechain) {
|
(function (NpmtsPromisechain) {
|
||||||
NpmtsPromisechain.init = function () {
|
NpmtsPromisechain.init = function () {
|
||||||
var promisechain;
|
var promisechain;
|
||||||
NpmtsOptions.run()
|
NpmtsConfigFile.run()
|
||||||
.then(NpmtsDefault.run)
|
.then(NpmtsOptions.run)
|
||||||
.then(NpmtsCustom.run)
|
.then(NpmtsCompile.run)
|
||||||
.then(NpmtsTests.run);
|
.then(NpmtsTests.run);
|
||||||
return promisechain;
|
return promisechain;
|
||||||
};
|
};
|
||||||
@ -253,12 +250,13 @@ var NpmtsPromisechain;
|
|||||||
/// <reference path="./npmts.plugins.ts" />
|
/// <reference path="./npmts.plugins.ts" />
|
||||||
/// <reference path="./npmts.cli.ts" />
|
/// <reference path="./npmts.cli.ts" />
|
||||||
/// <reference path="./npmts.paths.ts" />
|
/// <reference path="./npmts.paths.ts" />
|
||||||
|
/// <reference path="./npmts.configfile.ts" />
|
||||||
/// <reference path="./npmts.options.ts" />
|
/// <reference path="./npmts.options.ts" />
|
||||||
/// <reference path="./npmts.custom.ts" />
|
/// <reference path="./npmts.compile.ts" />
|
||||||
/// <reference path="./npmts.default.ts" />
|
|
||||||
/// <reference path="./npmts.tests.ts" />
|
/// <reference path="./npmts.tests.ts" />
|
||||||
/// <reference path="./npmts.promisechain.ts" />
|
/// <reference path="./npmts.promisechain.ts" />
|
||||||
console.log("**** starting NPMTS ****");
|
console.log("**** starting NPMTS ****");
|
||||||
var plugins = NpmtsPlugins.init();
|
var plugins = NpmtsPlugins.init();
|
||||||
|
plugins.beautylog.figletSync("NPMTS");
|
||||||
var paths = NpmtsPaths.init();
|
var paths = NpmtsPaths.init();
|
||||||
var promisechain = NpmtsPromisechain.init();
|
var promisechain = NpmtsPromisechain.init();
|
||||||
|
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "npmts",
|
"name": "npmts",
|
||||||
"version": "2.1.3",
|
"version": "3.0.0",
|
||||||
"description": "write npm modules with TypeScript",
|
"description": "write npm modules with TypeScript",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
@ -26,19 +26,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/npmts#readme",
|
"homepage": "https://github.com/pushrocks/npmts#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"beautylog": "2.0.7",
|
"beautylog": "2.1.1",
|
||||||
"fs-extra": "^0.26.5",
|
"fs-extra": "^0.26.5",
|
||||||
"gulp": "3.9.0",
|
"gulp": "3.9.1",
|
||||||
"gulp-insert": "0.5.0",
|
"gulp-coveralls": "^0.1.4",
|
||||||
"gulp-sequence": "^0.4.4",
|
"gulp-header": "^1.7.1",
|
||||||
"gulp-typescript": "2.10.0",
|
"gulp-istanbul": "^0.10.3",
|
||||||
|
"gulp-mocha": "^2.2.0",
|
||||||
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
|
"gulp-typescript": "2.11.0",
|
||||||
"gulp-typings": "0.0.0",
|
"gulp-typings": "0.0.0",
|
||||||
"mathjs": "^2.7.0",
|
|
||||||
"merge2": "1.0.1",
|
"merge2": "1.0.1",
|
||||||
"mocha": "^2.4.5",
|
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"smartcli": "0.0.11",
|
"smartcli": "0.0.11",
|
||||||
"smartfile": "0.0.11",
|
"smartfile": "0.0.11",
|
||||||
"typings": "^0.6.6"
|
"source-map-support": "^0.4.0",
|
||||||
|
"typings": "^0.6.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
test/assets/custom.d.ts
vendored
1
test/assets/custom.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
declare var hello: string;
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var hello = "hello";
|
|
4
test/assets/dist/index.d.ts
vendored
Normal file
4
test/assets/dist/index.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/// <reference path="typings/main.d.ts" />
|
||||||
|
declare var testplugin: {
|
||||||
|
logSomething: () => void;
|
||||||
|
};
|
11
test/assets/dist/index.js
vendored
Normal file
11
test/assets/dist/index.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/// <reference path="./typings/main.d.ts" />
|
||||||
|
var testplugin = {
|
||||||
|
logSomething: function () {
|
||||||
|
console.log("only function executed");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = testplugin;
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFJLFVBQVUsR0FBRztJQUNiLFlBQVksRUFBRTtRQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0osQ0FBQztBQUNGLE1BQU0sQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxudmFyIHRlc3RwbHVnaW4gPSB7XG4gICAgbG9nU29tZXRoaW5nOiBmdW5jdGlvbigpe1xuICAgICAgICBjb25zb2xlLmxvZyhcIm9ubHkgZnVuY3Rpb24gZXhlY3V0ZWRcIik7XG4gICAgfVxufTtcbm1vZHVsZS5leHBvcnRzID0gdGVzdHBsdWdpbjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=
|
0
test/assets/index.d.ts
vendored
0
test/assets/index.d.ts
vendored
@ -1,5 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
console.log("test");
|
|
||||||
}());
|
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mode":"custom",
|
"mode":"default",
|
||||||
"ts":{
|
"ts":{
|
||||||
"./customdir/*.ts":"./"
|
"./customdir/*.ts":"./"
|
||||||
},
|
},
|
||||||
@ -8,5 +8,6 @@
|
|||||||
"./subts1/",
|
"./subts1/",
|
||||||
"./subts2/",
|
"./subts2/",
|
||||||
"./customdir"
|
"./customdir"
|
||||||
]
|
],
|
||||||
|
"coveralls":true
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"version": "1.0.0",
|
"version": "2.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -8,6 +8,5 @@
|
|||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
BIN
test/assets/test/.DS_Store
vendored
Normal file
BIN
test/assets/test/.DS_Store
vendored
Normal file
Binary file not shown.
2
test/assets/test/test.d.ts
vendored
Normal file
2
test/assets/test/test.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/// <reference path="../ts/typings/main.d.ts" />
|
||||||
|
declare var testplugin: any;
|
@ -1 +1,11 @@
|
|||||||
|
/// <reference path="../ts/typings/main.d.ts" />
|
||||||
console.log("**** starting test ****");
|
console.log("**** starting test ****");
|
||||||
|
var testplugin = require("../dist/index.js");
|
||||||
|
describe("testplugins", function () {
|
||||||
|
describe(".logSomething", function () {
|
||||||
|
it("should log something", function () {
|
||||||
|
testplugin.logSomething();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=test.js.map
|
1
test/assets/test/test.js.map
Normal file
1
test/assets/test/test.js.map
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AACvC,IAAI,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC7C,QAAQ,CAAC,aAAa,EAAC;IACnB,QAAQ,CAAC,eAAe,EAAC;QACrB,EAAE,CAAC,sBAAsB,EAAC;YACtB,UAAU,CAAC,YAAY,EAAE,CAAA;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
10
test/assets/test/test.ts
Normal file
10
test/assets/test/test.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/// <reference path="../ts/typings/main.d.ts" />
|
||||||
|
console.log("**** starting test ****");
|
||||||
|
var testplugin = require("../dist/index.js");
|
||||||
|
describe("testplugins",function(){
|
||||||
|
describe(".logSomething",function(){
|
||||||
|
it("should log something",function(){
|
||||||
|
testplugin.logSomething()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
8
test/assets/test/typings.json
Normal file
8
test/assets/test/typings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"ambientDependencies": {
|
||||||
|
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777",
|
||||||
|
|
||||||
|
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts#09e37435ffb2c56a6f908081194a74756f24f99d",
|
||||||
|
"vinyl": "github:DefinitelyTyped/DefinitelyTyped/vinyl/vinyl.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777"
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
(function () {
|
/// <reference path="./typings/main.d.ts" />
|
||||||
console.log("test");
|
var testplugin = {
|
||||||
}());
|
logSomething: function () {
|
||||||
|
console.log("only function executed");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = testplugin;
|
||||||
//# sourceMappingURL=index.js.map
|
//# sourceMappingURL=index.js.map
|
@ -1 +1 @@
|
|||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,CAAC;IACG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACvB,CAAC,EAAE,CAAC,CAAC"}
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,IAAI,UAAU,GAAG;IACb,YAAY,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAC1C,CAAC;CACJ,CAAC;AACF,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC"}
|
@ -1,3 +1,7 @@
|
|||||||
(function(){
|
/// <reference path="./typings/main.d.ts" />
|
||||||
console.log("test")
|
var testplugin = {
|
||||||
}());
|
logSomething: function(){
|
||||||
|
console.log("only function executed");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = testplugin;
|
@ -1,2 +0,0 @@
|
|||||||
console.log("**** starting test ****");
|
|
||||||
//# sourceMappingURL=test.js.map
|
|
@ -1 +0,0 @@
|
|||||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@ -1 +0,0 @@
|
|||||||
console.log("**** starting test ****");
|
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"ambientDependencies": {
|
"ambientDependencies": {
|
||||||
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777",
|
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777",
|
||||||
|
"mocha": "github:Bartvds/tsd-deftools/typings/DefinitelyTyped/mocha/mocha.d.ts",
|
||||||
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts#09e37435ffb2c56a6f908081194a74756f24f99d",
|
"colors": "github:DefinitelyTyped/DefinitelyTyped/colors/colors.d.ts#09e37435ffb2c56a6f908081194a74756f24f99d",
|
||||||
"vinyl": "github:DefinitelyTyped/DefinitelyTyped/vinyl/vinyl.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777"
|
"vinyl": "github:DefinitelyTyped/DefinitelyTyped/vinyl/vinyl.d.ts#78d36dd49b6b55b9fdfe61776a12bf05c8b07777"
|
||||||
}
|
}
|
||||||
|
1
test/assets/tsfile1.d.ts
vendored
1
test/assets/tsfile1.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
declare var something: string;
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var something = "something";
|
|
@ -2,12 +2,13 @@
|
|||||||
/// <reference path="./npmts.plugins.ts" />
|
/// <reference path="./npmts.plugins.ts" />
|
||||||
/// <reference path="./npmts.cli.ts" />
|
/// <reference path="./npmts.cli.ts" />
|
||||||
/// <reference path="./npmts.paths.ts" />
|
/// <reference path="./npmts.paths.ts" />
|
||||||
|
/// <reference path="./npmts.configfile.ts" />
|
||||||
/// <reference path="./npmts.options.ts" />
|
/// <reference path="./npmts.options.ts" />
|
||||||
/// <reference path="./npmts.custom.ts" />
|
/// <reference path="./npmts.compile.ts" />
|
||||||
/// <reference path="./npmts.default.ts" />
|
|
||||||
/// <reference path="./npmts.tests.ts" />
|
/// <reference path="./npmts.tests.ts" />
|
||||||
/// <reference path="./npmts.promisechain.ts" />
|
/// <reference path="./npmts.promisechain.ts" />
|
||||||
console.log("**** starting NPMTS ****")
|
console.log("**** starting NPMTS ****");
|
||||||
var plugins = NpmtsPlugins.init();
|
var plugins = NpmtsPlugins.init();
|
||||||
|
plugins.beautylog.figletSync("NPMTS");
|
||||||
var paths = NpmtsPaths.init();
|
var paths = NpmtsPaths.init();
|
||||||
var promisechain = NpmtsPromisechain.init();
|
var promisechain = NpmtsPromisechain.init();
|
||||||
|
97
ts/npmts.compile.ts
Normal file
97
ts/npmts.compile.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module NpmtsCompile {
|
||||||
|
export var run = function(configArg){
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
var config = configArg;
|
||||||
|
plugins.beautylog.log("now running custom tasks");
|
||||||
|
var moduleStream = plugins.mergeStream({end: false});
|
||||||
|
/* -------------------------------------------------
|
||||||
|
* ----------- first install typings ---------------
|
||||||
|
* ----------------------------------------------- */
|
||||||
|
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) {
|
||||||
|
plugins.beautylog.log("now compiling" + key.blue);
|
||||||
|
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 tsStream = 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,
|
||||||
|
declaration: true,
|
||||||
|
target: "ES5",
|
||||||
|
module: "commonjs"
|
||||||
|
}));
|
||||||
|
var stream = plugins.mergeStream([
|
||||||
|
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
|
||||||
|
tsStream.js
|
||||||
|
.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(outputDir))
|
||||||
|
]);
|
||||||
|
moduleStream.add(stream);
|
||||||
|
}
|
||||||
|
moduleStream.on("queueDrain",function(){
|
||||||
|
plugins.beautylog.success("custom TypeScript installed successfully");
|
||||||
|
moduleStream.on("finish",function(){
|
||||||
|
done.resolve(config);
|
||||||
|
});
|
||||||
|
moduleStream.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}
|
26
ts/npmts.configfile.ts
Normal file
26
ts/npmts.configfile.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/// <reference path="./index.ts" />
|
||||||
|
module NpmtsConfigFile {
|
||||||
|
export var run = function(){
|
||||||
|
var done = plugins.q.defer();
|
||||||
|
var config:any = {};
|
||||||
|
var configPath = plugins.path.join(paths.cwd,"npmts.json");
|
||||||
|
if(plugins.smartfile.checks.fileExistsSync(configPath)){
|
||||||
|
plugins.beautylog.info("npmts.json".blue + " config file found!");
|
||||||
|
config = plugins.smartfile.readFileToObject(configPath);
|
||||||
|
switch (config.mode){
|
||||||
|
case "default":
|
||||||
|
case "custom":
|
||||||
|
plugins.beautylog.log("mode is " + config.mode.yellow);
|
||||||
|
done.resolve(config);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
|
||||||
|
config.mode = "default";
|
||||||
|
done.resolve(config);
|
||||||
|
};
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}
|
@ -1,95 +0,0 @@
|
|||||||
/// <reference path="./index.ts" />
|
|
||||||
module NpmtsCustom {
|
|
||||||
export var run = function(){
|
|
||||||
var done = plugins.q.defer();
|
|
||||||
var config = NpmtsOptions.config;
|
|
||||||
if(config.mode === "custom"){
|
|
||||||
plugins.beautylog.log("now running custom tasks");
|
|
||||||
var moduleStream = plugins.mergeStream({end: false});
|
|
||||||
/* -------------------------------------------------
|
|
||||||
* ----------- first install typings ---------------
|
|
||||||
* ----------------------------------------------- */
|
|
||||||
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) {
|
|
||||||
plugins.beautylog.log("now compiling" + key.blue);
|
|
||||||
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 tsStream = plugins.gulp.src(plugins.path.join(paths.cwd,key))
|
|
||||||
.pipe(plugins.g.typescript({
|
|
||||||
out: outputName,
|
|
||||||
declaration: true
|
|
||||||
}));
|
|
||||||
var stream = plugins.mergeStream([
|
|
||||||
tsStream.dts.pipe(plugins.gulp.dest(outputDir)),
|
|
||||||
tsStream.js
|
|
||||||
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
|
|
||||||
.pipe(plugins.gulp.dest(outputDir))
|
|
||||||
]);
|
|
||||||
moduleStream.add(stream);
|
|
||||||
}
|
|
||||||
moduleStream.on("queueDrain",function(){
|
|
||||||
plugins.beautylog.success("custom TypeScript installed successfully");
|
|
||||||
moduleStream.on("finish",function(){
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
moduleStream.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/// <reference path="./index.ts" />
|
|
||||||
|
|
||||||
module NpmtsDefault {
|
|
||||||
export var run = function() {
|
|
||||||
var done = plugins.q.defer();
|
|
||||||
plugins.gulp.task("defaultTypings",function(cb){
|
|
||||||
plugins.beautylog.log("now installing default typings");
|
|
||||||
plugins.typings.install({production: false, cwd: paths.tsDir})
|
|
||||||
.then(function(){
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
plugins.gulp.task("defaultIndexTS", function(){
|
|
||||||
plugins.beautylog.log("now compiling" + " ts/index.ts".blue);
|
|
||||||
var tsResult = plugins.gulp.src(paths.indexTS)
|
|
||||||
.pipe(plugins.g.typescript({
|
|
||||||
out:"./index.js",
|
|
||||||
declaration:true
|
|
||||||
}));
|
|
||||||
|
|
||||||
return plugins.mergeStream([
|
|
||||||
tsResult.dts.pipe(plugins.gulp.dest(paths.cwd)),
|
|
||||||
tsResult.js
|
|
||||||
.pipe(plugins.g.insert.prepend('#!/usr/bin/env node\n\n'))
|
|
||||||
.pipe(plugins.gulp.dest(paths.cwd))
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.gulp.task("defaultTestTS", function(){
|
|
||||||
plugins.beautylog.log("now compiling" + " ts/test.ts".blue);
|
|
||||||
var stream = plugins.gulp.src(paths.testTS)
|
|
||||||
.pipe(plugins.g.typescript({
|
|
||||||
out: "test.js"
|
|
||||||
}))
|
|
||||||
.pipe(plugins.gulp.dest(paths.testDir));
|
|
||||||
return stream;
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.gulp.task("defaultCleanup",function(cb){
|
|
||||||
plugins.beautylog.success("default TypeScript for this module compiled successfully.");
|
|
||||||
done.resolve();
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.gulp.task("default",function(cb){
|
|
||||||
if(NpmtsOptions.config.mode == "default"){
|
|
||||||
plugins.g.sequence("defaultTypings","defaultIndexTS","defaultTestTS","defaultCleanup",cb);
|
|
||||||
} else {
|
|
||||||
cb();
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.gulp.start.apply(plugins.gulp, ['default']);
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +1,24 @@
|
|||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
module NpmtsOptions {
|
module NpmtsOptions {
|
||||||
export var config:any = {};
|
export var run = function(configArg){
|
||||||
export var run = function(){
|
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
var configPath = plugins.path.join(paths.cwd,"npmts.json");
|
var config = configArg;
|
||||||
if(plugins.smartfile.checks.fileExistsSync(configPath)){
|
if (typeof config.coveralls === "undefined"){
|
||||||
plugins.beautylog.info("npmts.json".blue + " config file found!");
|
config.coveralls = false;
|
||||||
config = plugins.smartfile.readFileToObject(configPath);
|
}
|
||||||
switch (config.mode){
|
if (config.mode == "default"){
|
||||||
case "default":
|
config.typings = [
|
||||||
plugins.beautylog.log("mode is " + config.mode.yellow);
|
"./ts/"
|
||||||
done.resolve();
|
];
|
||||||
break;
|
config.ts = {
|
||||||
case "custom":
|
["./ts/**/*.ts"]: "./dist/",
|
||||||
plugins.beautylog.log("mode is " + config.mode.yellow);
|
["./test/test.ts"]: "./test/"
|
||||||
done.resolve();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
plugins.beautylog.error("mode " + config.mode.yellow + " not recognised!".red);
|
|
||||||
};
|
};
|
||||||
|
config.test = ["./index.js"];
|
||||||
|
done.resolve(config);
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.log("no config file found: so mode is " + "default".yellow);
|
done.resolve(config);
|
||||||
config.mode = "default";
|
}
|
||||||
done.resolve();
|
|
||||||
};
|
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,14 +6,16 @@ module NpmtsPlugins {
|
|||||||
fs: require("fs-extra"),
|
fs: require("fs-extra"),
|
||||||
gulp: require("gulp"),
|
gulp: require("gulp"),
|
||||||
g: {
|
g: {
|
||||||
insert: require("gulp-insert"),
|
coveralls: require("gulp-coveralls"),
|
||||||
sequence: require("gulp-sequence"),
|
header: require("gulp-header"),
|
||||||
|
istanbul: require("gulp-istanbul"),
|
||||||
|
mocha: require("gulp-mocha"),
|
||||||
|
sourcemaps: require("gulp-sourcemaps"),
|
||||||
typescript: require("gulp-typescript")
|
typescript: require("gulp-typescript")
|
||||||
|
|
||||||
},
|
},
|
||||||
mathjs: require("mathjs"),
|
|
||||||
mergeStream: require("merge2"),
|
mergeStream: require("merge2"),
|
||||||
mocha: require("mocha"),
|
sourceMapSupport:require("source-map-support").install(),
|
||||||
path: require("path"),
|
path: require("path"),
|
||||||
q:require("q"),
|
q:require("q"),
|
||||||
smartcli: require("smartcli"),
|
smartcli: require("smartcli"),
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
module NpmtsPromisechain {
|
module NpmtsPromisechain {
|
||||||
export var init = function(){
|
export var init = function(){
|
||||||
var promisechain;
|
var promisechain;
|
||||||
NpmtsOptions.run()
|
NpmtsConfigFile.run()
|
||||||
.then(NpmtsDefault.run)
|
.then(NpmtsOptions.run)
|
||||||
.then(NpmtsCustom.run)
|
.then(NpmtsCompile.run)
|
||||||
.then(NpmtsTests.run);
|
.then(NpmtsTests.run);
|
||||||
return promisechain;
|
return promisechain;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,43 @@
|
|||||||
/// <reference path="./index.ts" />
|
/// <reference path="./index.ts" />
|
||||||
module NpmtsTests {
|
module NpmtsTests {
|
||||||
export var run = function() {
|
export var run = function(configArg) {
|
||||||
var done = plugins.q.defer();
|
var done = plugins.q.defer();
|
||||||
plugins.fs.ensureDirSync(paths.testDir); //make sure that mocha has a directory to look for tests
|
var config = configArg;
|
||||||
plugins.beautylog.info("Now running mocha tests");
|
var istanbul = function () {
|
||||||
|
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"index.js")])
|
||||||
|
// Covering files
|
||||||
|
.pipe(plugins.g.istanbul())
|
||||||
|
// Force `require` to return covered files
|
||||||
|
.pipe(plugins.g.istanbul.hookRequire());
|
||||||
|
return stream;
|
||||||
|
};
|
||||||
|
|
||||||
var mocha = new plugins.mocha(); // Instantiate a Mocha instance.
|
var mocha = function () {
|
||||||
mocha.addFile(
|
var stream = plugins.gulp.src(["./test/test.js"])
|
||||||
plugins.path.join(paths.testDir, "test.js")
|
.pipe(plugins.g.mocha())
|
||||||
);
|
// Creating the reports after tests ran
|
||||||
mocha.run(function(failures){
|
.pipe(plugins.g.istanbul.writeReports())
|
||||||
process.on('exit', function () {
|
// Enforce a coverage of at least 90%
|
||||||
process.exit(failures);
|
.pipe(plugins.g.istanbul.enforceThresholds({ thresholds: { global: 30 } }));
|
||||||
});
|
return stream;
|
||||||
|
};
|
||||||
|
|
||||||
|
var coveralls = function(){
|
||||||
|
var stream = plugins.gulp.src([plugins.path.join(paths.cwd,"./coverage/lcov.info")])
|
||||||
|
.pipe(plugins.g.coveralls());
|
||||||
|
return stream;
|
||||||
|
};
|
||||||
|
|
||||||
|
istanbul().on("finish",function(){
|
||||||
|
mocha().on("finish",function(){
|
||||||
|
if(process.env.TRAVIS && config.coveralls){
|
||||||
|
coveralls().on("finish",function(){
|
||||||
|
done.resolve(config);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
done.resolve(config);
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user