diff --git a/.gitignore b/.gitignore index 5d05861..2de8774 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /typings /lib/**/*.js +!/lib/dts-bundle.js /test/tmp /test/build diff --git a/README.md b/README.md index b39b430..159ed1c 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ export interface BundleResult { // list of files not found that shouldn`t be no included in the bundle. noIncludeFilesNotFound: string[]; // true if dts-bunlde wrote the result, false otherwise. - emited?: boolean; + emitted?: boolean; // original options passed to the function. options: Options; } diff --git a/lib/dts-bundle.js b/lib/dts-bundle.js new file mode 100644 index 0000000..8bb01c0 --- /dev/null +++ b/lib/dts-bundle.js @@ -0,0 +1,89 @@ +#!/usr/bin/env node + +var pkg = require('../package'); +var program = require('commander'); +var dts = require("./index"); +var path = require('path'); +var os = require('os'); + +function mapOptions(argObj) { + var result = argObj.configJson ? require(path.resolve(argObj.configJson)) : {}; + + var optList = [ + "main", + "name", + "baseDir", + "out", + //"newline", // Manual + //"indent", // not implemented + "prefix", + "separator", + "externals", + //"exclude", // not implemented + "removeSource", + "verbose", + "referenceExternals", + "emitOnIncludedFileNotFound", + "emitOnNoIncludedFileNotFound" + ]; + + optList.forEach(function (optName) { + if (argObj.hasOwnProperty(optName)) + result[optName] = argObj[optName]; + }, this); + + if (argObj.hasOwnProperty("newline")) { + switch (argObj.newline) { + case "unix": + result.newline = "\n"; + break; + case "windows": + result.newline = "\r\n"; + break; + case "currentOsDefault": + result.newline = os.EOL; + break; + } + } + return result; +} + +function callBundle(options) { + if (!options.name || !options.main) { + console.log("'name' and 'main' parameters are required. --help for get option list.") + process.exit(1); + } + return dts.bundle(options); +} + +program + .version(pkg.version) + .option('--configJson ', "path to json config file. Load it first and override options with additional parameters") + .option('--name ', 'name of module likein package.json *required') + .option('--main ', 'path to entry-point (see documentation) *required') + .option('--baseDir [value]', 'base directory to be used for discovering type declarations') + .option('--out [value]', 'path of output file. Is relative from baseDir but you can use absolute paths. ') + .option('--externals', 'include typings outside of the "baseDir" (i.e. like node.d.ts)') + .option('--referenceExternals', 'reference external modules as tags *** Experimental, TEST NEEDED') +//.option('--exclude ', 'filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir') + .option('--removeSource', 'delete all source typings (i.e. "/**/*.d.ts")') + .option('--newline [style]', 'newline style to use in output file => unix|windows|currentOsDefault', /^(unix|windows|currentOsDefault)$/i) +//.option('--indent', 'indentation to use in output file') + .option('--prefix [value]', 'prefix for rewriting module names') + .option('--separator [value]', 'separator for rewriting module "path" names') + .option('--verbose', 'enable verbose mode, prints detailed info about all references and includes/excludes') + .option('--emitOnIncludedFileNotFound', 'emit although included files not found. See readme "Files not found" section. ') + .option('--emitOnNoIncludedFileNotFound', 'emit although no included files not found. See readme "Files not found" section. ') + .parse(process.argv); + +console.log("%s version %s\n%s\n", pkg.name, pkg.version, pkg.description); + +var options = mapOptions(program); + +var result = callBundle(options); + +if (!result.emitted) { + console.log("Result no emitted - use verbose to see details."); + process.exit(1); +} + \ No newline at end of file diff --git a/lib/index.ts b/lib/index.ts index b7d0e6a..d4e281a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -65,7 +65,7 @@ export interface BundleResult { fileMap: { [name: string]: Result; }; includeFilesNotFound: string[]; noIncludeFilesNotFound: string[]; - emited?: boolean; + emitted?: boolean; options: Options; } @@ -381,11 +381,11 @@ export function bundle(options: Options): BundleResult { } fs.writeFileSync(outFile, content, 'utf8'); - bundleResult.emited = true; + bundleResult.emitted = true; } else { warning(" XXX Not emit due to exist files not found.") trace("See documentation for emitOnIncludedFileNotFound and emitOnNoIncludedFileNotFound options.") - bundleResult.emited = false; + bundleResult.emitted = false; } // print some debug info diff --git a/package.json b/package.json index 563ebfd..2dd8210 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "export", "d.ts" ], + "bin": { + "dts-bundle": "./lib/dts-bundle.js" + }, "homepage": "https://github.com/grunt-ts/dts-bundle", "repository": { "type": "git", @@ -35,6 +38,7 @@ }, "main": "./index.js", "dependencies": { + "commander": "^2.9.0", "detect-indent": "^0.2.0", "glob": "^4.0.2", "mkdirp": "^0.5.0"