|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +// Remember remove \r chars at end of lines. |
| 4 | + |
| 5 | +var pkg = require("../package"); |
| 6 | +var program = require("commander"); |
| 7 | +var dts = require("./index"); |
| 8 | +var path = require("path"); |
| 9 | +var os = require("os"); |
| 10 | + |
| 11 | +function mapOptions(argObj) { |
| 12 | + var result = argObj.configJson ? require(path.resolve(argObj.configJson)) : {}; |
| 13 | + |
| 14 | + var optList = [ |
| 15 | + "main", |
| 16 | + "name", |
| 17 | + "baseDir", |
| 18 | + "out", |
| 19 | + //"newline", // Manual |
| 20 | + //"indent", // not implemented |
| 21 | + "prefix", |
| 22 | + // "separator", not implemented |
| 23 | + "externals", |
| 24 | + //"exclude", // not implemented |
| 25 | + "removeSource", |
| 26 | + "verbose", |
| 27 | + "referenceExternals", |
| 28 | + "emitOnIncludedFileNotFound", |
| 29 | + "emitOnNoIncludedFileNotFound", |
| 30 | + "outputAsModuleFolder", |
| 31 | + "headerPath", |
| 32 | + ]; |
| 33 | + |
| 34 | + optList.forEach(function (optName) { |
| 35 | + if (argObj.hasOwnProperty(optName)) result[optName] = argObj[optName]; |
| 36 | + }, this); |
| 37 | + |
| 38 | + if (argObj.hasOwnProperty("newline")) { |
| 39 | + switch (argObj.newline) { |
| 40 | + case "unix": |
| 41 | + result.newline = "\n"; |
| 42 | + break; |
| 43 | + case "windows": |
| 44 | + result.newline = "\r\n"; |
| 45 | + break; |
| 46 | + case "currentOsDefault": |
| 47 | + result.newline = os.EOL; |
| 48 | + break; |
| 49 | + } |
| 50 | + } |
| 51 | + return result; |
| 52 | +} |
| 53 | + |
| 54 | +function callBundle(options) { |
| 55 | + if (!options.name || !options.main) { |
| 56 | + console.log("'name' and 'main' parameters are required. --help for get option list."); |
| 57 | + process.exit(1); |
| 58 | + } |
| 59 | + return dts.bundle(options); |
| 60 | +} |
| 61 | + |
| 62 | +program |
| 63 | + .version(pkg.version) |
| 64 | + .option( |
| 65 | + "--configJson <value>", |
| 66 | + "path to json config file. Load it first and override options with additional parameters" |
| 67 | + ) |
| 68 | + .option("--name <value>", "name of module likein package.json *required") |
| 69 | + .option("--main <value>", "path to entry-point (see documentation) *required") |
| 70 | + .option("--baseDir [value]", "base directory to be used for discovering type declarations") |
| 71 | + .option("--out [value]", "path of output file. Is relative from baseDir but you can use absolute paths. ") |
| 72 | + .option("--externals", 'include typings outside of the "baseDir" (i.e. like node.d.ts)') |
| 73 | + .option( |
| 74 | + "--referenceExternals", |
| 75 | + 'reference external modules as <reference path="..." /> tags *** Experimental, TEST NEEDED' |
| 76 | + ) |
| 77 | + //.option('--exclude ', 'filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir') |
| 78 | + .option("--removeSource", 'delete all source typings (i.e. "<baseDir>/**/*.d.ts")') |
| 79 | + .option( |
| 80 | + "--newline [style]", |
| 81 | + "newline style to use in output file => unix|windows|currentOsDefault", |
| 82 | + /^(unix|windows|currentOsDefault)$/i |
| 83 | + ) |
| 84 | + //.option('--indent', 'indentation to use in output file') |
| 85 | + .option("--prefix [value]", "prefix for rewriting module names") |
| 86 | + // .option('--separator [value]', 'separator for rewriting module "path" names') |
| 87 | + .option("--verbose", "enable verbose mode, prints detailed info about all references and includes/excludes") |
| 88 | + .option( |
| 89 | + "--emitOnIncludedFileNotFound", |
| 90 | + 'emit although included files not found. See readme "Files not found" section. ' |
| 91 | + ) |
| 92 | + .option( |
| 93 | + "--emitOnNoIncludedFileNotFound", |
| 94 | + 'emit although no included files not found. See readme "Files not found" section. ' |
| 95 | + ) |
| 96 | + .option( |
| 97 | + "--outputAsModuleFolder", |
| 98 | + 'output as module folder format (no declare module) . See readme "Module folders" section.' |
| 99 | + ) |
| 100 | + .option("--headerPath [value]", "path to file that contains the header") |
| 101 | + .parse(process.argv); |
| 102 | + |
| 103 | +console.log("%s version %s\n%s\n", pkg.name, pkg.version, pkg.description); |
| 104 | + |
| 105 | +var options = mapOptions(program); |
| 106 | + |
| 107 | +var result = callBundle(options); |
| 108 | + |
| 109 | +if (!result.emitted) { |
| 110 | + console.log("Result no emitted - use verbose to see details."); |
| 111 | + process.exit(1); |
| 112 | +} |
0 commit comments