clean up TypeScript compilation handling

This commit is contained in:
LosslessBot 2016-04-30 05:49:53 +02:00
parent ea779add20
commit 07d752449e
9 changed files with 123 additions and 80 deletions

View File

@ -45,9 +45,41 @@ Then use it in package.json's script section to trigger a build:
#### npmts.json
the npmts.json is the main config file. You can use it to customize the behaviour of NPMTS.
```json
{
"mode":"default",
"ts":{
"./customdir/*.ts":"./"
},
"tsconfig":true,
"typings":[
"./ts/typings.json",
"./subts1/typings.json",
"./subts2/typings.json",
"./customdir/typings.json"
],
"codecov":true,
"docs": {
"publish":true
},
"cli":true
}
```
| key | description |
| --- | --- |
| mode | "default" will do some defualt stuff, "custom" only does what you specify |
| codecov | if true, coverage data will be uploaded to codecov when running on travis |
| docs | `{"publish":true}` lets you control what happens with your module documentation |
| | |
| | |
#### Typings
**npmts** looks for `./ts/typings.json` by default and installs any defined typings to `.ts/typings/`.
You can then reference the ./ts/typings/main.d.ts file in any of your TypeScript code.
> Note: You can reference the typings files in any of your TypeScript code with a
`/// <reference path="/some/path/main.d.ts">`
or use a tsconfig.json file.
#### TypeScript
by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to

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

@ -0,0 +1,31 @@
"use strict";
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
var outputPathIsDir = function (configArg, keyArg) {
try {
return plugins.fs.statSync(plugins.path.join(paths.cwd, configArg.ts[keyArg])).isDirectory();
}
catch (err) {
return false;
}
};
exports.outputNameSpecified = function (configArg, keyArg) {
return !outputPathIsDir(configArg, keyArg)
&& (plugins.path.extname(configArg.ts[keyArg]) == ".js");
};
exports.outputName = function (configArg, keyArg) {
if (exports.outputNameSpecified(configArg, keyArg)) {
return plugins.path.basename(configArg.ts[keyArg]);
}
else {
return undefined;
}
};
exports.outputDir = function (configArg, keyArg) {
if (exports.outputNameSpecified(configArg, keyArg)) {
return plugins.path.dirname(plugins.path.join(paths.cwd, configArg.ts[keyArg]));
}
else {
return plugins.path.join(paths.cwd, configArg.ts[keyArg]);
}
};

35
dist/npmts.compile.js vendored
View File

@ -2,6 +2,7 @@
/// <reference path="./typings/main.d.ts" />
var plugins = require("./npmts.plugins");
var paths = require("./npmts.paths");
var helpers = require("./npmts.compile.helpers");
exports.run = function (configArg) {
var done = plugins.Q.defer();
var config = configArg;
@ -11,43 +12,15 @@ exports.run = function (configArg) {
* ----------- compile TypeScript --------------------------
* ----------------------------------------------- */
for (var key in config.ts) {
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 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,
out: helpers.outputName(config, key),
target: "ES5",
module: "commonjs"
}))
.pipe(plugins.g.sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(plugins.gulp.dest(outputDir));
.pipe(plugins.gulp.dest(helpers.outputDir(config, key)));
moduleStream.add(stream);
}
moduleStream.on("queueDrain", function () {
@ -57,6 +30,6 @@ exports.run = function (configArg) {
});
moduleStream.end();
});
/*==================== END TYPESCRIPT =====================*/
/*==================== END TS Compilation =====================*/
return done.promise;
};

View File

@ -26,7 +26,7 @@
"homepage": "https://github.com/pushrocks/npmts#readme",
"dependencies": {
"beautylog": "4.1.2",
"fs-extra": "^0.26.7",
"fs-extra": "^0.30.0",
"gulp": "3.9.1",
"gulp-codecov": "^2.0.1",
"gulp-concat": "^2.6.0",
@ -35,18 +35,18 @@
"gulp-istanbul": "^0.10.4",
"gulp-jsdoc3": "^0.2.1",
"gulp-mocha": "^2.2.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "2.12.2",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-typescript": "2.13.0",
"gulp-typings": "1.3.4",
"merge2": "1.0.2",
"projectinfo": "1.0.1",
"q": "^1.4.1",
"shelljs": "^0.6.0",
"shelljs": "^0.7.0",
"smartci": "0.0.1",
"smartcli": "0.0.11",
"smartcov": "0.0.6",
"smartenv": "1.2.2",
"smartfile": "3.0.3",
"smartfile": "3.0.5",
"smartpath": "3.1.4",
"source-map-support": "^0.4.0"
},

View File

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

View File

@ -3,6 +3,7 @@
"ts":{
"./customdir/*.ts":"./"
},
"tsconfig":true,
"typings":[
"./ts/typings.json",
"./subts1/typings.json",

View File

@ -8,4 +8,4 @@ describe("testplugins", function () {
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsZ0RBQWdEO0FBQ2hELElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDO0FBQzdDLFFBQVEsQ0FBQyxhQUFhLEVBQUM7SUFDbkIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0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bi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXX0=

View File

@ -0,0 +1,34 @@
import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths");
let outputPathIsDir = function (configArg,keyArg) {
try {
return plugins.fs.statSync(plugins.path.join(paths.cwd, configArg.ts[keyArg])).isDirectory();
}
catch (err) {
return false;
}
};
export let outputNameSpecified = function (configArg, keyArg) {
return !outputPathIsDir(configArg,keyArg)
&& (plugins.path.extname(configArg.ts[keyArg]) == ".js");
}
export let outputName = function (configArg, keyArg) {
if (outputNameSpecified(configArg,keyArg)) {
return plugins.path.basename(configArg.ts[keyArg])
} else {
return undefined
}
};
export let outputDir = function (configArg, keyArg) {
if (outputNameSpecified(configArg,keyArg)) {
return plugins.path.dirname(
plugins.path.join(paths.cwd, configArg.ts[keyArg])
)
} else {
return plugins.path.join(paths.cwd, configArg.ts[keyArg])
}
};

View File

@ -1,59 +1,31 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./npmts.plugins");
import paths = require("./npmts.paths");
export var run = function(configArg){
var done = plugins.Q.defer();
var config = configArg;
import helpers = require("./npmts.compile.helpers");
export let run = function(configArg){
let done = plugins.Q.defer();
let config = configArg;
plugins.beautylog.log("now compiling " + "TypeScript".yellow);
var moduleStream = plugins.merge2({end: false});
let moduleStream = plugins.merge2({end: false});
/* -------------------------------------------------
* ----------- 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/**"])
for (let key in config.ts) {
let 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,
out: helpers.outputName(config,key),
target: "ES5",
module: "commonjs"
}))
.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));
.pipe(plugins.gulp.dest(helpers.outputDir(config,key)));
moduleStream.add(stream);
}
moduleStream.on("queueDrain",function(){
plugins.beautylog.ok("TypeScript has been compiled!");
moduleStream.on("finish",function(){
@ -61,7 +33,7 @@ export var run = function(configArg){
});
moduleStream.end();
});
/*==================== END TYPESCRIPT =====================*/
/*==================== END TS Compilation =====================*/