diff --git a/README.md b/README.md index 8f6168b..bc115c0 100644 --- a/README.md +++ b/README.md @@ -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 +`/// ` +or use a tsconfig.json file. #### TypeScript by default npmts looks for `./ts/*.ts` and `./test/test.ts` that will compile to diff --git a/dist/npmts.compile.helpers.js b/dist/npmts.compile.helpers.js new file mode 100644 index 0000000..38cbe02 --- /dev/null +++ b/dist/npmts.compile.helpers.js @@ -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]); + } +}; diff --git a/dist/npmts.compile.js b/dist/npmts.compile.js index f8c0704..90f9a1d 100644 --- a/dist/npmts.compile.js +++ b/dist/npmts.compile.js @@ -2,6 +2,7 @@ /// 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; }; diff --git a/package.json b/package.json index 6e89801..7d1b057 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/assets/dist/index.js b/test/assets/dist/index.js index 4ec8adb..79db4c1 100644 --- a/test/assets/dist/index.js +++ b/test/assets/dist/index.js @@ -6,4 +6,4 @@ var testplugin = { }; module.exports = testplugin; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFJLFVBQVUsR0FBRztJQUNiLFlBQVksRUFBRTtRQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0osQ0FBQztBQUNGLE1BQU0sQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxubGV0IHRlc3RwbHVnaW4gPSB7XG4gICAgbG9nU29tZXRoaW5nOiBmdW5jdGlvbigpe1xuICAgICAgICBjb25zb2xlLmxvZyhcIm9ubHkgZnVuY3Rpb24gZXhlY3V0ZWRcIik7XG4gICAgfVxufTtcbm1vZHVsZS5leHBvcnRzID0gdGVzdHBsdWdpbjsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= +//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLDRDQUE0QztBQUM1QyxJQUFJLFVBQVUsR0FBRztJQUNiLFlBQVksRUFBRTtRQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQztJQUMxQyxDQUFDO0NBQ0osQ0FBQztBQUNGLE1BQU0sQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxubGV0IHRlc3RwbHVnaW4gPSB7XG4gICAgbG9nU29tZXRoaW5nOiBmdW5jdGlvbigpe1xuICAgICAgICBjb25zb2xlLmxvZyhcIm9ubHkgZnVuY3Rpb24gZXhlY3V0ZWRcIik7XG4gICAgfVxufTtcbm1vZHVsZS5leHBvcnRzID0gdGVzdHBsdWdpbjsiXX0= diff --git a/test/assets/npmts.json b/test/assets/npmts.json index e05f47a..6a133e3 100644 --- a/test/assets/npmts.json +++ b/test/assets/npmts.json @@ -3,6 +3,7 @@ "ts":{ "./customdir/*.ts":"./" }, + "tsconfig":true, "typings":[ "./ts/typings.json", "./subts1/typings.json", diff --git a/test/assets/test/test.js b/test/assets/test/test.js index 7b80e8a..177b979 100644 --- a/test/assets/test/test.js +++ b/test/assets/test/test.js @@ -8,4 +8,4 @@ describe("testplugins", function () { }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIj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kIsUUFBUSxDQUFDLGVBQWUsRUFBQztRQUNyQixFQUFFLENBQUMsc0JBQXNCLEVBQUM7WUFDdEIsVUFBVSxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFDO0lBQ1AsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyIsImZpbGUiOiJ0ZXN0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4uL3RzL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbnZhciB0ZXN0cGx1Z2luID0gcmVxdWlyZShcIi4uL2Rpc3QvaW5kZXguanNcIik7XG5kZXNjcmliZShcInRlc3RwbHVnaW5zXCIsZnVuY3Rpb24oKXtcbiAgICBkZXNjcmliZShcIi5sb2dTb21ldGhpbmdcIixmdW5jdGlvbigpe1xuICAgICAgICBpdChcInNob3VsZCBsb2cgc29tZXRoaW5nXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RwbHVnaW4ubG9nU29tZXRoaW5nKClcbiAgICAgICAgfSk7XG4gICAgfSk7XG59KTsiXX0= diff --git a/ts/npmts.compile.helpers.ts b/ts/npmts.compile.helpers.ts new file mode 100644 index 0000000..a2dd093 --- /dev/null +++ b/ts/npmts.compile.helpers.ts @@ -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]) + } +}; \ No newline at end of file diff --git a/ts/npmts.compile.ts b/ts/npmts.compile.ts index 23b5925..3d47ae4 100644 --- a/ts/npmts.compile.ts +++ b/ts/npmts.compile.ts @@ -1,59 +1,31 @@ /// 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 =====================*/